blob: 61186405d02fdb08a4f28b96c1a3a5ab6a927c03 [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();
Steve Statia28b7cb32024-03-11 23:58:50 +00001591 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001592 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();
Steve Statia28b7cb32024-03-11 23:58:50 +00001606 int restrictedStatus =
1607 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1608 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1609 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001610 lockStatus = TelephonyManager
1611 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001612 }
1613 } else {
1614 Rlog.e(LOG_TAG,
1615 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1616 }
1617 callback.accept(lockStatus);
1618 } else {
1619 // This is for the implementation of getAllowedCarriers.
1620 notifyRequester(request);
1621 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001622 break;
1623
Nathan Haroldb3014052017-01-25 15:57:32 -08001624 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 if (ar.exception == null && ar.result != null) {
1628 request.result = ar.result;
1629 } else {
1630 request.result = new IllegalArgumentException(
1631 "Failed to retrieve Forbidden Plmns");
1632 if (ar.result == null) {
1633 loge("getForbiddenPlmns: Empty response");
1634 } else {
1635 loge("getForbiddenPlmns: Unknown exception");
1636 }
1637 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 break;
1640
1641 case CMD_GET_FORBIDDEN_PLMNS:
1642 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001643 uiccPort = getUiccPortFromRequest(request);
1644 if (uiccPort == null) {
1645 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001646 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001647 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001648 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001649 break;
1650 }
1651 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001652 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001653 if (uiccApp == null) {
1654 loge("getForbiddenPlmns() no app with specified type -- "
1655 + appType);
1656 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001657 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001658 break;
1659 } else {
1660 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1661 + " specified type -- " + appType);
1662 }
1663 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1664 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001665 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001666 break;
1667
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001668 case CMD_SWITCH_SLOTS:
1669 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001670 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001671 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001672 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001673 break;
1674
1675 case EVENT_SWITCH_SLOTS_DONE:
1676 ar = (AsyncResult) msg.obj;
1677 request = (MainThreadRequest) ar.userObj;
1678 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001679 notifyRequester(request);
1680 break;
1681 case CMD_GET_NETWORK_SELECTION_MODE:
1682 request = (MainThreadRequest) msg.obj;
1683 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1684 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1685 break;
1686
1687 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1688 ar = (AsyncResult) msg.obj;
1689 request = (MainThreadRequest) ar.userObj;
1690 if (ar.exception != null) {
1691 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1692 } else {
1693 int mode = ((int[]) ar.result)[0];
1694 if (mode == 0) {
1695 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1696 } else {
1697 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1698 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001699 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001700 notifyRequester(request);
1701 break;
1702 case CMD_GET_CDMA_ROAMING_MODE:
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1705 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1706 break;
1707 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1708 ar = (AsyncResult) msg.obj;
1709 request = (MainThreadRequest) ar.userObj;
1710 if (ar.exception != null) {
1711 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1712 } else {
1713 request.result = ((int[]) ar.result)[0];
1714 }
1715 notifyRequester(request);
1716 break;
1717 case CMD_SET_CDMA_ROAMING_MODE:
1718 request = (MainThreadRequest) msg.obj;
1719 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1720 int mode = (int) request.argument;
1721 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1722 break;
1723 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1724 ar = (AsyncResult) msg.obj;
1725 request = (MainThreadRequest) ar.userObj;
1726 request.result = ar.exception == null;
1727 notifyRequester(request);
1728 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001729 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1730 request = (MainThreadRequest) msg.obj;
1731 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1732 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1733 break;
1734 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 if (ar.exception != null) {
1738 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1739 } else {
1740 request.result = ((int[]) ar.result)[0];
1741 }
1742 notifyRequester(request);
1743 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001744 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1745 request = (MainThreadRequest) msg.obj;
1746 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1747 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001748 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1749 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001750 break;
1751 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754 request.result = ar.exception == null;
1755 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001756 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001757 case CMD_GET_ALL_CELL_INFO:
1758 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001759 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001760 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001761 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 case EVENT_GET_ALL_CELL_INFO_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001765 // If a timeout occurs, the response will be null
1766 request.result = (ar.exception == null && ar.result != null)
1767 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001768 synchronized (request) {
1769 request.notifyAll();
1770 }
1771 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001772 case CMD_REQUEST_CELL_INFO_UPDATE:
1773 request = (MainThreadRequest) msg.obj;
1774 request.phone.requestCellInfoUpdate(request.workSource,
1775 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1776 break;
1777 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1778 ar = (AsyncResult) msg.obj;
1779 request = (MainThreadRequest) ar.userObj;
1780 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1781 try {
1782 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001783 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001784 cb.onError(
1785 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1786 ar.exception.getClass().getName(),
1787 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001788 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001790 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001791 } else {
1792 // use the result as returned
1793 cb.onCellInfo((List<CellInfo>) ar.result);
1794 }
1795 } catch (RemoteException re) {
1796 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1797 }
1798 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001799 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001800 request = (MainThreadRequest) msg.obj;
1801 WorkSource ws = (WorkSource) request.argument;
1802 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001803 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001804 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001805 }
1806 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001807 ar = (AsyncResult) msg.obj;
1808 request = (MainThreadRequest) ar.userObj;
1809 if (ar.exception == null) {
1810 request.result = ar.result;
1811 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001812 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001813 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001814 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001815 }
1816
1817 synchronized (request) {
1818 request.notifyAll();
1819 }
1820 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001821 }
chen xu6dac5ab2018-10-26 17:39:23 -07001822 case CMD_MODEM_REBOOT:
1823 request = (MainThreadRequest) msg.obj;
1824 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001825 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001826 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001827 case EVENT_CMD_MODEM_REBOOT_DONE:
1828 handleNullReturnEvent(msg, "rebootModem");
1829 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001830 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001831 request = (MainThreadRequest) msg.obj;
1832 boolean enable = (boolean) request.argument;
1833 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001834 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001835 PhoneConfigurationManager.getInstance()
1836 .enablePhone(request.phone, enable, onCompleted);
1837 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001838 }
Michele Berionne5e411512020-11-13 02:36:59 +00001839 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001840 ar = (AsyncResult) msg.obj;
1841 request = (MainThreadRequest) ar.userObj;
1842 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001843 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001844 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001845 if ((boolean) request.result) {
1846 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1847 updateModemStateMetrics();
1848 } else {
1849 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1850 + ar.exception);
1851 }
1852 notifyRequester(request);
1853 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001854 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001855 case CMD_GET_MODEM_STATUS:
1856 request = (MainThreadRequest) msg.obj;
1857 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1858 PhoneConfigurationManager.getInstance()
1859 .getPhoneStatusFromModem(request.phone, onCompleted);
1860 break;
1861 case EVENT_GET_MODEM_STATUS_DONE:
1862 ar = (AsyncResult) msg.obj;
1863 request = (MainThreadRequest) ar.userObj;
1864 int id = request.phone.getPhoneId();
1865 if (ar.exception == null && ar.result != null) {
1866 request.result = ar.result;
1867 //update the cache as modem status has changed
1868 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1869 (boolean) request.result);
1870 } else {
1871 // Return true if modem status cannot be retrieved. For most cases,
1872 // modem status is on. And for older version modems, GET_MODEM_STATUS
1873 // and disable modem are not supported. Modem is always on.
1874 // TODO: this should be fixed in R to support a third
1875 // status UNKNOWN b/131631629
1876 request.result = true;
1877 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1878 + ar.exception);
1879 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001880 notifyRequester(request);
1881 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001882 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1883 request = (MainThreadRequest) msg.obj;
1884 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1885 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1886 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1887 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1888 break;
1889 }
1890 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1891 ar = (AsyncResult) msg.obj;
1892 request = (MainThreadRequest) ar.userObj;
1893 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1894 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1895 args.second.accept(ar.exception == null);
1896 notifyRequester(request);
1897 break;
1898 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001899 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1900 request = (MainThreadRequest) msg.obj;
1901 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1902 Phone phone = getPhoneFromRequest(request);
1903 if (phone != null) {
1904 phone.getSystemSelectionChannels(onCompleted);
1905 } else {
1906 loge("getSystemSelectionChannels: No phone object");
1907 request.result = new ArrayList<RadioAccessSpecifier>();
1908 notifyRequester(request);
1909 }
1910 break;
1911 }
1912 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1913 ar = (AsyncResult) msg.obj;
1914 request = (MainThreadRequest) ar.userObj;
1915 if (ar.exception == null && ar.result != null) {
1916 request.result = ar.result;
1917 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001918 request.result = new IllegalStateException(
1919 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001920 if (ar.result == null) {
1921 loge("getSystemSelectionChannels: Empty response");
1922 } else {
1923 loge("getSystemSelectionChannels: Unknown exception");
1924 }
1925 }
1926 notifyRequester(request);
1927 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001928 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1929 ar = (AsyncResult) msg.obj;
1930 request = (MainThreadRequest) ar.userObj;
1931 if (ar.exception == null && ar.result != null) {
1932 request.result = ar.result;
1933 } else {
1934 request.result = -1;
1935 loge("Failed to set Forbidden Plmns");
1936 if (ar.result == null) {
1937 loge("setForbidenPlmns: Empty response");
1938 } else if (ar.exception != null) {
1939 loge("setForbiddenPlmns: Exception: " + ar.exception);
1940 request.result = -1;
1941 } else {
1942 loge("setForbiddenPlmns: Unknown exception");
1943 }
1944 }
1945 notifyRequester(request);
1946 break;
1947 case CMD_SET_FORBIDDEN_PLMNS:
1948 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001949 uiccPort = getUiccPortFromRequest(request);
1950 if (uiccPort == null) {
1951 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001952 request.result = -1;
1953 notifyRequester(request);
1954 break;
1955 }
1956 Pair<Integer, List<String>> setFplmnsArgs =
1957 (Pair<Integer, List<String>>) request.argument;
1958 appType = setFplmnsArgs.first;
1959 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001960 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001961 if (uiccApp == null) {
1962 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1963 request.result = -1;
1964 loge("Failed to get UICC App");
1965 notifyRequester(request);
1966 } else {
1967 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1968 ((SIMRecords) uiccApp.getIccRecords())
1969 .setForbiddenPlmns(onCompleted, fplmns);
1970 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001971 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001972 case CMD_ERASE_MODEM_CONFIG:
1973 request = (MainThreadRequest) msg.obj;
1974 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1975 defaultPhone.eraseModemConfig(onCompleted);
1976 break;
1977 case EVENT_ERASE_MODEM_CONFIG_DONE:
1978 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001979 break;
zoey chene02881a2019-12-30 16:11:23 +08001980
Kai Shif70f46f2021-03-03 13:59:46 -08001981 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1982 request = (MainThreadRequest) msg.obj;
1983 request.result = defaultPhone.eraseDataInSharedPreferences();
1984 notifyRequester(request);
1985 break;
1986
zoey chene02881a2019-12-30 16:11:23 +08001987 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1988 request = (MainThreadRequest) msg.obj;
1989 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1990 Pair<String, String> changed = (Pair<String, String>) request.argument;
1991 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1992 changed.first, changed.second, onCompleted);
1993 break;
1994 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1995 ar = (AsyncResult) msg.obj;
1996 request = (MainThreadRequest) ar.userObj;
1997 if (ar.exception == null) {
1998 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001999 // If the operation is successful, update the PIN storage
2000 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2001 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002002 UiccController.getInstance().getPinStorage()
2003 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002004 } else {
2005 request.result = msg.arg1;
2006 }
2007 notifyRequester(request);
2008 break;
2009
Michele Berionne5e411512020-11-13 02:36:59 +00002010 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002011 request = (MainThreadRequest) msg.obj;
2012 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2013 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2014 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2015 enabled.first, enabled.second, onCompleted);
2016 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002017 }
zoey chene02881a2019-12-30 16:11:23 +08002018 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2019 ar = (AsyncResult) msg.obj;
2020 request = (MainThreadRequest) ar.userObj;
2021 if (ar.exception == null) {
2022 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002023 // If the operation is successful, update the PIN storage
2024 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2025 int phoneId = getPhoneFromRequest(request).getPhoneId();
2026 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002027 UiccController.getInstance().getPinStorage()
2028 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002029 } else {
2030 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2031 }
zoey chene02881a2019-12-30 16:11:23 +08002032 } else {
2033 request.result = msg.arg1;
2034 }
Michele Berionne5e411512020-11-13 02:36:59 +00002035
2036
zoey chene02881a2019-12-30 16:11:23 +08002037 notifyRequester(request);
2038 break;
2039
Peter Wangdafb9ac2020-01-15 14:13:38 -08002040 case MSG_NOTIFY_USER_ACTIVITY:
2041 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002042 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002043 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2044 getDefaultPhone().getContext().sendBroadcastAsUser(
2045 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2046 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002047
2048 case CMD_SET_DATA_THROTTLING: {
2049 request = (MainThreadRequest) msg.obj;
2050 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2051 DataThrottlingRequest dataThrottlingRequest =
2052 (DataThrottlingRequest) request.argument;
2053 Phone phone = getPhoneFromRequest(request);
2054 if (phone != null) {
2055 phone.setDataThrottling(onCompleted,
2056 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2057 dataThrottlingRequest.getCompletionDurationMillis());
2058 } else {
2059 loge("setDataThrottling: No phone object");
2060 request.result =
2061 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2062 notifyRequester(request);
2063 }
2064
2065 break;
2066 }
2067 case EVENT_SET_DATA_THROTTLING_DONE:
2068 ar = (AsyncResult) msg.obj;
2069 request = (MainThreadRequest) ar.userObj;
2070
2071 if (ar.exception == null) {
2072 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2073 } else if (ar.exception instanceof CommandException) {
2074 loge("setDataThrottling: CommandException: " + ar.exception);
2075 CommandException.Error error =
2076 ((CommandException) (ar.exception)).getCommandError();
2077
2078 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2079 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002080 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002081 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2082 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002083 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2084 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002085 } else {
2086 request.result =
2087 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2088 }
2089 } else {
2090 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2091 }
2092 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2093 notifyRequester(request);
2094 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002095
2096 case CMD_SET_SIM_POWER: {
2097 request = (MainThreadRequest) msg.obj;
2098 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2099 request = (MainThreadRequest) msg.obj;
2100 int stateToSet =
2101 ((Pair<Integer, IIntegerConsumer>)
2102 request.argument).first;
2103 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2104 break;
2105 }
2106 case EVENT_SET_SIM_POWER_DONE: {
2107 ar = (AsyncResult) msg.obj;
2108 request = (MainThreadRequest) ar.userObj;
2109 IIntegerConsumer callback =
2110 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2111 if (ar.exception != null) {
2112 loge("setSimPower exception: " + ar.exception);
2113 int errorCode = TelephonyManager.CallForwardingInfoCallback
2114 .RESULT_ERROR_UNKNOWN;
2115 if (ar.exception instanceof CommandException) {
2116 CommandException.Error error =
2117 ((CommandException) (ar.exception)).getCommandError();
2118 if (error == CommandException.Error.SIM_ERR) {
2119 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2120 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2121 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2122 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2123 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2124 } else {
2125 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2126 }
2127 }
2128 try {
2129 callback.accept(errorCode);
2130 } catch (RemoteException e) {
2131 // Ignore if the remote process is no longer available to call back.
2132 Log.w(LOG_TAG, "setSimPower: callback not available.");
2133 }
2134 } else {
2135 try {
2136 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2137 } catch (RemoteException e) {
2138 // Ignore if the remote process is no longer available to call back.
2139 Log.w(LOG_TAG, "setSimPower: callback not available.");
2140 }
2141 }
2142 break;
2143 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002144 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2145 request = (MainThreadRequest) msg.obj;
2146
2147 final Phone phone = getPhoneFromRequest(request);
2148 if (phone == null || phone.getServiceStateTracker() == null) {
2149 request.result = new IllegalStateException("Phone or SST is null");
2150 notifyRequester(request);
2151 break;
2152 }
2153
2154 Pair<Integer, SignalStrengthUpdateRequest> pair =
2155 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2156 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2157 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002158 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002159 request.subId, pair.first /*callingUid*/,
2160 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002161 break;
2162 }
2163 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2164 ar = (AsyncResult) msg.obj;
2165 request = (MainThreadRequest) ar.userObj;
2166 // request.result will be the exception of ar if present, true otherwise.
2167 // Be cautious not to leave result null which will wait() forever
2168 request.result = ar.exception != null ? ar.exception : true;
2169 notifyRequester(request);
2170 break;
2171 }
2172 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2173 request = (MainThreadRequest) msg.obj;
2174
2175 Phone phone = getPhoneFromRequest(request);
2176 if (phone == null || phone.getServiceStateTracker() == null) {
2177 request.result = new IllegalStateException("Phone or SST is null");
2178 notifyRequester(request);
2179 break;
2180 }
2181
2182 Pair<Integer, SignalStrengthUpdateRequest> pair =
2183 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2184 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2185 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002186 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002187 request.subId, pair.first /*callingUid*/,
2188 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002189 break;
2190 }
2191 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2192 ar = (AsyncResult) msg.obj;
2193 request = (MainThreadRequest) ar.userObj;
2194 request.result = ar.exception != null ? ar.exception : true;
2195 notifyRequester(request);
2196 break;
2197 }
Jordan Liu109698e2020-11-24 14:50:34 -08002198
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002199 case CMD_GET_SLICING_CONFIG: {
2200 request = (MainThreadRequest) msg.obj;
2201 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2202 request.phone.getSlicingConfig(onCompleted);
2203 break;
2204 }
2205 case EVENT_GET_SLICING_CONFIG_DONE: {
2206 ar = (AsyncResult) msg.obj;
2207 request = (MainThreadRequest) ar.userObj;
2208 ResultReceiver result = (ResultReceiver) request.argument;
2209
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002210 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002211 Bundle bundle = new Bundle();
2212 int resultCode = 0;
2213 if (ar.exception != null) {
2214 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2215 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002216 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002217 } else if (ar.result == null) {
2218 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002219 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002220 } else {
2221 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002222 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2223 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002224 }
2225
2226 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002227 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002228 }
2229 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2230 result.send(resultCode, bundle);
2231 notifyRequester(request);
2232 break;
2233 }
2234
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236 request = (MainThreadRequest) msg.obj;
2237 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 PurchasePremiumCapabilityArgument arg =
2239 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002240 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2241 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246 ar = (AsyncResult) msg.obj;
2247 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 PurchasePremiumCapabilityArgument arg =
2249 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250 try {
2251 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002252 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002253 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002254 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002255 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256 + TelephonyManager.convertPurchaseResultToString(result));
2257 } catch (RemoteException e) {
2258 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002260 + " failed: " + e;
2261 if (DBG) log(logStr);
2262 AnomalyReporter.reportAnomaly(
2263 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2264 }
2265 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002266 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002267
Michele Berionne5e411512020-11-13 02:36:59 +00002268 case CMD_PREPARE_UNATTENDED_REBOOT:
2269 request = (MainThreadRequest) msg.obj;
2270 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002271 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002272 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002273 notifyRequester(request);
2274 break;
2275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 default:
2277 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2278 break;
2279 }
2280 }
Jake Hambye994d462014-02-03 13:10:13 -08002281
Pengquan Menga1bb6272018-09-06 09:59:22 -07002282 private void notifyRequester(MainThreadRequest request) {
2283 synchronized (request) {
2284 request.notifyAll();
2285 }
2286 }
2287
Jake Hambye994d462014-02-03 13:10:13 -08002288 private void handleNullReturnEvent(Message msg, String command) {
2289 AsyncResult ar = (AsyncResult) msg.obj;
2290 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2291 if (ar.exception == null) {
2292 request.result = true;
2293 } else {
2294 request.result = false;
2295 if (ar.exception instanceof CommandException) {
2296 loge(command + ": CommandException: " + ar.exception);
2297 } else {
2298 loge(command + ": Unknown exception");
2299 }
2300 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002301 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 }
2304
2305 /**
2306 * Posts the specified command to be executed on the main thread,
2307 * waits for the request to complete, and returns the result.
2308 * @see #sendRequestAsync
2309 */
2310 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002311 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2312 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002313 }
2314
2315 /**
2316 * Posts the specified command to be executed on the main thread,
2317 * waits for the request to complete, and returns the result.
2318 * @see #sendRequestAsync
2319 */
2320 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2321 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002322 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002323 }
2324
2325 /**
2326 * Posts the specified command to be executed on the main thread,
2327 * waits for the request to complete, and returns the result.
2328 * @see #sendRequestAsync
2329 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002330 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002331 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2332 }
2333
2334 /**
2335 * Posts the specified command to be executed on the main thread,
2336 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2337 * if not timeout or null otherwise.
2338 * @see #sendRequestAsync
2339 */
2340 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2341 long timeoutInMs) {
2342 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002343 }
2344
2345 /**
2346 * Posts the specified command to be executed on the main thread,
2347 * waits for the request to complete, and returns the result.
2348 * @see #sendRequestAsync
2349 */
Nathan Harold92bed182018-10-12 18:16:49 -07002350 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002351 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002352 }
2353
2354 /**
2355 * Posts the specified command to be executed on the main thread,
2356 * waits for the request to complete, and returns the result.
2357 * @see #sendRequestAsync
2358 */
2359 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002360 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2361 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002362 }
2363
2364 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002365 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2366 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2367 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002368 * @see #sendRequestAsync
2369 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2371 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2373 throw new RuntimeException("This method will deadlock if called from the main thread.");
2374 }
2375
Nathan Harold92bed182018-10-12 18:16:49 -07002376 MainThreadRequest request = null;
2377 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2378 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2379 } else if (phone != null) {
2380 request = new MainThreadRequest(argument, phone, workSource);
2381 } else {
2382 request = new MainThreadRequest(argument, subId, workSource);
2383 }
2384
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 Message msg = mMainThreadHandler.obtainMessage(command, request);
2386 msg.sendToTarget();
2387
Rambo Wang0f050d82021-02-12 11:43:36 -08002388
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002390 if (timeoutInMs >= 0) {
2391 // Wait for at least timeoutInMs before returning null request result
2392 long now = SystemClock.elapsedRealtime();
2393 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002394 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002395 try {
2396 request.wait(deadline - now);
2397 } catch (InterruptedException e) {
2398 // Do nothing, go back and check if request is completed or timeout
2399 } finally {
2400 now = SystemClock.elapsedRealtime();
2401 }
2402 }
2403 } else {
2404 // Wait for the request to complete
2405 while (request.result == null) {
2406 try {
2407 request.wait();
2408 } catch (InterruptedException e) {
2409 // Do nothing, go back and wait until the request is complete
2410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 }
2412 }
2413 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002414 if (request.result == null) {
2415 Log.wtf(LOG_TAG,
2416 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 return request.result;
2419 }
2420
2421 /**
2422 * Asynchronous ("fire and forget") version of sendRequest():
2423 * Posts the specified command to be executed on the main thread, and
2424 * returns immediately.
2425 * @see #sendRequest
2426 */
2427 private void sendRequestAsync(int command) {
2428 mMainThreadHandler.sendEmptyMessage(command);
2429 }
2430
2431 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002432 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002433 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002434 */
2435 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002436 sendRequestAsync(command, argument, null, null);
2437 }
2438
2439 /**
2440 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2441 * @see {@link #sendRequest(int,Object)}
2442 */
2443 private void sendRequestAsync(
2444 int command, Object argument, Phone phone, WorkSource workSource) {
2445 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002446 Message msg = mMainThreadHandler.obtainMessage(command, request);
2447 msg.sendToTarget();
2448 }
2449
2450 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 * Initialize the singleton PhoneInterfaceManager instance.
2452 * This is only done once, at startup, from PhoneApp.onCreate().
2453 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002454 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 synchronized (PhoneInterfaceManager.class) {
2456 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002457 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 } else {
2459 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2460 }
2461 return sInstance;
2462 }
2463 }
2464
2465 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002466 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002468 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002469 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002471 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002472 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002473 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2475 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002476 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002477 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002478 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002479 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002480 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002481 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002482 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2483 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002484 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 publish();
arunvoddud7401012022-12-15 16:08:12 +00002486 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002487
2488 // Create the SatelliteEntitlementController singleton, for using the get the
2489 // entitlementStatus for satellite service.
2490 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
2492
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002493 @VisibleForTesting
2494 public SharedPreferences getSharedPreferences() {
2495 return mTelephonySharedPreferences;
2496 }
2497
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002498 /**
2499 * Get the default phone for this device.
2500 */
2501 @VisibleForTesting
2502 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002503 Phone thePhone = getPhone(getDefaultSubscription());
2504 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2505 }
2506
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 private void publish() {
2508 if (DBG) log("publish: " + this);
2509
Peter Wangc035ce42020-01-08 21:00:22 -08002510 TelephonyFrameworkInitializer
2511 .getTelephonyServiceManager()
2512 .getTelephonyServiceRegisterer()
2513 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 }
2515
Stuart Scott584921c2015-01-15 17:10:34 -08002516 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002517 if (request.phone != null) {
2518 return request.phone;
2519 } else {
2520 return getPhoneFromSubId(request.subId);
2521 }
2522 }
2523
2524 private Phone getPhoneFromSubId(int subId) {
2525 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2526 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002527 }
2528
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002529 /**
2530 * Get phone object associated with a subscription.
2531 * Return default phone if phone object associated with subscription is null
2532 * @param subId - subscriptionId
2533 * @return phone object associated with a subscription or default phone if null.
2534 */
Ling Mac28f0212023-03-24 16:07:15 -07002535 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002536 Phone phone = getPhoneFromSubId(subId);
2537 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002538 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002539 phone = getDefaultPhone();
2540 }
2541 return phone;
2542 }
2543
Rambo Wange53e07d2022-05-10 13:01:13 -07002544 @Nullable
2545 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002546 Phone phone = getPhoneFromRequest(request);
2547 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002548 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002549 }
2550
Ling Mac28f0212023-03-24 16:07:15 -07002551 /**
2552 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2553 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2554 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2555 * @return The Phone associated the sub Id
2556 */
2557 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002558 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560
Kai Shif70f46f2021-03-03 13:59:46 -08002561 private void sendEraseModemConfig(@NonNull Phone phone) {
2562 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2563 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2564 }
2565
2566 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2567 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2568 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002569 }
2570
Peter Wang44b186e2020-01-13 23:33:09 -08002571 private boolean isImsAvailableOnDevice() {
2572 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2573 if (pm == null) {
2574 // For some reason package manger is not available.. This will fail internally anyway,
2575 // so do not throw error and allow.
2576 return true;
2577 }
2578 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2579 }
2580
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002582 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2583 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2584
Wink Savilleadd7cc52014-09-08 14:23:09 -07002585 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002586 }
2587
Wink Savilleb564aae2014-10-23 10:18:09 -07002588 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 if (DBG) log("dial: " + number);
2590 // No permission check needed here: This is just a wrapper around the
2591 // ACTION_DIAL intent, which is available to any app since it puts up
2592 // the UI before it does anything.
2593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 String url = createTelUrl(number);
2597 if (url == null) {
2598 return;
2599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 // PENDING: should we just silently fail if phone is offhook or ringing?
2602 PhoneConstants.State state = mCM.getState(subId);
2603 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2604 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2605 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2606 mApp.startActivity(intent);
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
2611 }
2612
2613 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002614 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002615 }
2616
Wink Savilleb564aae2014-10-23 10:18:09 -07002617 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 if (DBG) log("call: " + number);
2619
2620 // This is just a wrapper around the ACTION_CALL intent, but we still
2621 // need to do a permission check since we're calling startActivity()
2622 // from the context of the phone app.
2623 enforceCallPermission();
2624
Jordan Liu1617b712019-07-10 15:06:26 -07002625 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 != AppOpsManager.MODE_ALLOWED) {
2627 return;
2628 }
2629
joonhunshin4ac60942023-11-15 15:23:39 +00002630 enforceTelephonyFeatureWithException(callingPackage,
2631 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 String url = createTelUrl(number);
2636 if (url == null) {
2637 return;
2638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 boolean isValid = false;
2641 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2642 if (slist != null) {
2643 for (SubscriptionInfo subInfoRecord : slist) {
2644 if (subInfoRecord.getSubscriptionId() == subId) {
2645 isValid = true;
2646 break;
2647 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002648 }
Wink Saville08874612014-08-31 19:19:58 -07002649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 if (!isValid) {
2651 return;
2652 }
Wink Saville08874612014-08-31 19:19:58 -07002653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2655 intent.putExtra(SUBSCRIPTION_KEY, subId);
2656 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2657 mApp.startActivity(intent);
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
2662
Wink Savilleb564aae2014-10-23 10:18:09 -07002663 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002664 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002665 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2666 }
2667
Wink Savilleb564aae2014-10-23 10:18:09 -07002668 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002669 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002670 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2671 }
2672
Wink Savilleb564aae2014-10-23 10:18:09 -07002673 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675
joonhunshin4ac60942023-11-15 15:23:39 +00002676 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2677 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2678 "supplyPinReportResultForSubscriber");
2679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 final long identity = Binder.clearCallingIdentity();
2681 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002682 Phone phone = getPhone(subId);
2683 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 checkSimPin.start();
2685 return checkSimPin.unlockSim(null, pin);
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 }
2690
Wink Savilleb564aae2014-10-23 10:18:09 -07002691 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
joonhunshin4ac60942023-11-15 15:23:39 +00002694 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2695 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002699 Phone phone = getPhone(subId);
2700 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 checkSimPuk.start();
2702 return checkSimPuk.unlockSim(puk, pin);
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 }
2707
2708 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002709 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 * a synchronous one.
2711 */
2712 private static class UnlockSim extends Thread {
2713
2714 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002715 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716
2717 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002718 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2719 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720
2721 // For replies from SimCard interface
2722 private Handler mHandler;
2723
2724 // For async handler to identify request type
2725 private static final int SUPPLY_PIN_COMPLETE = 100;
2726
Michele Berionne5e411512020-11-13 02:36:59 +00002727 UnlockSim(int phoneId, IccCard simCard) {
2728 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 mSimCard = simCard;
2730 }
2731
2732 @Override
2733 public void run() {
2734 Looper.prepare();
2735 synchronized (UnlockSim.this) {
2736 mHandler = new Handler() {
2737 @Override
2738 public void handleMessage(Message msg) {
2739 AsyncResult ar = (AsyncResult) msg.obj;
2740 switch (msg.what) {
2741 case SUPPLY_PIN_COMPLETE:
2742 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2743 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002744 mRetryCount = msg.arg1;
2745 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002746 CommandException.Error error = null;
2747 if (ar.exception instanceof CommandException) {
2748 error = ((CommandException) (ar.exception))
2749 .getCommandError();
2750 }
2751 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002752 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002753 } else if (error == CommandException.Error.ABORTED) {
2754 /* When UiccCardApp dispose, handle message and return
2755 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002756 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002757 } else {
2758 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2759 }
2760 } else {
2761 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 mDone = true;
2764 UnlockSim.this.notifyAll();
2765 }
2766 break;
2767 }
2768 }
2769 };
2770 UnlockSim.this.notifyAll();
2771 }
2772 Looper.loop();
2773 }
2774
2775 /*
2776 * Use PIN or PUK to unlock SIM card
2777 *
2778 * If PUK is null, unlock SIM card with PIN
2779 *
2780 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302781 *
2782 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2783 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 */
Wink Saville9de0f752013-10-22 19:04:03 -07002785 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786
2787 while (mHandler == null) {
2788 try {
2789 wait();
2790 } catch (InterruptedException e) {
2791 Thread.currentThread().interrupt();
2792 }
2793 }
2794 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2795
2796 if (puk == null) {
2797 mSimCard.supplyPin(pin, callback);
2798 } else {
2799 mSimCard.supplyPuk(puk, pin, callback);
2800 }
2801
2802 while (!mDone) {
2803 try {
2804 Log.d(LOG_TAG, "wait for done");
2805 wait();
2806 } catch (InterruptedException e) {
2807 // Restore the interrupted status
2808 Thread.currentThread().interrupt();
2809 }
2810 }
2811 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002812 int[] resultArray = new int[2];
2813 resultArray[0] = mResult;
2814 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002815
2816 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002817 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002818 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302819 // This instance is no longer reused, so quit its thread's looper.
2820 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002821
Wink Saville9de0f752013-10-22 19:04:03 -07002822 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 }
2824 }
2825
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002826 /**
2827 * This method has been removed due to privacy and stability concerns.
2828 */
2829 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002831 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2832 return;
Wink Saville36469e72014-06-11 15:17:00 -07002833 }
2834
Nathan Harold1f889d82020-06-04 17:05:26 -07002835 @Override
2836 public void updateServiceLocationWithPackageName(String callingPackage) {
2837 mApp.getSystemService(AppOpsManager.class)
2838 .checkPackage(Binder.getCallingUid(), callingPackage);
2839
Nathan Haroldf096d982020-11-18 17:18:06 -08002840 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002841 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2842 // Callers targeting S have no business invoking this method.
2843 return;
2844 }
2845
2846 LocationAccessPolicy.LocationPermissionResult locationResult =
2847 LocationAccessPolicy.checkLocationPermission(mApp,
2848 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2849 .setCallingPackage(callingPackage)
2850 .setCallingFeatureId(null)
2851 .setCallingPid(Binder.getCallingPid())
2852 .setCallingUid(Binder.getCallingUid())
2853 .setMethod("updateServiceLocation")
2854 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2855 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2856 .build());
2857 // Apps that lack location permission have no business calling this method;
2858 // however, because no permission was declared in the public API, denials must
2859 // all be "soft".
2860 switch (locationResult) {
2861 case DENIED_HARD: /* fall through */
2862 case DENIED_SOFT:
2863 return;
2864 }
2865
2866 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 final long identity = Binder.clearCallingIdentity();
2868 try {
Ling Mac28f0212023-03-24 16:07:15 -07002869 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870 } finally {
2871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 }
2874
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002875 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002876 @Override
2877 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002878 return isRadioOnWithFeature(callingPackage, null);
2879 }
2880
2881
2882 @Override
2883 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2884 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2885 callingFeatureId);
2886 }
2887
2888 @Deprecated
2889 @Override
2890 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2891 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002892 }
2893
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002894 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002895 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2896 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002898 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002899 return false;
2900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901
joonhunshin4ac60942023-11-15 15:23:39 +00002902 enforceTelephonyFeatureWithException(callingPackage,
2903 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 return isRadioOnForSubscriber(subId);
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002911 }
2912
2913 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 final long identity = Binder.clearCallingIdentity();
2915 try {
2916 final Phone phone = getPhone(subId);
2917 if (phone != null) {
2918 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2919 } else {
2920 return false;
2921 }
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002925 }
2926
2927 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002928 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
Wink Saville36469e72014-06-11 15:17:00 -07002930
Wink Savilleb564aae2014-10-23 10:18:09 -07002931 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933
joonhunshin4ac60942023-11-15 15:23:39 +00002934 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2935 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 final Phone phone = getPhone(subId);
2940 if (phone != null) {
2941 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2942 }
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002945 }
Wink Saville36469e72014-06-11 15:17:00 -07002946 }
2947
2948 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002949 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002950 }
2951
Wink Savilleb564aae2014-10-23 10:18:09 -07002952 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002953 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 final Phone phone = getPhone(subId);
2958 if (phone == null) {
2959 return false;
2960 }
2961 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2962 toggleRadioOnOffForSubscriber(subId);
2963 }
2964 return true;
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 }
Wink Saville36469e72014-06-11 15:17:00 -07002969
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002970 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002971 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002972
2973 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2974 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2975
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002976 /*
2977 * If any of the Radios are available, it will need to be
2978 * shutdown. So return true if any Radio is available.
2979 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2983 Phone phone = PhoneFactory.getPhone(i);
2984 if (phone != null && phone.isRadioAvailable()) return true;
2985 }
2986 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2987 return false;
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002990 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002991 }
2992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002994 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 enforceModifyPermission();
2996
joonhunshin4ac60942023-11-15 15:23:39 +00002997 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2998 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3003 logv("Shutting down Phone " + i);
3004 shutdownRadioUsingPhoneId(i);
3005 }
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003008 }
3009 }
3010
3011 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003012 Phone phone = PhoneFactory.getPhone(phoneId);
3013 if (phone != null && phone.isRadioAvailable()) {
3014 phone.shutdownRadio();
3015 }
3016 }
3017
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003019 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
Ling Ma83dc5ea2023-01-12 15:06:04 -08003021 if (!turnOn) {
3022 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3023 }
3024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3028 if (defaultPhone != null) {
3029 defaultPhone.setRadioPower(turnOn);
3030 return true;
3031 } else {
3032 loge("There's no default phone.");
3033 return false;
3034 }
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003037 }
Wink Saville36469e72014-06-11 15:17:00 -07003038 }
3039
Wink Savilleb564aae2014-10-23 10:18:09 -07003040 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
Ling Ma83dc5ea2023-01-12 15:06:04 -08003043 if (!turnOn) {
3044 log("setRadioPowerForSubscriber off: subId=" + subId
3045 + ",callingPackage=" + getCurrentPackageName());
3046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 final Phone phone = getPhone(subId);
3050 if (phone != null) {
3051 phone.setRadioPower(turnOn);
3052 return true;
3053 } else {
3054 return false;
3055 }
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 }
3060
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003061 /**
3062 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3063 * no reason to power it off. When any of the voters want to power it off, it will be turned
3064 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3065 * powering it off, and these radio off votes will be cleared.
3066 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3067 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3068 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3069 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3070 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3071 * check its vote.
3072 *
3073 * @param subId The subscription ID.
3074 * @param reason The reason for powering off radio.
3075 * @return true on success and false on failure.
3076 */
3077 public boolean requestRadioPowerOffForReason(int subId,
3078 @TelephonyManager.RadioPowerReason int reason) {
3079 enforceModifyPermission();
3080
joonhunshin4ac60942023-11-15 15:23:39 +00003081 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3082 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3083
Ling Ma83dc5ea2023-01-12 15:06:04 -08003084 log("requestRadioPowerOffForReason: subId=" + subId
3085 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003086 final long identity = Binder.clearCallingIdentity();
3087 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003088 boolean result = false;
3089 for (Phone phone : PhoneFactory.getPhones()) {
3090 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003091 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003092 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003093 if (!result) {
3094 loge("requestRadioPowerOffForReason: no phone exists");
3095 }
3096 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
3100 }
3101
3102 /**
3103 * Remove the vote on powering off the radio for a reason, as requested by
3104 * {@link requestRadioPowerOffForReason}.
3105 *
3106 * @param subId The subscription ID.
3107 * @param reason The reason for powering off radio.
3108 * @return true on success and false on failure.
3109 */
3110 public boolean clearRadioPowerOffForReason(int subId,
3111 @TelephonyManager.RadioPowerReason int reason) {
3112 enforceModifyPermission();
3113
joonhunshin4ac60942023-11-15 15:23:39 +00003114 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3115 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3116
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003117 final long identity = Binder.clearCallingIdentity();
3118 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003119 boolean result = false;
3120 for (Phone phone : PhoneFactory.getPhones()) {
3121 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003122 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003123 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003124 if (!result) {
3125 loge("clearRadioPowerOffForReason: no phone exists");
3126 }
3127 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
3131 }
3132
3133 /**
3134 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3135 *
3136 * @param subId The subscription ID.
3137 * @param callingPackage The package making the call.
3138 * @param callingFeatureId The feature in the package.
3139 * @return List of reasons for powering off radio.
3140 */
3141 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3142 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3143
joonhunshin4ac60942023-11-15 15:23:39 +00003144 enforceTelephonyFeatureWithException(callingPackage,
3145 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3146
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003147 final long identity = Binder.clearCallingIdentity();
3148 List result = new ArrayList();
3149 try {
3150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3151 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3152 return result;
3153 }
3154
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003155 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003156 if (phone != null) {
3157 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003158 } else {
3159 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003160 }
3161 } finally {
3162 Binder.restoreCallingIdentity(identity);
3163 }
3164 return result;
3165 }
3166
Wink Saville36469e72014-06-11 15:17:00 -07003167 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003168 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003169 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171
joonhunshin4ac60942023-11-15 15:23:39 +00003172 enforceTelephonyFeatureWithException(callingPackage,
3173 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final long identity = Binder.clearCallingIdentity();
3176 try {
Jack Yu285100e2022-12-02 22:48:35 -08003177 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003178 final Phone phone = getPhone(subId);
3179 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003180 phone.getDataSettingsManager().setDataEnabled(
3181 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182 return true;
3183 } else {
3184 return false;
3185 }
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 }
3190
Wink Saville36469e72014-06-11 15:17:00 -07003191 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003192 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003193 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195
joonhunshin4ac60942023-11-15 15:23:39 +00003196 enforceTelephonyFeatureWithException(callingPackage,
3197 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
Jack Yu285100e2022-12-02 22:48:35 -08003201 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 final Phone phone = getPhone(subId);
3203 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003204 phone.getDataSettingsManager().setDataEnabled(
3205 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 return true;
3207 } else {
3208 return false;
3209 }
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 }
3214
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003216 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003217 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3218 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 final Phone phone = getPhone(subId);
3223 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003224 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 } else {
3226 return false;
3227 }
3228 } finally {
3229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003231 }
3232
3233 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003234 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003235 }
3236
pkanwarae03a6b2016-11-06 20:37:09 -08003237 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 enforceCallPermission();
3239
joonhunshin4ac60942023-11-15 15:23:39 +00003240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3241 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3246 return;
3247 }
3248 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3249 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
pkanwar32d516d2016-10-14 19:37:38 -07003253 };
3254
Wink Savilleb564aae2014-10-23 10:18:09 -07003255 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257
joonhunshin4ac60942023-11-15 15:23:39 +00003258 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3259 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3264 return false;
3265 }
3266 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3267 } finally {
3268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 }
3271
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003272 /**
3273 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3274 * tag on getCallState Binder call.
3275 */
3276 @Deprecated
3277 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003279 if (CompatChanges.isChangeEnabled(
3280 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3281 Binder.getCallingUid())) {
3282 // Do not allow this API to be called on API version 31+, it should only be
3283 // called on old apps using this Binder call directly.
3284 throw new SecurityException("This method can only be used for applications "
3285 + "targeting API version 30 or less.");
3286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287 final long identity = Binder.clearCallingIdentity();
3288 try {
Ling Mac28f0212023-03-24 16:07:15 -07003289 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3290 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
3294 }
3295
3296 @Override
3297 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3298 if (CompatChanges.isChangeEnabled(
3299 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3300 Binder.getCallingUid())) {
3301 // Check READ_PHONE_STATE for API version 31+
3302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3303 featureId, "getCallStateForSubscription")) {
3304 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3305 + "targeting API level 31+.");
3306 }
3307 }
joonhunshin4ac60942023-11-15 15:23:39 +00003308
3309 enforceTelephonyFeatureWithException(callingPackage,
3310 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3311
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3316 PhoneConstantConversions.convertCallState(phone.getState());
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003320 }
3321
Sanket Padawe356d7632015-06-22 14:03:32 -07003322 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003323 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003324 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003325 }
3326
3327 @Override
3328 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003329 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3330 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 final long identity = Binder.clearCallingIdentity();
3333 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003334 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003336 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 } else {
3338 return PhoneConstantConversions.convertDataState(
3339 PhoneConstants.DataState.DISCONNECTED);
3340 }
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 }
3345
Sanket Padawe356d7632015-06-22 14:03:32 -07003346 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003347 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003348 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003349 }
3350
3351 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003352 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003353 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3354 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 final long identity = Binder.clearCallingIdentity();
3357 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003358 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003360 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 } else {
3362 return TelephonyManager.DATA_ACTIVITY_NONE;
3363 }
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 }
3368
3369 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003370 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003371 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003372 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003373
3374 LocationAccessPolicy.LocationPermissionResult locationResult =
3375 LocationAccessPolicy.checkLocationPermission(mApp,
3376 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3377 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003378 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003379 .setCallingPid(Binder.getCallingPid())
3380 .setCallingUid(Binder.getCallingUid())
3381 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003382 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003383 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3384 .build());
3385 switch (locationResult) {
3386 case DENIED_HARD:
3387 throw new SecurityException("Not allowed to access cell location");
3388 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003389 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3390 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003391 }
3392
joonhunshin4ac60942023-11-15 15:23:39 +00003393 enforceTelephonyFeatureWithException(callingPackage,
3394 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3395
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003396 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003400 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003401 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 } finally {
3403 Binder.restoreCallingIdentity(identity);
3404 }
Svetoslav64fad262015-04-14 14:35:21 -07003405 }
3406
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003407 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003408 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003409 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3410 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3411
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003412 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3413 // registered cell info, so return a NULL country instead.
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003416 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3417 // Get default phone in this case.
3418 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3419 }
Jack Yu285100e2022-12-02 22:48:35 -08003420 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003422 if (phone == null) return "";
3423 ServiceStateTracker sst = phone.getServiceStateTracker();
3424 if (sst == null) return "";
3425 LocaleTracker lt = sst.getLocaleTracker();
3426 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003427 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003431 }
3432
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003433 /**
3434 * This method was removed due to potential issues caused by performing partial
3435 * updates of service state, and lack of a credible use case.
3436 *
3437 * This has the ability to break the telephony implementation by disabling notification of
3438 * changes in device connectivity. DO NOT USE THIS!
3439 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003440 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003441 public void enableLocationUpdates() {
3442 mApp.enforceCallingOrSelfPermission(
3443 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 }
3445
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003446 /**
3447 * This method was removed due to potential issues caused by performing partial
3448 * updates of service state, and lack of a credible use case.
3449 *
3450 * This has the ability to break the telephony implementation by disabling notification of
3451 * changes in device connectivity. DO NOT USE THIS!
3452 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 @Override
3454 public void disableLocationUpdates() {
3455 mApp.enforceCallingOrSelfPermission(
3456 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003457 }
3458
3459 @Override
3460 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003461 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3462 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003463 try {
3464 mApp.getSystemService(AppOpsManager.class)
3465 .checkPackage(Binder.getCallingUid(), callingPackage);
3466 } catch (SecurityException e) {
3467 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3468 throw e;
3469 }
3470
Nathan Haroldf096d982020-11-18 17:18:06 -08003471 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003472 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3473 throw new SecurityException(
3474 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3475 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003476
Jordan Liu1617b712019-07-10 15:06:26 -07003477 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3479 return null;
3480 }
Svetoslav64fad262015-04-14 14:35:21 -07003481
joonhunshin4ac60942023-11-15 15:23:39 +00003482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3483 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3484
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003485 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003487 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003488 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003489
Nathan Haroldf180aac2018-06-01 18:43:55 -07003490 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3491 for (CellInfo ci : info) {
3492 if (ci instanceof CellInfoGsm) {
3493 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3494 } else if (ci instanceof CellInfoWcdma) {
3495 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003498 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003499 }
3500
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003501 private List<CellInfo> getCachedCellInfo() {
3502 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3503 for (Phone phone : PhoneFactory.getPhones()) {
3504 List<CellInfo> info = phone.getAllCellInfo();
3505 if (info != null) cellInfos.addAll(info);
3506 }
3507 return cellInfos;
3508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003509
3510 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003511 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003512 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003513 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003514
3515 LocationAccessPolicy.LocationPermissionResult locationResult =
3516 LocationAccessPolicy.checkLocationPermission(mApp,
3517 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3518 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003519 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003520 .setCallingPid(Binder.getCallingPid())
3521 .setCallingUid(Binder.getCallingUid())
3522 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003523 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003524 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3525 .build());
3526 switch (locationResult) {
3527 case DENIED_HARD:
3528 throw new SecurityException("Not allowed to access cell info");
3529 case DENIED_SOFT:
3530 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531 }
3532
Nathan Haroldf096d982020-11-18 17:18:06 -08003533 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003534 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3535 return getCachedCellInfo();
3536 }
3537
joonhunshin4ac60942023-11-15 15:23:39 +00003538 enforceTelephonyFeatureWithException(callingPackage,
3539 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3540
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003541 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003542 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3546 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003547 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003548 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 if (info != null) cellInfos.addAll(info);
3550 }
3551 return cellInfos;
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003554 }
3555 }
3556
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003557 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003558 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3559 String callingFeatureId) {
3560 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3561 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003562 }
3563
3564 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003565 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3566 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003567 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003568 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003569 }
3570
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003571 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3572 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003573 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003574 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003575
3576 LocationAccessPolicy.LocationPermissionResult locationResult =
3577 LocationAccessPolicy.checkLocationPermission(mApp,
3578 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3579 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003580 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003581 .setCallingPid(Binder.getCallingPid())
3582 .setCallingUid(Binder.getCallingUid())
3583 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003584 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3585 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003586 .build());
3587 switch (locationResult) {
3588 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003589 if (TelephonyPermissions
3590 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003591 // Safetynet logging for b/154934934
3592 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3593 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003594 throw new SecurityException("Not allowed to access cell info");
3595 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003596 if (TelephonyPermissions
3597 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003598 // Safetynet logging for b/154934934
3599 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3600 }
Nathan Harold5320c422019-05-09 10:26:08 -07003601 try {
3602 cb.onCellInfo(new ArrayList<CellInfo>());
3603 } catch (RemoteException re) {
3604 // Drop without consequences
3605 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003606 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003607 }
3608
joonhunshin4ac60942023-11-15 15:23:39 +00003609 enforceTelephonyFeatureWithException(callingPackage,
3610 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003611
3612 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003613 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3614
3615 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3616 }
3617
3618 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003619 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003620 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003625 Phone phone = getPhone(subId);
3626 if (phone == null) {
3627 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3628 } else {
3629 phone.setCellInfoListRate(rateInMillis, workSource);
3630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631 } finally {
3632 Binder.restoreCallingIdentity(identity);
3633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003634 }
3635
Shishir Agrawala9f32182016-04-12 12:00:16 -07003636 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003637 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003638 Phone phone = PhoneFactory.getPhone(slotIndex);
3639 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003640 return null;
3641 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003642 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003643 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003644 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003645 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003646 return null;
3647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
joonhunshin4ac60942023-11-15 15:23:39 +00003649 enforceTelephonyFeatureWithException(callingPackage,
3650 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 return phone.getImei();
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003658 }
3659
3660 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003661 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3662 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3663 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3664 callingFeatureId, "getPrimaryImei")) {
3665 throw new SecurityException("Caller does not have permission");
3666 }
joonhunshin4ac60942023-11-15 15:23:39 +00003667
3668 enforceTelephonyFeatureWithException(callingPackage,
3669 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3670
arunvoddud5c6ce02022-12-11 06:03:12 +00003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 for (Phone phone : PhoneFactory.getPhones()) {
3674 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3675 return phone.getImei();
3676 }
3677 }
3678 throw new UnsupportedOperationException("Operation not supported");
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
3682 }
3683
3684 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003685 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3687 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3688
David Kelly5e06a7f2018-03-12 14:10:59 +00003689 Phone phone = PhoneFactory.getPhone(slotIndex);
3690 String tac = null;
3691 if (phone != null) {
3692 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003693 try {
3694 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3695 } catch (IndexOutOfBoundsException e) {
3696 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3697 return null;
3698 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003699 }
3700 return tac;
3701 }
3702
3703 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003704 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003705 try {
3706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3707 } catch (SecurityException se) {
3708 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3709 throw new SecurityException("Package " + callingPackage + " does not belong to "
3710 + Binder.getCallingUid());
3711 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003712 Phone phone = PhoneFactory.getPhone(slotIndex);
3713 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003714 return null;
3715 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716
Jeff Davidson913390f2018-02-23 17:11:49 -08003717 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003718 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003719 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003720 return null;
3721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722
joonhunshin4ac60942023-11-15 15:23:39 +00003723 enforceTelephonyFeatureWithException(callingPackage,
3724 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 return phone.getMeid();
3729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Jack Yu2af8d712017-03-15 17:14:14 -07003732 }
3733
3734 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003735 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3737 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3738
David Kelly5e06a7f2018-03-12 14:10:59 +00003739 Phone phone = PhoneFactory.getPhone(slotIndex);
3740 String manufacturerCode = null;
3741 if (phone != null) {
3742 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003743 try {
3744 manufacturerCode =
3745 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3746 } catch (IndexOutOfBoundsException e) {
3747 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3748 return null;
3749 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003750 }
3751 return manufacturerCode;
3752 }
3753
3754 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003755 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3756 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003757 Phone phone = PhoneFactory.getPhone(slotIndex);
3758 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003759 return null;
3760 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003761 int subId = phone.getSubId();
3762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 mApp, subId, callingPackage, callingFeatureId,
3764 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003765 return null;
3766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767
joonhunshin4ac60942023-11-15 15:23:39 +00003768 enforceTelephonyFeatureWithException(callingPackage,
3769 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 return phone.getDeviceSvn();
3774 } finally {
3775 Binder.restoreCallingIdentity(identity);
3776 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003777 }
3778
fionaxu43304da2017-11-27 22:51:16 -08003779 @Override
3780 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003781 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3782 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 final Phone phone = getPhone(subId);
3787 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
fionaxu43304da2017-11-27 22:51:16 -08003791 }
3792
3793 @Override
3794 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003795 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3796 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 final Phone phone = getPhone(subId);
3801 return phone == null ? null : phone.getCarrierName();
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
fionaxu43304da2017-11-27 22:51:16 -08003805 }
3806
calvinpanffe225e2018-11-01 19:43:06 +08003807 @Override
chen xu0026ca62019-03-06 15:28:50 -08003808 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3810 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3811
chen xu25637222018-11-04 17:17:00 -08003812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 final Phone phone = getPhone(subId);
3815 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003816 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
3820 }
3821
3822 @Override
chen xu0026ca62019-03-06 15:28:50 -08003823 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003824 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3825 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3826 "getSubscriptionSpecificCarrierName");
3827
chen xu25637222018-11-04 17:17:00 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003831 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
3835 }
3836
chen xu651eec72018-11-11 19:03:44 -08003837 @Override
chen xu864e11c2018-12-06 22:10:03 -08003838 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3839 if (!isSubscriptionMccMnc) {
3840 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3841 }
chen xu651eec72018-11-11 19:03:44 -08003842 final Phone phone = PhoneFactory.getPhone(slotIndex);
3843 if (phone == null) {
3844 return TelephonyManager.UNKNOWN_CARRIER_ID;
3845 }
joonhunshin4ac60942023-11-15 15:23:39 +00003846
3847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3848 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3849
chen xu651eec72018-11-11 19:03:44 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
3856 }
3857
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003858 //
3859 // Internal helper methods.
3860 //
3861
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003862 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003863 * Make sure the caller is the calling package itself
3864 *
3865 * @throws SecurityException if the caller is not the calling package
3866 */
3867 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3868 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003869 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3870 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003871 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003872 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003873 } catch (PackageManager.NameNotFoundException e) {
3874 // packageUid is -1
3875 }
3876 if (packageUid != callingUid) {
3877 throw new SecurityException(message + ": Package " + callingPackage
3878 + " does not belong to " + callingUid);
3879 }
3880 }
3881
3882 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003883 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3884 *
3885 * @throws SecurityException if the caller does not have the required permission
3886 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003887 @VisibleForTesting
3888 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3890 }
3891
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003892 /**
arunvoddud7401012022-12-15 16:08:12 +00003893 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003894 *
3895 * @throws SecurityException if the caller does not have the required permission
3896 */
3897 @VisibleForTesting
3898 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003899 enforceReadPermission(null);
3900 }
3901
3902 /**
3903 * Make sure the caller has the READ_PHONE_STATE permissions.
3904 *
3905 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3906 */
3907 @VisibleForTesting
3908 public void enforceReadPermission(String msg) {
3909 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003910 }
3911
Shuo Qian3b6ee772019-11-13 17:43:31 -08003912 private void enforceActiveEmergencySessionPermission() {
3913 mApp.enforceCallingOrSelfPermission(
3914 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3915 }
3916
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003917 /**
3918 * Make sure the caller has the CALL_PHONE permission.
3919 *
3920 * @throws SecurityException if the caller does not have the required permission
3921 */
3922 private void enforceCallPermission() {
3923 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3924 }
3925
paulhu5a773602019-08-23 19:17:33 +08003926 private void enforceSettingsPermission() {
3927 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003928 }
3929
Michele Berionne5e411512020-11-13 02:36:59 +00003930 private void enforceRebootPermission() {
3931 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3932 }
3933
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003934 /**
3935 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3936 * @param message - log message to print.
3937 * @throws SecurityException if the caller does not have the required permission
3938 */
3939 private void enforceSatelliteCommunicationPermission(String message) {
3940 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3941 }
3942
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003943 private String createTelUrl(String number) {
3944 if (TextUtils.isEmpty(number)) {
3945 return null;
3946 }
3947
Jake Hambye994d462014-02-03 13:10:13 -08003948 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003949 }
3950
Ihab Awadf9e92732013-12-05 18:02:52 -08003951 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003952 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003953 }
3954
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003955 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003956 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003957 }
3958
Ihab Awadf9e92732013-12-05 18:02:52 -08003959 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003960 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003961 }
3962
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003963 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003964 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003965 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003966 }
3967
Sanket Padawe356d7632015-06-22 14:03:32 -07003968 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003969 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3971 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 final Phone phone = PhoneFactory.getPhone(slotIndex);
3976 if (phone == null) {
3977 return PhoneConstants.PHONE_TYPE_NONE;
3978 } else {
3979 return phone.getPhoneType();
3980 }
3981 } finally {
3982 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003984 }
3985
3986 /**
3987 * Returns the CDMA ERI icon index to display
3988 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003989 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003990 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3991 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3992 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003993 }
3994
Sanket Padawe356d7632015-06-22 14:03:32 -07003995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003996 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3997 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003999 mApp, subId, callingPackage, callingFeatureId,
4000 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004001 return -1;
4002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003
joonhunshin4ac60942023-11-15 15:23:39 +00004004 enforceTelephonyFeatureWithException(callingPackage,
4005 PackageManager.FEATURE_TELEPHONY_CDMA,
4006 "getCdmaEriIconIndexForSubscriber");
4007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 final Phone phone = getPhone(subId);
4011 if (phone != null) {
4012 return phone.getCdmaEriIconIndex();
4013 } else {
4014 return -1;
4015 }
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004018 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004019 }
4020
4021 /**
4022 * Returns the CDMA ERI icon mode,
4023 * 0 - ON
4024 * 1 - FLASHING
4025 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004027 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4028 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4029 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004030 }
4031
Sanket Padawe356d7632015-06-22 14:03:32 -07004032 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004033 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4034 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004036 mApp, subId, callingPackage, callingFeatureId,
4037 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004038 return -1;
4039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040
4041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 final Phone phone = getPhone(subId);
4044 if (phone != null) {
4045 return phone.getCdmaEriIconMode();
4046 } else {
4047 return -1;
4048 }
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004052 }
4053
4054 /**
4055 * Returns the CDMA ERI text,
4056 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004058 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4059 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4060 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004061 }
4062
Sanket Padawe356d7632015-06-22 14:03:32 -07004063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004064 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4065 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004067 mApp, subId, callingPackage, callingFeatureId,
4068 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004069 return null;
4070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071
4072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 final Phone phone = getPhone(subId);
4075 if (phone != null) {
4076 return phone.getCdmaEriText();
4077 } else {
4078 return null;
4079 }
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004083 }
4084
4085 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004086 * Returns the CDMA MDN.
4087 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004088 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004089 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4091 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092
joonhunshin4ac60942023-11-15 15:23:39 +00004093 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4094 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004099 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 return phone.getLine1Number();
4101 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004102 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 return null;
4104 }
4105 } finally {
4106 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004107 }
4108 }
4109
4110 /**
4111 * Returns the CDMA MIN.
4112 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004113 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004114 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4116 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117
joonhunshin4ac60942023-11-15 15:23:39 +00004118 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4119 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 final Phone phone = getPhone(subId);
4124 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4125 return phone.getCdmaMin();
4126 } else {
4127 return null;
4128 }
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004131 }
4132 }
4133
Hall Liud892bec2018-11-30 14:51:45 -08004134 @Override
4135 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4136 INumberVerificationCallback callback, String callingPackage) {
4137 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4138 != PERMISSION_GRANTED) {
4139 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4140 }
4141 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4142
4143 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4144 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004145 throw new SecurityException("Calling package must be configured in the device config: "
4146 + "calling package: " + callingPackage
4147 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004148 }
4149
joonhunshin4ac60942023-11-15 15:23:39 +00004150 enforceTelephonyFeatureWithException(callingPackage,
4151 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4152
Hall Liud892bec2018-11-30 14:51:45 -08004153 if (range == null) {
4154 throw new NullPointerException("Range must be non-null");
4155 }
4156
4157 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004158 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004159
4160 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4161 }
4162
Junda Liuca05d5d2014-08-14 22:36:34 -07004163 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004164 * Returns true if CDMA provisioning needs to run.
4165 */
4166 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004167 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4168 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 final long identity = Binder.clearCallingIdentity();
4171 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004172 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004176 }
4177
4178 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004179 * Sets the voice mail number of a given subId.
4180 */
4181 @Override
4182 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004183 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4184 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185
joonhunshin4ac60942023-11-15 15:23:39 +00004186 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4187 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189 final long identity = Binder.clearCallingIdentity();
4190 try {
4191 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4192 new Pair<String, String>(alphaTag, number), new Integer(subId));
4193 return success;
4194 } finally {
4195 Binder.restoreCallingIdentity(identity);
4196 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004197 }
4198
Ta-wei Yen87c49842016-05-13 21:19:52 -07004199 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004200 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4201 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004202 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4203 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004204 if (!TextUtils.equals(callingPackage, systemDialer)) {
4205 throw new SecurityException("caller must be system dialer");
4206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004207
joonhunshin4ac60942023-11-15 15:23:39 +00004208 enforceTelephonyFeatureWithException(callingPackage,
4209 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
4213 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4214 if (phoneAccountHandle == null) {
4215 return null;
4216 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004217 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 } finally {
4219 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004220 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004221 }
4222
4223 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004224 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4225 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004226 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004228 mApp, subId, callingPackage, callingFeatureId,
4229 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004230 return null;
4231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232
joonhunshin4ac60942023-11-15 15:23:39 +00004233 enforceTelephonyFeatureWithException(callingPackage,
4234 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4235
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004236 final long identity = Binder.clearCallingIdentity();
4237 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004238 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004242 }
4243
4244 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004245 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4246 VisualVoicemailSmsFilterSettings settings) {
4247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248
joonhunshin4ac60942023-11-15 15:23:39 +00004249 enforceTelephonyFeatureWithException(callingPackage,
4250 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004255 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004259 }
4260
4261 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004262 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4263 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264
joonhunshin4ac60942023-11-15 15:23:39 +00004265 enforceTelephonyFeatureWithException(callingPackage,
4266 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 final long identity = Binder.clearCallingIdentity();
4269 try {
4270 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004271 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272 } finally {
4273 Binder.restoreCallingIdentity(identity);
4274 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004275 }
4276
4277 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004278 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4279 String callingPackage, int subId) {
4280 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281
4282 final long identity = Binder.clearCallingIdentity();
4283 try {
4284 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004285 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004289 }
4290
4291 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004292 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
4297 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004298 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004302 }
4303
4304 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004305 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4306 String callingAttributionTag, int subId, String number, int port, String text,
4307 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004308 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004309 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004310 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004311
4312 enforceTelephonyFeatureWithException(callingPackage,
4313 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4314
Amit Mahajandccb3f12019-05-13 13:48:32 -07004315 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004316 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4317 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004318 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004319
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004320 /**
fionaxu0152e512016-11-14 13:36:14 -08004321 * Sets the voice activation state of a given subId.
4322 */
4323 @Override
4324 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4326 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327
joonhunshin4ac60942023-11-15 15:23:39 +00004328 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4329 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 final Phone phone = getPhone(subId);
4334 if (phone != null) {
4335 phone.setVoiceActivationState(activationState);
4336 } else {
4337 loge("setVoiceActivationState fails with invalid subId: " + subId);
4338 }
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004341 }
4342 }
4343
4344 /**
4345 * Sets the data activation state of a given subId.
4346 */
4347 @Override
4348 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4350 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351
joonhunshin4ac60942023-11-15 15:23:39 +00004352 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4353 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 final Phone phone = getPhone(subId);
4358 if (phone != null) {
4359 phone.setDataActivationState(activationState);
4360 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004361 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362 }
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004365 }
4366 }
4367
4368 /**
4369 * Returns the voice activation state of a given subId.
4370 */
4371 @Override
4372 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374
joonhunshin4ac60942023-11-15 15:23:39 +00004375 enforceTelephonyFeatureWithException(callingPackage,
4376 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4377
fionaxu0152e512016-11-14 13:36:14 -08004378 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379 final long identity = Binder.clearCallingIdentity();
4380 try {
4381 if (phone != null) {
4382 return phone.getVoiceActivationState();
4383 } else {
4384 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4385 }
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004388 }
4389 }
4390
4391 /**
4392 * Returns the data activation state of a given subId.
4393 */
4394 @Override
4395 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397
joonhunshin4ac60942023-11-15 15:23:39 +00004398 enforceTelephonyFeatureWithException(callingPackage,
4399 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4400
fionaxu0152e512016-11-14 13:36:14 -08004401 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
4404 if (phone != null) {
4405 return phone.getDataActivationState();
4406 } else {
4407 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4408 }
4409 } finally {
4410 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004411 }
4412 }
4413
4414 /**
Wink Saville36469e72014-06-11 15:17:00 -07004415 * Returns the unread count of voicemails for a subId
4416 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004418 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4419 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004421 mApp, subId, callingPackage, callingFeatureId,
4422 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004423 return 0;
4424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425 final long identity = Binder.clearCallingIdentity();
4426 try {
4427 final Phone phone = getPhone(subId);
4428 if (phone != null) {
4429 return phone.getVoiceMessageCount();
4430 } else {
4431 return 0;
4432 }
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004436 }
4437
4438 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004439 * returns true, if the device is in a state where both voice and data
4440 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004441 */
4442 @Override
4443 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004444 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4445 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 final long identity = Binder.clearCallingIdentity();
4448 try {
Ling Mac28f0212023-03-24 16:07:15 -07004449 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004453 }
4454
4455 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004456 * Send the dialer code if called from the current default dialer or the caller has
4457 * carrier privilege.
4458 * @param inputCode The dialer code to send
4459 */
4460 @Override
4461 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004462 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004463 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004464 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4465 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004466 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004467 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004468 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470
joonhunshin4ac60942023-11-15 15:23:39 +00004471 enforceTelephonyFeatureWithException(callingPackage,
4472 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 final long identity = Binder.clearCallingIdentity();
4475 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004476 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
fionaxu235cc5e2017-03-06 22:25:57 -08004480 }
4481
Pengquan Menga1bb6272018-09-06 09:59:22 -07004482 @Override
4483 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004484 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004485 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4486 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004487
4488 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4489 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4490
shilufc958392020-01-20 11:36:01 -08004491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 if (!isActiveSubscription(subId)) {
4494 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4495 }
4496 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4497 } finally {
4498 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004499 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004500 }
4501
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004503 public boolean isInEmergencySmsMode() {
4504 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004505
4506 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4507 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4508
Brad Ebingerb2b65522019-03-15 13:48:47 -07004509 final long identity = Binder.clearCallingIdentity();
4510 try {
4511 for (Phone phone : PhoneFactory.getPhones()) {
4512 if (phone.isInEmergencySmsMode()) {
4513 return true;
4514 }
4515 }
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
4519 return false;
4520 }
4521
shilu366312e2019-12-17 09:28:10 -08004522 /**
4523 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4524 * @param subId The subscription to use to check the configuration.
4525 * @param c The callback that will be used to send the result.
4526 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004527 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004528 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4529 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004530 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004531 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004532
4533 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4534 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4535 "IMS not available on device.");
4536 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 final long token = Binder.clearCallingIdentity();
4538 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004539 int slotId = getSlotIndexOrException(subId);
4540 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004541
4542 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4543 if (controller != null) {
4544 ImsManager imsManager = controller.getImsManager(subId);
4545 if (imsManager != null) {
4546 imsManager.addRegistrationCallbackForSubscription(c, subId);
4547 } else {
4548 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4549 }
4550 } else {
4551 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4552 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004553 } catch (ImsException e) {
4554 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004555 } finally {
4556 Binder.restoreCallingIdentity(token);
4557 }
4558 }
4559
shilu366312e2019-12-17 09:28:10 -08004560 /**
4561 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4562 * @param subId The subscription to use to check the configuration.
4563 * @param c The callback that will be used to send the result.
4564 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004565 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004566 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004567 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004568 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004569 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4570 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4571 }
Meng Wangafbc5852019-09-19 17:37:13 -07004572 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004573
Meng Wangafbc5852019-09-19 17:37:13 -07004574 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004575 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4576 if (controller != null) {
4577 ImsManager imsManager = controller.getImsManager(subId);
4578 if (imsManager != null) {
4579 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4580 } else {
4581 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4582 + "is inactive, ignoring unregister.");
4583 // If the ImsManager is not valid, just return, since the callback
4584 // will already have been removed internally.
4585 }
4586 }
Meng Wangafbc5852019-09-19 17:37:13 -07004587 } finally {
4588 Binder.restoreCallingIdentity(token);
4589 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004590 }
4591
Brad Ebingera34a6c22019-10-22 17:36:18 -07004592 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004593 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4594 * @param subId The subscription to use to check the configuration.
4595 * @param c The callback that will be used to send the result.
4596 */
4597 @Override
4598 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4599 throws RemoteException {
4600 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4601 mApp, subId, "registerImsEmergencyRegistrationCallback");
4602
4603 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4604 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4605 "IMS not available on device.");
4606 }
4607 final long token = Binder.clearCallingIdentity();
4608 try {
4609 int slotId = getSlotIndexOrException(subId);
4610 verifyImsMmTelConfiguredOrThrow(slotId);
4611
4612 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4613 if (controller != null) {
4614 ImsManager imsManager = controller.getImsManager(subId);
4615 if (imsManager != null) {
4616 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4617 } else {
4618 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4619 }
4620 } else {
4621 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4622 }
4623 } catch (ImsException e) {
4624 throw new ServiceSpecificException(e.getCode());
4625 } finally {
4626 Binder.restoreCallingIdentity(token);
4627 }
4628 }
4629
4630 /**
4631 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4632 * @param subId The subscription to use to check the configuration.
4633 * @param c The callback that will be used to send the result.
4634 */
4635 @Override
4636 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4637 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4638 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4639 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4640 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4641 }
4642 final long token = Binder.clearCallingIdentity();
4643
4644 try {
4645 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4646 if (controller != null) {
4647 ImsManager imsManager = controller.getImsManager(subId);
4648 if (imsManager != null) {
4649 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4650 } else {
4651 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4652 + "is inactive, ignoring unregister.");
4653 // If the ImsManager is not valid, just return, since the callback
4654 // will already have been removed internally.
4655 }
4656 }
4657 } finally {
4658 Binder.restoreCallingIdentity(token);
4659 }
4660 }
4661
4662 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004663 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4664 */
4665 @Override
4666 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4667 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4668 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4669 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4670 "IMS not available on device.");
4671 }
4672 final long token = Binder.clearCallingIdentity();
4673 try {
4674 Phone phone = getPhone(subId);
4675 if (phone == null) {
4676 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4677 + subId + "'");
4678 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4679 }
4680 phone.getImsRegistrationState(regState -> {
4681 try {
4682 consumer.accept((regState == null)
4683 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4684 } catch (RemoteException e) {
4685 // Ignore if the remote process is no longer available to call back.
4686 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4687 }
4688 });
4689 } finally {
4690 Binder.restoreCallingIdentity(token);
4691 }
4692 }
4693
4694 /**
4695 * Get the transport type for the IMS service registration state.
4696 */
4697 @Override
4698 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004699 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004700 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004701 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4702 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4703 "IMS not available on device.");
4704 }
4705 final long token = Binder.clearCallingIdentity();
4706 try {
4707 Phone phone = getPhone(subId);
4708 if (phone == null) {
4709 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4710 + subId + "'");
4711 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4712 }
4713 phone.getImsRegistrationTech(regTech -> {
4714 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4715 int regTechConverted = (regTech == null)
4716 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4717 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4718 regTechConverted);
4719 try {
4720 consumer.accept(regTechConverted);
4721 } catch (RemoteException e) {
4722 // Ignore if the remote process is no longer available to call back.
4723 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4724 }
4725 });
4726 } finally {
4727 Binder.restoreCallingIdentity(token);
4728 }
4729 }
4730
shilu366312e2019-12-17 09:28:10 -08004731 /**
4732 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4733 * @param subId The subscription to use to check the configuration.
4734 * @param c The callback that will be used to send the result.
4735 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004736 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004737 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4738 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004739 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004740 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004741 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4742 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4743 "IMS not available on device.");
4744 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004745 final long token = Binder.clearCallingIdentity();
4746 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004747 int slotId = getSlotIndexOrException(subId);
4748 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004749
4750 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4751 if (controller != null) {
4752 ImsManager imsManager = controller.getImsManager(subId);
4753 if (imsManager != null) {
4754 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4755 } else {
4756 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4757 }
4758 } else {
4759 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4760 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004761 } catch (ImsException e) {
4762 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004763 } finally {
4764 Binder.restoreCallingIdentity(token);
4765 }
4766 }
4767
shilu366312e2019-12-17 09:28:10 -08004768 /**
4769 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4770 * @param subId The subscription to use to check the configuration.
4771 * @param c The callback that will be used to send the result.
4772 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004773 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004774 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004775 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004776 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004777 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4778 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4779 }
Meng Wangafbc5852019-09-19 17:37:13 -07004780
4781 final long token = Binder.clearCallingIdentity();
4782 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004783 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4784 if (controller != null) {
4785 ImsManager imsManager = controller.getImsManager(subId);
4786 if (imsManager != null) {
4787 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4788 } else {
4789 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4790 + " is inactive, ignoring unregister.");
4791 // If the ImsManager is not valid, just return, since the callback
4792 // will already have been removed internally.
4793 }
4794 }
Meng Wangafbc5852019-09-19 17:37:13 -07004795 } finally {
4796 Binder.restoreCallingIdentity(token);
4797 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004798 }
4799
4800 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004801 public boolean isCapable(int subId, int capability, int regTech) {
4802 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004803
4804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4805 FEATURE_TELEPHONY_IMS, "isCapable");
4806
Brad Ebinger35c841c2018-10-01 10:40:55 -07004807 final long token = Binder.clearCallingIdentity();
4808 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004809 int slotId = getSlotIndexOrException(subId);
4810 verifyImsMmTelConfiguredOrThrow(slotId);
4811 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4812 } catch (com.android.ims.ImsException e) {
4813 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4814 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004815 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004816 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4817 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004818 } finally {
4819 Binder.restoreCallingIdentity(token);
4820 }
4821 }
4822
4823 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004824 public boolean isAvailable(int subId, int capability, int regTech) {
4825 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004826
4827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4828 FEATURE_TELEPHONY_IMS, "isAvailable");
4829
Brad Ebinger35c841c2018-10-01 10:40:55 -07004830 final long token = Binder.clearCallingIdentity();
4831 try {
4832 Phone phone = getPhone(subId);
4833 if (phone == null) return false;
4834 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004835 } catch (com.android.ims.ImsException e) {
4836 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4837 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 } finally {
4839 Binder.restoreCallingIdentity(token);
4840 }
4841 }
4842
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004843 /**
4844 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4845 * subscription.
4846 * @param subId The subscription to use to check the configuration.
4847 * @param callback The callback that will be used to send the result.
4848 * @param capability The MmTelFeature capability that will be used to send the result.
4849 * @param transportType The transport type of the MmTelFeature capability.
4850 */
4851 @Override
4852 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4853 int transportType) {
4854 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004855 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4856 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4857 "IMS not available on device.");
4858 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004859 final long token = Binder.clearCallingIdentity();
4860 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004861 int slotId = getSlotIndex(subId);
4862 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4863 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4864 + subId + "'");
4865 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4866 }
4867 verifyImsMmTelConfiguredOrThrow(slotId);
4868 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4869 transportType, aBoolean -> {
4870 try {
4871 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4872 } catch (RemoteException e) {
4873 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4874 + "running. Ignore");
4875 }
4876 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004877 } catch (ImsException e) {
4878 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004879 } finally {
4880 Binder.restoreCallingIdentity(token);
4881 }
4882 }
4883
shilu366312e2019-12-17 09:28:10 -08004884 /**
4885 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4886 * @param subId The subscription to use to check the configuration.
4887 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004888 @Override
4889 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004890 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004891 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004892
joonhunshin4ac60942023-11-15 15:23:39 +00004893 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4894 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4895
Brad Ebinger35c841c2018-10-01 10:40:55 -07004896 final long token = Binder.clearCallingIdentity();
4897 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004898 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004899 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004900 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004901 } catch (ImsException e) {
4902 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004903 } finally {
4904 Binder.restoreCallingIdentity(token);
4905 }
4906 }
4907
4908 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004909 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004911 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004912
4913 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4914 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4915
Brad Ebinger35c841c2018-10-01 10:40:55 -07004916 final long identity = Binder.clearCallingIdentity();
4917 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004918 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004919 // This setting doesn't require an active ImsService connection, so do not verify. The
4920 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004921 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004922 } catch (ImsException e) {
4923 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004924 } finally {
4925 Binder.restoreCallingIdentity(identity);
4926 }
4927 }
4928
shilu366312e2019-12-17 09:28:10 -08004929 /**
4930 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4931 * @param subId The subscription to use to check the configuration.
4932 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004933 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004934 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004935 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004936 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004937
4938 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4939 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4940
Brad Ebinger35c841c2018-10-01 10:40:55 -07004941 final long identity = Binder.clearCallingIdentity();
4942 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004943 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004944 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004945 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004946 } catch (ImsException e) {
4947 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
4951 }
4952
4953 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004954 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004956 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004957
4958 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4959 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4960
Brad Ebinger35c841c2018-10-01 10:40:55 -07004961 final long identity = Binder.clearCallingIdentity();
4962 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004963 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004964 // This setting doesn't require an active ImsService connection, so do not verify. The
4965 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004966 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004967 } catch (ImsException e) {
4968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
4972 }
4973
shilu366312e2019-12-17 09:28:10 -08004974 /**
4975 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4976 * @param subId The subscription to use to check the configuration.
4977 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004978 @Override
4979 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004980 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004981 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004982
4983 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4984 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4985
Brad Ebinger35c841c2018-10-01 10:40:55 -07004986 final long identity = Binder.clearCallingIdentity();
4987 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004988 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004989 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004990 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004991 } catch (ImsException e) {
4992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
4996 }
4997
4998 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004999 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005001 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005002
5003 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5004 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5005
Brad Ebinger35c841c2018-10-01 10:40:55 -07005006 final long identity = Binder.clearCallingIdentity();
5007 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005008 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005009 // This setting doesn't require an active ImsService connection, so do not verify. The
5010 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005011 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005012 } catch (ImsException e) {
5013 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
5017 }
5018
shilu366312e2019-12-17 09:28:10 -08005019 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005020 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5021 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5022 * @param subId The subscription to use to check the configuration.
5023 */
5024 @Override
5025 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005026 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005027 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005028
5029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5030 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5031
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005032 final long identity = Binder.clearCallingIdentity();
5033 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005034 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005035 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005036 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005037 } catch (ImsException e) {
5038 throw new ServiceSpecificException(e.getCode());
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
5041 }
5042 }
5043
5044 /**
5045 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5046 * Requires MODIFY_PHONE_STATE permission.
5047 * @param subId The subscription to use to check the configuration.
5048 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5049 * false otherwise
5050 */
5051 @Override
5052 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5054 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005055
5056 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5057 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5058
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005061 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005062 // This setting doesn't require an active ImsService connection, so do not verify. The
5063 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005064 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005065 } catch (ImsException e) {
5066 throw new ServiceSpecificException(e.getCode());
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
5069 }
5070 }
5071
5072 /**
shilu366312e2019-12-17 09:28:10 -08005073 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5074 * @param subId The subscription to use to check the configuration.
5075 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005076 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005077
Brad Ebinger35c841c2018-10-01 10:40:55 -07005078 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005079 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005080 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005081
5082 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5083 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5084
Brad Ebinger35c841c2018-10-01 10:40:55 -07005085 final long identity = Binder.clearCallingIdentity();
5086 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005087 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005088 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005089 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005090 } catch (ImsException e) {
5091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005092 } finally {
5093 Binder.restoreCallingIdentity(identity);
5094 }
5095 }
5096
5097 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005098 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005100 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005101
5102 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5103 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5104
Brad Ebinger35c841c2018-10-01 10:40:55 -07005105 final long identity = Binder.clearCallingIdentity();
5106 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005107 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005108 // This setting doesn't require an active ImsService connection, so do not verify. The
5109 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005110 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005111 } catch (ImsException e) {
5112 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005113 } finally {
5114 Binder.restoreCallingIdentity(identity);
5115 }
5116 }
5117
5118 @Override
5119 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5121 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005122
5123 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5124 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5125
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 final long identity = Binder.clearCallingIdentity();
5127 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005128 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005129 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005130 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005131 } catch (ImsException e) {
5132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
5136 }
5137
shilu366312e2019-12-17 09:28:10 -08005138 /**
5139 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5140 * @param subId The subscription to use to check the configuration.
5141 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005142 @Override
5143 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005144 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005145 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005146
5147 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5148 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5149
Brad Ebinger35c841c2018-10-01 10:40:55 -07005150 final long identity = Binder.clearCallingIdentity();
5151 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005152 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005153 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005154 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005155 } catch (ImsException e) {
5156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
5160 }
5161
5162 @Override
5163 public void setVoWiFiModeSetting(int subId, int mode) {
5164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5165 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005166
5167 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5168 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5169
Brad Ebinger35c841c2018-10-01 10:40:55 -07005170 final long identity = Binder.clearCallingIdentity();
5171 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005172 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005173 // This setting doesn't require an active ImsService connection, so do not verify. The
5174 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005175 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005176 } catch (ImsException e) {
5177 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
5181 }
5182
5183 @Override
5184 public int getVoWiFiRoamingModeSetting(int subId) {
5185 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005186
5187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5188 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5189
Brad Ebinger35c841c2018-10-01 10:40:55 -07005190 final long identity = Binder.clearCallingIdentity();
5191 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005192 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005193 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005195 } catch (ImsException e) {
5196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
5200 }
5201
5202 @Override
5203 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5205 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005206
5207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5208 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5209
Brad Ebinger35c841c2018-10-01 10:40:55 -07005210 final long identity = Binder.clearCallingIdentity();
5211 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005212 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005213 // This setting doesn't require an active ImsService connection, so do not verify. The
5214 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005215 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005216 } catch (ImsException e) {
5217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
5221 }
5222
5223 @Override
5224 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5226 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005227
5228 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5229 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5230
Brad Ebinger35c841c2018-10-01 10:40:55 -07005231 final long identity = Binder.clearCallingIdentity();
5232 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005233 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005234 // This setting doesn't require an active ImsService connection, so do not verify. The
5235 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005236 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005237 } catch (ImsException e) {
5238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
5242 }
5243
shilu366312e2019-12-17 09:28:10 -08005244 /**
5245 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5246 * @param subId The subscription to use to check the configuration.
5247 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005248 @Override
5249 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005250 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005251 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005252
5253 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5254 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5255
Brad Ebinger35c841c2018-10-01 10:40:55 -07005256 final long identity = Binder.clearCallingIdentity();
5257 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005258 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005259 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005260 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005261 } catch (ImsException e) {
5262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
5266 }
5267
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005268 @Override
5269 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5270 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005271
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005272 final long identity = Binder.clearCallingIdentity();
5273 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005274 if (!isImsAvailableOnDevice()) {
5275 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5276 "IMS not available on device.");
5277 }
5278 int slotId = getSlotIndexOrException(subId);
5279 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005280
5281 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5282 if (controller != null) {
5283 ImsManager imsManager = controller.getImsManager(subId);
5284 if (imsManager != null) {
5285 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5286 } else {
5287 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5288 }
5289 } else {
5290 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5291 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005292 } catch (ImsException e) {
5293 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
5297 }
5298
5299 @Override
5300 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5301 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005302
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005303 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005304 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5305 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5306 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005307 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005308 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5309 if (controller != null) {
5310 ImsManager imsManager = controller.getImsManager(subId);
5311 if (imsManager != null) {
5312 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5313 } else {
5314 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5315 + " is inactive, ignoring unregister.");
5316 // If the ImsManager is not valid, just return, since the callback will already
5317 // have been removed internally.
5318 }
5319 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322 }
5323 }
5324
joonhunshincffb7fc2021-11-28 07:32:01 +00005325 @Override
5326 public void registerFeatureProvisioningChangedCallback(int subId,
5327 IFeatureProvisioningCallback callback) {
5328 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5329 mApp, subId, "registerFeatureProvisioningChangedCallback");
5330
5331 final long identity = Binder.clearCallingIdentity();
5332 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5333 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5334 }
5335
joonhunshin91bc1952022-04-29 08:47:15 +00005336 try {
5337 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5338 if (controller == null) {
5339 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5340 "Device does not support IMS");
5341 }
5342 controller.addFeatureProvisioningChangedCallback(subId, callback);
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
5345 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005346 }
5347
5348 @Override
5349 public void unregisterFeatureProvisioningChangedCallback(int subId,
5350 IFeatureProvisioningCallback callback) {
5351 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5352 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5353
5354 final long identity = Binder.clearCallingIdentity();
5355 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5356 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5357 }
5358
joonhunshin91bc1952022-04-29 08:47:15 +00005359 try {
5360 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5361 if (controller == null) {
5362 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5363 return;
5364 }
5365 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
5368 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005369 }
allenwtsu99c623b2020-01-03 18:24:23 +08005370
5371 private void checkModifyPhoneStatePermission(int subId, String message) {
5372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5373 message);
5374 }
5375
allenwtsu99c623b2020-01-03 18:24:23 +08005376 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005377 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005378 boolean isProvisioned) {
5379 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5380
joonhunshin4ac60942023-11-15 15:23:39 +00005381 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5382 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5383
allenwtsu99c623b2020-01-03 18:24:23 +08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005386 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5387 if (controller == null) {
5388 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5389 return;
5390 }
5391 controller.setRcsProvisioningStatusForCapability(
5392 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005393 } finally {
5394 Binder.restoreCallingIdentity(identity);
5395 }
allenwtsu99c623b2020-01-03 18:24:23 +08005396 }
5397
5398
5399 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005400 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5401 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5402 mApp, subId, "getRcsProvisioningStatusForCapability");
5403
joonhunshin4ac60942023-11-15 15:23:39 +00005404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5405 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5406
allenwtsu99c623b2020-01-03 18:24:23 +08005407 final long identity = Binder.clearCallingIdentity();
5408 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005409 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5410 if (controller == null) {
5411 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5412
5413 // device does not support IMS, this method will return true always.
5414 return true;
5415 }
5416 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
5420 }
5421
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005422 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005423 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5424 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005425 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005426
joonhunshin4ac60942023-11-15 15:23:39 +00005427 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5428 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5429
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005432 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5433 if (controller == null) {
5434 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5435 return;
5436 }
5437 controller.setImsProvisioningStatusForCapability(
5438 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005439 } finally {
5440 Binder.restoreCallingIdentity(identity);
5441 }
5442 }
5443
5444 @Override
5445 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005446 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5447 mApp, subId, "getProvisioningStatusForCapability");
5448
joonhunshin4ac60942023-11-15 15:23:39 +00005449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5450 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5451
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005454 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5455 if (controller == null) {
5456 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005457
joonhunshin91bc1952022-04-29 08:47:15 +00005458 // device does not support IMS, this method will return true always.
5459 return true;
5460 }
5461 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
5465 }
5466
5467 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005468 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5469 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5470 mApp, subId, "isProvisioningRequiredForCapability");
5471
joonhunshin4ac60942023-11-15 15:23:39 +00005472 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5473 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5474
joonhunshincffb7fc2021-11-28 07:32:01 +00005475 final long identity = Binder.clearCallingIdentity();
5476 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005477 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5478 if (controller == null) {
5479 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5480
5481 // device does not support IMS, this method will return false
5482 return false;
5483 }
5484 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005485 } finally {
5486 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005487 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005488 }
5489
5490 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005491 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5492 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5493 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005494
joonhunshin4ac60942023-11-15 15:23:39 +00005495 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5496 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5497
joonhunshincffb7fc2021-11-28 07:32:01 +00005498 final long identity = Binder.clearCallingIdentity();
5499 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005500 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5501 if (controller == null) {
5502 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5503
5504 // device does not support IMS, this method will return false
5505 return false;
5506 }
5507 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
5510 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005511 }
5512
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005513 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005514 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005515 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5516 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5517 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005518 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5519 mApp, subId, "getImsProvisioningInt");
5520
joonhunshin4ac60942023-11-15 15:23:39 +00005521 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5522 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5523
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005527 int slotId = getSlotIndex(subId);
5528 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5529 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5530 + subId + "' for key:" + key);
5531 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5532 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005533
joonhunshin91bc1952022-04-29 08:47:15 +00005534 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5535 if (controller == null) {
5536 loge("getImsProvisioningInt: Device does not support IMS");
5537
5538 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5539 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5540 }
5541 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005542 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5543 return retVal;
5544 }
5545
calvinpanb5a34062021-02-08 19:59:36 +08005546 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005547 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005548 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5549 + subId + "' for key:" + key);
5550 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
5554 }
5555
5556 @Override
5557 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005558 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5559 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5560 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005561 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5562 mApp, subId, "getImsProvisioningString");
5563
joonhunshin4ac60942023-11-15 15:23:39 +00005564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5565 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5566
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005567 final long identity = Binder.clearCallingIdentity();
5568 try {
5569 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005570 int slotId = getSlotIndex(subId);
5571 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5572 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5573 + subId + "' for key:" + key);
5574 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5575 }
calvinpanb5a34062021-02-08 19:59:36 +08005576 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005577 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005578 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5579 + subId + "' for key:" + key);
5580 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
5584 }
5585
5586 @Override
5587 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005588 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5589 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5590 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5592 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005593
joonhunshin4ac60942023-11-15 15:23:39 +00005594 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5595 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5596
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005600 int slotId = getSlotIndex(subId);
5601 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5602 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5603 + subId + "' for key:" + key);
5604 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5605 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005606
joonhunshin91bc1952022-04-29 08:47:15 +00005607 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5608 if (controller == null) {
5609 loge("setImsProvisioningInt: Device does not support IMS");
5610
5611 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5612 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5613 }
5614 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005615 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5616 return retVal;
5617 }
5618
calvinpanb5a34062021-02-08 19:59:36 +08005619 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5620 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005621 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005622 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005623 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
5627 }
5628
5629 @Override
5630 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005631 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5632 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5633 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5635 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005636
5637 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5638 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5639
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005643 int slotId = getSlotIndex(subId);
5644 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5645 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5646 + subId + "' for key:" + key);
5647 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5648 }
calvinpanb5a34062021-02-08 19:59:36 +08005649 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5650 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005651 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005652 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005653 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
5657 }
5658
Brad Ebinger919631e2021-06-02 17:46:35 -07005659 /**
5660 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5661 * for the given slot ID or no ImsResolver instance has been created.
5662 * @param slotId The slot ID that the IMS service is created for.
5663 * @throws ImsException If there is no ImsService configured for this slot.
5664 */
5665 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5666 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5667 ImsFeature.FEATURE_MMTEL)) {
5668 throw new ImsException("This subscription does not support MMTEL over IMS",
5669 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5670 }
5671 }
5672
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005673 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005674 int slotId = SubscriptionManager.getSlotIndex(subId);
5675 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005676 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5677 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005678 }
5679 return slotId;
5680 }
5681
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005682 private int getSlotIndex(int subId) {
5683 int slotId = SubscriptionManager.getSlotIndex(subId);
5684 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5685 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5686 }
5687 return slotId;
5688 }
5689
Wink Saville36469e72014-06-11 15:17:00 -07005690 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005691 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005692 */
5693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005694 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5695 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005696 try {
5697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5698 } catch (SecurityException se) {
5699 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5700 throw new SecurityException("Package " + callingPackage + " does not belong to "
5701 + Binder.getCallingUid());
5702 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005703 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005704 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005705 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005706 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005707 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005708 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005709 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005710 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5711 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005712
joonhunshin4ac60942023-11-15 15:23:39 +00005713 enforceTelephonyFeatureWithException(callingPackage,
5714 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 final Phone phone = getPhone(subId);
5719 if (phone != null) {
5720 return phone.getServiceState().getDataNetworkType();
5721 } else {
5722 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5723 }
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005727 }
5728
5729 /**
5730 * Returns the data network type
5731 */
5732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005733 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005734 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005735 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005736 }
5737
5738 /**
5739 * Returns the data network type for a subId
5740 */
5741 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005742 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5743 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005744 String functionName = "getDataNetworkTypeForSubscriber";
5745 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5746 mApp, functionName)) {
5747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5748 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5749 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5750 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005751 }
5752
joonhunshin4ac60942023-11-15 15:23:39 +00005753 enforceTelephonyFeatureWithException(callingPackage,
5754 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 final Phone phone = getPhone(subId);
5759 if (phone != null) {
5760 return phone.getServiceState().getDataNetworkType();
5761 } else {
5762 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5763 }
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005767 }
5768
5769 /**
Wink Saville36469e72014-06-11 15:17:00 -07005770 * Returns the Voice network type for a subId
5771 */
5772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005773 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5774 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005775 String functionName = "getVoiceNetworkTypeForSubscriber";
5776 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5777 mApp, functionName)) {
5778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5779 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5780 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5781 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005782 }
5783
joonhunshin4ac60942023-11-15 15:23:39 +00005784 enforceTelephonyFeatureWithException(callingPackage,
5785 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 final Phone phone = getPhone(subId);
5790 if (phone != null) {
5791 return phone.getServiceState().getVoiceNetworkType();
5792 } else {
5793 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5794 }
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005798 }
5799
5800 /**
5801 * @return true if a ICC card is present
5802 */
5803 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005804 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005805 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005806 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005807 }
5808
5809 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005810 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005811 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005812 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005813 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005814 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5815 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 final Phone phone = PhoneFactory.getPhone(slotIndex);
5820 if (phone != null) {
5821 return phone.getIccCard().hasIccCard();
5822 } else {
5823 return false;
5824 }
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005828 }
5829
5830 /**
5831 * Return if the current radio is LTE on CDMA. This
5832 * is a tri-state return value as for a period of time
5833 * the mode may be unknown.
5834 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005835 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005836 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005837 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005838 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005839 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005840 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5841 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5842 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005843 }
5844
Sanket Padawe356d7632015-06-22 14:03:32 -07005845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005846 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5847 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005848 try {
5849 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5850 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005851 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5852 }
5853
joonhunshin4ac60942023-11-15 15:23:39 +00005854 enforceTelephonyFeatureWithException(callingPackage,
5855 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 final Phone phone = getPhone(subId);
5860 if (phone == null) {
5861 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5862 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005863 return TelephonyProperties.lte_on_cdma_device()
5864 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 }
5866 } finally {
5867 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005868 }
Wink Saville36469e72014-06-11 15:17:00 -07005869 }
5870
Wink Saville36469e72014-06-11 15:17:00 -07005871 /**
5872 * {@hide}
5873 * Returns Default subId, 0 in the case of single standby.
5874 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005875 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005876 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005877 }
5878
Shishir Agrawala9f32182016-04-12 12:00:16 -07005879 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005880 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005881 }
5882
Wink Savilleb564aae2014-10-23 10:18:09 -07005883 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005884 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005885 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005886
Pengquan Menge92a50d2018-09-21 15:54:48 -07005887 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005888 return getSubscriptionManagerService().isActiveSubId(subId,
5889 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005890 }
5891
Ihab Awadf2177b72013-11-25 13:33:23 -08005892 /**
5893 * @see android.telephony.TelephonyManager.WifiCallingChoices
5894 */
5895 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 final long identity = Binder.clearCallingIdentity();
5897 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005898 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5900 getWhenToMakeWifiCallsDefaultPreference());
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005904 }
5905
5906 /**
5907 * @see android.telephony.TelephonyManager.WifiCallingChoices
5908 */
5909 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 final long identity = Binder.clearCallingIdentity();
5911 try {
5912 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005913 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005918 }
5919
Sailesh Nepald1e68152013-12-12 19:08:02 -08005920 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005921 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005922 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005923 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005924
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005925 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5926 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5927 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005928 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005929 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005930 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005931 }
5932 return PhoneFactory.getPhone(phoneId);
5933 }
5934
Shishir Agrawal566b7612013-10-28 14:41:00 -07005935 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005936 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005937 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005938
Rambo Wanga1782702021-11-10 20:15:19 -08005939 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5940 /*message=*/ "iccOpenLogicalChannel");
5941
5942 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5943 // Verify that the callingPackage in the request belongs to the calling UID
5944 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5945
joonhunshin4ac60942023-11-15 15:23:39 +00005946 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5947 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5948
Rambo Wanga1782702021-11-10 20:15:19 -08005949 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005950 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005951
Rambo Wanga1782702021-11-10 20:15:19 -08005952 private Phone getPhoneFromValidIccLogicalChannelRequest(
5953 @NonNull IccLogicalChannelRequest request, String message) {
5954 Phone phone;
5955 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5957 mApp, request.subId, message);
5958 phone = getPhoneFromSubId(request.subId);
5959 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5960 enforceModifyPermission();
5961 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5962 } else {
5963 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005964 }
Rambo Wanga1782702021-11-10 20:15:19 -08005965 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005966 }
5967
5968 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005969 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 final long identity = Binder.clearCallingIdentity();
5971 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005972 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005974 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5975 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005976 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5977 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 loge("The calling package is not allowed to access ISD-R.");
5979 throw new SecurityException(
5980 "The calling package is not allowed to access ISD-R.");
5981 }
Derek Tan740e1672017-06-27 14:56:27 -07005982 }
Derek Tan740e1672017-06-27 14:56:27 -07005983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005985 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5986 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 return response;
5988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005991 }
5992
5993 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005994 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005995 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5996 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5997
Rambo Wanga1782702021-11-10 20:15:19 -08005998 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5999 /*message=*/"iccCloseLogicalChannel");
6000
6001 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6002
6003 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006004 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006005
Rambo Wanga1782702021-11-10 20:15:19 -08006006 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6007 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006008 // before this feature is enabled, this API should only return false if
6009 // the operation fails instead of throwing runtime exception for
6010 // backward-compatibility.
6011 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6012 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 final long identity = Binder.clearCallingIdentity();
6014 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006015 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006016 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 }
Chen Xue9d737e2022-01-01 23:41:31 -08006018 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006019 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006020 Boolean success = false;
6021 if (result instanceof RuntimeException) {
6022 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006023 if (shouldThrowExceptionOnFailure) {
6024 throw (RuntimeException) result;
6025 } else {
6026 return false;
6027 }
Chen Xue9d737e2022-01-01 23:41:31 -08006028 } else if (result instanceof Boolean) {
6029 success = (Boolean) result;
6030 } else {
6031 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6032 }
Rambo Wanga1782702021-11-10 20:15:19 -08006033 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 return success;
6035 } finally {
6036 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006037 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006038 }
6039
6040 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006041 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006042 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6044 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006045
6046 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6047 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6048
Jordan Liu4c733742019-02-28 12:03:40 -08006049 if (DBG) {
6050 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6051 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6052 + p3 + " data=" + data);
6053 }
6054 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6055 command, p1, p2, p3, data);
6056 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006057
Jordan Liu4c733742019-02-28 12:03:40 -08006058 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006059 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006060 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006061 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006062
6063 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6064 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6065 "iccTransmitApduLogicalChannelBySlot");
6066
Jordan Liu4c733742019-02-28 12:03:40 -08006067 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006068 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006069 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6070 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006071 }
6072 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006073 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6074 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006075 }
6076
6077 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6078 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 final long identity = Binder.clearCallingIdentity();
6080 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006081 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 return "";
6083 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006086 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6087 null /* workSource */);
6088 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 // Append the returned status code to the end of the response payload.
6091 String s = Integer.toHexString(
6092 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6093 if (response.payload != null) {
6094 s = IccUtils.bytesToHexString(response.payload) + s;
6095 }
6096 return s;
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006099 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006100 }
Jake Hambye994d462014-02-03 13:10:13 -08006101
Evan Charltonc66da362014-05-16 14:06:40 -07006102 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006103 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6104 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6106 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006108
6109 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6110 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6111
Jordan Liu4c733742019-02-28 12:03:40 -08006112 if (DBG) {
6113 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6114 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6115 }
6116 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6117 cla, command, p1, p2, p3, data);
6118 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006119
Jordan Liu4c733742019-02-28 12:03:40 -08006120 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006121 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006122 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006123 enforceModifyPermission();
6124 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006125
6126 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6127 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6128
Jordan Liu4c733742019-02-28 12:03:40 -08006129 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006130 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006131 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6132 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006133 }
6134
6135 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006136 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6137 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006138 }
6139
6140 // open APDU basic channel assuming the caller has sufficient permissions
6141 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6142 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 final long identity = Binder.clearCallingIdentity();
6144 try {
6145 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6146 && TextUtils.equals(ISDR_AID, data)) {
6147 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006148 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6149 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 if (bestComponent == null
6151 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6152 loge("The calling package is not allowed to select ISD-R.");
6153 throw new SecurityException(
6154 "The calling package is not allowed to select ISD-R.");
6155 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006156 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006159 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6160 null /* workSource */);
6161 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 // Append the returned status code to the end of the response payload.
6164 String s = Integer.toHexString(
6165 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6166 if (response.payload != null) {
6167 s = IccUtils.bytesToHexString(response.payload) + s;
6168 }
6169 return s;
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006172 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006173 }
6174
6175 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006176 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006177 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6179 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006180
joonhunshin4ac60942023-11-15 15:23:39 +00006181 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6182 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 final long identity = Binder.clearCallingIdentity();
6185 try {
6186 if (DBG) {
6187 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6188 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6189 }
6190
6191 IccIoResult response =
6192 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6193 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6194 subId);
6195
6196 if (DBG) {
6197 log("Exchange SIM_IO [R]" + response);
6198 }
6199
6200 byte[] result = null;
6201 int length = 2;
6202 if (response.payload != null) {
6203 length = 2 + response.payload.length;
6204 result = new byte[length];
6205 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6206 } else {
6207 result = new byte[length];
6208 }
6209
6210 result[length - 1] = (byte) response.sw2;
6211 result[length - 2] = (byte) response.sw1;
6212 return result;
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006215 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006216 }
6217
Nathan Haroldb3014052017-01-25 15:57:32 -08006218 /**
6219 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6220 * on a particular subscription
6221 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006222 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6223 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006225 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006226 return null;
6227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228
joonhunshin4ac60942023-11-15 15:23:39 +00006229 enforceTelephonyFeatureWithException(callingPackage,
6230 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 final long identity = Binder.clearCallingIdentity();
6233 try {
6234 if (appType != TelephonyManager.APPTYPE_USIM
6235 && appType != TelephonyManager.APPTYPE_SIM) {
6236 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6237 return null;
6238 }
6239 Object response = sendRequest(
6240 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6241 if (response instanceof String[]) {
6242 return (String[]) response;
6243 }
yincheng zhao2737e882019-09-06 17:06:54 -07006244 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006246 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006247 } finally {
6248 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006249 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006250 }
6251
yincheng zhao2737e882019-09-06 17:06:54 -07006252 /**
6253 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6254 * subscription.
6255 *
6256 * @param subId the id of the subscription.
6257 * @param appType the uicc app type, must be USIM or SIM.
6258 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6259 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006260 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006261 * @return number of fplmns that is successfully written to the SIM.
6262 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006263 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6264 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6266 mApp, subId, "setForbiddenPlmns");
6267
joonhunshin4ac60942023-11-15 15:23:39 +00006268 enforceTelephonyFeatureWithException(callingPackage,
6269 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6270
yincheng zhao2737e882019-09-06 17:06:54 -07006271 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6272 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6273 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6274 }
6275 if (fplmns == null) {
6276 throw new IllegalArgumentException("Fplmn List provided is null");
6277 }
6278 for (String fplmn : fplmns) {
6279 if (!CellIdentity.isValidPlmn(fplmn)) {
6280 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6281 }
6282 }
6283 final long identity = Binder.clearCallingIdentity();
6284 try {
6285 Object response = sendRequest(
6286 CMD_SET_FORBIDDEN_PLMNS,
6287 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6288 subId);
6289 return (int) response;
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
6292 }
6293 }
6294
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006295 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006296 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6298 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006299
joonhunshin4ac60942023-11-15 15:23:39 +00006300 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6301 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 final long identity = Binder.clearCallingIdentity();
6304 try {
6305 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6306 if (response.payload == null) {
6307 return "";
6308 }
Evan Charltonc66da362014-05-16 14:06:40 -07006309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 // Append the returned status code to the end of the response payload.
6311 String s = Integer.toHexString(
6312 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6313 s = IccUtils.bytesToHexString(response.payload) + s;
6314 return s;
6315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
Evan Charltonc66da362014-05-16 14:06:40 -07006318 }
6319
Jake Hambye994d462014-02-03 13:10:13 -08006320 /**
6321 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6322 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6323 *
6324 * @param itemID the ID of the item to read
6325 * @return the NV item as a String, or null on error.
6326 */
6327 @Override
6328 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006329 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6331 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
6335 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006336 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6338 return value;
6339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
Jake Hambye994d462014-02-03 13:10:13 -08006342 }
6343
6344 /**
6345 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6346 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6347 *
6348 * @param itemID the ID of the item to read
6349 * @param itemValue the value to write, as a String
6350 * @return true on success; false on any failure
6351 */
6352 @Override
6353 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6356 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6361 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006362 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6364 return success;
6365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
Jake Hambye994d462014-02-03 13:10:13 -08006368 }
6369
6370 /**
6371 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6372 * Used for device configuration by some CDMA operators.
6373 *
6374 * @param preferredRoamingList byte array containing the new PRL
6375 * @return true on success; false on any failure
6376 */
6377 @Override
6378 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6380 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381
6382 final long identity = Binder.clearCallingIdentity();
6383 try {
6384 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6385 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6386 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6387 return success;
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
Jake Hambye994d462014-02-03 13:10:13 -08006391 }
6392
6393 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006394 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006395 * Used for device configuration by some CDMA operators.
6396 *
chen xu6dac5ab2018-10-26 17:39:23 -07006397 * @param slotIndex - device slot.
6398 *
Jake Hambye994d462014-02-03 13:10:13 -08006399 * @return true on success; false on any failure
6400 */
6401 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006402 public boolean resetModemConfig(int slotIndex) {
6403 Phone phone = PhoneFactory.getPhone(slotIndex);
6404 if (phone != null) {
6405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6406 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407
joonhunshin4ac60942023-11-15 15:23:39 +00006408 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6409 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6410
chen xu6dac5ab2018-10-26 17:39:23 -07006411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6414 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6415 return success;
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 }
chen xu6dac5ab2018-10-26 17:39:23 -07006420 return false;
6421 }
6422
6423 /**
6424 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6425 *
6426 * @param slotIndex - device slot.
6427 *
6428 * @return true on success; false on any failure
6429 */
6430 @Override
6431 public boolean rebootModem(int slotIndex) {
6432 Phone phone = PhoneFactory.getPhone(slotIndex);
6433 if (phone != null) {
6434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6435 mApp, phone.getSubId(), "rebootModem");
6436
joonhunshin4ac60942023-11-15 15:23:39 +00006437 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6438 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6439
chen xu6dac5ab2018-10-26 17:39:23 -07006440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6443 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6444 return success;
6445 } finally {
6446 Binder.restoreCallingIdentity(identity);
6447 }
6448 }
6449 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006450 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006451
Brad Ebinger51f743a2017-01-23 13:50:20 -08006452 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006453 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6454 * {@link #disableIms(int)}.
6455 * @param slotIndex device slot.
6456 */
6457 public void resetIms(int slotIndex) {
6458 enforceModifyPermission();
6459
joonhunshin4ac60942023-11-15 15:23:39 +00006460 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6461 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6462
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 if (mImsResolver == null) {
6466 // may happen if the does not support IMS.
6467 return;
6468 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006469 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
6473 }
6474
6475 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006476 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6477 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006478 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006479 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006480 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006484 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006485 // may happen if the device does not support IMS.
6486 return;
6487 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006488 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006492 }
6493
6494 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006495 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6496 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006497 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006498 public void disableIms(int slotId) {
6499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500
6501 final long identity = Binder.clearCallingIdentity();
6502 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006503 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006504 // may happen if the device does not support IMS.
6505 return;
6506 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006507 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 } finally {
6509 Binder.restoreCallingIdentity(identity);
6510 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006511 }
6512
6513 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006514 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6515 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006516 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006517 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006518 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520
6521 final long identity = Binder.clearCallingIdentity();
6522 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006523 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006524 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6525 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006526 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006527 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006531 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006532 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006533 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6534 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006535 @Override
6536 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006537 enforceModifyPermission();
6538
6539 final long identity = Binder.clearCallingIdentity();
6540 try {
6541 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006542 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006543 } finally {
6544 Binder.restoreCallingIdentity(identity);
6545 }
6546 }
6547
6548 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006549 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006550 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006551 */
6552 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006557 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006558 // may happen if the device does not support IMS.
6559 return null;
6560 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006561 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006565 }
6566
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006567 /**
6568 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006569 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006570 */
6571 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573
6574 final long identity = Binder.clearCallingIdentity();
6575 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006576 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006577 // may happen if the device does not support IMS.
6578 return null;
6579 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006580 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006584 }
6585
Brad Ebinger884c07b2018-02-15 16:17:40 -08006586 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006587 * Sets the ImsService Package Name that Telephony will bind to.
6588 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006589 * @param slotIndex the slot ID that the ImsService should bind for.
6590 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006591 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006592 * @param featureTypes An integer array of feature types associated with a packageName.
6593 * @param packageName The name of the package that the current configuration will be replaced
6594 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006595 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006596 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006597 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6598 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006599 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006601 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 final long identity = Binder.clearCallingIdentity();
6604 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006605 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006606 // may happen if the device does not support IMS.
6607 return false;
6608 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006609 Map<Integer, String> featureConfig = new HashMap<>();
6610 for (int featureType : featureTypes) {
6611 featureConfig.put(featureType, packageName);
6612 }
6613 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6614 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 } finally {
6616 Binder.restoreCallingIdentity(identity);
6617 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006618 }
6619
6620 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006621 * Clears any carrier ImsService overrides for the slot index specified that were previously
6622 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6623 *
6624 * This should only be used for testing.
6625 *
6626 * @param slotIndex the slot ID that the ImsService should bind for.
6627 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6628 */
6629 @Override
6630 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6632 "clearCarrierImsServiceOverride");
6633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006634 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006635
6636 final long identity = Binder.clearCallingIdentity();
6637 try {
6638 if (mImsResolver == null) {
6639 // may happen if the device does not support IMS.
6640 return false;
6641 }
6642 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
6646 }
6647
6648 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006649 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006650 *
6651 * @param slotId The slot that the ImsService is associated with.
6652 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6653 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006655 * @return the package name of the ImsService configuration.
6656 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6658 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006659 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006660 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6661 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 final long identity = Binder.clearCallingIdentity();
6664 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006665 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006666 // may happen if the device does not support IMS.
6667 return "";
6668 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006669 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006670 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6671 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672 } finally {
6673 Binder.restoreCallingIdentity(identity);
6674 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006675 }
6676
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006677 /**
6678 * Get the MmTelFeature state associated with the requested subscription id.
6679 * @param subId The subscription that the MmTelFeature is associated with.
6680 * @param callback A callback with an integer containing the
6681 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6682 */
6683 @Override
6684 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6685 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006686 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6687 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6688 "IMS not available on device.");
6689 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006690 final long token = Binder.clearCallingIdentity();
6691 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006692 int slotId = getSlotIndex(subId);
6693 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6694 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6695 + subId + "'");
6696 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6697 }
6698 verifyImsMmTelConfiguredOrThrow(slotId);
6699 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6700 try {
6701 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6702 } catch (RemoteException e) {
6703 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6704 + "Ignore");
6705 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006706 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006707 } catch (ImsException e) {
6708 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006709 } finally {
6710 Binder.restoreCallingIdentity(token);
6711 }
6712 }
6713
Daniel Brightbb5840b2021-01-12 15:48:18 -08006714 /**
6715 * Sets the ims registration state on all valid {@link Phone}s.
6716 */
6717 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006718 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719
6720 final long identity = Binder.clearCallingIdentity();
6721 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006722 // NOTE: Before S, this method only set the default phone.
6723 for (final Phone phone : PhoneFactory.getPhones()) {
6724 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6725 phone.setImsRegistrationState(registered);
6726 }
6727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 } finally {
6729 Binder.restoreCallingIdentity(identity);
6730 }
Wink Saville36469e72014-06-11 15:17:00 -07006731 }
6732
6733 /**
Stuart Scott54788802015-03-30 13:18:01 -07006734 * Set the network selection mode to automatic.
6735 *
6736 */
6737 @Override
6738 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6740 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741
joonhunshin4ac60942023-11-15 15:23:39 +00006742 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6743 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 final long identity = Binder.clearCallingIdentity();
6746 try {
shilufc958392020-01-20 11:36:01 -08006747 if (!isActiveSubscription(subId)) {
6748 return;
6749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006751 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6752 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 } finally {
6754 Binder.restoreCallingIdentity(identity);
6755 }
Stuart Scott54788802015-03-30 13:18:01 -07006756 }
6757
Jack Yud10cdd42020-09-28 20:28:01 -07006758 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006759 * Ask the radio to connect to the input network and change selection mode to manual.
6760 *
6761 * @param subId the id of the subscription.
6762 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6763 * the operator to attach to.
6764 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6765 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6766 * normal network selection next time.
6767 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006768 */
6769 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006770 public boolean setNetworkSelectionModeManual(
6771 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6773 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006774
joonhunshin4ac60942023-11-15 15:23:39 +00006775 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6776 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6777
Jack Yu285100e2022-12-02 22:48:35 -08006778 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006779 if (!isActiveSubscription(subId)) {
6780 return false;
6781 }
6782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006784 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006786 if (DBG) {
6787 log("setNetworkSelectionModeManual: subId: " + subId
6788 + " operator: " + operatorInfo);
6789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006794 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006795 /**
shilu84f6e8b2019-12-19 13:58:01 -08006796 * Get the manual network selection
6797 *
6798 * @param subId the id of the subscription.
6799 *
6800 * @return the previously saved user selected PLMN
6801 */
6802 @Override
6803 public String getManualNetworkSelectionPlmn(int subId) {
6804 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006805 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6806 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006807
joonhunshin4ac60942023-11-15 15:23:39 +00006808 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6809 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6810
shilu84f6e8b2019-12-19 13:58:01 -08006811 final long identity = Binder.clearCallingIdentity();
6812 try {
6813 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006814 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006815 }
6816
6817 final Phone phone = getPhone(subId);
6818 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006819 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006820 }
6821 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6822 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006823 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006824 } finally {
6825 Binder.restoreCallingIdentity(identity);
6826 }
6827 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006828
6829 /**
6830 * Scans for available networks.
6831 */
6832 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006833 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6834 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6836 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006837 LocationAccessPolicy.LocationPermissionResult locationResult =
6838 LocationAccessPolicy.checkLocationPermission(mApp,
6839 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6840 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006841 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006842 .setCallingPid(Binder.getCallingPid())
6843 .setCallingUid(Binder.getCallingUid())
6844 .setMethod("getCellNetworkScanResults")
6845 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006846 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6847 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006848 .build());
6849 switch (locationResult) {
6850 case DENIED_HARD:
6851 throw new SecurityException("Not allowed to access scan results -- location");
6852 case DENIED_SOFT:
6853 return null;
6854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855
Pengquan Menga1bb6272018-09-06 09:59:22 -07006856 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 try {
6858 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006859 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 } finally {
6862 Binder.restoreCallingIdentity(identity);
6863 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006864 }
6865
6866 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006867 * Get the call forwarding info, given the call forwarding reason.
6868 */
6869 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006870 public void getCallForwarding(int subId, int callForwardingReason,
6871 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006872 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006873
6874 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6875 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6876
Shuo Qian4a594052020-01-23 11:59:30 -08006877 long identity = Binder.clearCallingIdentity();
6878 try {
6879 if (DBG) {
6880 log("getCallForwarding: subId " + subId
6881 + " callForwardingReason" + callForwardingReason);
6882 }
Hall Liu27d24262020-09-18 19:04:59 -07006883
6884 Phone phone = getPhone(subId);
6885 if (phone == null) {
6886 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006887 callback.onError(
6888 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006889 } catch (RemoteException e) {
6890 // ignore
6891 }
6892 return;
6893 }
6894
6895 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6896 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6897 @Override
6898 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6899 try {
6900 callback.onCallForwardingInfoAvailable(info);
6901 } catch (RemoteException e) {
6902 // ignore
6903 }
6904 }
6905
6906 @Override
6907 public void onError(int error) {
6908 try {
6909 callback.onError(error);
6910 } catch (RemoteException e) {
6911 // ignore
6912 }
6913 }
6914 });
6915 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006916 } finally {
6917 Binder.restoreCallingIdentity(identity);
6918 }
6919 }
6920
6921 /**
6922 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6923 * reason, the number to forward, and the timeout before the forwarding is attempted.
6924 */
6925 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006926 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6927 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006928 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006929
6930 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6931 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6932
Shuo Qian4a594052020-01-23 11:59:30 -08006933 long identity = Binder.clearCallingIdentity();
6934 try {
6935 if (DBG) {
6936 log("setCallForwarding: subId " + subId
6937 + " callForwardingInfo" + callForwardingInfo);
6938 }
Hall Liu27d24262020-09-18 19:04:59 -07006939
6940 Phone phone = getPhone(subId);
6941 if (phone == null) {
6942 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006943 callback.accept(
6944 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006945 } catch (RemoteException e) {
6946 // ignore
6947 }
6948 return;
6949 }
6950
6951 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6952 FunctionalUtils.ignoreRemoteException(callback::accept));
6953
6954 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 }
6959
6960 /**
Hall Liu27d24262020-09-18 19:04:59 -07006961 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006962 */
6963 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006964 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006965 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006966
6967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6968 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6969
Shuo Qian4a594052020-01-23 11:59:30 -08006970 long identity = Binder.clearCallingIdentity();
6971 try {
Hall Liu27d24262020-09-18 19:04:59 -07006972 Phone phone = getPhone(subId);
6973 if (phone == null) {
6974 try {
6975 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6976 } catch (RemoteException e) {
6977 // ignore
6978 }
6979 return;
6980 }
SongFerngWang0e767992021-03-31 22:08:45 +08006981 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6982 PersistableBundle c = configManager.getConfigForSubId(subId);
6983 boolean requireUssd = c.getBoolean(
6984 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006985
Shuo Qian4a594052020-01-23 11:59:30 -08006986 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006987 if (requireUssd) {
6988 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6989 getSubscriptionCarrierId(subId));
6990 String newUssdCommand = "";
6991 try {
6992 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006993 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006994 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6995 } catch (NullPointerException e) {
6996 loge("Failed to generate USSD number" + e);
6997 }
6998 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6999 mMainThreadHandler, callback, carrierXmlParser,
7000 CarrierXmlParser.SsEntry.SSAction.QUERY);
7001 final String ussdCommand = newUssdCommand;
7002 Executors.newSingleThreadExecutor().execute(() -> {
7003 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7004 });
7005 } else {
7006 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7007 callback::accept);
7008 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7009 }
Shuo Qian4a594052020-01-23 11:59:30 -08007010 } finally {
7011 Binder.restoreCallingIdentity(identity);
7012 }
7013 }
7014
7015 /**
Hall Liu27d24262020-09-18 19:04:59 -07007016 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007017 */
7018 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007019 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007020 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007021
7022 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7023 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7024
Shuo Qian4a594052020-01-23 11:59:30 -08007025 long identity = Binder.clearCallingIdentity();
7026 try {
Hall Liu27d24262020-09-18 19:04:59 -07007027 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7028
7029 Phone phone = getPhone(subId);
7030 if (phone == null) {
7031 try {
7032 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7033 } catch (RemoteException e) {
7034 // ignore
7035 }
7036 return;
7037 }
7038
SongFerngWang0e767992021-03-31 22:08:45 +08007039 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7040 PersistableBundle c = configManager.getConfigForSubId(subId);
7041 boolean requireUssd = c.getBoolean(
7042 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007043
SongFerngWang0e767992021-03-31 22:08:45 +08007044 if (DBG) log("getCallWaitingStatus: subId " + subId);
7045 if (requireUssd) {
7046 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7047 getSubscriptionCarrierId(subId));
7048 CarrierXmlParser.SsEntry.SSAction ssAction =
7049 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7050 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7051 String newUssdCommand = "";
7052 try {
7053 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007054 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007055 .makeCommand(ssAction, null);
7056 } catch (NullPointerException e) {
7057 loge("Failed to generate USSD number" + e);
7058 }
7059 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7060 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7061 final String ussdCommand = newUssdCommand;
7062 Executors.newSingleThreadExecutor().execute(() -> {
7063 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7064 });
7065 } else {
7066 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7067 FunctionalUtils.ignoreRemoteException(callback::accept));
7068
7069 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7070 }
Shuo Qian4a594052020-01-23 11:59:30 -08007071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
7074 }
7075
7076 /**
yinxub1bed742017-04-17 11:45:04 -07007077 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007078 *
yinxub1bed742017-04-17 11:45:04 -07007079 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007080 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7081 * location related information which will be sent if the caller already possess
7082 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007083 * @param request contains the radio access networks with bands/channels to scan
7084 * @param messenger callback messenger for scan results or errors
7085 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007086 * @return the id of the requested scan which can be used to stop the scan.
7087 */
7088 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007089 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7090 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007091 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7093 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007094 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007095 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7096 if (!renounceFineLocationAccess) {
7097 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007098 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7099 .setCallingPackage(callingPackage)
7100 .setCallingFeatureId(callingFeatureId)
7101 .setCallingPid(Binder.getCallingPid())
7102 .setCallingUid(Binder.getCallingUid())
7103 .setMethod("requestNetworkScan")
7104 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7105 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7106 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7107 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007108 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007109 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007110 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7111 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007112 if (e != null) {
7113 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7114 throw e;
7115 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007116 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007117 return TelephonyScanManager.INVALID_SCAN_ID;
7118 }
7119 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 }
joonhunshin4ac60942023-11-15 15:23:39 +00007121
7122 enforceTelephonyFeatureWithException(callingPackage,
7123 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7124
Hall Liu912dfd32019-04-25 14:02:26 -07007125 int callingUid = Binder.getCallingUid();
7126 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007130 renounceFineLocationAccess, request, messenger, binder,
7131 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007132 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007133 } finally {
7134 Binder.restoreCallingIdentity(identity);
7135 }
yinxu504e1392017-04-12 16:03:22 -07007136 }
7137
Hall Liub2ac8ef2019-02-28 15:56:23 -08007138 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007139 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007140 boolean hasCarrierPriv;
7141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7144 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7145 } finally {
7146 Binder.restoreCallingIdentity(identity);
7147 }
Hall Liu558027f2019-05-15 19:14:05 -07007148 boolean hasNetworkScanPermission =
7149 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007150 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007151
7152 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7153 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7154 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007155 }
7156
7157 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7158 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007159 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7160 return new SecurityException("Specific channels must not be"
7161 + " scanned without location access.");
7162 }
7163 }
7164 }
7165
Hall Liub2ac8ef2019-02-28 15:56:23 -08007166 return null;
7167 }
7168
yinxu504e1392017-04-12 16:03:22 -07007169 /**
7170 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007171 *
7172 * @param subId id of the subscription
7173 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007174 */
7175 @Override
7176 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7178 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179
Hall Liu912dfd32019-04-25 14:02:26 -07007180 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 final long identity = Binder.clearCallingIdentity();
7182 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007183 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
yinxu504e1392017-04-12 16:03:22 -07007187 }
7188
7189 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007190 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007191 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007192 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007193 */
7194 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007195 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007196 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007197 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007198 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199
joonhunshin4ac60942023-11-15 15:23:39 +00007200 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7201 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7202
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 final long identity = Binder.clearCallingIdentity();
7204 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007205 if (DBG) log("getAllowedNetworkTypesBitmask");
7206 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7207 int networkTypesBitmask = (result != null ? result[0] : -1);
7208 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7209 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 } finally {
7211 Binder.restoreCallingIdentity(identity);
7212 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007213 }
7214
7215 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007216 * Get the allowed network types for certain reason.
7217 *
7218 * @param subId the id of the subscription.
7219 * @param reason the reason the allowed network type change is taking place
7220 * @return the allowed network types.
7221 */
7222 @Override
7223 public long getAllowedNetworkTypesForReason(int subId,
7224 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007225 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007226 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007227
7228 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7229 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7230
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007231 final long identity = Binder.clearCallingIdentity();
7232 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007233 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007234 } finally {
7235 Binder.restoreCallingIdentity(identity);
7236 }
7237 }
7238
7239 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007240 * Enable/Disable E-UTRA-NR Dual Connectivity
7241 * @param subId subscription id of the sim card
7242 * @param nrDualConnectivityState expected NR dual connectivity state
7243 * This can be passed following states
7244 * <ol>
7245 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7246 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7247 * <li>Disable NR dual connectivity and force secondary cell to be released
7248 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7249 * </ol>
7250 * @return operation result.
7251 */
7252 @Override
7253 public int setNrDualConnectivityState(int subId,
7254 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7256 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007257 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007258 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7259 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7260 }
7261
Sooraj Sasindran37444802020-08-11 10:40:43 -07007262 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7266 nrDualConnectivityState, subId,
7267 workSource);
7268 if (DBG) log("enableNRDualConnectivity result: " + result);
7269 return result;
7270 } finally {
7271 Binder.restoreCallingIdentity(identity);
7272 }
7273 }
7274
7275 /**
7276 * Is E-UTRA-NR Dual Connectivity enabled
7277 * @return true if dual connectivity is enabled else false
7278 */
7279 @Override
7280 public boolean isNrDualConnectivityEnabled(int subId) {
7281 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007282 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007283 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007284 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007285 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7286 return false;
7287 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7289 final long identity = Binder.clearCallingIdentity();
7290 try {
7291 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7292 null, subId, workSource);
7293 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7294 return isEnabled;
7295 } finally {
7296 Binder.restoreCallingIdentity(identity);
7297 }
7298 }
7299
7300 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007301 * Set the allowed network types of the device and
7302 * provide the reason triggering the allowed network change.
7303 *
7304 * @param subId the id of the subscription.
7305 * @param reason the reason the allowed network type change is taking place
7306 * @param allowedNetworkTypes the allowed network types.
7307 * @return true on success; false on any failure.
7308 */
7309 @Override
7310 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007311 @TelephonyManager.AllowedNetworkTypesReason int reason,
7312 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7314 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007315 // If the caller only has carrier privileges, then they should not be able to override
7316 // any network types which were set for security reasons.
7317 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7318 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007319 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007320 throw new SecurityException(
7321 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007322 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007323 }
joonhunshin4ac60942023-11-15 15:23:39 +00007324
7325 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7326 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7327
SongFerngWang3ef3e072020-12-21 16:41:52 +08007328 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007329 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007330 return false;
7331 }
7332 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7333 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007334 return false;
7335 }
7336
Jack Yu5b494332023-01-23 18:18:04 +00007337 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7338 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007339
Jack Yue37dd262022-12-16 11:53:37 -08007340 Phone phone = getPhone(subId);
7341 if (phone == null) {
7342 return false;
7343 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007344
Jack Yue37dd262022-12-16 11:53:37 -08007345 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007346 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007347 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007348 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007349
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007350 final long identity = Binder.clearCallingIdentity();
7351 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007352 Boolean success = (Boolean) sendRequest(
7353 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7354 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7355
7356 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7357 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007358 } finally {
7359 Binder.restoreCallingIdentity(identity);
7360 }
7361 }
7362
7363 /**
Miaoa84611c2019-03-15 09:21:10 +08007364 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007365 *
Miaoa84611c2019-03-15 09:21:10 +08007366 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007367 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007368 * @hide
7369 */
7370 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007371 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007372 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007373
7374 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7375 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007378 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 try {
Miaoa84611c2019-03-15 09:21:10 +08007380 if (phone != null) {
7381 return phone.hasMatchedTetherApnSetting();
7382 } else {
7383 return false;
7384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 } finally {
7386 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007387 }
Junda Liu475951f2014-11-07 16:45:03 -08007388 }
7389
7390 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007391 * Get the user enabled state of Mobile Data.
7392 *
7393 * TODO: remove and use isUserDataEnabled.
7394 * This can't be removed now because some vendor codes
7395 * calls through ITelephony directly while they should
7396 * use TelephonyManager.
7397 *
7398 * @return true on enabled
7399 */
7400 @Override
7401 public boolean getDataEnabled(int subId) {
7402 return isUserDataEnabled(subId);
7403 }
7404
7405 /**
7406 * Get whether mobile data is enabled per user setting.
7407 *
7408 * There are other factors deciding whether mobile data is actually enabled, but they are
7409 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007410 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007411 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7412 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007413 *
7414 * @return {@code true} if data is enabled else {@code false}
7415 */
7416 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007417 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007418 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007419 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007420 try {
7421 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7422 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007423 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007424 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7425 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007426 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007428 mApp, subId, functionName);
7429
Robert Greenwalt646120a2014-05-23 11:54:03 -07007430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431
7432 final long identity = Binder.clearCallingIdentity();
7433 try {
Jack Yu285100e2022-12-02 22:48:35 -08007434 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7436 Phone phone = PhoneFactory.getPhone(phoneId);
7437 if (phone != null) {
7438 boolean retVal = phone.isUserDataEnabled();
7439 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7440 return retVal;
7441 } else {
7442 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7443 return false;
7444 }
7445 } finally {
7446 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007447 }
7448 }
7449
7450 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007451 * Checks if the device is capable of mobile data by considering whether whether the
7452 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7453 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007454 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007455 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007456 */
7457 @Override
7458 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007459 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007460 try {
7461 try {
7462 mApp.enforceCallingOrSelfPermission(
7463 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007464 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007465 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007466 try {
7467 mApp.enforceCallingOrSelfPermission(
7468 android.Manifest.permission.READ_PHONE_STATE,
7469 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007470 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007471 mApp.enforceCallingOrSelfPermission(
7472 permission.READ_BASIC_PHONE_STATE, functionName);
7473 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007474 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007475 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007476 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478
joonhunshin4ac60942023-11-15 15:23:39 +00007479 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7480 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 final long identity = Binder.clearCallingIdentity();
7483 try {
Jack Yu285100e2022-12-02 22:48:35 -08007484 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 Phone phone = PhoneFactory.getPhone(phoneId);
7486 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007487 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007488 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 return retVal;
7490 } else {
7491 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7492 return false;
7493 }
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007496 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007497 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007498
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007499 /**
7500 * Check if data is enabled for a specific reason
7501 * @param subId Subscription index
7502 * @param reason the reason the data enable change is taking place
7503 * @return {@code true} if the overall data is enabled; {@code false} if not.
7504 */
7505 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007506 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007507 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007508 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007509 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007510 try {
7511 mApp.enforceCallingOrSelfPermission(
7512 android.Manifest.permission.ACCESS_NETWORK_STATE,
7513 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007514 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007515 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7516 functionName);
7517 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007518 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007519 try {
7520 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007521 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007522 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007524 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007525 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007526 }
7527
joonhunshin4ac60942023-11-15 15:23:39 +00007528 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7529 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007530
7531 final long identity = Binder.clearCallingIdentity();
7532 try {
Jack Yu285100e2022-12-02 22:48:35 -08007533 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007534 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007535 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007536 + " reason=" + reason);
7537 }
7538 Phone phone = PhoneFactory.getPhone(phoneId);
7539 if (phone != null) {
7540 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007541 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007542 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007543 return retVal;
7544 } else {
7545 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007546 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007547 + subId + " retVal=false");
7548 }
7549 return false;
7550 }
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
7554 }
7555
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007556 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007557 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007558 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7559 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7560
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007561 // No permission needed; this only lets the caller inspect their own status.
7562 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007563 }
Junda Liu29340342014-07-10 15:23:27 -07007564
7565 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007566 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007567 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007568
7569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7570 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7571
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007572 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7573 }
7574
7575 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7576 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007577 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007578 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007579 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7580 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007581 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7582 if (cpt == null) {
7583 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007584 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7585 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007586 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007587 }
7588
7589 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007590 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007591 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007592
7593 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7594 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7595
chen xuf7e9fe82019-05-09 19:31:02 -07007596 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007597 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007598 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007599 Phone phone = getPhone(subId);
7600 if (phone == null) {
7601 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7602 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7603 }
7604 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7605 if (cpt == null) {
7606 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007607 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7608 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007609 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007610 }
7611
7612 @Override
7613 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007614 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007615
7616 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7617 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7618 "checkCarrierPrivilegesForPackageAnyPhone");
7619
Rambo Wange7209ce2022-02-23 13:41:02 -08007620 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7621 }
7622
7623 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007624 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007625 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007626 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007627 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007628 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7629 Phone phone = PhoneFactory.getPhone(phoneId);
7630 if (phone == null) {
7631 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007632 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007633 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7634 if (cpt == null) {
7635 continue;
7636 }
7637 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007638 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7639 break;
7640 }
7641 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007642 return result;
Junda Liu29340342014-07-10 15:23:27 -07007643 }
Derek Tan89e89d42014-07-08 17:00:10 -07007644
7645 @Override
Junda Liue64de782015-04-16 17:19:16 -07007646 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007647 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007648
7649 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7650 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7651 "getCarrierPackageNamesForIntentAndPhone");
7652
Rambo Wang8a247eb2022-02-08 21:11:18 +00007653 Phone phone = PhoneFactory.getPhone(phoneId);
7654 if (phone == null) {
7655 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007656 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007657 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7658 if (cpt == null) {
7659 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007660 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007661 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007662 }
7663
Amith Yamasani6e118872016-02-19 12:53:51 -08007664 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007665 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007666 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007667 Phone phone = PhoneFactory.getPhone(phoneId);
7668 if (phone == null) {
7669 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007670 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007671 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7672 if (cpt == null) {
7673 return Collections.emptyList();
7674 }
7675 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007676 }
7677
chen xuf7e9fe82019-05-09 19:31:02 -07007678 @Override
7679 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007680 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007681
7682 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7683 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7684 "getPackagesWithCarrierPrivilegesForAllPhones");
7685
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007686 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007687 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007688 try {
7689 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7690 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7691 }
7692 } finally {
7693 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007694 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007695 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007696 }
7697
Rambo Wang6812ffb2022-03-15 16:54:17 -07007698 @Override
7699 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7700 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7701
joonhunshin4ac60942023-11-15 15:23:39 +00007702 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7703 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7704 "getCarrierServicePackageNameForLogicalSlot");
7705
Rambo Wang6812ffb2022-03-15 16:54:17 -07007706 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7707 if (phone == null) {
7708 return null;
7709 }
7710 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7711 if (cpt == null) {
7712 return null;
7713 }
7714 return cpt.getCarrierServicePackageName();
7715 }
7716
Wink Savilleb564aae2014-10-23 10:18:09 -07007717 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007718 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007719 UiccPort port = phone == null ? null : phone.getUiccPort();
7720 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007721 return null;
7722 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007723 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007724 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007725 return null;
7726 }
7727 return iccId;
7728 }
7729
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007730 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007731 public void setCallComposerStatus(int subId, int status) {
7732 enforceModifyPermission();
7733
joonhunshin4ac60942023-11-15 15:23:39 +00007734 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7735 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7736
Shuo Qiane4e11672020-12-15 22:15:33 -08007737 final long identity = Binder.clearCallingIdentity();
7738 try {
7739 Phone phone = getPhone(subId);
7740 if (phone != null) {
7741 Phone defaultPhone = phone.getImsPhone();
7742 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7743 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7744 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007745 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7746 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007747 }
7748 }
Shuo Qian284ae752020-12-22 19:10:14 -08007749 } catch (ImsException e) {
7750 throw new ServiceSpecificException(e.getCode());
7751 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007752 Binder.restoreCallingIdentity(identity);
7753 }
7754 }
7755
7756 @Override
7757 public int getCallComposerStatus(int subId) {
7758 enforceReadPrivilegedPermission("getCallComposerStatus");
7759
joonhunshin4ac60942023-11-15 15:23:39 +00007760 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7761 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7762
Shuo Qiane4e11672020-12-15 22:15:33 -08007763 final long identity = Binder.clearCallingIdentity();
7764 try {
7765 Phone phone = getPhone(subId);
7766 if (phone != null) {
7767 Phone defaultPhone = phone.getImsPhone();
7768 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7769 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7770 return imsPhone.getCallComposerStatus();
7771 }
7772 }
7773 } finally {
7774 Binder.restoreCallingIdentity(identity);
7775 }
7776 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7777 }
7778
7779 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007780 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7781 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007782 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007783 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007784
joonhunshin4ac60942023-11-15 15:23:39 +00007785 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7786 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7787 "setLine1NumberForDisplayForSubscriber");
7788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 final long identity = Binder.clearCallingIdentity();
7790 try {
7791 final String iccId = getIccId(subId);
7792 final Phone phone = getPhone(subId);
7793 if (phone == null) {
7794 return false;
7795 }
7796 final String subscriberId = phone.getSubscriberId();
7797
7798 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007799 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 + subscriberId + " to " + number);
7801 }
7802
7803 if (TextUtils.isEmpty(iccId)) {
7804 return false;
7805 }
7806
7807 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7808
7809 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7810 if (alphaTag == null) {
7811 editor.remove(alphaTagPrefKey);
7812 } else {
7813 editor.putString(alphaTagPrefKey, alphaTag);
7814 }
7815
7816 // Record both the line number and IMSI for this ICCID, since we need to
7817 // track all merged IMSIs based on line number
7818 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7819 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7820 if (number == null) {
7821 editor.remove(numberPrefKey);
7822 editor.remove(subscriberPrefKey);
7823 } else {
7824 editor.putString(numberPrefKey, number);
7825 editor.putString(subscriberPrefKey, subscriberId);
7826 }
7827
7828 editor.commit();
7829 return true;
7830 } finally {
7831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007832 }
Derek Tan7226c842014-07-02 17:42:23 -07007833 }
7834
7835 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007836 public String getLine1NumberForDisplay(int subId, String callingPackage,
7837 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007838 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007840 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007841 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007842 return null;
7843 }
Derek Tan97ebb422014-09-05 16:55:38 -07007844
joonhunshin4ac60942023-11-15 15:23:39 +00007845 enforceTelephonyFeatureWithException(callingPackage,
7846 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848 final long identity = Binder.clearCallingIdentity();
7849 try {
7850 String iccId = getIccId(subId);
7851 if (iccId != null) {
7852 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7853 if (DBG_MERGE) {
7854 log("getLine1NumberForDisplay returning "
7855 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7856 }
7857 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007859 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7860 return null;
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007863 }
Derek Tan7226c842014-07-02 17:42:23 -07007864 }
7865
7866 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007867 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7868 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007870 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007871 return null;
7872 }
Derek Tan97ebb422014-09-05 16:55:38 -07007873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 final long identity = Binder.clearCallingIdentity();
7875 try {
7876 String iccId = getIccId(subId);
7877 if (iccId != null) {
7878 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7879 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7880 }
7881 return null;
7882 } finally {
7883 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007884 }
Derek Tan7226c842014-07-02 17:42:23 -07007885 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007886
7887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007888 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7889 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007890 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7891 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007893 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007894 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007895 return null;
7896 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007897
Jordan Liub49b04b2019-05-06 14:45:15 -07007898 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7899 // the process, where TelephonyManager was instantiated.
7900 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007901 final long identity = Binder.clearCallingIdentity();
7902 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007903 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904 final TelephonyManager tele = TelephonyManager.from(context);
7905 final SubscriptionManager sub = SubscriptionManager.from(context);
7906
7907 // Figure out what subscribers are currently active
7908 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909
Jordan Liub49b04b2019-05-06 14:45:15 -07007910 // Only consider subs which match the current subId
7911 // This logic can be simplified. See b/131189269 for progress.
7912 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007913 activeSubscriberIds.add(tele.getSubscriberId(subId));
7914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915
7916 // First pass, find a number override for an active subscriber
7917 String mergeNumber = null;
7918 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7919 for (String key : prefs.keySet()) {
7920 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7921 final String subscriberId = (String) prefs.get(key);
7922 if (activeSubscriberIds.contains(subscriberId)) {
7923 final String iccId = key.substring(
7924 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7925 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7926 mergeNumber = (String) prefs.get(numberKey);
7927 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007928 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007929 + " for active subscriber " + subscriberId);
7930 }
7931 if (!TextUtils.isEmpty(mergeNumber)) {
7932 break;
7933 }
7934 }
7935 }
7936 }
7937
7938 // Shortcut when no active merged subscribers
7939 if (TextUtils.isEmpty(mergeNumber)) {
7940 return null;
7941 }
7942
7943 // Second pass, find all subscribers under that line override
7944 final ArraySet<String> result = new ArraySet<>();
7945 for (String key : prefs.keySet()) {
7946 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7947 final String number = (String) prefs.get(key);
7948 if (mergeNumber.equals(number)) {
7949 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7950 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7951 final String subscriberId = (String) prefs.get(subscriberKey);
7952 if (!TextUtils.isEmpty(subscriberId)) {
7953 result.add(subscriberId);
7954 }
7955 }
7956 }
7957 }
7958
7959 final String[] resultArray = result.toArray(new String[result.size()]);
7960 Arrays.sort(resultArray);
7961 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007962 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7964 }
7965 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007966 } finally {
7967 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007968 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007969 }
7970
7971 @Override
zoey chen38003472019-12-13 17:16:31 +08007972 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7973 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007974
joonhunshin4ac60942023-11-15 15:23:39 +00007975 enforceTelephonyFeatureWithException(callingPackage,
7976 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7977
Malcolm Chen6ca97372019-07-01 16:28:21 -07007978 final long identity = Binder.clearCallingIdentity();
7979 try {
7980 final TelephonyManager telephonyManager = mApp.getSystemService(
7981 TelephonyManager.class);
7982 String subscriberId = telephonyManager.getSubscriberId(subId);
7983 if (subscriberId == null) {
7984 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007985 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007986 + subId);
7987 }
7988 return null;
7989 }
7990
Jack Yu3beaf9d2023-04-14 09:17:27 -07007991 final SubscriptionInfo info = getSubscriptionManagerService()
7992 .getSubscriptionInfo(subId);
7993 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007994 // If it doesn't belong to any group, return just subscriberId of itself.
7995 if (groupUuid == null) {
7996 return new String[]{subscriberId};
7997 }
7998
7999 // Get all subscriberIds from the group.
8000 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008001 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8002 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8003 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008004 for (SubscriptionInfo subInfo : groupInfos) {
8005 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8006 if (subscriberId != null) {
8007 mergedSubscriberIds.add(subscriberId);
8008 }
8009 }
8010
8011 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
8014
8015 }
8016 }
8017
8018 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008019 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008020 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008021 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022
joonhunshin4ac60942023-11-15 15:23:39 +00008023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8024 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 final long identity = Binder.clearCallingIdentity();
8027 try {
8028 final Phone phone = getPhone(subId);
8029 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8030 } finally {
8031 Binder.restoreCallingIdentity(identity);
8032 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008033 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008034
8035 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008036 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008037 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8038 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008039 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8040 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041
8042 final long identity = Binder.clearCallingIdentity();
8043 try {
8044 final Phone phone = getPhone(subId);
8045 if (phone == null) {
8046 return false;
8047 }
8048 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8049 cdmaNonRoamingList);
8050 } finally {
8051 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008052 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008053 }
8054
8055 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008056 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008057 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008058 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008059 if (phone == null) {
8060 return raf;
8061 }
8062
Shuo Qiandee53402020-05-29 14:08:15 -07008063 try {
8064 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008065 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008066 mApp, phone.getSubId(), "getRadioAccessFamily");
8067 } catch (SecurityException e) {
8068 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8069 throw e;
8070 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008071
joonhunshin4ac60942023-11-15 15:23:39 +00008072 enforceTelephonyFeatureWithException(callingPackage,
8073 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 final long identity = Binder.clearCallingIdentity();
8076 try {
chen xub97461a2018-10-26 14:17:57 -07008077 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078 } finally {
8079 Binder.restoreCallingIdentity(identity);
8080 }
chen xub97461a2018-10-26 14:17:57 -07008081 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008082 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008083
8084 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008085 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008086 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008087 try {
8088 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8089 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008090 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008091 }
8092 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008093 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008094 }
joonhunshin4ac60942023-11-15 15:23:39 +00008095
8096 enforceTelephonyFeatureWithException(callingPackage,
8097 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8098
Hall Liu82694d52020-12-11 18:22:04 -08008099 RoleManager rm = mApp.getSystemService(RoleManager.class);
8100 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8101 if (!dialerRoleHolders.contains(callingPackage)) {
8102 throw new SecurityException("App must be the dialer role holder to"
8103 + " upload a call composer pic");
8104 }
8105
8106 Executors.newSingleThreadExecutor().execute(() -> {
8107 ByteArrayOutputStream output = new ByteArrayOutputStream(
8108 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8109 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8110 boolean readUntilEnd = false;
8111 int totalBytesRead = 0;
8112 byte[] buffer = new byte[16 * 1024];
8113 while (true) {
8114 int numRead;
8115 try {
8116 numRead = input.read(buffer);
8117 } catch (IOException e) {
8118 try {
8119 fd.checkError();
8120 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8121 null);
8122 } catch (IOException e1) {
8123 // This means that the other side closed explicitly with an error. If this
8124 // happens, log and ignore.
8125 loge("Remote end of call composer picture pipe closed: " + e1);
8126 }
8127 break;
8128 }
8129 if (numRead == -1) {
8130 readUntilEnd = true;
8131 break;
8132 }
8133 totalBytesRead += numRead;
8134 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8135 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8136 try {
8137 input.close();
8138 } catch (IOException e) {
8139 // ignore
8140 }
8141 break;
8142 }
8143 output.write(buffer, 0, numRead);
8144 }
8145 // Generally, the remote end will close the file descriptors. The only case where we
8146 // close is above, where the picture size is too big.
8147
8148 try {
8149 fd.checkError();
8150 } catch (IOException e) {
8151 loge("Remote end for call composer closed with an error: " + e);
8152 return;
8153 }
8154
Hall Liuaa4211e2021-01-20 15:43:39 -08008155 if (!readUntilEnd) {
8156 loge("Did not finish reading entire image; aborting");
8157 return;
8158 }
Hall Liu82694d52020-12-11 18:22:04 -08008159
Hall Liuaa4211e2021-01-20 15:43:39 -08008160 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8161 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8162 new CallComposerPictureTransfer.Factory() {},
8163 imageData,
8164 (result) -> {
8165 if (result.first != null) {
8166 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8167 Bundle outputResult = new Bundle();
8168 outputResult.putParcelable(
8169 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8170 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8171 outputResult);
8172 } else {
8173 callback.send(result.second, null);
8174 }
8175 }
8176 );
Hall Liu82694d52020-12-11 18:22:04 -08008177 });
8178 }
8179
8180 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008181 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008182 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008183 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184
joonhunshin4ac60942023-11-15 15:23:39 +00008185 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8186 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188 final long identity = Binder.clearCallingIdentity();
8189 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008190 ImsManager.getInstance(defaultPhone.getContext(),
8191 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192 } finally {
8193 Binder.restoreCallingIdentity(identity);
8194 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008195 }
8196
8197 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008198 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008199 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8201 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008202 return false;
8203 }
Svet Ganovb320e182015-04-16 12:30:10 -07008204
joonhunshin4ac60942023-11-15 15:23:39 +00008205 enforceTelephonyFeatureWithException(callingPackage,
8206 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 final long identity = Binder.clearCallingIdentity();
8209 try {
8210 // Check the user preference and the system-level IMS setting. Even if the user has
8211 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8212 // In the long run, we may instead need to check if there exists a connection service
8213 // which can support video calling.
8214 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008215 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216 return imsManager.isVtEnabledByPlatform()
8217 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8218 && imsManager.isVtEnabledByUser();
8219 } finally {
8220 Binder.restoreCallingIdentity(identity);
8221 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008222 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008223
Andrew Leea1239f22015-03-02 17:44:07 -08008224 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008225 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8226 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008228 mApp, subId, callingPackage, callingFeatureId,
8229 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230 return false;
8231 }
8232
joonhunshin4ac60942023-11-15 15:23:39 +00008233 enforceTelephonyFeatureWithException(callingPackage,
8234 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 final long identity = Binder.clearCallingIdentity();
8237 try {
8238 CarrierConfigManager configManager =
8239 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008240 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8242 } finally {
8243 Binder.restoreCallingIdentity(identity);
8244 }
Andrew Leea1239f22015-03-02 17:44:07 -08008245 }
8246
8247 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008248 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008250 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 return false;
8252 }
8253
joonhunshin4ac60942023-11-15 15:23:39 +00008254 enforceTelephonyFeatureWithException(callingPackage,
8255 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 final long identity = Binder.clearCallingIdentity();
8258 try {
8259 CarrierConfigManager configManager =
8260 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008261 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8263 } finally {
8264 Binder.restoreCallingIdentity(identity);
8265 }
Andrew Leea1239f22015-03-02 17:44:07 -08008266 }
8267
Andrew Lee9431b832015-03-09 18:46:45 -07008268 @Override
8269 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008270 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008271 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008272 }
8273
8274 @Override
8275 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008276 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8277 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 final long identity = Binder.clearCallingIdentity();
8280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008281 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
Andrew Lee9431b832015-03-09 18:46:45 -07008285 }
8286
Hall Liuf6668912018-10-31 17:05:23 -07008287 /**
8288 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8289 * support for the feature and device firmware support.
8290 *
8291 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8292 */
8293 @Override
8294 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008295 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8296 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008299 final Phone phone = getPhone(subscriptionId);
8300 if (phone == null) {
8301 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8302 return false;
8303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008305 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008307 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8308 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8309 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 return isCarrierSupported && isDeviceSupported;
8311 } finally {
8312 Binder.restoreCallingIdentity(identity);
8313 }
Hall Liu98187582018-01-22 19:15:32 -08008314 }
8315
Hall Liuf6668912018-10-31 17:05:23 -07008316 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008317 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8318 * RTT setting, will return true if the device and carrier both support RTT.
8319 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008320 */
8321 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 final long identity = Binder.clearCallingIdentity();
8323 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008324 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8325 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8326 return false;
8327 }
8328 }
8329
Hall Liu5bab75c2019-12-11 23:58:20 +00008330 boolean isRttSupported = isRttSupported(subscriptionId);
8331 boolean isUserRttSettingOn = Settings.Secure.getInt(
8332 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8333 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8334 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8335 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008339 }
8340
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008341 @Deprecated
8342 @Override
8343 public String getDeviceId(String callingPackage) {
8344 return getDeviceIdWithFeature(callingPackage, null);
8345 }
8346
Sanket Padawe7310cc72015-01-14 09:53:20 -08008347 /**
8348 * Returns the unique device ID of phone, for example, the IMEI for
8349 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8350 *
8351 * <p>Requires Permission:
8352 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8353 */
8354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008355 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008356 try {
8357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8358 } catch (SecurityException se) {
8359 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8360 throw new SecurityException("Package " + callingPackage + " does not belong to "
8361 + Binder.getCallingUid());
8362 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008363 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008364 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008365 return null;
8366 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008367 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008368 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008369 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008370 return null;
8371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372
8373 final long identity = Binder.clearCallingIdentity();
8374 try {
8375 return phone.getDeviceId();
8376 } finally {
8377 Binder.restoreCallingIdentity(identity);
8378 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008379 }
8380
Ping Sunc67b7c22016-03-02 19:16:45 +08008381 /**
8382 * {@hide}
8383 * Returns the IMS Registration Status on a particular subid
8384 *
8385 * @param subId
8386 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008387 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008388 Phone phone = getPhone(subId);
8389 if (phone != null) {
8390 return phone.isImsRegistered();
8391 } else {
8392 return false;
8393 }
8394 }
8395
Santos Cordon7a1885b2015-02-03 11:15:19 -08008396 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008397 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008398 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008400 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008401 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8402 }
8403 final long identity = Binder.clearCallingIdentity();
8404 try {
8405 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8406 } finally {
8407 Binder.restoreCallingIdentity(identity);
8408 }
8409 }
8410
8411 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008412 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008413 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008414 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008415 mApp,
8416 subscriptionId,
8417 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8418 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008419
8420 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8421 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8422
Tyler Gunnf70ed162019-04-03 15:28:53 -07008423 final long identity = Binder.clearCallingIdentity();
8424 try {
8425 Phone phone = getPhone(subscriptionId);
8426 if (phone == null) {
8427 return null;
8428 }
8429 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8430 } finally {
8431 Binder.restoreCallingIdentity(identity);
8432 }
8433 }
8434
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008435 /**
8436 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008437 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008438 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439 final long identity = Binder.clearCallingIdentity();
8440 try {
8441 Phone phone = getPhone(subId);
8442 if (phone != null) {
8443 return phone.isWifiCallingEnabled();
8444 } else {
8445 return false;
8446 }
8447 } finally {
8448 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008449 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008450 }
8451
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008452 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008453 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008454 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008455 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456 final long identity = Binder.clearCallingIdentity();
8457 try {
8458 Phone phone = getPhone(subId);
8459 if (phone != null) {
8460 return phone.isVideoEnabled();
8461 } else {
8462 return false;
8463 }
8464 } finally {
8465 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008466 }
8467 }
8468
8469 /**
8470 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8471 * defined in {@link ImsRegistrationImplBase}.
8472 */
8473 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008474 final long identity = Binder.clearCallingIdentity();
8475 try {
8476 Phone phone = getPhone(subId);
8477 if (phone != null) {
8478 return phone.getImsRegistrationTech();
8479 } else {
8480 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8481 }
8482 } finally {
8483 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008484 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008485 }
8486
Stuart Scott8eef64f2015-04-08 15:13:54 -07008487 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008488 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008489 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008490
8491 enforceTelephonyFeatureWithException(callingPackage,
8492 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8493
Stuart Scott981d8582015-04-21 14:09:50 -07008494 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8495 return;
8496 }
Kai Shif70f46f2021-03-03 13:59:46 -08008497 Phone defaultPhone = getDefaultPhone();
8498 if (defaultPhone != null) {
8499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8500 mApp, getDefaultPhone().getSubId(), "factoryReset");
8501 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008502 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008503
Svet Ganovcc087f82015-05-12 20:35:54 -07008504 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008505 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8506 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008507 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008508 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008509 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008510 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008511 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008512 setDataRoamingEnabled(subId, phone == null ? false
8513 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008514 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008515 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008516 // There has been issues when Sms raw table somehow stores orphan
8517 // fragments. They lead to garbled message when new fragments come
8518 // in and combined with those stale ones. In case this happens again,
8519 // user can reset all network settings which will clean up this table.
8520 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008521 // Clean up IMS settings as well here.
8522 int slotId = getSlotIndex(subId);
8523 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8524 ImsManager.getInstance(mApp, slotId).factoryReset();
8525 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008526
Kai Shif70f46f2021-03-03 13:59:46 -08008527 if (defaultPhone == null) {
8528 return;
8529 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008530 // Erase modem config if erase modem on network setting is enabled.
8531 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8532 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8533 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008534 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008535 }
Kai Shif70f46f2021-03-03 13:59:46 -08008536
8537 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008538 } finally {
8539 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008540 }
8541 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008542
SongFerngWangfd89b102021-05-27 22:44:54 +08008543 @VisibleForTesting
8544 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8545 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8546 return;
8547 }
8548 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8549 RILConstants.PREFERRED_NETWORK_MODE);
8550 SubscriptionManager.setSubscriptionProperty(subId,
8551 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8552 "user=" + defaultNetworkType);
8553 phone.loadAllowedNetworksFromSubscriptionDatabase();
8554 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8555 defaultNetworkType, null);
8556 }
8557
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008558 private void cleanUpSmsRawTable(Context context) {
8559 ContentResolver resolver = context.getContentResolver();
8560 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8561 resolver.delete(uri, null, null);
8562 }
8563
Narayan Kamath1c496c22015-04-16 14:40:19 +01008564 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008565 public String getSimLocaleForSubscriber(int subId) {
8566 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008567
8568 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8569 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8570
chen xu5d3637b2019-01-21 23:31:38 -08008571 final Phone phone = getPhone(subId);
8572 if (phone == null) {
8573 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008574 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008576 final long identity = Binder.clearCallingIdentity();
8577 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008578 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8579 phone.getContext().getOpPackageName(),
8580 phone.getContext().getAttributionTag());
8581 if (info == null) {
8582 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8583 return null;
chen xu6291c472019-02-04 12:55:53 -08008584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008585 // Try and fetch the locale from the carrier properties or from the SIM language
8586 // preferences (EF-PL and EF-LI)...
8587 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008588 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008589 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8590 if (localeFromDefaultSim != null) {
8591 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8592 if (DBG) log("Using locale from subId: " + subId + " locale: "
8593 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008594 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008595 } else {
8596 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 }
8598 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600 // The SIM language preferences only store a language (e.g. fr = French), not an
8601 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8602 // the SIM and carrier preferences does not include a country we add the country
8603 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008604 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008606 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008607 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608 }
8609
8610 if (DBG) log("No locale found - returning null");
8611 return null;
8612 } finally {
8613 Binder.restoreCallingIdentity(identity);
8614 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008615 }
8616
tom hsu0b59d292022-09-29 23:49:21 +08008617 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008618 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008619 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008620 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008621 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008622 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8623 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008624 Locale.forLanguageTag(localeTag).getCountry())) {
8625 return localeTag;
8626 }
8627 }
8628 return inputLocale.toLanguageTag();
8629 }
8630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008631 /**
8632 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8633 */
8634 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008635 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008636 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008637 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008638
Gary Jian3aa9a762022-01-24 16:41:19 +08008639 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8640 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008641
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008642 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008643 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8644 * representing the state of the modem.
8645 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008646 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8647 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008648 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008649 */
8650 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008651 public void requestModemActivityInfo(ResultReceiver result) {
8652 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008653
8654 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8655 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8656
vagdeviaf9a5b92018-08-15 16:01:53 -07008657 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658
8659 final long identity = Binder.clearCallingIdentity();
8660 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008661 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008662 } finally {
8663 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008664 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008665 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008666
Gary Jian76280a42022-12-07 16:18:33 +08008667 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008668 // less than total activity duration.
8669 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8670 if (info == null) {
8671 return false;
8672 }
8673 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008674 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008675 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8676
Hall Liu49656c02020-10-09 19:00:11 -07008677 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8678
Siddharth Rayb8114062018-06-17 15:02:38 -07008679 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008680 && (info.getSleepTimeMillis() <= activityDurationMs)
8681 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008682 }
8683
Gary Jian3aa9a762022-01-24 16:41:19 +08008684 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8685 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8686 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8687 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8688
8689 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8690 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8691 }
8692
8693 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8694 mLastModemActivityInfo.setReceiveTimeMillis(
8695 rat,
8696 freq,
8697 info.getReceiveTimeMillis(rat, freq)
8698 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8699 }
8700
8701 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8702 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8703 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8704 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8705
8706 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8707 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8708 }
8709 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8710 mLastModemActivityInfo.setReceiveTimeMillis(
8711 rat,
8712 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8713 }
8714
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008715 /**
8716 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8717 * @param info recent ModemActivityInfo
8718 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008719 private void mergeModemActivityInfo(ModemActivityInfo info) {
8720 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008721 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008722 boolean matched;
8723 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8724 matched = false;
8725 int rat = info.getSpecificInfoRat(i);
8726 int freq = info.getSpecificInfoFrequencyRange(i);
8727 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8728 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8729 //if it already exists
8730 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8731 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8732 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8733 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8734 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8735 updateLastModemActivityInfo(info, rat, freq);
8736 matched = true;
8737 }
8738 } else {
8739 updateLastModemActivityInfo(info, rat);
8740 matched = true;
8741 }
8742 }
8743 }
8744
8745 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008746 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008747 new ActivityStatsTechSpecificInfo(
8748 rat,
8749 freq,
8750 info.getTransmitTimeMillis(rat, freq),
8751 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008752 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008753 }
8754 }
8755 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8756 mLastModemActivitySpecificInfo =
8757 new ActivityStatsTechSpecificInfo[merged.size()];
8758 merged.toArray(mLastModemActivitySpecificInfo);
8759
8760 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8761 mLastModemActivityInfo.setSleepTimeMillis(
8762 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008763 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008764 mLastModemActivityInfo.setIdleTimeMillis(
8765 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008766 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008767
8768 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008769 new ModemActivityInfo(
8770 mLastModemActivityInfo.getTimestampMillis(),
8771 mLastModemActivityInfo.getSleepTimeMillis(),
8772 mLastModemActivityInfo.getIdleTimeMillis(),
8773 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008774 }
8775
8776 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8777 ActivityStatsTechSpecificInfo[] info) {
8778 int infoSize = info.length;
8779 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8780 for (int i = 0; i < infoSize; i++) {
8781 ret[i] = new ActivityStatsTechSpecificInfo(
8782 info[i].getRat(), info[i].getFrequencyRange(),
8783 info[i].getTransmitTimeMillis(),
8784 (int) info[i].getReceiveTimeMillis());
8785 }
8786 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008787 }
8788
Jack Yu85bd38a2015-11-09 11:34:32 -08008789 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008790 * Returns the service state information on specified subscription.
8791 */
8792 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008793 public ServiceState getServiceStateForSubscriber(int subId,
8794 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8795 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008797 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008798 return null;
8799 }
8800
joonhunshin4ac60942023-11-15 15:23:39 +00008801 enforceTelephonyFeatureWithException(callingPackage,
8802 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8803
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008804 boolean hasFinePermission = false;
8805 boolean hasCoarsePermission = false;
8806 if (!renounceFineLocationAccess) {
8807 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8808 LocationAccessPolicy.checkLocationPermission(mApp,
8809 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8810 .setCallingPackage(callingPackage)
8811 .setCallingFeatureId(callingFeatureId)
8812 .setCallingPid(Binder.getCallingPid())
8813 .setCallingUid(Binder.getCallingUid())
8814 .setMethod("getServiceStateForSubscriber")
8815 .setLogAsInfo(true)
8816 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8817 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8818 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8819 .build());
8820 hasFinePermission =
8821 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8822 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008823
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008824 if (!renounceCoarseLocationAccess) {
8825 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8826 LocationAccessPolicy.checkLocationPermission(mApp,
8827 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8828 .setCallingPackage(callingPackage)
8829 .setCallingFeatureId(callingFeatureId)
8830 .setCallingPid(Binder.getCallingPid())
8831 .setCallingUid(Binder.getCallingUid())
8832 .setMethod("getServiceStateForSubscriber")
8833 .setLogAsInfo(true)
8834 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8835 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8836 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8837 .build());
8838 hasCoarsePermission =
8839 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8840 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008841
Jack Yu479f40e2020-10-27 21:29:25 -07008842 final Phone phone = getPhone(subId);
8843 if (phone == null) {
8844 return null;
8845 }
8846
Jordan Liu0f2bc442020-11-18 16:47:37 -08008847 final long identity = Binder.clearCallingIdentity();
8848
Jack Yu479f40e2020-10-27 21:29:25 -07008849 boolean isCallingPackageDataService = phone.getDataServicePackages()
8850 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008851 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008852 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008853 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8854 .getSubscriptionInfoInternal(subId);
8855 if (subInfo == null || !subInfo.isActive()) {
8856 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8857 + "subId=" + subId);
8858 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008859 }
8860
Hall Liuf19c44f2018-11-27 14:38:17 -08008861 ServiceState ss = phone.getServiceState();
8862
8863 // Scrub out the location info in ServiceState depending on what level of access
8864 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008865 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008866 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8867 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008868 } finally {
8869 Binder.restoreCallingIdentity(identity);
8870 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008871 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008872
8873 /**
8874 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8875 *
8876 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8877 * voicemail ringtone.
8878 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8879 * PhoneAccount.
8880 */
8881 @Override
8882 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008883 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8884 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886 final long identity = Binder.clearCallingIdentity();
8887 try {
8888 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8889 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008890 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008893 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8894 } finally {
8895 Binder.restoreCallingIdentity(identity);
8896 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008897 }
8898
8899 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008900 * Sets the per-account voicemail ringtone.
8901 *
8902 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8903 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8904 *
8905 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8906 * voicemail ringtone.
8907 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8908 * PhoneAccount.
8909 */
8910 @Override
8911 public void setVoicemailRingtoneUri(String callingPackage,
8912 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008913 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008915 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8916 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8918 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8919 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008921
joonhunshin4ac60942023-11-15 15:23:39 +00008922 enforceTelephonyFeatureWithException(callingPackage,
8923 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925 final long identity = Binder.clearCallingIdentity();
8926 try {
8927 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8928 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008929 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008930 }
8931 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8932 } finally {
8933 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008934 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008935 }
8936
8937 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008938 * Returns whether vibration is set for voicemail notification in Phone settings.
8939 *
8940 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8941 * voicemail vibration setting.
8942 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8943 */
8944 @Override
8945 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008946 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8947 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949 final long identity = Binder.clearCallingIdentity();
8950 try {
8951 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8952 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008953 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8957 } finally {
8958 Binder.restoreCallingIdentity(identity);
8959 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008960 }
8961
Youhan Wange64578a2016-05-02 15:32:42 -07008962 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008963 * Sets the per-account voicemail vibration.
8964 *
8965 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8966 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8967 *
8968 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8969 * voicemail vibration setting.
8970 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8971 * specific PhoneAccount.
8972 */
8973 @Override
8974 public void setVoicemailVibrationEnabled(String callingPackage,
8975 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008976 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008978 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8979 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8981 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8982 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008983 }
8984
joonhunshin4ac60942023-11-15 15:23:39 +00008985 enforceTelephonyFeatureWithException(callingPackage,
8986 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8991 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008992 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008993 }
8994 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8995 } finally {
8996 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008997 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008998 }
8999
9000 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009001 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9002 *
9003 * @throws SecurityException if the caller does not have the required permission
9004 */
arunvoddud7401012022-12-15 16:08:12 +00009005 @VisibleForTesting
9006 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009007 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009008 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009009 }
9010
9011 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009012 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9013 * permission.
9014 *
9015 * @throws SecurityException if the caller does not have the required permission
9016 */
9017 private void enforceSendSmsPermission() {
9018 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9019 }
9020
9021 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009022 * Make sure either called from same process as self (phone) or IPC caller has interact across
9023 * users permission.
9024 *
9025 * @throws SecurityException if the caller does not have the required permission
9026 */
9027 private void enforceInteractAcrossUsersPermission(String message) {
9028 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9029 }
9030
9031 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009032 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009033 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009034 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009035 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009036 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009037 final long identity = Binder.clearCallingIdentity();
9038 try {
9039 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009040 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 if (componentName == null) {
9042 throw new SecurityException(
9043 "Caller not current active visual voicemail package[null]");
9044 }
9045 String vvmPackage = componentName.getPackageName();
9046 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009047 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009048 }
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009051 }
9052 }
9053
9054 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009055 * Return the application ID for the app type.
9056 *
9057 * @param subId the subscription ID that this request applies to.
9058 * @param appType the uicc app type.
9059 * @return Application ID for specificied app type, or null if no uicc.
9060 */
9061 @Override
9062 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009063 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009064
9065 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9066 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9067
Youhan Wange64578a2016-05-02 15:32:42 -07009068 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009069
9070 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009071 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009072 if (phone == null) {
9073 return null;
9074 }
9075 String aid = null;
9076 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009077 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009078 .getApplicationByType(appType).getAid();
9079 } catch (Exception e) {
9080 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9081 }
9082 return aid;
9083 } finally {
9084 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009085 }
Youhan Wange64578a2016-05-02 15:32:42 -07009086 }
9087
Youhan Wang4001d252016-05-11 10:29:41 -07009088 /**
9089 * Return the Electronic Serial Number.
9090 *
9091 * @param subId the subscription ID that this request applies to.
9092 * @return ESN or null if error.
9093 */
9094 @Override
9095 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009096 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009097 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098
9099 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009100 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009101 if (phone == null) {
9102 return null;
9103 }
9104 String esn = null;
9105 try {
9106 esn = phone.getEsn();
9107 } catch (Exception e) {
9108 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9109 }
9110 return esn;
9111 } finally {
9112 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009113 }
Youhan Wang4001d252016-05-11 10:29:41 -07009114 }
9115
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009116 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009117 * Return the Preferred Roaming List Version.
9118 *
9119 * @param subId the subscription ID that this request applies to.
9120 * @return PRLVersion or null if error.
9121 */
9122 @Override
9123 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009124 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009125
9126 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9127 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9128
Youhan Wang66ad5d72016-07-18 17:56:58 -07009129 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009130
9131 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009132 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009133 if (phone == null) {
9134 return null;
9135 }
9136 String cdmaPrlVersion = null;
9137 try {
9138 cdmaPrlVersion = phone.getCdmaPrlVersion();
9139 } catch (Exception e) {
9140 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9141 }
9142 return cdmaPrlVersion;
9143 } finally {
9144 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009145 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009146 }
9147
9148 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009149 * Get snapshot of Telephony histograms
9150 * @return List of Telephony histograms
9151 * @hide
9152 */
9153 @Override
9154 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9156 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009157
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
9160 return RIL.getTelephonyRILTimingHistograms();
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009164 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009165
9166 /**
9167 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009168 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9169 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009170 * Require system privileges. In the future we may add this to carrier APIs.
9171 *
Michele Berionne482f8202018-11-27 18:57:59 -08009172 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009173 */
9174 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009175 @TelephonyManager.SetCarrierRestrictionResult
9176 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009177 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009178
9179 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9180 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9181
vagdeviaf9a5b92018-08-15 16:01:53 -07009182 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009183
Michele Berionne482f8202018-11-27 18:57:59 -08009184 if (carrierRestrictionRules == null) {
9185 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009186 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009188 final long identity = Binder.clearCallingIdentity();
9189 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009190 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009191 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009192 } finally {
9193 Binder.restoreCallingIdentity(identity);
9194 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009195 }
9196
9197 /**
9198 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009199 * Get the allowed carrier list and the excluded carrier list, including the priority between
9200 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009201 * Require system privileges. In the future we may add this to carrier APIs.
9202 *
Michele Berionne482f8202018-11-27 18:57:59 -08009203 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009204 */
9205 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009206 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009207 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009208
9209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9210 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9211
vagdeviaf9a5b92018-08-15 16:01:53 -07009212 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009213
9214 final long identity = Binder.clearCallingIdentity();
9215 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009216 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9217 if (response instanceof CarrierRestrictionRules) {
9218 return (CarrierRestrictionRules) response;
9219 }
9220 // Response is an Exception of some kind,
9221 // which is signalled to the user as a NULL retval
9222 return null;
9223 } catch (Exception e) {
9224 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9225 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009229 }
9230
fionaxu59545b42016-05-25 15:53:37 -07009231 /**
arunvoddud7401012022-12-15 16:08:12 +00009232 * Fetches the carrier restriction status of the device and sends the status to the caller
9233 * through the callback.
9234 *
9235 * @param callback The callback that will be used to send the result.
9236 * @throws SecurityException if the caller does not have the required permission/privileges or
9237 * the caller is not allowlisted.
9238 */
9239 @Override
9240 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9241 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009242
9243 enforceTelephonyFeatureWithException(packageName,
9244 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9245
Steve Statia28b7cb32024-03-11 23:58:50 +00009246 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9247 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009248 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9249 throw new SecurityException("Not an authorized caller");
9250 }
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009254 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009255 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
9259 }
9260
arunvoddu567f2b42023-04-25 17:22:00 +00009261 @Override
9262 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9263 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9264 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9265 return allowListInfo.getShaIdList(pkgName, carrierId);
9266 }
9267
arunvoddud7401012022-12-15 16:08:12 +00009268 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009269 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009270 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009271 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009272 }
9273
9274 /**
fionaxu59545b42016-05-25 15:53:37 -07009275 * Action set from carrier signalling broadcast receivers to enable/disable radio
9276 * @param subId the subscription ID that this action applies to.
9277 * @param enabled control enable or disable radio.
9278 * {@hide}
9279 */
9280 @Override
9281 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9282 enforceModifyPermission();
9283 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009284
9285 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009286 if (phone == null) {
9287 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9288 return;
9289 }
9290 try {
9291 phone.carrierActionSetRadioEnabled(enabled);
9292 } catch (Exception e) {
9293 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009294 } finally {
9295 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009296 }
9297 }
9298
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009299 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009300 * Enable or disable Voice over NR (VoNR)
9301 * @param subId the subscription ID that this action applies to.
9302 * @param enabled enable or disable VoNR.
9303 * @return operation result.
9304 */
9305 @Override
9306 public int setVoNrEnabled(int subId, boolean enabled) {
9307 enforceModifyPermission();
9308 final Phone phone = getPhone(subId);
9309
9310 final long identity = Binder.clearCallingIdentity();
9311 if (phone == null) {
9312 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9313 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9314 }
9315
9316 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9317 try {
9318 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9319 workSource);
9320 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009321
9322 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9323 if (DBG) {
9324 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9325 }
9326 SubscriptionManager.setSubscriptionProperty(
9327 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9328 (enabled ? "1" : "0"));
9329 }
9330
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009331 return result;
9332 } finally {
9333 Binder.restoreCallingIdentity(identity);
9334 }
9335 }
9336
9337 /**
9338 * Is voice over NR enabled
9339 * @return true if VoNR is enabled else false
9340 */
9341 @Override
9342 public boolean isVoNrEnabled(int subId) {
9343 enforceReadPrivilegedPermission("isVoNrEnabled");
9344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9345 final long identity = Binder.clearCallingIdentity();
9346 try {
9347 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9348 null, subId, workSource);
9349 if (DBG) log("isVoNrEnabled: " + isEnabled);
9350 return isEnabled;
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 }
9355
9356 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009357 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9358 * network status based on which carrier apps could apply actions accordingly,
9359 * enable/disable default url handler for example.
9360 *
9361 * @param subId the subscription ID that this action applies to.
9362 * @param report control start/stop reporting the default network status.
9363 * {@hide}
9364 */
9365 @Override
9366 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9367 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009368
9369 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9370 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9371 "carrierActionReportDefaultNetworkStatus");
9372
fionaxu8da9cb12017-05-23 15:02:46 -07009373 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009374
9375 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009376 if (phone == null) {
9377 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9378 return;
9379 }
9380 try {
9381 phone.carrierActionReportDefaultNetworkStatus(report);
9382 } catch (Exception e) {
9383 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009384 } finally {
9385 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009386 }
9387 }
9388
9389 /**
fionaxud9622282017-07-17 17:51:30 -07009390 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9391 * @param subId the subscription ID that this action applies to.
9392 * {@hide}
9393 */
9394 @Override
9395 public void carrierActionResetAll(int subId) {
9396 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009397
9398 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9399 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9400
fionaxud9622282017-07-17 17:51:30 -07009401 final Phone phone = getPhone(subId);
9402 if (phone == null) {
9403 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9404 return;
9405 }
9406 try {
9407 phone.carrierActionResetAll();
9408 } catch (Exception e) {
9409 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9410 }
9411 }
9412
9413 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009414 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9415 * bug report is being generated.
9416 */
9417 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009418 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009419 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9420 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009421 writer.println("Permission Denial: can't dump Phone from pid="
9422 + Binder.getCallingPid()
9423 + ", uid=" + Binder.getCallingUid()
9424 + "without permission "
9425 + android.Manifest.permission.DUMP);
9426 return;
9427 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009428 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009429 }
Jack Yueb89b242016-06-22 13:27:47 -07009430
Brad Ebingerdac2f002018-04-03 15:17:52 -07009431 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009432 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9433 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9434 @NonNull String[] args) {
9435 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9436 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009437 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009438 }
9439
Jack Yueb89b242016-06-22 13:27:47 -07009440 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009441 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009442 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009443 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009444 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009445 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009446 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009447 */
9448 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009449 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009450 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009451 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9452 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9453 try {
9454 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009455 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009456 } catch (SecurityException se) {
9457 enforceModifyPermission();
9458 }
9459 } else {
9460 enforceModifyPermission();
9461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009462
joonhunshin4ac60942023-11-15 15:23:39 +00009463 enforceTelephonyFeatureWithException(callingPackage,
9464 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9465
Nate Myren116695d2024-02-09 09:36:01 -08009466 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009467 final long identity = Binder.clearCallingIdentity();
9468 try {
Nate Myren116695d2024-02-09 09:36:01 -08009469 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9470 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009471 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009472 callingUid, callingPackage, null, null);
9473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009474 Phone phone = getPhone(subId);
9475 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009476 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9477 phone.carrierActionSetMeteredApnsEnabled(enabled);
9478 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009479 phone.getDataSettingsManager().setDataEnabled(
9480 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009482 }
9483 } finally {
9484 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009485 }
9486 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009487
9488 /**
9489 * Get Client request stats
9490 * @return List of Client Request Stats
9491 * @hide
9492 */
9493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009494 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9495 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009497 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009498 return null;
9499 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009500 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009502 final long identity = Binder.clearCallingIdentity();
9503 try {
9504 if (phone != null) {
9505 return phone.getClientRequestStats();
9506 }
9507
9508 return null;
9509 } finally {
9510 Binder.restoreCallingIdentity(identity);
9511 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009512 }
9513
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009514 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009515 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009516 if (uid == Process.ROOT_UID && packageName == null) {
9517 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9518 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9519 // exception. ROOT_UID seems not to have a valid package name returned by
9520 // PackageManager, so just fake it here to avoid issues when running telephony shell
9521 // commands that plumb through the RIL as root, like so:
9522 // $ adb root
9523 // $ adb shell cmd phone ...
9524 packageName = "root";
9525 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009526 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009527 }
Jack Yueb4124c2017-02-16 15:32:43 -08009528
9529 /**
Grace Chen70990072017-03-24 17:21:30 -07009530 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009531 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009532 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009533 * @param state State of SIM (power down, power up, pass through)
9534 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9535 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9536 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009537 *
9538 **/
9539 @Override
Grace Chen70990072017-03-24 17:21:30 -07009540 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009541 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009542
9543 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9544 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9545
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009546 Phone phone = PhoneFactory.getPhone(slotIndex);
9547
vagdeviaf9a5b92018-08-15 16:01:53 -07009548 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009550 final long identity = Binder.clearCallingIdentity();
9551 try {
9552 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009553 phone.setSimPowerState(state, null, workSource);
9554 }
9555 } finally {
9556 Binder.restoreCallingIdentity(identity);
9557 }
9558 }
9559
9560 /**
9561 * Set SIM card power state.
9562 *
9563 * @param slotIndex SIM slot id.
9564 * @param state State of SIM (power down, power up, pass through)
9565 * @param callback callback to trigger after success or failure
9566 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9567 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9568 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9569 *
9570 **/
9571 @Override
9572 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9573 IIntegerConsumer callback) {
9574 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009575
9576 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9577 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9578 "setSimPowerStateForSlotWithCallback");
9579
Jordan Liu109698e2020-11-24 14:50:34 -08009580 Phone phone = PhoneFactory.getPhone(slotIndex);
9581
9582 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9583
9584 final long identity = Binder.clearCallingIdentity();
9585 try {
9586 if (phone != null) {
9587 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9588 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009589 }
9590 } finally {
9591 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009592 }
9593 }
Shuo Qiandd210312017-04-12 22:11:33 +00009594
Tyler Gunn65d45c22017-06-05 11:22:26 -07009595 private boolean isUssdApiAllowed(int subId) {
9596 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009597 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009598 if (configManager == null) {
9599 return false;
9600 }
9601 PersistableBundle pb = configManager.getConfigForSubId(subId);
9602 if (pb == null) {
9603 return false;
9604 }
9605 return pb.getBoolean(
9606 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9607 }
9608
Shuo Qiandd210312017-04-12 22:11:33 +00009609 /**
Ling Mac28f0212023-03-24 16:07:15 -07009610 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009611 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009612 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009613 */
goneil9c5f4872017-12-05 14:07:56 -08009614 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009615 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009616 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009617
9618 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9619 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009621 final long identity = Binder.clearCallingIdentity();
9622 try {
Ling Mac28f0212023-03-24 16:07:15 -07009623 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009624 } finally {
9625 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009626 }
9627 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009628
9629 /**
9630 * Get the current signal strength information for the given subscription.
9631 * Because this information is not updated when the device is in a low power state
9632 * it should not be relied-upon to be current.
9633 * @param subId Subscription index
9634 * @return the most recent cached signal strength info from the modem
9635 */
9636 @Override
9637 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009638 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9639 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009641 final long identity = Binder.clearCallingIdentity();
9642 try {
9643 Phone p = getPhone(subId);
9644 if (p == null) {
9645 return null;
9646 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009648 return p.getSignalStrength();
9649 } finally {
9650 Binder.restoreCallingIdentity(identity);
9651 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009652 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009653
Pengquan Meng77b7f132018-08-22 14:49:57 -07009654 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009655 * Get the current modem radio state for the given slot.
9656 * @param slotIndex slot index.
9657 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009658 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009659 * @return the current radio power state from the modem
9660 */
9661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009662 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009663 Phone phone = PhoneFactory.getPhone(slotIndex);
9664 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9666 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009667 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9668 }
9669
joonhunshin4ac60942023-11-15 15:23:39 +00009670 enforceTelephonyFeatureWithException(callingPackage,
9671 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9672
Chen Xuf792fd62018-10-17 17:54:36 +00009673 final long identity = Binder.clearCallingIdentity();
9674 try {
9675 return phone.getRadioPowerState();
9676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
9679 }
9680 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9681 }
9682
9683 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009684 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9685 *
9686 * <p>Requires one of the following permissions:
9687 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009688 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009689 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9690 * privileges.
9691 *
9692 * @param subId subscription id
9693 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9694 * {@code false}.
9695 */
9696 @Override
9697 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009698 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009699 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009700 try {
9701 mApp.enforceCallingOrSelfPermission(
9702 android.Manifest.permission.ACCESS_NETWORK_STATE,
9703 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009704 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009705 mApp.enforceCallingOrSelfPermission(
9706 permission.READ_BASIC_PHONE_STATE, functionName);
9707 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009708 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009709 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009710 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009711 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009712
joonhunshin4ac60942023-11-15 15:23:39 +00009713 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9714 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9715
Pengquan Menga1bb6272018-09-06 09:59:22 -07009716 boolean isEnabled = false;
9717 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009718 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009719 Phone phone = getPhone(subId);
9720 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009721 } finally {
9722 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009723 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009724 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009725 }
9726
9727
9728 /**
9729 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9730 *
9731 * <p> Requires permission:
9732 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9733 * privileges.
9734 *
9735 * @param subId subscription id
9736 * @param isEnabled {@code true} means enable, {@code false} means disable.
9737 */
9738 @Override
9739 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9741 mApp, subId, "setDataRoamingEnabled");
9742
joonhunshin4ac60942023-11-15 15:23:39 +00009743 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9744 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9745
Pengquan Menga1bb6272018-09-06 09:59:22 -07009746 final long identity = Binder.clearCallingIdentity();
9747 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009748 Phone phone = getPhone(subId);
9749 if (phone != null) {
9750 phone.setDataRoamingEnabled(isEnabled);
9751 }
9752 } finally {
9753 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009754 }
9755 }
9756
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009757 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009758 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009759 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009760 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009761 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009762
joonhunshin4ac60942023-11-15 15:23:39 +00009763 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9764 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9765
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009766 boolean isAllowed = true;
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009769 Phone phone = getPhone(subId);
9770 if (phone != null) {
9771 isAllowed = phone.isCspPlmnEnabled();
9772 }
9773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 return isAllowed;
9777 }
9778
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009779 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9780 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009781 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009782 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009783 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009784 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9785 if (phone == null) {
9786 return false;
9787 }
9788 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9789 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9790 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009791 }
9792
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009793 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009794 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009795 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009796 mApp.getSystemService(AppOpsManager.class)
9797 .checkPackage(Binder.getCallingUid(), callingPackage);
9798
Jordan Liu1e142fc2019-04-22 15:10:43 -07009799 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009800 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009801 try {
9802 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009803 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009804 } catch (SecurityException e) {
9805 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9806 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009807 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009808 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009809 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009810 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009811 }
joonhunshin4ac60942023-11-15 15:23:39 +00009812
9813 enforceTelephonyFeatureWithException(callingPackage,
9814 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9815
sandeepjsb6c87872021-09-27 15:34:44 +00009816 // checking compatibility, if calling app's target SDK is T and beyond.
9817 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9818 Binder.getCallingUid())) {
9819 isIccIdAccessRestricted = true;
9820 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009821 final long identity = Binder.clearCallingIdentity();
9822 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009823 UiccController uiccController = UiccController.getInstance();
9824 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009825 if (hasReadPermission) {
9826 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009827 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009828
9829 // Remove private info if the caller doesn't have access
9830 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9831 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009832 //setting the value after compatibility check
9833 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009834 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9835 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009836 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009837 if (card == null) {
9838 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009839 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009840 continue;
9841 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009842 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9843 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009844 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009845 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009846 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009847 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9848 for (UiccPortInfo portInfo : portInfos) {
9849 UiccPort port = uiccController.getUiccPortForSlot(
9850 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9851 if (port == null) {
9852 // assume no access if port is null
9853 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9854 continue;
9855 }
9856 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9857 uiccPortInfos.add(portInfo);
9858 } else {
9859 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9860 }
9861 }
9862 filteredInfos.add(new UiccCardInfo(
9863 cardInfo.isEuicc(),
9864 cardInfo.getCardId(),
9865 null,
9866 cardInfo.getPhysicalSlotIndex(),
9867 cardInfo.isRemovable(),
9868 cardInfo.isMultipleEnabledProfilesSupported(),
9869 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009870 }
9871 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009872 } finally {
9873 Binder.restoreCallingIdentity(identity);
9874 }
9875 }
9876
sandeepjsb6c87872021-09-27 15:34:44 +00009877 /**
9878 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9879 * generally private and require carrier privileges to view.
9880 *
9881 * @hide
9882 */
9883 @NonNull
9884 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9885 List<UiccPortInfo> portinfo = new ArrayList<>();
9886 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9887 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9888 }
9889 return new UiccCardInfo(
9890 cardInfo.isEuicc(),
9891 cardInfo.getCardId(),
9892 null,
9893 cardInfo.getPhysicalSlotIndex(),
9894 cardInfo.isRemovable(),
9895 cardInfo.isMultipleEnabledProfilesSupported(),
9896 portinfo
9897 );
9898 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009899
sandeepjsb6c87872021-09-27 15:34:44 +00009900 /**
9901 * @hide
9902 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9903 * These values are generally private and require carrier privileges to view.
9904 */
9905 @NonNull
9906 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9907 return new UiccPortInfo(
9908 UiccPortInfo.ICCID_REDACTED,
9909 portInfo.getPortIndex(),
9910 portInfo.getLogicalSlotIndex(),
9911 portInfo.isActive()
9912 );
9913 }
9914 @Override
9915 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009916 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009917 mApp.getSystemService(AppOpsManager.class)
9918 .checkPackage(Binder.getCallingUid(), callingPackage);
9919
sandeepjsb6c87872021-09-27 15:34:44 +00009920 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009921
Aman Guptaf3c90b32022-03-17 04:54:16 +00009922 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9923 // we are reading iccId which is PII data.
9924 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009925
joonhunshin4ac60942023-11-15 15:23:39 +00009926 enforceTelephonyFeatureWithException(callingPackage,
9927 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9928
sandeepjsb6c87872021-09-27 15:34:44 +00009929 // checking compatibility, if calling app's target SDK is T and beyond.
9930 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9931 Binder.getCallingUid())) {
9932 isLogicalSlotAccessRestricted = true;
9933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009934 final long identity = Binder.clearCallingIdentity();
9935 try {
9936 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009937 if (slots == null || slots.length == 0) {
9938 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009939 return null;
9940 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009941 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9942 for (int i = 0; i < slots.length; i++) {
9943 UiccSlot slot = slots[i];
9944 if (slot == null) {
9945 continue;
9946 }
9947
Jordan Liu7be7e652019-05-06 18:55:02 +00009948 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009949 UiccCard card = slot.getUiccCard();
9950 if (card != null) {
9951 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009952 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009953 cardId = slot.getEid();
9954 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009955 // If cardId is null, use iccId of default port as cardId.
9956 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009958 }
9959
Jordan Liu857451f2019-05-09 16:35:35 -07009960 if (cardId != null) {
9961 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9962 // if cardId is an EID, it's all digits so this is fine
9963 cardId = IccUtils.stripTrailingFs(cardId);
9964 }
9965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009966 int cardState = 0;
9967 switch (slot.getCardState()) {
9968 case CARDSTATE_ABSENT:
9969 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9970 break;
9971 case CARDSTATE_PRESENT:
9972 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9973 break;
9974 case CARDSTATE_ERROR:
9975 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9976 break;
9977 case CARDSTATE_RESTRICTED:
9978 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9979 break;
9980 default:
9981 break;
9982
9983 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009984 List<UiccPortInfo> portInfos = new ArrayList<>();
9985 int[] portIndexes = slot.getPortList();
9986 for (int portIdx : portIndexes) {
9987 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009988 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009989 portInfos.add(new UiccPortInfo(iccId, portIdx,
9990 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009992 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009993 slot.isEuicc(),
9994 cardId,
9995 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009996 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009997 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009998 //setting the value after compatibility check
9999 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010000 }
10001 return infos;
10002 } finally {
10003 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010004 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010005 }
10006
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010007 /* Returns null if doesn't have read permission or carrier privilege access. */
10008 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10009 boolean hasReadPermission) {
10010 String iccId = slot.getIccId(portIndex);
10011 if (hasReadPermission) { // if has read permission
10012 return iccId;
10013 } else {
10014 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10015 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10016 // if no read permission, checking carrier privilege access
10017 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10018 return iccId;
10019 }
10020 }
10021 }
10022 // No read permission or carrier privilege access.
10023 return UiccPortInfo.ICCID_REDACTED;
10024 }
10025
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010026 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010027 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010028 public boolean switchSlots(int[] physicalSlots) {
10029 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010030
joonhunshin4ac60942023-11-15 15:23:39 +000010031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10032 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10033
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010034 final long identity = Binder.clearCallingIdentity();
10035 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010036 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10037 for (int i = 0; i < physicalSlots.length; i++) {
10038 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10039 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10040 physicalSlots[i], i));
10041 }
10042 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010043 } finally {
10044 Binder.restoreCallingIdentity(identity);
10045 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010046 }
Jack Yu4c988042018-02-27 15:30:01 -080010047
10048 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010049 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10050 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10051 enforceModifyPermission();
10052
joonhunshin4ac60942023-11-15 15:23:39 +000010053 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10054 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10055
sandeepjsb6c87872021-09-27 15:34:44 +000010056 final long identity = Binder.clearCallingIdentity();
10057 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010058 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010059 } finally {
10060 Binder.restoreCallingIdentity(identity);
10061 }
10062 }
10063
10064 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010065 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010066 enforceTelephonyFeatureWithException(callingPackage,
10067 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10068
Jordan Liu7de49fa2018-12-06 14:48:49 -080010069 final long identity = Binder.clearCallingIdentity();
10070 try {
10071 return UiccController.getInstance().getCardIdForDefaultEuicc();
10072 } finally {
10073 Binder.restoreCallingIdentity(identity);
10074 }
10075 }
10076
Pengquan Meng85728fb2018-03-12 16:31:21 -070010077 /**
goneil47ffb6e2018-04-06 15:40:58 -070010078 * A test API to reload the UICC profile.
10079 *
10080 * <p>Requires that the calling app has permission
10081 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10082 * @hide
10083 */
10084 @Override
10085 public void refreshUiccProfile(int subId) {
10086 enforceModifyPermission();
10087
10088 final long identity = Binder.clearCallingIdentity();
10089 try {
10090 Phone phone = getPhone(subId);
10091 if (phone == null) {
10092 return;
10093 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010094 UiccPort uiccPort = phone.getUiccPort();
10095 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010096 return;
10097 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010098 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010099 if (uiccProfile == null) {
10100 return;
10101 }
10102 uiccProfile.refresh();
10103 } finally {
10104 Binder.restoreCallingIdentity(identity);
10105 }
10106 }
10107
10108 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010109 * Returns false if the mobile data is disabled by default, otherwise return true.
10110 */
10111 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010112 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010113 }
10114
10115 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010116 * Returns the default network type for the given {@code subId}, if the default network type is
10117 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10118 */
10119 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010120 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010121 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010122 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10123 return list.get(phoneId);
10124 }
10125 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010126 }
fionaxua13278b2018-03-21 00:08:13 -070010127
10128 @Override
10129 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010130 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010132
10133 final long identity = Binder.clearCallingIdentity();
10134 try {
10135 final Phone phone = getPhone(subId);
10136 if (phone == null) {
10137 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10138 return;
10139 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010140 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10141 if (cpt != null) {
10142 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10143 }
10144 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010145 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10146 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010147 if (carrierPrivilegeRules == null) {
10148 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10149 } else {
10150 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010152 } finally {
10153 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010154 }
fionaxua13278b2018-03-21 00:08:13 -070010155 }
10156
10157 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010158 public void setCarrierServicePackageOverride(
10159 int subId, String carrierServicePackage, String callingPackage) {
10160 TelephonyPermissions.enforceShellOnly(
10161 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10162
Benedict Wong66477622023-02-03 23:30:57 +000010163 final long identity = Binder.clearCallingIdentity();
10164 try {
10165 final Phone phone = getPhone(subId);
10166 if (phone == null || phone.getSubId() != subId) {
10167 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10168 throw new IllegalArgumentException("No phone for subid");
10169 }
10170 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10171 if (cpt == null) {
10172 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10173 throw new IllegalStateException("No CPT for phone");
10174 }
10175 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10176 } finally {
10177 Binder.restoreCallingIdentity(identity);
10178 }
10179 }
10180
10181 @Override
fionaxua13278b2018-03-21 00:08:13 -070010182 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010183 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010184
10185 final long identity = Binder.clearCallingIdentity();
10186 try {
10187 final Phone phone = getPhone(subId);
10188 if (phone == null) {
10189 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10190 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10191 }
10192 return phone.getCarrierIdListVersion();
10193 } finally {
10194 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010195 }
fionaxua13278b2018-03-21 00:08:13 -070010196 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010197
10198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010199 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10200 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010202 mApp, subId, callingPackage, callingFeatureId,
10203 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010204 return -1;
10205 }
10206
10207 final long identity = Binder.clearCallingIdentity();
10208 try {
10209 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10210 } finally {
10211 Binder.restoreCallingIdentity(identity);
10212 }
10213 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010214
10215 @Override
10216 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010217 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010218 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010219 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010220
joonhunshin4ac60942023-11-15 15:23:39 +000010221 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10222 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10223
Pengquan Menga1bb6272018-09-06 09:59:22 -070010224 final long identity = Binder.clearCallingIdentity();
10225 try {
10226 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10227 } finally {
10228 Binder.restoreCallingIdentity(identity);
10229 }
10230 }
10231
10232 @Override
10233 public boolean setCdmaRoamingMode(int subId, int mode) {
10234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10235 mApp, subId, "setCdmaRoamingMode");
10236
joonhunshin4ac60942023-11-15 15:23:39 +000010237 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10238 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10239
Pengquan Menga1bb6272018-09-06 09:59:22 -070010240 final long identity = Binder.clearCallingIdentity();
10241 try {
10242 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10243 } finally {
10244 Binder.restoreCallingIdentity(identity);
10245 }
10246 }
10247
10248 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010249 public int getCdmaSubscriptionMode(int subId) {
10250 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010251 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010252 mApp, subId, "getCdmaSubscriptionMode");
10253
joonhunshin4ac60942023-11-15 15:23:39 +000010254 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10255 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10256
Sarah Chinbaab1432020-10-28 13:46:24 -070010257 final long identity = Binder.clearCallingIdentity();
10258 try {
10259 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10260 } finally {
10261 Binder.restoreCallingIdentity(identity);
10262 }
10263 }
10264
10265 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010266 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10268 mApp, subId, "setCdmaSubscriptionMode");
10269
joonhunshin4ac60942023-11-15 15:23:39 +000010270 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10271 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10272
Pengquan Menga1bb6272018-09-06 09:59:22 -070010273 final long identity = Binder.clearCallingIdentity();
10274 try {
10275 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10276 } finally {
10277 Binder.restoreCallingIdentity(identity);
10278 }
10279 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010280
sqianc5eccab2018-10-19 18:46:41 -070010281 @Override
sqian8c685422019-02-22 15:55:18 -080010282 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010283 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010285 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10286 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010287 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10288 }
joonhunshin4ac60942023-11-15 15:23:39 +000010289
10290 enforceTelephonyFeatureWithException(callingPackage,
10291 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10292
sqian11b7a0e2018-12-05 18:48:28 -080010293 final long identity = Binder.clearCallingIdentity();
10294 try {
sqian854d44b2018-12-12 16:48:18 -080010295 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10296 for (Phone phone: PhoneFactory.getPhones()) {
10297 if (phone.getEmergencyNumberTracker() != null
10298 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10299 emergencyNumberListInternal.put(
10300 phone.getSubId(),
10301 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10302 }
sqian11b7a0e2018-12-05 18:48:28 -080010303 }
sqian854d44b2018-12-12 16:48:18 -080010304 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010305 } finally {
10306 Binder.restoreCallingIdentity(identity);
10307 }
sqianc5eccab2018-10-19 18:46:41 -070010308 }
10309
10310 @Override
sqian8c685422019-02-22 15:55:18 -080010311 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010312 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010313 if (!exactMatch) {
10314 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010315 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010316 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010317 }
joonhunshin4ac60942023-11-15 15:23:39 +000010318
10319 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10320 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10321
sqian11b7a0e2018-12-05 18:48:28 -080010322 final long identity = Binder.clearCallingIdentity();
10323 try {
sqian854d44b2018-12-12 16:48:18 -080010324 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010325 //Note: we ignore passed in param exactMatch. We can remove it once
10326 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010327 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010328 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010329 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010330 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010331 }
sqian11b7a0e2018-12-05 18:48:28 -080010332 }
10333 return false;
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
10338
sqianf4ca7ed2019-01-15 18:32:07 -080010339 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010340 * Start emergency callback mode for GsmCdmaPhone for testing.
10341 */
10342 @Override
10343 public void startEmergencyCallbackMode() {
10344 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10345 "startEmergencyCallbackMode");
10346 enforceModifyPermission();
10347 final long identity = Binder.clearCallingIdentity();
10348 try {
10349 for (Phone phone : PhoneFactory.getPhones()) {
10350 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10351 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10352 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10353 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10354 gsmCdmaPhone.obtainMessage(
10355 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10356 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10357 }
10358 }
10359 } finally {
10360 Binder.restoreCallingIdentity(identity);
10361 }
10362 }
10363
10364 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010365 * Update emergency number list for test mode.
10366 */
10367 @Override
10368 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10369 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10370 "updateEmergencyNumberListTestMode");
10371
10372 final long identity = Binder.clearCallingIdentity();
10373 try {
10374 for (Phone phone: PhoneFactory.getPhones()) {
10375 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10376 if (tracker != null) {
10377 tracker.executeEmergencyNumberTestModeCommand(action, num);
10378 }
10379 }
10380 } finally {
10381 Binder.restoreCallingIdentity(identity);
10382 }
10383 }
10384
10385 /**
10386 * Get the full emergency number list for test mode.
10387 */
10388 @Override
10389 public List<String> getEmergencyNumberListTestMode() {
10390 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10391 "getEmergencyNumberListTestMode");
10392
10393 final long identity = Binder.clearCallingIdentity();
10394 try {
10395 Set<String> emergencyNumbers = new HashSet<>();
10396 for (Phone phone: PhoneFactory.getPhones()) {
10397 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10398 if (tracker != null) {
10399 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10400 emergencyNumbers.add(num.getNumber());
10401 }
10402 }
10403 }
10404 return new ArrayList<>(emergencyNumbers);
10405 } finally {
10406 Binder.restoreCallingIdentity(identity);
10407 }
10408 }
10409
chen xud6b45bd2018-10-30 22:27:10 -070010410 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010411 public int getEmergencyNumberDbVersion(int subId) {
10412 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10413
joonhunshin4ac60942023-11-15 15:23:39 +000010414 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10415 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10416
Shuo Qian3b6ee772019-11-13 17:43:31 -080010417 final long identity = Binder.clearCallingIdentity();
10418 try {
10419 final Phone phone = getPhone(subId);
10420 if (phone == null) {
10421 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10422 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10423 }
10424 return phone.getEmergencyNumberDbVersion();
10425 } finally {
10426 Binder.restoreCallingIdentity(identity);
10427 }
10428 }
10429
10430 @Override
10431 public void notifyOtaEmergencyNumberDbInstalled() {
10432 enforceModifyPermission();
10433
joonhunshin4ac60942023-11-15 15:23:39 +000010434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10435 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10436
Shuo Qian3b6ee772019-11-13 17:43:31 -080010437 final long identity = Binder.clearCallingIdentity();
10438 try {
10439 for (Phone phone: PhoneFactory.getPhones()) {
10440 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10441 if (tracker != null) {
10442 tracker.updateOtaEmergencyNumberDatabase();
10443 }
10444 }
10445 } finally {
10446 Binder.restoreCallingIdentity(identity);
10447 }
10448 }
10449
10450 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010451 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010452 enforceActiveEmergencySessionPermission();
10453
joonhunshin4ac60942023-11-15 15:23:39 +000010454 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10455 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10456
Shuo Qian3b6ee772019-11-13 17:43:31 -080010457 final long identity = Binder.clearCallingIdentity();
10458 try {
10459 for (Phone phone: PhoneFactory.getPhones()) {
10460 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10461 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010462 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10463 }
10464 }
10465 } finally {
10466 Binder.restoreCallingIdentity(identity);
10467 }
10468 }
10469
10470 @Override
10471 public void resetOtaEmergencyNumberDbFilePath() {
10472 enforceActiveEmergencySessionPermission();
10473
joonhunshin4ac60942023-11-15 15:23:39 +000010474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10475 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10476
Shuo Qianc373f112020-03-05 17:55:34 -080010477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 for (Phone phone: PhoneFactory.getPhones()) {
10480 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10481 if (tracker != null) {
10482 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010483 }
10484 }
10485 } finally {
10486 Binder.restoreCallingIdentity(identity);
10487 }
10488 }
10489
10490 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010491 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10492 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10493 Phone phone = getPhone(subId);
10494 if (phone == null) {
10495 return null;
10496 }
10497 final long identity = Binder.clearCallingIdentity();
10498 try {
10499 UiccProfile profile = UiccController.getInstance()
10500 .getUiccProfileForPhone(phone.getPhoneId());
10501 if (profile != null) {
10502 return profile.getCertsFromCarrierPrivilegeAccessRules();
10503 }
10504 } finally {
10505 Binder.restoreCallingIdentity(identity);
10506 }
10507 return null;
10508 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010509
10510 /**
10511 * Enable or disable a modem stack.
10512 */
10513 @Override
10514 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10515 enforceModifyPermission();
10516
joonhunshin4ac60942023-11-15 15:23:39 +000010517 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10518 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10519
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010520 final long identity = Binder.clearCallingIdentity();
10521 try {
10522 Phone phone = PhoneFactory.getPhone(slotIndex);
10523 if (phone == null) {
10524 return false;
10525 } else {
10526 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10527 }
10528 } finally {
10529 Binder.restoreCallingIdentity(identity);
10530 }
10531 }
Michelecea4cf22018-12-21 15:00:11 -080010532
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010533 /**
10534 * Whether a modem stack is enabled or not.
10535 */
10536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010537 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10538 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010539 Phone phone = PhoneFactory.getPhone(slotIndex);
10540 if (phone == null) return false;
10541
10542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010543 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10544 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010545 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10546 }
10547
joonhunshin4ac60942023-11-15 15:23:39 +000010548 enforceTelephonyFeatureWithException(callingPackage,
10549 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10550
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010551 final long identity = Binder.clearCallingIdentity();
10552 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010553 try {
10554 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10555 } catch (NoSuchElementException ex) {
10556 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10557 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010558 } finally {
10559 Binder.restoreCallingIdentity(identity);
10560 }
10561 }
10562
Michelecea4cf22018-12-21 15:00:11 -080010563 @Override
Michele0ea7d782019-03-19 14:58:42 -070010564 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010565 enforceModifyPermission();
10566
joonhunshin4ac60942023-11-15 15:23:39 +000010567 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10568 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10569
Michelecea4cf22018-12-21 15:00:11 -080010570 final long identity = Binder.clearCallingIdentity();
10571 try {
10572 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010573 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010574 .commit();
10575 } finally {
10576 Binder.restoreCallingIdentity(identity);
10577 }
10578 }
10579
10580 @Override
Michele0ea7d782019-03-19 14:58:42 -070010581 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010582 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010584 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10585 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010586 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010587 }
Michelecea4cf22018-12-21 15:00:11 -080010588
joonhunshin4ac60942023-11-15 15:23:39 +000010589 enforceTelephonyFeatureWithException(callingPackage,
10590 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10591
Michelecea4cf22018-12-21 15:00:11 -080010592 final long identity = Binder.clearCallingIdentity();
10593 try {
Michele0ea7d782019-03-19 14:58:42 -070010594 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010599
Michele0ea7d782019-03-19 14:58:42 -070010600 @TelephonyManager.IsMultiSimSupportedResult
10601 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010602 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10603 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10604 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010605 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10606 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010607 }
10608 // Check if the hardware supports multisim functionality. If usage of multisim is not
10609 // supported by the modem, indicate that it is restricted.
10610 PhoneCapability staticCapability =
10611 mPhoneConfigurationManager.getStaticPhoneCapability();
10612 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010613 loge("isMultiSimSupportedInternal: no static configuration available");
10614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010615 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010616 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010617 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10618 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010619 }
10620 // Check if support of multiple SIMs is restricted by carrier
10621 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010622 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010623 }
10624
Michele0ea7d782019-03-19 14:58:42 -070010625 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010626 }
10627
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010628 /**
10629 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010630 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10631 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10632 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010633 * @param numOfSims number of active sims we want to switch to
10634 */
10635 @Override
10636 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010637 if (numOfSims == 1) {
10638 enforceModifyPermission();
10639 } else {
10640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10641 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10642 }
joonhunshin4ac60942023-11-15 15:23:39 +000010643
10644 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10645 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10646
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010647 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010648
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010649 try {
Michele30b57b22019-03-01 12:01:14 -080010650 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010651 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010652 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10653 return;
10654 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010655 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10656 } finally {
10657 Binder.restoreCallingIdentity(identity);
10658 }
10659 }
10660
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010661 @Override
10662 public boolean isApplicationOnUicc(int subId, int appType) {
10663 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010664
10665 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10666 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10667
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010668 Phone phone = getPhone(subId);
10669 if (phone == null) {
10670 return false;
10671 }
10672 final long identity = Binder.clearCallingIdentity();
10673 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010674 UiccPort uiccPort = phone.getUiccPort();
10675 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010676 return false;
10677 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010678 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010679 if (uiccProfile == null) {
10680 return false;
10681 }
10682 if (TelephonyManager.APPTYPE_SIM <= appType
10683 && appType <= TelephonyManager.APPTYPE_ISIM) {
10684 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10685 }
10686 return false;
10687 } finally {
10688 Binder.restoreCallingIdentity(identity);
10689 }
10690 }
10691
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010692 /**
chen xub4baa772019-04-03 10:23:41 -070010693 * Get whether making changes to modem configurations will trigger reboot.
10694 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010695 */
10696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010697 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10698 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010700 mApp, subId, callingPackage, callingFeatureId,
10701 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010702 return false;
10703 }
joonhunshin4ac60942023-11-15 15:23:39 +000010704
10705 enforceTelephonyFeatureWithException(callingPackage,
10706 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10707 "doesSwitchMultiSimConfigTriggerReboot");
10708
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010709 final long identity = Binder.clearCallingIdentity();
10710 try {
10711 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10712 } finally {
10713 Binder.restoreCallingIdentity(identity);
10714 }
10715 }
10716
Nathan Harold29f5f052019-02-15 13:41:57 -080010717 private void updateModemStateMetrics() {
10718 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10719 // TODO: check the state for each modem if the api is ready.
10720 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10721 }
10722
Pengquan Meng3889a572019-01-23 11:16:29 -080010723 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010724 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010725 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010726 // Verify that the callingPackage belongs to the calling UID
10727 mApp.getSystemService(AppOpsManager.class)
10728 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010729
10730 enforceTelephonyFeatureWithException(callingPackage,
10731 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10732
Pengquan Meng3889a572019-01-23 11:16:29 -080010733 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010734 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010735 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010736 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10737 if (slotInfos != null) {
10738 for (int i = 0; i < slotInfos.length; i++) {
10739 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10740 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10741 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10742 portInfo.getLogicalSlotIndex()));
10743 }
10744 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010745 }
10746 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010747 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010752
10753 /**
10754 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010755 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010756 */
jimsunf9ec1622022-09-13 21:18:43 +080010757 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010758 @Override
10759 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010760 return getHalVersion(HAL_SERVICE_RADIO);
10761 }
10762
10763 /**
10764 * Get the HAL Version of a specific service
10765 */
10766 @Override
10767 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010768 Phone phone = getDefaultPhone();
10769 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010770 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010771 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10772 return hv.major * 100 + hv.minor;
10773 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010774
10775 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010776 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010777 *
10778 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010779 */
10780 @Override
sangyun097dcf72024-01-04 10:35:49 +090010781 public @Nullable String getCurrentPackageName() {
10782 PackageManager pm = mApp.getPackageManager();
10783 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10784 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010785 }
10786
10787 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010788 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10789 * corresponding network requests on a subId.
10790 *
10791 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010792 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010793 * 2) APN is un-metered for this subscription, or
10794 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010795 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010796 *
10797 * @return whether data is allowed for a apn type.
10798 *
10799 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010800 */
10801 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010802 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010803 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10804 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010805
joonhunshin4ac60942023-11-15 15:23:39 +000010806 enforceTelephonyFeatureWithException(callingPackage,
10807 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10808
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010809 // Now that all security checks passes, perform the operation as ourselves.
10810 final long identity = Binder.clearCallingIdentity();
10811 try {
10812 Phone phone = getPhone(subId);
10813 if (phone == null) return false;
10814
Jack Yu27422a52022-03-21 10:38:05 -070010815 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010816 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010817 isMetered = phone.getDataNetworkController().getDataConfigManager()
10818 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10819 phone.getServiceState().getDataRoaming());
10820 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010821 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
10827 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010828 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010829 enforceReadPrivilegedPermission("isApnMetered");
10830
joonhunshin4ac60942023-11-15 15:23:39 +000010831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10832 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10833
Malcolm Chene5ad5792019-04-18 13:51:02 -070010834 // Now that all security checks passes, perform the operation as ourselves.
10835 final long identity = Binder.clearCallingIdentity();
10836 try {
10837 Phone phone = getPhone(subId);
10838 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010839 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10840 DataUtils.apnTypeToNetworkCapability(apnType),
10841 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010846
10847 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010848 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10849 int subscriptionId, IBooleanConsumer resultCallback) {
10850 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010851
10852 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10853 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10854
Hall Liu73f5d362020-01-20 13:42:00 -080010855 long token = Binder.clearCallingIdentity();
10856 try {
10857 Phone phone = getPhone(subscriptionId);
10858 if (phone == null) {
10859 try {
10860 if (resultCallback != null) {
10861 resultCallback.accept(false);
10862 }
10863 } catch (RemoteException e) {
10864 // ignore
10865 }
10866 return;
10867 }
10868 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10869 Pair.create(specifiers, (x) -> {
10870 try {
10871 if (resultCallback != null) {
10872 resultCallback.accept(x);
10873 }
10874 } catch (RemoteException e) {
10875 // ignore
10876 }
10877 });
10878 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10879 } finally {
10880 Binder.restoreCallingIdentity(token);
10881 }
10882 }
10883
10884 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010885 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10886 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010887 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010888 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010889
10890 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10891 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10892
Sarah Chin679c08a2020-11-18 13:39:35 -080010893 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010896 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10897 if (result instanceof IllegalStateException) {
10898 throw (IllegalStateException) result;
10899 }
10900 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010901 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10902 return specifiers;
10903 } finally {
10904 Binder.restoreCallingIdentity(identity);
10905 }
10906 }
10907
10908 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010909 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010910 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010911
10912 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10913 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10914
Jack Yu8b766fc2022-03-21 09:42:33 -070010915 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010916 }
10917
10918 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010919 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10920 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010921 if (callingPackage == null) {
10922 callingPackage = getCurrentPackageName();
10923 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010924 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10925 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010926 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10927 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010928 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10929 }
10930 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10931 Intent intent = new Intent();
10932 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10933 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10934 // Bring up choose default SMS subscription dialog right now
10935 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10936 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10937 mApp.startActivity(intent);
10938 }
chen xud5ca2d52019-05-28 15:20:57 -070010939
10940 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010941 public void showSwitchToManagedProfileDialog() {
10942 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010943 try {
10944 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10945 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10946 // for work telephony.
10947 Intent intent = new Intent(Intent.ACTION_SENDTO);
10948 intent.setData(Uri.parse("smsto:"));
10949 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10950 mApp.startActivity(intent);
10951 } catch (ActivityNotFoundException e) {
10952 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10953 Intent intent = new Intent();
10954 intent.setClass(mApp, ErrorDialogActivity.class);
10955 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10956 mApp.startActivity(intent);
10957 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010958 }
10959
10960 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010961 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010962 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10963 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10964
chen xud5ca2d52019-05-28 15:20:57 -070010965 //TODO investigate if this API should require proper permission check in R b/133791609
10966 final long identity = Binder.clearCallingIdentity();
10967 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010968 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10969 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10970 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10971 return carrierUAProfUrl;
10972 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010973 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10974 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010975 } finally {
10976 Binder.restoreCallingIdentity(identity);
10977 }
10978 }
10979
10980 @Override
10981 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10983 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10984
chen xud5ca2d52019-05-28 15:20:57 -070010985 //TODO investigate if this API should require proper permission check in R b/133791609
10986 final long identity = Binder.clearCallingIdentity();
10987 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010988 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10989 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10990 if (!TextUtils.isEmpty(carrierUserAgent)) {
10991 return carrierUserAgent;
10992 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010993 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10994 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
Jack Yub07d4972019-05-28 16:12:25 -070010999
11000 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011001 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11002 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011003
joonhunshin4ac60942023-11-15 15:23:39 +000011004 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11005 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11006
Jack Yub07d4972019-05-28 16:12:25 -070011007 final long identity = Binder.clearCallingIdentity();
11008 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011009 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011010 if (phone == null) return false;
11011
Ling Maf188d502022-09-16 15:22:36 -070011012 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011013 } finally {
11014 Binder.restoreCallingIdentity(identity);
11015 }
11016 }
11017
11018 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011019 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011020 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011021 enforceModifyPermission();
11022
joonhunshin4ac60942023-11-15 15:23:39 +000011023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11024 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11025
changbettyd5c246e2019-12-24 15:40:37 +080011026 final long identity = Binder.clearCallingIdentity();
11027 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011028 Phone phone = getPhone(subscriptionId);
11029 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011030
Ling Maf188d502022-09-16 15:22:36 -070011031 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011032 } finally {
11033 Binder.restoreCallingIdentity(identity);
11034 }
11035 }
11036
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011037 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011038 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011039 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11040 * otherwise.
11041 */
11042 @Override
11043 public void setCepEnabled(boolean isCepEnabled) {
11044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11045
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
11048 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11049 for (Phone phone : PhoneFactory.getPhones()) {
11050 Phone defaultPhone = phone.getImsPhone();
11051 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11052 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11053 ImsPhoneCallTracker imsPhoneCallTracker =
11054 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11055 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11056 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11057 + imsPhone.getMsisdn());
11058 }
11059 }
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
allenwtsu46dcc572020-01-08 18:24:03 +080011064
11065 /**
11066 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11067 *
11068 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11069 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11070 * before being read.
11071 */
11072 @Override
11073 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11074 isCompressed) {
11075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11076 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011077 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11078 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11079 }
joonhunshin4ac60942023-11-15 15:23:39 +000011080
11081 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11082 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11083 Binder.getCallingUserHandle())) {
11084 if (!isImsAvailableOnDevice()) {
11085 // ProvisioningManager can not handle ServiceSpecificException.
11086 // Throw the IllegalStateException and annotate ProvisioningManager.
11087 throw new IllegalStateException("IMS not available on device.");
11088 }
11089 } else {
11090 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11091 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11092 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011093 }
11094
11095 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011096 try {
Hui Wang761a6682020-10-31 05:12:53 +000011097 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11098 } finally {
11099 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011100 }
11101 }
zoey chene02881a2019-12-30 16:11:23 +080011102
11103 @Override
11104 public boolean isIccLockEnabled(int subId) {
11105 enforceReadPrivilegedPermission("isIccLockEnabled");
11106
joonhunshin4ac60942023-11-15 15:23:39 +000011107 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11108 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11109
zoey chene02881a2019-12-30 16:11:23 +080011110 // Now that all security checks passes, perform the operation as ourselves.
11111 final long identity = Binder.clearCallingIdentity();
11112 try {
11113 Phone phone = getPhone(subId);
11114 if (phone != null && phone.getIccCard() != null) {
11115 return phone.getIccCard().getIccLockEnabled();
11116 } else {
11117 return false;
11118 }
11119 } finally {
11120 Binder.restoreCallingIdentity(identity);
11121 }
11122 }
11123
11124 /**
11125 * Set the ICC pin lock enabled or disabled.
11126 *
11127 * @return an integer representing the status of IccLock enabled or disabled in the following
11128 * three cases:
11129 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11130 * successfully.
11131 * - Positive number and zero for remaining password attempts.
11132 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11133 *
11134 */
11135 @Override
11136 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11137 enforceModifyPermission();
11138
joonhunshin4ac60942023-11-15 15:23:39 +000011139 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11140 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11141
zoey chene02881a2019-12-30 16:11:23 +080011142 Phone phone = getPhone(subId);
11143 if (phone == null) {
11144 return 0;
11145 }
11146 // Now that all security checks passes, perform the operation as ourselves.
11147 final long identity = Binder.clearCallingIdentity();
11148 try {
11149 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11150 new Pair<Boolean, String>(enabled, password), phone, null);
11151 return attemptsRemaining;
11152
11153 } catch (Exception e) {
11154 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11155 } finally {
11156 Binder.restoreCallingIdentity(identity);
11157 }
11158 return 0;
11159 }
11160
11161 /**
11162 * Change the ICC password used in ICC pin lock.
11163 *
11164 * @return an integer representing the status of IccLock changed in the following three cases:
11165 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11166 * - Positive number and zero for remaining password attempts.
11167 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11168 *
11169 */
11170 @Override
11171 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11172 enforceModifyPermission();
11173
joonhunshin4ac60942023-11-15 15:23:39 +000011174 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11175 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11176
zoey chene02881a2019-12-30 16:11:23 +080011177 Phone phone = getPhone(subId);
11178 if (phone == null) {
11179 return 0;
11180 }
11181 // Now that all security checks passes, perform the operation as ourselves.
11182 final long identity = Binder.clearCallingIdentity();
11183 try {
11184 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11185 new Pair<String, String>(oldPassword, newPassword), phone, null);
11186 return attemptsRemaining;
11187
11188 } catch (Exception e) {
11189 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11190 } finally {
11191 Binder.restoreCallingIdentity(identity);
11192 }
11193 return 0;
11194 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011195
11196 /**
11197 * Request for receiving user activity notification
11198 */
11199 @Override
11200 public void requestUserActivityNotification() {
11201 if (!mNotifyUserActivity.get()
11202 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11203 mNotifyUserActivity.set(true);
11204 }
11205 }
11206
11207 /**
11208 * Called when userActivity is signalled in the power manager.
11209 * This is safe to call from any thread, with any window manager locks held or not.
11210 */
11211 @Override
11212 public void userActivity() {
11213 // ***************************************
11214 // * Inherited from PhoneWindowManager *
11215 // ***************************************
11216 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11217 // WITH ITS LOCKS HELD.
11218 //
11219 // This code must be VERY careful about the locks
11220 // it acquires.
11221 // In fact, the current code acquires way too many,
11222 // and probably has lurking deadlocks.
11223
11224 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11225 throw new SecurityException("Only the OS may call notifyUserActivity()");
11226 }
11227
11228 if (mNotifyUserActivity.getAndSet(false)) {
11229 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11230 USER_ACTIVITY_NOTIFICATION_DELAY);
11231 }
11232 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011233
11234 @Override
11235 public boolean canConnectTo5GInDsdsMode() {
11236 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11237 }
Jack Yud10cdd42020-09-28 20:28:01 -070011238
11239 @Override
11240 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11241 String callingFeatureId) {
11242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11243 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11244 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11245 }
11246
joonhunshin4ac60942023-11-15 15:23:39 +000011247 enforceTelephonyFeatureWithException(callingPackage,
11248 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11249
Jack Yud10cdd42020-09-28 20:28:01 -070011250 Phone phone = getPhone(subId);
11251 if (phone == null) {
11252 throw new RuntimeException("phone is not available");
11253 }
11254 // Now that all security checks passes, perform the operation as ourselves.
11255 final long identity = Binder.clearCallingIdentity();
11256 try {
11257 return phone.getEquivalentHomePlmns();
11258 } finally {
11259 Binder.restoreCallingIdentity(identity);
11260 }
11261 }
Daniel Bright59e67312020-11-13 11:49:37 -080011262
11263 @Override
11264 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011265 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011266 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11267 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11268 "isRadioInterfaceCapabilitySupported");
11269
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011270 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011271 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011272 if (radioInterfaceCapabilities == null) {
11273 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011274 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011275 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011276 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011277
Hui Wang641e81c2020-10-12 12:14:23 -070011278 @Override
11279 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11280 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011281 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11282 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11283 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11284 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11285 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011286
11287 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11288 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11289
Hui Wang641e81c2020-10-12 12:14:23 -070011290 if (DBG) {
11291 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11292 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11293 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11294 }
11295
11296 if (!SubscriptionManager.isValidSubscriptionId(subId)
11297 || appType < TelephonyManager.APPTYPE_UNKNOWN
11298 || appType > TelephonyManager.APPTYPE_ISIM
11299 || nafUrl == null || securityProtocol == null || callback == null) {
11300 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11301 if (callback != null) {
11302 try {
11303 callback.onAuthenticationFailure(
11304 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11305 } catch (RemoteException exception) {
11306 log("Fail to notify onAuthenticationFailure due to " + exception);
11307 }
11308 return;
11309 }
11310 }
11311
11312 final long token = Binder.clearCallingIdentity();
11313 try {
11314 getGbaManager(subId).bootstrapAuthenticationRequest(
11315 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011316 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011317 } finally {
11318 Binder.restoreCallingIdentity(token);
11319 }
11320 }
11321
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011322 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011323 * Attempts to set the radio power state for all phones for thermal reason.
11324 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011325 * requested radio power state will actually be set. See {@link
11326 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11327 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011328 * @param enable {@code true} if trying to turn radio on.
11329 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11330 * false}.
11331 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011332 private boolean setRadioPowerForThermal(boolean enable) {
11333 boolean isPhoneAvailable = false;
11334 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11335 Phone phone = PhoneFactory.getPhone(i);
11336 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011337 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011338 isPhoneAvailable = true;
11339 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011340 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011341
11342 // return true if successfully informed the phone object about the thermal radio power
11343 // request.
11344 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011345 }
11346
11347 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011348 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011349 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11350 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11351 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11352 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11353 throw new IllegalArgumentException("modem does not support data throttling");
11354 }
11355
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011356 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11357 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011358 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011359 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11360 }
11361
Sarah Chinecc78c42022-03-31 21:16:48 -070011362 setDataEnabledForReason(
11363 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011365 if (isDataThrottlingSupported) {
11366 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011367 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011368 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11369 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11370 } else if (thermalMitigationResult
11371 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011372 log("Modem likely does not support data throttling on secondary carrier. Data " +
11373 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11374 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011375 }
11376 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011377 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011378
11379 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011380 }
11381
Jack Nudelman644b91a2021-03-12 14:09:48 -080011382 private static List<String> getThermalMitigationAllowlist(Context context) {
11383 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11384 for (String pckg : context.getResources()
11385 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11386 sThermalMitigationAllowlistedPackages.add(pckg);
11387 }
11388 }
11389
11390 return sThermalMitigationAllowlistedPackages;
11391 }
11392
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011393 private boolean isAnyPhoneInEmergencyState() {
11394 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11395 if (tm.isInEmergencyCall()) {
11396 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11397 return true;
11398 }
11399 for (Phone phone : PhoneFactory.getPhones()) {
11400 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11401 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011402 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11403 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011404 return true;
11405 }
11406 }
11407
11408 return false;
11409 }
11410
Jack Nudelman644b91a2021-03-12 14:09:48 -080011411 /**
11412 * Used by shell commands to add an authorized package name for thermal mitigation.
11413 * @param packageName name of package to be allowlisted
11414 * @param context
11415 */
11416 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11417 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11418 sThermalMitigationAllowlistedPackages.add(packageName);
11419 }
11420
11421 /**
11422 * Used by shell commands to remove an authorized package name for thermal mitigation.
11423 * @param packageName name of package to remove from allowlist
11424 * @param context
11425 */
11426 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11427 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11428 sThermalMitigationAllowlistedPackages.remove(packageName);
11429 }
11430
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011431 /**
11432 * Thermal mitigation request to control functionalities at modem.
11433 *
11434 * @param subId the id of the subscription.
11435 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011436 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011437 *
11438 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11439 */
11440 @Override
11441 @ThermalMitigationResult
11442 public int sendThermalMitigationRequest(
11443 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011444 ThermalMitigationRequest thermalMitigationRequest,
11445 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011446 enforceModifyPermission();
11447
Jack Nudelman644b91a2021-03-12 14:09:48 -080011448 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011449
11450 enforceTelephonyFeatureWithException(callingPackage,
11451 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11452
Jack Nudelman644b91a2021-03-12 14:09:48 -080011453 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11454 .contains(callingPackage)) {
11455 throw new SecurityException("Calling package must be configured in the device config. "
11456 + "calling package: " + callingPackage);
11457 }
11458
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011459 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11460 final long identity = Binder.clearCallingIdentity();
11461
11462 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11463 try {
11464 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11465 switch (thermalMitigationAction) {
11466 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11467 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011468 handleDataThrottlingRequest(subId,
11469 thermalMitigationRequest.getDataThrottlingRequest(),
11470 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011471 break;
11472 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11473 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11474 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11475 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11476 }
11477
11478 // Ensure that radio is on. If not able to power on due to phone being
11479 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011480 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011481 thermalMitigationResult =
11482 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11483 break;
11484 }
11485
11486 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011487 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011488 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11489 break;
11490 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11491 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11492 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11493 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11494 }
11495
11496 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11497 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011498 Phone phone = getPhone(subId);
11499 if (phone == null) {
11500 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011501 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011502 break;
11503 }
11504
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011505 TelephonyConnectionService service =
11506 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011507 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011508 Log.e(LOG_TAG, "An emergency call is pending");
11509 thermalMitigationResult =
11510 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11511 break;
11512 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011513 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011514 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011515 break;
11516 }
11517 } else {
11518 thermalMitigationResult =
11519 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11520 break;
11521 }
11522
11523 // Turn radio off. If not able to power off due to phone being unavailable,
11524 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011525 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011526 thermalMitigationResult =
11527 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11528 break;
11529 }
11530 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011531 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011532 break;
11533 default:
11534 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11535 + "not exist. Requested action: " + thermalMitigationAction);
11536 }
11537 } catch (IllegalArgumentException e) {
11538 throw e;
11539 } catch (Exception e) {
11540 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11541 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11542 } finally {
11543 Binder.restoreCallingIdentity(identity);
11544 }
11545
11546 if (DBG) {
11547 log("thermalMitigationRequest returning with thermalMitigationResult: "
11548 + thermalMitigationResult);
11549 }
11550
11551 return thermalMitigationResult;
11552 }
Hui Wang641e81c2020-10-12 12:14:23 -070011553
11554 /**
11555 * Set the GbaService Package Name that Telephony will bind to.
11556 *
11557 * @param subId The sim that the GbaService is associated with.
11558 * @param packageName The name of the package to be replaced with.
11559 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11560 */
11561 @Override
11562 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11563 enforceModifyPermission();
11564
11565 final long identity = Binder.clearCallingIdentity();
11566 try {
11567 return getGbaManager(subId).overrideServicePackage(packageName);
11568 } finally {
11569 Binder.restoreCallingIdentity(identity);
11570 }
11571 }
11572
11573 /**
11574 * Return the package name of the currently bound GbaService.
11575 *
11576 * @param subId The sim that the GbaService is associated with.
11577 * @return the package name of the GbaService configuration, null if GBA is not supported.
11578 */
11579 @Override
11580 public String getBoundGbaService(int subId) {
11581 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11582
11583 final long identity = Binder.clearCallingIdentity();
11584 try {
11585 return getGbaManager(subId).getServicePackage();
11586 } finally {
11587 Binder.restoreCallingIdentity(identity);
11588 }
11589 }
11590
11591 /**
11592 * Set the release time for telephony to unbind GbaService.
11593 *
11594 * @param subId The sim that the GbaService is associated with.
11595 * @param interval The release time to unbind GbaService by millisecond.
11596 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11597 */
11598 @Override
11599 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11600 enforceModifyPermission();
11601
11602 final long identity = Binder.clearCallingIdentity();
11603 try {
11604 return getGbaManager(subId).overrideReleaseTime(interval);
11605 } finally {
11606 Binder.restoreCallingIdentity(identity);
11607 }
11608 }
11609
11610 /**
11611 * Return the release time for telephony to unbind GbaService.
11612 *
11613 * @param subId The sim that the GbaService is associated with.
11614 * @return The release time to unbind GbaService by millisecond.
11615 */
11616 @Override
11617 public int getGbaReleaseTime(int subId) {
11618 enforceReadPrivilegedPermission("getGbaReleaseTime");
11619
11620 final long identity = Binder.clearCallingIdentity();
11621 try {
11622 return getGbaManager(subId).getReleaseTime();
11623 } finally {
11624 Binder.restoreCallingIdentity(identity);
11625 }
11626 }
11627
11628 private GbaManager getGbaManager(int subId) {
11629 GbaManager instance = GbaManager.getInstance(subId);
11630 if (instance == null) {
11631 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11632 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11633 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11634 }
11635 return instance;
11636 }
Hui Wang761a6682020-10-31 05:12:53 +000011637
11638 /**
11639 * indicate whether the device and the carrier can support
11640 * RCS VoLTE single registration.
11641 */
11642 @Override
11643 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011644 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11645 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11646 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11647 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011648
11649 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11650 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11651 }
11652
11653 final long identity = Binder.clearCallingIdentity();
11654 try {
11655 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11656 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011657 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11658 if (isCapable != null) {
11659 return isCapable;
11660 }
Hui Wang761a6682020-10-31 05:12:53 +000011661 }
Hui Wang67af90e2021-06-04 16:57:15 -070011662 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11663 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011664 } finally {
11665 Binder.restoreCallingIdentity(identity);
11666 }
11667 }
11668
11669 /**
11670 * Register RCS provisioning callback.
11671 */
11672 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011673 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011674 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011675 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011676 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011677 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11678 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011679
11680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11681 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11682 }
joonhunshin4ac60942023-11-15 15:23:39 +000011683 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11684 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11685 Binder.getCallingUserHandle())) {
11686 if (!isImsAvailableOnDevice()) {
11687 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11688 "IMS not available on device.");
11689 }
11690 } else {
11691 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11692 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011693 }
11694
11695 final long identity = Binder.clearCallingIdentity();
11696 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011697 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011698 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011699 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11700 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011701 }
Hui Wang761a6682020-10-31 05:12:53 +000011702 } finally {
11703 Binder.restoreCallingIdentity(identity);
11704 }
11705 }
11706
11707 /**
11708 * Unregister RCS provisioning callback.
11709 */
11710 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011711 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011712 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011713 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011714 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011715 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11716 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011717
11718 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11719 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11720 }
joonhunshin4ac60942023-11-15 15:23:39 +000011721
11722 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11723 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11724 Binder.getCallingUserHandle())) {
11725 if (!isImsAvailableOnDevice()) {
11726 // operation failed silently
11727 Rlog.w(LOG_TAG, "IMS not available on device.");
11728 return;
11729 }
11730 } else {
11731 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11732 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11733 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011734 }
11735
11736 final long identity = Binder.clearCallingIdentity();
11737 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011738 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011739 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011740 } finally {
11741 Binder.restoreCallingIdentity(identity);
11742 }
11743 }
11744
11745 /**
11746 * trigger RCS reconfiguration.
11747 */
11748 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011749 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11750 "triggerRcsReconfiguration",
11751 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011752
11753 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11754 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11755 }
joonhunshin4ac60942023-11-15 15:23:39 +000011756 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11757 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11758 Binder.getCallingUserHandle())) {
11759 if (!isImsAvailableOnDevice()) {
11760 // ProvisioningManager can not handle ServiceSpecificException.
11761 // Throw the IllegalStateException and annotate ProvisioningManager.
11762 throw new IllegalStateException("IMS not available on device.");
11763 }
11764 } else {
11765 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11766 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011767 }
11768
11769 final long identity = Binder.clearCallingIdentity();
11770 try {
11771 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11772 } finally {
11773 Binder.restoreCallingIdentity(identity);
11774 }
11775 }
11776
11777 /**
11778 * Provide the client configuration parameters of the RCS application.
11779 */
11780 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011781 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11782 "setRcsClientConfiguration",
11783 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011784
11785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11786 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11787 }
joonhunshin4ac60942023-11-15 15:23:39 +000011788 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11789 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11790 Binder.getCallingUserHandle())) {
11791 if (!isImsAvailableOnDevice()) {
11792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11793 "IMS not available on device.");
11794 }
11795 } else {
11796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11797 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011798 }
11799
11800 final long identity = Binder.clearCallingIdentity();
11801
11802 try {
11803 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11804 if (configBinder == null) {
11805 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011806 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11807 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011808 } else {
11809 configBinder.setRcsClientConfiguration(rcc);
11810 }
joonhunshin3e154242021-09-17 06:33:39 +000011811
11812 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11813 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011814 } catch (RemoteException e) {
11815 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011816 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11817 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011818 } finally {
11819 Binder.restoreCallingIdentity(identity);
11820 }
11821 }
11822
11823 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011824 * Enables or disables the test mode for RCS VoLTE single registration.
11825 */
11826 @Override
11827 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11829 "setRcsSingleRegistrationTestModeEnabled");
11830
11831 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11832 }
11833
11834 /**
11835 * Gets the test mode for RCS VoLTE single registration.
11836 */
11837 @Override
11838 public boolean getRcsSingleRegistrationTestModeEnabled() {
11839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11840 "getRcsSingleRegistrationTestModeEnabled");
11841
11842 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11843 }
11844
11845 /**
Hui Wang761a6682020-10-31 05:12:53 +000011846 * Overrides the config of RCS VoLTE single registration enabled for the device.
11847 */
11848 @Override
11849 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11850 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11851 "setDeviceSingleRegistrationEnabledOverride");
11852 enforceModifyPermission();
11853
11854 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11855 : Boolean.parseBoolean(enabledStr);
11856 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011857 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011858 }
11859
11860 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011861 * Sends a device to device communication message. Only usable via shell.
11862 * @param message message to send.
11863 * @param value message value.
11864 */
11865 @Override
11866 public void sendDeviceToDeviceMessage(int message, int value) {
11867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011868 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011869 enforceModifyPermission();
11870
11871 final long identity = Binder.clearCallingIdentity();
11872 try {
11873 TelephonyConnectionService service =
11874 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11875 if (service == null) {
11876 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11877 return;
11878 }
11879 service.sendTestDeviceToDeviceMessage(message, value);
11880 } finally {
11881 Binder.restoreCallingIdentity(identity);
11882 }
11883 }
11884
Tyler Gunnbabbda02021-02-10 11:05:02 -080011885 /**
11886 * Sets the specified device to device transport active.
11887 * @param transport The transport to set active.
11888 */
11889 @Override
11890 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11892 "setActiveDeviceToDeviceTransport");
11893 enforceModifyPermission();
11894
11895 final long identity = Binder.clearCallingIdentity();
11896 try {
11897 TelephonyConnectionService service =
11898 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11899 if (service == null) {
11900 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11901 return;
11902 }
11903 service.setActiveDeviceToDeviceTransport(transport);
11904 } finally {
11905 Binder.restoreCallingIdentity(identity);
11906 }
11907 }
Tyler Gunn92479152021-01-20 16:30:10 -080011908
Tyler Gunnd4339262021-05-03 14:46:49 -070011909 @Override
11910 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11912 "setDeviceToDeviceForceEnabled");
11913
11914 final long identity = Binder.clearCallingIdentity();
11915 try {
11916 Arrays.stream(PhoneFactory.getPhones()).forEach(
11917 p -> {
11918 Phone thePhone = p.getImsPhone();
11919 if (thePhone != null && thePhone instanceof ImsPhone) {
11920 ImsPhone imsPhone = (ImsPhone) thePhone;
11921 CallTracker tracker = imsPhone.getCallTracker();
11922 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11923 ImsPhoneCallTracker imsPhoneCallTracker =
11924 (ImsPhoneCallTracker) tracker;
11925 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11926 }
11927 }
11928 }
11929 );
11930 } finally {
11931 Binder.restoreCallingIdentity(identity);
11932 }
11933 }
11934
Tyler Gunn92479152021-01-20 16:30:10 -080011935 /**
Hui Wang761a6682020-10-31 05:12:53 +000011936 * Gets the config of RCS VoLTE single registration enabled for the device.
11937 */
11938 @Override
11939 public boolean getDeviceSingleRegistrationEnabled() {
11940 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11941 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11942 }
11943
11944 /**
11945 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11946 */
11947 @Override
11948 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11949 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11950 "setCarrierSingleRegistrationEnabledOverride");
11951 enforceModifyPermission();
11952
11953 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11954 : Boolean.parseBoolean(enabledStr);
11955 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11956 subId, enabled);
11957 }
11958
11959 /**
11960 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11961 */
11962 @Override
11963 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11964 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11965 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11966 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011967
11968 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011969 * Overrides the ims feature validation result
11970 */
11971 @Override
11972 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11974 "setImsFeatureValidationOverride");
11975
11976 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11977 : Boolean.parseBoolean(enabledStr);
11978 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11979 subId, enabled);
11980 }
11981
11982 /**
11983 * Gets the ims feature validation override value
11984 */
11985 @Override
11986 public boolean getImsFeatureValidationOverride(int subId) {
11987 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11988 "getImsFeatureValidationOverride");
11989 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11990 }
11991
11992 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011993 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11994 * their mobile plan.
11995 */
11996 @Override
11997 public String getMobileProvisioningUrl() {
11998 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11999 final long identity = Binder.clearCallingIdentity();
12000 try {
12001 return getDefaultPhone().getMobileProvisioningUrl();
12002 } finally {
12003 Binder.restoreCallingIdentity(identity);
12004 }
12005 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012006
James.cf Linbcdf8b32021-01-14 16:44:13 +080012007 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012008 * Get the EAB contact from the EAB database.
12009 */
12010 @Override
12011 public String getContactFromEab(String contact) {
12012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12013 enforceModifyPermission();
12014 final long identity = Binder.clearCallingIdentity();
12015 try {
12016 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12017 } finally {
12018 Binder.restoreCallingIdentity(identity);
12019 }
12020 }
12021
12022 /**
Calvin Pana1434322021-07-01 19:27:01 +080012023 * Get the EAB capability from the EAB database.
12024 */
12025 @Override
12026 public String getCapabilityFromEab(String contact) {
12027 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12028 enforceModifyPermission();
12029 final long identity = Binder.clearCallingIdentity();
12030 try {
12031 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12032 } finally {
12033 Binder.restoreCallingIdentity(identity);
12034 }
12035 }
12036
12037 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012038 * Remove the EAB contacts from the EAB database.
12039 */
12040 @Override
12041 public int removeContactFromEab(int subId, String contacts) {
12042 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12043 enforceModifyPermission();
12044 final long identity = Binder.clearCallingIdentity();
12045 try {
12046 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12047 } finally {
12048 Binder.restoreCallingIdentity(identity);
12049 }
12050 }
12051
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012052 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012053 public boolean getDeviceUceEnabled() {
12054 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12055 final long identity = Binder.clearCallingIdentity();
12056 try {
12057 return mApp.getDeviceUceEnabled();
12058 } finally {
12059 Binder.restoreCallingIdentity(identity);
12060 }
12061 }
12062
12063 @Override
12064 public void setDeviceUceEnabled(boolean isEnabled) {
12065 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12066 final long identity = Binder.clearCallingIdentity();
12067 try {
12068 mApp.setDeviceUceEnabled(isEnabled);
12069 } finally {
12070 Binder.restoreCallingIdentity(identity);
12071 }
12072 }
12073
Brad Ebinger14d467f2021-02-12 06:18:28 +000012074 /**
12075 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12076 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12077 */
12078 // Used for SHELL command only right now.
12079 @Override
12080 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12081 List<String> featureTags) {
12082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12083 "addUceRegistrationOverrideShell");
12084 final long identity = Binder.clearCallingIdentity();
12085 try {
12086 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12087 new ArraySet<>(featureTags));
12088 } catch (ImsException e) {
12089 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12090 } finally {
12091 Binder.restoreCallingIdentity(identity);
12092 }
12093 }
12094
12095 /**
12096 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12097 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12098 */
12099 // Used for SHELL command only right now.
12100 @Override
12101 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12102 List<String> featureTags) {
12103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12104 "removeUceRegistrationOverrideShell");
12105 final long identity = Binder.clearCallingIdentity();
12106 try {
12107 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12108 new ArraySet<>(featureTags));
12109 } catch (ImsException e) {
12110 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12111 } finally {
12112 Binder.restoreCallingIdentity(identity);
12113 }
12114 }
12115
12116 /**
12117 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12118 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12119 */
12120 // Used for SHELL command only right now.
12121 @Override
12122 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12124 "clearUceRegistrationOverrideShell");
12125 final long identity = Binder.clearCallingIdentity();
12126 try {
12127 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12128 } catch (ImsException e) {
12129 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12130 } finally {
12131 Binder.restoreCallingIdentity(identity);
12132 }
12133 }
12134
12135 /**
12136 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12137 */
12138 // Used for SHELL command only right now.
12139 @Override
12140 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12141 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12142 "getLatestRcsContactUceCapabilityShell");
12143 final long identity = Binder.clearCallingIdentity();
12144 try {
12145 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12146 } catch (ImsException e) {
12147 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12148 } finally {
12149 Binder.restoreCallingIdentity(identity);
12150 }
12151 }
12152
12153 /**
12154 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12155 * device does not have an active PUBLISH.
12156 */
12157 // Used for SHELL command only right now.
12158 @Override
12159 public String getLastUcePidfXmlShell(int subId) {
12160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12161 final long identity = Binder.clearCallingIdentity();
12162 try {
12163 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12164 } catch (ImsException e) {
12165 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12166 } finally {
12167 Binder.restoreCallingIdentity(identity);
12168 }
12169 }
12170
James.cf Line8713a42021-04-29 16:04:26 +080012171 /**
12172 * Remove UCE requests cannot be sent to the network status.
12173 */
12174 // Used for SHELL command only right now.
12175 @Override
12176 public boolean removeUceRequestDisallowedStatus(int subId) {
12177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12178 final long identity = Binder.clearCallingIdentity();
12179 try {
12180 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12181 } catch (ImsException e) {
12182 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12183 } finally {
12184 Binder.restoreCallingIdentity(identity);
12185 }
12186 }
12187
James.cf Lin18bb9002021-05-25 01:37:38 +080012188 /**
12189 * Remove UCE requests cannot be sent to the network status.
12190 */
12191 // Used for SHELL command only.
12192 @Override
12193 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12195 final long identity = Binder.clearCallingIdentity();
12196 try {
12197 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12198 } catch (ImsException e) {
12199 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12200 } finally {
12201 Binder.restoreCallingIdentity(identity);
12202 }
12203 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012204
James.cf Lin4b784aa2021-01-31 03:25:15 +080012205 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012206 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12207 String callingPackage) {
12208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12209 mApp, subId, "setSignalStrengthUpdateRequest");
12210
joonhunshin4ac60942023-11-15 15:23:39 +000012211 enforceTelephonyFeatureWithException(callingPackage,
12212 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12213
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012214 final int callingUid = Binder.getCallingUid();
12215 // Verify that tha callingPackage belongs to the calling UID
12216 mApp.getSystemService(AppOpsManager.class)
12217 .checkPackage(callingUid, callingPackage);
12218
Rambo Wang3607f502021-02-01 21:51:40 -080012219 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012220
12221 final long identity = Binder.clearCallingIdentity();
12222 try {
12223 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12224 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12225
12226 if (result instanceof IllegalStateException) {
12227 throw (IllegalStateException) result;
12228 }
12229 } finally {
12230 Binder.restoreCallingIdentity(identity);
12231 }
12232 }
12233
12234 @Override
12235 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12236 String callingPackage) {
12237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12238 mApp, subId, "clearSignalStrengthUpdateRequest");
12239
joonhunshin4ac60942023-11-15 15:23:39 +000012240 enforceTelephonyFeatureWithException(callingPackage,
12241 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12242
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012243 final int callingUid = Binder.getCallingUid();
12244 // Verify that tha callingPackage belongs to the calling UID
12245 mApp.getSystemService(AppOpsManager.class)
12246 .checkPackage(callingUid, callingPackage);
12247
12248 final long identity = Binder.clearCallingIdentity();
12249 try {
12250 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12251 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12252
12253 if (result instanceof IllegalStateException) {
12254 throw (IllegalStateException) result;
12255 }
12256 } finally {
12257 Binder.restoreCallingIdentity(identity);
12258 }
12259 }
12260
Rambo Wang3607f502021-02-01 21:51:40 -080012261 private static void validateSignalStrengthUpdateRequest(Context context,
12262 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012263 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12264 // phone/system process do not have further restriction on request
12265 return;
12266 }
12267
12268 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012269 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012270 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012271 context.enforceCallingOrSelfPermission(
12272 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12273 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012274 }
12275
12276 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012277 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012278 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012279 || info.isEnabled()) {
12280 throw new IllegalArgumentException(
12281 "Only system can set hide fields in SignalThresholdInfo");
12282 }
12283
12284 // Thresholds length for each RAN need in range. This has been validated in
12285 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12286 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12287 final int[] thresholds = info.getThresholds();
12288 Objects.requireNonNull(thresholds);
12289 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12290 || thresholds.length
12291 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12292 throw new IllegalArgumentException(
12293 "thresholds length is out of range: " + thresholds.length);
12294 }
12295 }
12296 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012297
12298 /**
12299 * Gets the current phone capability.
12300 *
12301 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12302 * @return the PhoneCapability which describes the data connection capability of modem.
12303 * It's used to evaluate possible phone config change, for example from single
12304 * SIM device to multi-SIM device.
12305 */
12306 @Override
12307 public PhoneCapability getPhoneCapability() {
12308 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012309
12310 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12311 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12312
SongFerngWang8236caa2021-01-17 21:51:44 +080012313 final long identity = Binder.clearCallingIdentity();
12314 try {
12315 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12316 } finally {
12317 Binder.restoreCallingIdentity(identity);
12318 }
12319 }
Michele Berionne5e411512020-11-13 02:36:59 +000012320
12321 /**
12322 * Prepare TelephonyManager for an unattended reboot. The reboot is
12323 * required to be done shortly after the API is invoked.
12324 */
12325 @Override
12326 @TelephonyManager.PrepareUnattendedRebootResult
12327 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012329 enforceRebootPermission();
12330
joonhunshin4ac60942023-11-15 15:23:39 +000012331 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12332 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12333
Michele Berionne5e411512020-11-13 02:36:59 +000012334 final long identity = Binder.clearCallingIdentity();
12335 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012336 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012337 } finally {
12338 Binder.restoreCallingIdentity(identity);
12339 }
12340 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012341
12342 /**
12343 * Request to get the current slicing configuration including URSP rules and
12344 * NSSAIs (configured, allowed and rejected).
12345 *
12346 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12347 */
12348 @Override
12349 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012350 TelephonyPermissions
12351 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12352 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012353
joonhunshin4ac60942023-11-15 15:23:39 +000012354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12355 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12356 "getSlicingConfig");
12357
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012358 final long identity = Binder.clearCallingIdentity();
12359 try {
12360 Phone phone = getDefaultPhone();
12361 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12362 } finally {
12363 Binder.restoreCallingIdentity(identity);
12364 }
12365 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012366
12367 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012368 * Check whether the given premium capability is available for purchase from the carrier.
12369 *
12370 * @param capability The premium capability to check.
12371 * @param subId The subId to check the premium capability for.
12372 *
12373 * @return Whether the given premium capability is available to purchase.
12374 */
12375 @Override
12376 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12377 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12378 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12379 log("Premium capability "
12380 + TelephonyManager.convertPremiumCapabilityToString(capability)
12381 + " is not available for purchase due to missing permissions.");
12382 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12383 + "permission READ_BASIC_PHONE_STATE.");
12384 }
12385
joonhunshin4ac60942023-11-15 15:23:39 +000012386 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12387 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12388
Sarah Chin2ec39f62022-08-31 17:03:26 -070012389 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012390 if (phone == null) {
12391 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12392 return false;
12393 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012394 final long identity = Binder.clearCallingIdentity();
12395 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012396 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012397 .isPremiumCapabilityAvailableForPurchase(capability);
12398 } finally {
12399 Binder.restoreCallingIdentity(identity);
12400 }
12401 }
12402
12403 /**
12404 * Purchase the given premium capability from the carrier.
12405 *
12406 * @param capability The premium capability to purchase.
12407 * @param callback The result of the purchase request.
12408 * @param subId The subId to purchase the premium capability for.
12409 */
12410 @Override
12411 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12412 log("purchasePremiumCapability: capability="
12413 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12414 + getCurrentPackageName());
12415
12416 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12417 mApp, "purchasePremiumCapability")) {
12418 log("purchasePremiumCapability "
12419 + TelephonyManager.convertPremiumCapabilityToString(capability)
12420 + " failed due to missing permissions.");
12421 throw new SecurityException("purchasePremiumCapability requires permission "
12422 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012423 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12424 mApp, "purchasePremiumCapability")) {
12425 log("purchasePremiumCapability "
12426 + TelephonyManager.convertPremiumCapabilityToString(capability)
12427 + " failed due to missing permissions.");
12428 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012429 }
12430
joonhunshin4ac60942023-11-15 15:23:39 +000012431 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12432 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12433
Sarah Chin2ec39f62022-08-31 17:03:26 -070012434 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012435 if (phone == null) {
12436 try {
12437 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12438 callback.accept(result);
12439 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12440 } catch (RemoteException e) {
12441 String logStr = "Purchase premium capability "
12442 + TelephonyManager.convertPremiumCapabilityToString(capability)
12443 + " failed due to RemoteException handling null phone: " + e;
12444 if (DBG) log(logStr);
12445 AnomalyReporter.reportAnomaly(
12446 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12447 }
12448 return;
12449 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012450
12451 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012452 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012453 callingProcess = mApp.getPackageManager().getApplicationInfo(
12454 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012455 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012456 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012457 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012458
12459 boolean isVisible = false;
12460 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12461 if (am != null) {
12462 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12463 if (processes != null) {
12464 for (ActivityManager.RunningAppProcessInfo process : processes) {
12465 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012466 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012467 if (process.processName.equals(callingProcess) && process.importance
12468 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12469 isVisible = true;
12470 break;
12471 }
12472 }
12473 }
12474 }
12475
12476 if (!isVisible) {
12477 try {
12478 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12479 callback.accept(result);
12480 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12481 } catch (RemoteException e) {
12482 String logStr = "Purchase premium capability "
12483 + TelephonyManager.convertPremiumCapabilityToString(capability)
12484 + " failed due to RemoteException handling background application: " + e;
12485 if (DBG) log(logStr);
12486 AnomalyReporter.reportAnomaly(
12487 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12488 }
12489 return;
12490 }
12491
Sarah Chin71b3a852022-09-28 15:54:19 -070012492 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012493 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012494 }
12495
12496 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012497 * Register an IMS connection state callback
12498 */
12499 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012500 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12501 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012502 if (feature == ImsFeature.FEATURE_MMTEL) {
12503 // ImsMmTelManager
12504 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12505 TelephonyPermissions
12506 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12507 mApp, subId, "registerImsStateCallback");
12508 } else if (feature == ImsFeature.FEATURE_RCS) {
12509 // ImsRcsManager or SipDelegateManager
12510 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12511 Binder.getCallingUid(), "registerImsStateCallback",
12512 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12513 Manifest.permission.READ_PRECISE_PHONE_STATE,
12514 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12515 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12516 }
12517
12518 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12519 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12520 "IMS not available on device.");
12521 }
12522
12523 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12524 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12525 }
12526
12527 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12528 if (controller == null) {
12529 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12530 "IMS not available on device.");
12531 }
12532
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012533 if (callingPackage == null) {
12534 callingPackage = getCurrentPackageName();
12535 }
12536
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012537 final long token = Binder.clearCallingIdentity();
12538 try {
12539 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012540 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012541 } catch (ImsException e) {
12542 throw new ServiceSpecificException(e.getCode());
12543 } finally {
12544 Binder.restoreCallingIdentity(token);
12545 }
12546 }
12547
12548 /**
12549 * Unregister an IMS connection state callback
12550 */
12551 @Override
12552 public void unregisterImsStateCallback(IImsStateCallback cb) {
12553 final long token = Binder.clearCallingIdentity();
12554 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12555 if (controller == null) {
12556 return;
12557 }
12558 try {
12559 controller.unregisterImsStateCallback(cb);
12560 } finally {
12561 Binder.restoreCallingIdentity(token);
12562 }
12563 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012564
12565 /**
12566 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12567 *
12568 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012569 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012570 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012571 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012572 * If there is current registered network this value will be same as the registered cell
12573 * identity. If the device goes out of service the previous cell identity is cached and
12574 * will be returned. If the cache age of the Cell identity is more than 24 hours
12575 * it will be cleared and null will be returned.
12576 *
12577 */
12578 @Override
12579 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12580 String callingFeatureId) {
12581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12582 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12583 LocationAccessPolicy.checkLocationPermission(mApp,
12584 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12585 .setCallingPackage(callingPackage)
12586 .setCallingFeatureId(callingFeatureId)
12587 .setCallingPid(Binder.getCallingPid())
12588 .setCallingUid(Binder.getCallingUid())
12589 .setMethod("getLastKnownCellIdentity")
12590 .setLogAsInfo(true)
12591 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12592 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12593 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12594 .build());
12595
12596 boolean hasFinePermission =
12597 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12598 if (!hasFinePermission
12599 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12600 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012601 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012602 }
12603
12604 final long identity = Binder.clearCallingIdentity();
12605 try {
Ling Mac28f0212023-03-24 16:07:15 -070012606 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012607 if (sst == null) return null;
12608 return sst.getLastKnownCellIdentity();
12609 } finally {
12610 Binder.restoreCallingIdentity(identity);
12611 }
12612 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012613
jimsun3b9ccac2021-10-26 15:01:23 +080012614 /**
12615 * Sets the modem service class Name that Telephony will bind to.
12616 *
12617 * @param serviceName The class name of the modem service.
12618 * @return true if the operation is succeed, otherwise false.
12619 */
12620 public boolean setModemService(String serviceName) {
12621 Log.d(LOG_TAG, "setModemService - " + serviceName);
12622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012624 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12625 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012626 return mPhoneConfigurationManager.setModemService(serviceName);
12627 }
12628
12629 /**
12630 * Return the class name of the currently bounded modem service.
12631 *
12632 * @return the class name of the modem service.
12633 */
12634 public String getModemService() {
12635 String result;
12636 Log.d(LOG_TAG, "getModemService");
12637 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12638 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012639 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012640 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12641 "getModemService");
12642 result = mPhoneConfigurationManager.getModemService();
12643 Log.d(LOG_TAG, "result = " + result);
12644 return result;
12645 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012646
Hakjun Choi3ee81112023-12-19 15:40:58 +000012647 /**
12648 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12649 * including carrier config, entitlement server, and config update.
12650 *
12651 * @param subId subId The subscription ID of the carrier.
12652 *
12653 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12654 * be returned.
12655 *
12656 * @throws SecurityException if the caller doesn't have the required permission.
12657 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012658 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12659 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012660 final long identity = Binder.clearCallingIdentity();
12661 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012662 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012663 } finally {
12664 Binder.restoreCallingIdentity(identity);
12665 }
12666 }
12667
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012668 @Override
12669 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12670 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12671 mApp.enforceCallingOrSelfPermission(
12672 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12674
12675 final long identity = Binder.clearCallingIdentity();
12676 try {
12677 Phone phone = getPhone(subId);
12678 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012679 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12680 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012681 phone.setVoiceServiceStateOverride(hasService);
12682 } finally {
12683 Binder.restoreCallingIdentity(identity);
12684 }
12685 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012686
12687 /**
12688 * set removable eSIM as default eUICC.
12689 *
12690 * @hide
12691 */
12692 @Override
12693 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12694 enforceModifyPermission();
12695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12696
12697 final long identity = Binder.clearCallingIdentity();
12698 try {
12699 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12700 } finally {
12701 Binder.restoreCallingIdentity(identity);
12702 }
12703 }
12704
12705 /**
12706 * Returns whether the removable eSIM is default eUICC or not.
12707 *
12708 * @hide
12709 */
12710 @Override
12711 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12712 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12714
12715 final long identity = Binder.clearCallingIdentity();
12716 try {
12717 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12718 } finally {
12719 Binder.restoreCallingIdentity(identity);
12720 }
12721 }
12722
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012723 /**
12724 * Get the component name of the default app to direct respond-via-message intent for the
12725 * user associated with this subscription, update the cache if there is no respond-via-message
12726 * application currently configured for this user.
12727 * @return component name of the app and class to direct Respond Via Message intent to, or
12728 * {@code null} if the functionality is not supported.
12729 * @hide
12730 */
12731 @Override
12732 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12733 boolean updateIfNeeded) {
12734 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012735
joonhunshin4ac60942023-11-15 15:23:39 +000012736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12737 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12738 "getDefaultRespondViaMessageApplication");
12739
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012740 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12741
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012742 UserHandle userHandle = null;
12743 final long identity = Binder.clearCallingIdentity();
12744 try {
12745 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12746 } finally {
12747 Binder.restoreCallingIdentity(identity);
12748 }
12749 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12750 updateIfNeeded, userHandle);
12751 }
Jack Yuf5badd92022-12-08 00:50:53 -080012752
12753 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012754 * Set whether the device is able to connect with null ciphering or integrity
12755 * algorithms. This is a global setting and will apply to all active subscriptions
12756 * and all new subscriptions after this.
12757 *
12758 * @param enabled when true, null cipher and integrity algorithms are allowed.
12759 * @hide
12760 */
12761 @Override
12762 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12763 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12764 enforceModifyPermission();
12765 checkForNullCipherAndIntegritySupport();
12766
12767 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12768 // for listening to these preference changes and applying them immediately.
12769 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12770 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12771 editor.apply();
12772
12773 for (Phone phone: PhoneFactory.getPhones()) {
12774 phone.handleNullCipherEnabledChange();
12775 }
12776 }
12777
12778
12779 /**
12780 * Get whether the device is able to connect with null ciphering or integrity
12781 * algorithms. Note that this retrieves the phone-global preference and not
12782 * the state of the radio.
12783 *
12784 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12785 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12786 * version for this feature.
12787 * @hide
12788 */
12789 @Override
12790 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12791 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12792 enforceReadPermission();
12793 checkForNullCipherAndIntegritySupport();
12794 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12795 }
12796
12797 private void checkForNullCipherAndIntegritySupport() {
12798 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12799 throw new UnsupportedOperationException(
12800 "Null cipher and integrity operations require HAL 2.1 or above");
12801 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012802 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12803 throw new UnsupportedOperationException(
12804 "Null cipher and integrity operations unsupported by modem");
12805 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012806 }
12807
Gil Cukierman06403e12023-11-29 16:33:03 +000012808 private void checkForIdentifierDisclosureNotificationSupport() {
12809 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12810 throw new UnsupportedOperationException(
12811 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12812 + "above");
12813 }
12814 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12815 throw new UnsupportedOperationException(
12816 "Cellular identifier disclosure transparency operations unsupported by modem");
12817 }
12818 }
12819
Michael Groover826b71d2023-12-21 22:08:06 -060012820 private void checkForNullCipherNotificationSupport() {
12821 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12822 throw new UnsupportedOperationException(
12823 "Null cipher notification operations require HAL 2.2 or above");
12824 }
12825 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12826 throw new UnsupportedOperationException(
12827 "Null cipher notification operations unsupported by modem");
12828 }
12829 }
12830
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012831 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012832 * Get the SIM state for the slot index.
12833 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12834 *
12835 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12836 */
12837 @Override
12838 @SimState
12839 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012840 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12841 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12842
Jack Yuf5badd92022-12-08 00:50:53 -080012843 IccCardConstants.State simState;
12844 if (slotIndex < 0) {
12845 simState = IccCardConstants.State.UNKNOWN;
12846 } else {
12847 Phone phone = null;
12848 try {
12849 phone = PhoneFactory.getPhone(slotIndex);
12850 } catch (IllegalStateException e) {
12851 // ignore
12852 }
12853 if (phone == null) {
12854 simState = IccCardConstants.State.UNKNOWN;
12855 } else {
12856 IccCard icc = phone.getIccCard();
12857 if (icc == null) {
12858 simState = IccCardConstants.State.UNKNOWN;
12859 } else {
12860 simState = icc.getState();
12861 }
12862 }
12863 }
12864 return simState.ordinal();
12865 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012866
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012867 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12868 boolean enableLogcat,
12869 long logcatStartTimestampMillis, boolean enableTelecomDump,
12870 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012871 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012872 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12873 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12874 ecdDataBuilder
12875 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12876 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012877 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012878 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012879 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012880 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12881 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012882 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12883 Executors.newCachedThreadPool(), db,
12884 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012885 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012886 }
12887
12888 /**
12889 * Request telephony to persist state for debugging emergency call failures.
12890 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012891 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012892 * @param enableLogcat whether to collect logcat output
12893 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12894 * @param enableTelecomDump whether to collect telecom dumpsys
12895 * @param enableTelephonyDump whether to collect telephony dumpsys
12896 */
12897 @Override
12898 @RequiresPermission(android.Manifest.permission.DUMP)
12899 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12900 long logcatStartTimestampMillis, boolean enableTelecomDump,
12901 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012902 // Verify that the caller has READ_DROPBOX_DATA permission.
12903 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12904 && Flags.enableReadDropboxPermission()) {
12905 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12906 "persistEmergencyCallDiagnosticData");
12907 } else {
12908 // Otherwise, enforce legacy permission.
12909 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12910 "persistEmergencyCallDiagnosticData");
12911 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012912 final long identity = Binder.clearCallingIdentity();
12913 try {
12914 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12915 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12916
12917 } finally {
12918 Binder.restoreCallingIdentity(identity);
12919 }
12920 }
12921
Hui Wang9b5793a2022-12-05 14:38:06 -060012922 /**
12923 * Get current cell broadcast ranges.
12924 */
12925 @Override
12926 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12927 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12928 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12929 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012930
12931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12932 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12933
Hui Wang9b5793a2022-12-05 14:38:06 -060012934 final long identity = Binder.clearCallingIdentity();
12935 try {
12936 return getPhone(subId).getCellBroadcastIdRanges();
12937 } finally {
12938 Binder.restoreCallingIdentity(identity);
12939 }
12940 }
12941
12942 /**
12943 * Set reception of cell broadcast messages with the list of the given ranges
12944 *
12945 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12946 */
12947 @Override
12948 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12949 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12950 @Nullable IIntegerConsumer callback) {
12951 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12952 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012953
12954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12955 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12956
Hui Wang9b5793a2022-12-05 14:38:06 -060012957 final long identity = Binder.clearCallingIdentity();
12958 try {
12959 Phone phone = getPhoneFromSubId(subId);
12960 if (DBG) {
12961 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12962 }
12963 phone.setCellBroadcastIdRanges(ranges, result -> {
12964 if (callback != null) {
12965 try {
12966 callback.accept(result);
12967 } catch (RemoteException e) {
12968 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12969 }
12970 }
12971 });
12972 } finally {
12973 Binder.restoreCallingIdentity(identity);
12974 }
12975 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012976
12977 /**
12978 * Returns whether the device supports the domain selection service.
12979 *
12980 * @return {@code true} if the device supports the domain selection service.
12981 */
12982 @Override
12983 public boolean isDomainSelectionSupported() {
12984 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12985 "isDomainSelectionSupported");
12986
12987 final long identity = Binder.clearCallingIdentity();
12988 try {
12989 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12990 } finally {
12991 Binder.restoreCallingIdentity(identity);
12992 }
12993 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012994
12995 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012996 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12997 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12998 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012999 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013000 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013001 * @param enableSatellite {@code true} to enable the satellite modem and
13002 * {@code false} to disable.
13003 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013004 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013005 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013006 *
13007 * @throws SecurityException if the caller doesn't have the required permission.
13008 */
13009 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013010 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013011 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013012 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013013 if (enableSatellite) {
13014 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13015 @Override
13016 protected void onReceiveResult(int resultCode, Bundle resultData) {
13017 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13018 + ", resultData=" + resultData);
13019 boolean isAllowed = false;
13020 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13021 callback::accept);
13022 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13023 if (resultData != null
13024 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13025 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13026 } else {
13027 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13028 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013029 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013030 result.accept(resultCode);
13031 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013032 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013033 if (isAllowed) {
13034 mSatelliteController.requestSatelliteEnabled(
13035 subId, enableSatellite, enableDemoMode, callback);
13036 } else {
13037 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13038 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013039 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013040 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013041 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013042 subId, resultReceiver);
13043 } else {
13044 // No need to check if satellite is allowed at current location when disabling satellite
13045 mSatelliteController.requestSatelliteEnabled(
13046 subId, enableSatellite, enableDemoMode, callback);
13047 }
Sarah Chin503828c2023-02-01 23:54:20 -080013048 }
13049
13050 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013051 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013052 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013053 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013054 * @param result The result receiver that returns whether the satellite modem is enabled
13055 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013056 *
13057 * @throws SecurityException if the caller doesn't have the required permission.
13058 */
13059 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013060 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13061 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013062 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013063 }
13064
13065 /**
Sarah Chin43457982023-02-15 17:50:38 -080013066 * Request to get whether the satellite service demo mode is enabled.
13067 *
13068 * @param subId The subId of the subscription to check whether the satellite demo mode
13069 * is enabled for.
13070 * @param result The result receiver that returns whether the satellite demo mode is enabled
13071 * if the request is successful or an error code if the request failed.
13072 *
13073 * @throws SecurityException if the caller doesn't have the required permission.
13074 */
13075 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013076 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13077 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13078 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013079 }
13080
13081 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013082 * Request to get whether the satellite service is enabled with emergency mode.
13083 *
13084 * @param subId The subId of the subscription to check whether the satellite demo mode
13085 * is enabled for.
13086 * @param result The result receiver that returns whether the satellite emergency mode is
13087 * enabled if the request is successful or an error code if the request failed.
13088 *
13089 * @throws SecurityException if the caller doesn't have the required permission.
13090 */
13091 @Override
13092 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13093 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13094 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13095 }
13096
13097 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013098 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013099 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013100 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013101 * @param result The result receiver that returns whether the satellite service is supported on
13102 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013103 */
13104 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013105 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013106 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013107 }
13108
13109 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013110 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013111 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013112 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013113 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13114 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013115 *
13116 * @throws SecurityException if the caller doesn't have required permission.
13117 */
13118 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013119 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13120 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013121 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013122 }
13123
13124 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013125 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013126 * This can be called by the pointing UI when the user starts pointing to the satellite.
13127 * Modem should continue to report the pointing input as the device or satellite moves.
13128 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013129 * @param subId The subId of the subscription to start satellite transmission updates for.
13130 * @param resultCallback The callback to get the result of the request.
13131 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013132 *
13133 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013134 */
13135 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013136 public void startSatelliteTransmissionUpdates(int subId,
13137 @NonNull IIntegerConsumer resultCallback,
13138 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13139 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13140 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013141 }
13142
13143 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013144 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013145 * This can be called by the pointing UI when the user stops pointing to the satellite.
13146 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013147 * @param subId The subId of the subscription to stop satellite transmission updates for.
13148 * @param resultCallback The callback to get the result of the request.
13149 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13150 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013151 *
13152 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013153 */
13154 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013155 public void stopSatelliteTransmissionUpdates(int subId,
13156 @NonNull IIntegerConsumer resultCallback,
13157 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13158 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13159 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013160 }
13161
13162 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013163 * Register the subscription with a satellite provider.
13164 * This is needed to register the subscription if the provider allows dynamic registration.
13165 *
13166 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013167 * @param token The token to be used as a unique identifier for provisioning with satellite
13168 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013169 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013170 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013171 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013172 * @return The signal transport used by the caller to cancel the provision request,
13173 * or {@code null} if the request failed.
13174 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013175 * @throws SecurityException if the caller doesn't have the required permission.
13176 */
13177 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013178 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013179 @NonNull String token, @NonNull byte[] provisionData,
13180 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013181 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013182 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13183 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013184 }
13185
13186 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013187 * Unregister the device/subscription with the satellite provider.
13188 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013189 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013190 * should report as deprovisioned.
13191 *
13192 * @param subId The subId of the subscription to be deprovisioned.
13193 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013194 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013195 *
13196 * @throws SecurityException if the caller doesn't have the required permission.
13197 */
13198 @Override
13199 public void deprovisionSatelliteService(int subId,
13200 @NonNull String token, @NonNull IIntegerConsumer callback) {
13201 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013202 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013203 }
13204
13205 /**
Sarah Chin43457982023-02-15 17:50:38 -080013206 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013207 *
Sarah Chin43457982023-02-15 17:50:38 -080013208 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013209 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013210 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013211 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013212 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013213 * @throws SecurityException if the caller doesn't have the required permission.
13214 */
13215 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013216 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13217 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013218 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013219 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013220 }
13221
13222 /**
Sarah Chin43457982023-02-15 17:50:38 -080013223 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013224 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013225 *
Sarah Chin43457982023-02-15 17:50:38 -080013226 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013227 * @param callback The callback that was passed to
13228 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013229 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013230 * @throws SecurityException if the caller doesn't have the required permission.
13231 */
13232 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013233 public void unregisterForSatelliteProvisionStateChanged(
13234 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013235 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013236 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013237 }
13238
13239 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013240 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013241 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013242 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013243 * @param result The result receiver that returns whether the device is provisioned with a
13244 * satellite provider if the request is successful or an error code if the
13245 * request failed.
13246 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013247 * @throws SecurityException if the caller doesn't have the required permission.
13248 */
13249 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013250 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13251 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013252 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013253 }
13254
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013255 /**
Sarah Chin43457982023-02-15 17:50:38 -080013256 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013257 *
Sarah Chin43457982023-02-15 17:50:38 -080013258 * @param subId The subId of the subscription to register for satellite modem state changed.
13259 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013260 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013261 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013262 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013263 * @throws SecurityException if the caller doesn't have the required permission.
13264 */
13265 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013266 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013267 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013268 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013269 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013270 }
13271
13272 /**
Sarah Chin43457982023-02-15 17:50:38 -080013273 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013274 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013275 *
Sarah Chin43457982023-02-15 17:50:38 -080013276 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013277 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013278 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013279 *
13280 * @throws SecurityException if the caller doesn't have the required permission.
13281 */
13282 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013283 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013284 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013285 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13286 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013287 }
13288
13289 /**
13290 * Register to receive incoming datagrams over satellite.
13291 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013292 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013293 * @param callback The callback to handle incoming datagrams over satellite.
13294 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013295 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013296 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013297 * @throws SecurityException if the caller doesn't have the required permission.
13298 */
13299 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013300 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013301 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013302 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13303 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013304 }
13305
13306 /**
13307 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013308 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013309 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013310 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13311 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013312 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013313 *
13314 * @throws SecurityException if the caller doesn't have the required permission.
13315 */
13316 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013317 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013318 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013319 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13320 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013321 }
13322
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013323 /**
13324 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013325 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013326 * This method requests modem to check if there are any pending datagrams to be received over
13327 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013328 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013329 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013330 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013331 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013332 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013333 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013334 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013335 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13336 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13337 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013338 }
13339
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013340 /**
13341 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013342 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013343 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13344 * input to this method. Datagram received here will be passed down to modem without any
13345 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013346 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013347 * @param subId The subId of the subscription to send satellite datagrams for.
13348 * @param datagramType datagram type indicating whether the datagram is of type
13349 * SOS_SMS or LOCATION_SHARING.
13350 * @param datagram encoded gateway datagram which is encrypted by the caller.
13351 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013352 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13353 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013354 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013355 *
13356 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013357 */
13358 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013359 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013360 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13361 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013362 enforceSatelliteCommunicationPermission("sendDatagram");
13363 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13364 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013365 }
13366
Sarah Chindf715ec2023-02-13 13:46:24 -080013367 /**
13368 * Request to get whether satellite communication is allowed for the current location.
13369 *
13370 * @param subId The subId of the subscription to check whether satellite communication is
13371 * allowed for the current location for.
13372 * @param result The result receiver that returns whether satellite communication is allowed
13373 * for the current location if the request is successful or an error code
13374 * if the request failed.
13375 *
13376 * @throws SecurityException if the caller doesn't have the required permission.
13377 */
13378 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013379 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013380 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013381 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13382 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13383 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013384 }
13385
13386 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013387 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013388 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013389 * @param subId The subId to get the time after which the satellite will be visible for.
13390 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013391 * be visible if the request is successful or an error code if the request failed.
13392 *
13393 * @throws SecurityException if the caller doesn't have the required permission.
13394 */
13395 @Override
13396 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13397 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013398 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013399 }
13400
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013401 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013402 * Inform that Device is aligned to satellite for demo mode.
13403 *
13404 * @param subId The subId to get the time after which the satellite will be visible for.
13405 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13406 * {@code false} Device fails to align with the satellite for demo mode.
13407 *
13408 * @throws SecurityException if the caller doesn't have required permission.
13409 */
13410 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13411
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013412 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013413 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013414 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013415 }
13416
13417 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013418 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13419 * by modem.
13420 *
13421 * @param subId The subId of the subscription to request for.
13422 * @param reason Reason for disallowing satellite communication for carrier.
13423 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13424 * operation.
13425 *
13426 * @throws SecurityException if the caller doesn't have required permission.
13427 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013428 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013429 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13430 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013431 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013432 final long identity = Binder.clearCallingIdentity();
13433 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013434 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013435 } finally {
13436 Binder.restoreCallingIdentity(identity);
13437 }
13438 }
13439
13440 /**
13441 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13442 * by modem.
13443 *
13444 * @param subId The subId of the subscription to request for.
13445 * @param reason Reason for disallowing satellite communication.
13446 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13447 * operation.
13448 *
13449 * @throws SecurityException if the caller doesn't have required permission.
13450 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013451 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013452 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13453 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013454 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013455 final long identity = Binder.clearCallingIdentity();
13456 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013457 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013458 } finally {
13459 Binder.restoreCallingIdentity(identity);
13460 }
13461 }
13462
13463 /**
13464 * Get reasons for disallowing satellite communication, as requested by
13465 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13466 *
13467 * @param subId The subId of the subscription to request for.
13468 *
13469 * @return Integer array of reasons for disallowing satellite communication.
13470 *
13471 * @throws SecurityException if the caller doesn't have the required permission.
13472 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013473 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013474 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013475 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013476 final long identity = Binder.clearCallingIdentity();
13477 try {
13478 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013479 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013480 return reasonSet.stream().mapToInt(i->i).toArray();
13481 } finally {
13482 Binder.restoreCallingIdentity(identity);
13483 }
13484 }
13485
13486 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013487 * Request to get the signal strength of the satellite connection.
13488 *
13489 * @param subId The subId of the subscription to request for.
13490 * @param result Result receiver to get the error code of the request and the current signal
13491 * strength of the satellite connection.
13492 *
13493 * @throws SecurityException if the caller doesn't have required permission.
13494 */
13495 @Override
13496 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13497 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13498 final long identity = Binder.clearCallingIdentity();
13499 try {
13500 mSatelliteController.requestNtnSignalStrength(subId, result);
13501 } finally {
13502 Binder.restoreCallingIdentity(identity);
13503 }
13504 }
13505
13506 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013507 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13508 * is not successful, a {@link ServiceSpecificException} that contains
13509 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013510 *
13511 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013512 * @param callback The callback to handle the NTN signal strength changed event. If the
13513 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13514 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13515 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13516 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013517 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013518 * @throws SecurityException If the caller doesn't have the required permission.
13519 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013520 */
13521 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013522 public void registerForNtnSignalStrengthChanged(int subId,
13523 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013524 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13525 final long identity = Binder.clearCallingIdentity();
13526 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013527 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013528 } finally {
13529 Binder.restoreCallingIdentity(identity);
13530 }
13531 }
13532
13533 /**
13534 * Unregisters for NTN signal strength changed from satellite modem.
13535 * If callback was not registered before, the request will be ignored.
13536 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013537 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13538 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013539 * @param callback The callback that was passed to
13540 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13541 *
13542 * @throws SecurityException if the caller doesn't have the required permission.
13543 */
13544 @Override
13545 public void unregisterForNtnSignalStrengthChanged(
13546 int subId, @NonNull INtnSignalStrengthCallback callback) {
13547 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13548 final long identity = Binder.clearCallingIdentity();
13549 try {
13550 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13551 } finally {
13552 Binder.restoreCallingIdentity(identity);
13553 }
13554 }
13555
13556 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013557 * Registers for satellite capabilities change event from the satellite service.
13558 *
13559 * @param subId The subId of the subscription to request for.
13560 * @param callback The callback to handle the satellite capabilities changed event.
13561 *
13562 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13563 *
13564 * @throws SecurityException if the caller doesn't have required permission.
13565 */
13566 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013567 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013568 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013569 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013570 final long identity = Binder.clearCallingIdentity();
13571 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013572 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013573 } finally {
13574 Binder.restoreCallingIdentity(identity);
13575 }
13576 }
13577
13578 /**
13579 * Unregisters for satellite capabilities change event from the satellite service.
13580 * If callback was not registered before, the request will be ignored.
13581 *
13582 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13583 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013584 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013585 *
13586 * @throws SecurityException if the caller doesn't have required permission.
13587 */
13588 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013589 public void unregisterForCapabilitiesChanged(int subId,
13590 @NonNull ISatelliteCapabilitiesCallback callback) {
13591 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013592 final long identity = Binder.clearCallingIdentity();
13593 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013594 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013595 } finally {
13596 Binder.restoreCallingIdentity(identity);
13597 }
13598 }
13599
13600 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013601 * This API can be used by only CTS to update satellite vendor service package name.
13602 *
13603 * @param servicePackageName The package name of the satellite vendor service.
13604 * @return {@code true} if the satellite vendor service is set successfully,
13605 * {@code false} otherwise.
13606 */
13607 public boolean setSatelliteServicePackageName(String servicePackageName) {
13608 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13609 TelephonyPermissions.enforceShellOnly(
13610 Binder.getCallingUid(), "setSatelliteServicePackageName");
13611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13612 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13613 "setSatelliteServicePackageName");
13614 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13615 }
13616
13617 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013618 * This API can be used by only CTS to update satellite gateway service package name.
13619 *
13620 * @param servicePackageName The package name of the satellite gateway service.
13621 * @return {@code true} if the satellite gateway service is set successfully,
13622 * {@code false} otherwise.
13623 */
13624 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13625 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13626 TelephonyPermissions.enforceShellOnly(
13627 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13629 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13630 "setSatelliteGatewayServicePackageName");
13631 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13632 }
13633
13634 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013635 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13636 *
13637 * @param packageName The package name of the satellite pointing UI app.
13638 * @param className The class name of the satellite pointing UI app.
13639 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13640 * {@code false} otherwise.
13641 */
13642 public boolean setSatellitePointingUiClassName(
13643 @Nullable String packageName, @Nullable String className) {
13644 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13645 + ", className=" + className);
13646 TelephonyPermissions.enforceShellOnly(
13647 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13649 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13650 "setSatelliteGatewayServicePackageName");
13651 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13652 }
13653
13654 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013655 * This API can be used by only CTS to update the timeout duration in milliseconds that
13656 * satellite should stay at listening mode to wait for the next incoming page before disabling
13657 * listening mode.
13658 *
13659 * @param timeoutMillis The timeout duration in millisecond.
13660 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13661 */
13662 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13663 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13664 TelephonyPermissions.enforceShellOnly(
13665 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13667 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13668 "setSatelliteListeningTimeoutDuration");
13669 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13670 }
13671
13672 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013673 * This API can be used by only CTS to override the timeout durations used by the
13674 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013675 *
13676 * @param timeoutMillis The timeout duration in millisecond.
13677 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13678 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013679 public boolean setDatagramControllerTimeoutDuration(
13680 boolean reset, int timeoutType, long timeoutMillis) {
13681 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13682 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013683 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013684 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13686 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013687 "setDatagramControllerTimeoutDuration");
13688 return mSatelliteController.setDatagramControllerTimeoutDuration(
13689 reset, timeoutType, timeoutMillis);
13690 }
13691
13692 /**
13693 * This API can be used by only CTS to override the timeout durations used by the
13694 * SatelliteController module.
13695 *
13696 * @param timeoutMillis The timeout duration in millisecond.
13697 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13698 */
13699 public boolean setSatelliteControllerTimeoutDuration(
13700 boolean reset, int timeoutType, long timeoutMillis) {
13701 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13702 + reset + ", timeoutMillis=" + timeoutMillis);
13703 TelephonyPermissions.enforceShellOnly(
13704 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13706 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13707 "setSatelliteControllerTimeoutDuration");
13708 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13709 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013710 }
13711
13712 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013713 * This API can be used in only testing to override connectivity status in monitoring emergency
13714 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13715 *
13716 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13717 * of the following values to enable the override:
13718 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13719 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13720 * To disable the override, use -1 for handoverType.
13721 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13722 * delaySeconds after the emergency call starts.
13723 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13724 */
13725 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13726 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13727 TelephonyPermissions.enforceShellOnly(
13728 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13730 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13731 "setEmergencyCallToSatelliteHandoverType");
13732 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13733 handoverType, delaySeconds);
13734 }
13735
13736 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013737 * This API can be used in only testing to override oem-enabled satellite provision status.
13738 *
13739 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13740 * otherwise.
13741 * @param isProvisioned The overriding provision status.
13742 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13743 */
13744 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13745 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13746 + ", isProvisioned=" + isProvisioned);
13747 TelephonyPermissions.enforceShellOnly(
13748 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13750 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13751 "setOemEnabledSatelliteProvisionStatus");
13752 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13753 }
13754
13755 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013756 * This API should be used by only CTS tests to forcefully set telephony country codes.
13757 *
13758 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13759 */
13760 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13761 Map cachedNetworkCountryCodes, String locationCountryCode,
13762 long locationCountryCodeTimestampNanos) {
13763 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13764 + String.join(", ", currentNetworkCountryCodes)
13765 + ", locationCountryCode=" + locationCountryCode
13766 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13767 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13768 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13769 TelephonyPermissions.enforceShellOnly(
13770 Binder.getCallingUid(), "setCachedLocationCountryCode");
13771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13772 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13773 "setCachedLocationCountryCode");
13774 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13775 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13776 locationCountryCodeTimestampNanos);
13777 }
13778
13779 /**
13780 * This API should be used by only CTS tests to override the overlay configs of satellite
13781 * access controller.
13782 *
13783 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13784 * otherwise.
13785 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13786 */
13787 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13788 String s2CellFile, long locationFreshDurationNanos,
13789 List<String> satelliteCountryCodes) {
13790 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13791 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13792 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13793 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13794 ? String.join(", ", satelliteCountryCodes) : null));
13795 TelephonyPermissions.enforceShellOnly(
13796 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13798 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13799 "setSatelliteAccessControlOverlayConfigs");
13800 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13801 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13802 }
13803
13804 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013805 * This API can be used by only CTS to override the cached value for the device overlay config
13806 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13807 * outgoing satellite datagrams should be sent to modem in demo mode.
13808 *
13809 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13810 * satellite modem or not.
13811 *
13812 * @return {@code true} if the operation is successful, {@code false} otherwise.
13813 */
13814 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13815 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13816 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13817 + "disabled");
13818 return false;
13819 }
13820 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13821 TelephonyPermissions.enforceShellOnly(
13822 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13824 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13825 "setShouldSendDatagramToModemInDemoMode");
13826 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13827 shouldSendToModemInDemoMode);
13828 }
13829
13830 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013831 * Sets the service defined in ComponentName to be bound.
13832 *
13833 * This should only be used for testing.
13834 * @return {@code true} if the DomainSelectionService to bind to was set,
13835 * {@code false} otherwise.
13836 */
13837 @Override
13838 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13839 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13840
13841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13842 "setDomainSelectionServiceOverride");
13843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13844 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13845
13846 final long identity = Binder.clearCallingIdentity();
13847 try {
13848 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13849 return DomainSelectionResolver.getInstance()
13850 .setDomainSelectionServiceOverride(componentName);
13851 }
13852 } finally {
13853 Binder.restoreCallingIdentity(identity);
13854 }
13855 return false;
13856 }
13857
13858 /**
13859 * Clears the DomainSelectionService override.
13860 *
13861 * This should only be used for testing.
13862 * @return {@code true} if the DomainSelectionService override was cleared,
13863 * {@code false} otherwise.
13864 */
13865 @Override
13866 public boolean clearDomainSelectionServiceOverride() {
13867 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13868
13869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13870 "clearDomainSelectionServiceOverride");
13871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13872 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13873
13874 final long identity = Binder.clearCallingIdentity();
13875 try {
13876 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13877 return DomainSelectionResolver.getInstance()
13878 .clearDomainSelectionServiceOverride();
13879 }
13880 } finally {
13881 Binder.restoreCallingIdentity(identity);
13882 }
13883 return false;
13884 }
13885
13886 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013887 * Enable or disable notifications sent for cellular identifier disclosure events.
13888 *
13889 * Disclosure events are defined as instances where a device has sent a cellular identifier
13890 * on the Non-access stratum (NAS) before a security context is established. As a result the
13891 * identifier is sent in the clear, which has privacy implications for the user.
13892 *
13893 * @param enable if notifications about disclosure events should be enabled
13894 * @throws SecurityException if the caller does not have the required privileges
13895 * @throws UnsupportedOperationException if the modem does not support this feature.
13896 */
13897 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013898 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013899 enforceModifyPermission();
13900 checkForIdentifierDisclosureNotificationSupport();
13901
13902 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13903 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13904 editor.apply();
13905
13906 // Each phone instance is responsible for updating its respective modem immediately
13907 // after we've made a preference change.
13908 for (Phone phone : PhoneFactory.getPhones()) {
13909 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13910 }
13911 }
13912
13913 /**
13914 * Get whether or not cellular identifier disclosure notifications are enabled.
13915 *
13916 * @throws SecurityException if the caller does not have the required privileges
13917 * @throws UnsupportedOperationException if the modem does not support this feature.
13918 */
13919 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013920 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013921 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13922 checkForIdentifierDisclosureNotificationSupport();
13923 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13924 }
13925
13926 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013927 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13928 * are in use by the cellular modem.
13929 *
13930 * @throws IllegalStateException if the Telephony process is not currently available
13931 * @throws SecurityException if the caller does not have the required privileges
13932 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13933 * and integrity algorithms in use
13934 * @hide
13935 */
13936 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013937 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013938 enforceModifyPermission();
13939 checkForNullCipherNotificationSupport();
13940
13941 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13942 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13943 editor.apply();
13944
13945 // Each phone instance is responsible for updating its respective modem immediately
13946 // after a preference change.
13947 for (Phone phone : PhoneFactory.getPhones()) {
13948 phone.handleNullCipherNotificationPreferenceChanged();
13949 }
13950 }
13951
13952 /**
13953 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13954 * cellular modem.
13955 *
13956 * @throws IllegalStateException if the Telephony process is not currently available
13957 * @throws SecurityException if the caller does not have the required privileges
13958 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13959 * and integrity algorithms in use
13960 * @hide
13961 */
13962 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
13963 public boolean isNullCipherNotificationsEnabled() {
13964 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
13965 checkForNullCipherNotificationSupport();
13966 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
13967 }
13968
13969 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013970 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13971 *
13972 * <p>This method behaves in one of the following ways:
13973 * <ul>
13974 * <li>return true : if the calling package has the appop permission {@link
13975 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13976 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13977 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13978 * Owner device identifier access check, or the calling package has carrier privileges</>
13979 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13980 * </ul>
13981 */
13982 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13983 String callingPackage, @Nullable String callingFeatureId, String message) {
13984 for (Phone phone : PhoneFactory.getPhones()) {
13985 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13986 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13987 return true;
13988 }
13989 }
13990 return false;
13991 }
arunvoddud7401012022-12-15 16:08:12 +000013992
13993 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013994 * @return The subscription manager service instance.
13995 */
13996 public SubscriptionManagerService getSubscriptionManagerService() {
13997 return SubscriptionManagerService.getInstance();
13998 }
13999
14000 /**
arunvoddud7401012022-12-15 16:08:12 +000014001 * Class binds the consumer[callback] and carrierId.
14002 */
14003 private static class CallerCallbackInfo {
14004 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014005 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014006
Steve Statia28b7cb32024-03-11 23:58:50 +000014007 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014008 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014009 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014010 }
14011
14012 public Consumer<Integer> getConsumer() {
14013 return mConsumer;
14014 }
14015
Steve Statia28b7cb32024-03-11 23:58:50 +000014016 public Set<Integer> getCarrierIds() {
14017 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014018 }
14019 }
joonhunshin4ac60942023-11-15 15:23:39 +000014020
14021 /*
14022 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14023 * But the context that is passed in is unused if the phone app is already alive.
14024 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14025 */
14026 @VisibleForTesting
14027 public void setPackageManager(PackageManager packageManager) {
14028 mPackageManager = packageManager;
14029 }
14030
14031 /*
Nate Myren453c3472024-03-13 11:28:11 -070014032 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14033 * But the context that is passed in is unused if the phone app is already alive.
14034 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14035 */
14036 @VisibleForTesting
14037 public void setAppOpsManager(AppOpsManager appOps) {
14038 mAppOps = appOps;
14039 }
14040
14041 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014042 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14043 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14044 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14045 */
14046 @VisibleForTesting
14047 public void setFeatureFlags(FeatureFlags featureFlags) {
14048 mFeatureFlags = featureFlags;
14049 }
14050
14051 /**
14052 * Make sure the device has required telephony feature
14053 *
14054 * @throws UnsupportedOperationException if the device does not have required telephony feature
14055 */
14056 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14057 @NonNull String telephonyFeature, @NonNull String methodName) {
14058 if (callingPackage == null || mPackageManager == null) {
14059 return;
14060 }
14061
14062 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14063 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14064 Binder.getCallingUserHandle())) {
14065 return;
14066 }
14067
14068 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14069 throw new UnsupportedOperationException(
14070 methodName + " is unsupported without " + telephonyFeature);
14071 }
14072 }
Jack Yufa8ed012023-02-11 15:42:28 -080014073}