blob: e18818c0f33f6e972c529461034f29f808d2bc79 [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;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800260import com.android.services.telephony.TelecomAccountRegistry;
261import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800262import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800263
Hall Liu82694d52020-12-11 18:22:04 -0800264import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700265import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.io.IOException;
267import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700268import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800270import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000271import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800272import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800273import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800274import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800275import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100276import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800277import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700278import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800279import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800280import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700281import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800282import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800284import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285
286/**
287 * Implementation of the ITelephony interface.
288 */
Santos Cordon117fee72014-05-16 17:56:12 -0700289public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290 private static final String LOG_TAG = "PhoneInterfaceManager";
291 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
292 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800293 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294
295 // Message codes used with mMainThreadHandler
296 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700297 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
298 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700299 private static final int CMD_OPEN_CHANNEL = 9;
300 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
301 private static final int CMD_CLOSE_CHANNEL = 11;
302 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800303 private static final int CMD_NV_READ_ITEM = 13;
304 private static final int EVENT_NV_READ_ITEM_DONE = 14;
305 private static final int CMD_NV_WRITE_ITEM = 15;
306 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
307 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
308 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700309 private static final int CMD_RESET_MODEM_CONFIG = 19;
310 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800311 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
312 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800313 private static final int CMD_SEND_ENVELOPE = 25;
314 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700315 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
316 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
317 private static final int CMD_EXCHANGE_SIM_IO = 31;
318 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800319 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
320 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700321 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
322 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700323 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
324 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700325 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
326 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
327 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
328 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700329 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
330 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
331 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
332 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700333 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800334 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
335 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000336 private static final int CMD_SWITCH_SLOTS = 50;
337 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700338 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
339 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
340 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
341 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
342 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
343 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
344 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
345 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700346 private static final int CMD_GET_ALL_CELL_INFO = 60;
347 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
348 private static final int CMD_GET_CELL_LOCATION = 62;
349 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700350 private static final int CMD_MODEM_REBOOT = 64;
351 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700352 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
353 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800354 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
355 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700356 private static final int CMD_GET_MODEM_STATUS = 70;
357 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700358 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
359 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700360 private static final int CMD_ERASE_MODEM_CONFIG = 74;
361 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800362 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
363 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
364 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
365 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800366 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
367 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800368 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800369 private static final int CMD_GET_CALL_FORWARDING = 83;
370 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
371 private static final int CMD_SET_CALL_FORWARDING = 85;
372 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
373 private static final int CMD_GET_CALL_WAITING = 87;
374 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
375 private static final int CMD_SET_CALL_WAITING = 89;
376 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700377 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
378 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
379 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
380 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700381 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
382 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800383 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
384 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800385 private static final int CMD_SET_DATA_THROTTLING = 99;
386 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800387 private static final int CMD_SET_SIM_POWER = 101;
388 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800389 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
390 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
391 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
392 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800393 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
394 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000395 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800396 private static final int CMD_GET_SLICING_CONFIG = 110;
397 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800398 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700399 private static final int CMD_ENABLE_VONR = 113;
400 private static final int EVENT_ENABLE_VONR_DONE = 114;
401 private static final int CMD_IS_VONR_ENABLED = 115;
402 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700403 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
404 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000405
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800406 // Parameters of select command.
407 private static final int SELECT_COMMAND = 0xA4;
408 private static final int SELECT_P1 = 0x04;
409 private static final int SELECT_P2 = 0;
410 private static final int SELECT_P3 = 0x10;
411
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000412 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
413 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000414 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
415 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600416 // Null cipher notification support was added in IRadioNetwork 2.2
417 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000418
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419 /** The singleton instance. */
420 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800421 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422
Sarah Chin4beb2b72023-02-14 14:47:54 -0800423 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000424 private FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800425 private final CallManager mCM;
426 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000427
428 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800429 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800430 private final UserManager mUserManager;
431 private final AppOpsManager mAppOps;
432 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800433 private final SharedPreferences mTelephonySharedPreferences;
434 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800435 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
joonhunshin4ac60942023-11-15 15:23:39 +0000436 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437
Peter Wangdafb9ac2020-01-15 14:13:38 -0800438 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800439 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800440 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800441 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800442
Derek Tan97ebb422014-09-05 16:55:38 -0700443 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
444 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800445 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800446 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700447
Michelecea4cf22018-12-21 15:00:11 -0800448 // String to store multi SIM allowed
449 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
450
Derek Tan740e1672017-06-27 14:56:27 -0700451 // The AID of ISD-R.
452 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
453
yinxub1bed742017-04-17 11:45:04 -0700454 private NetworkScanRequestTracker mNetworkScanRequestTracker;
455
David Kelly5e06a7f2018-03-12 14:10:59 +0000456 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
457 private static final int MANUFACTURER_CODE_LENGTH = 8;
458
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800459 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800460 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800461
Sarah Chin2ec39f62022-08-31 17:03:26 -0700462 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
463 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
464
Derek Tan89e89d42014-07-08 17:00:10 -0700465 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700466 * Experiment flag to enable erase modem config on reset network, default value is false
467 */
468 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
469 "reset_network_erase_modem_config_enabled";
470
Rambo Wang0f050d82021-02-12 11:43:36 -0800471 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800472
Gary Jian76280a42022-12-07 16:18:33 +0800473 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
474
sandeepjsb6c87872021-09-27 15:34:44 +0000475 /**
476 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
477 * one ICCID active at the same time.
478 * Apps should use below API signatures if targeting SDK is T and beyond.
479 *
480 * @hide
481 */
482 @ChangeId
483 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
484 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800485
Naina Nallurid63128d2019-09-17 14:10:30 -0700486 /**
Chen Xu540470b2021-12-14 17:15:47 -0800487 * Apps targeting on Android T and beyond will get exception whenever icc close channel
488 * operation fails.
489 */
490 @ChangeId
491 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
492 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
493
494 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 * A request object to use for transmitting data to an ICC.
496 */
497 private static final class IccAPDUArgument {
498 public int channel, cla, command, p1, p2, p3;
499 public String data;
500
501 public IccAPDUArgument(int channel, int cla, int command,
502 int p1, int p2, int p3, String data) {
503 this.channel = channel;
504 this.cla = cla;
505 this.command = command;
506 this.p1 = p1;
507 this.p2 = p2;
508 this.p3 = p3;
509 this.data = data;
510 }
511 }
512
513 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700514 * A request object to use for transmitting data to an ICC.
515 */
516 private static final class ManualNetworkSelectionArgument {
517 public OperatorInfo operatorInfo;
518 public boolean persistSelection;
519
520 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
521 this.operatorInfo = operatorInfo;
522 this.persistSelection = persistSelection;
523 }
524 }
525
Sarah Chin71b3a852022-09-28 15:54:19 -0700526 private static final class PurchasePremiumCapabilityArgument {
527 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700528 public @NonNull IIntegerConsumer callback;
529
530 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800531 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700532 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700533 this.callback = callback;
534 }
535 }
536
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700537 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
539 * request after sending. The main thread will notify the request when it is complete.
540 */
541 private static final class MainThreadRequest {
542 /** The argument to use for the request */
543 public Object argument;
544 /** The result of the request that is run on the main thread */
545 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800546 // The subscriber id that this request applies to. Defaults to
547 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
548 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549
Nathan Harold92bed182018-10-12 18:16:49 -0700550 // In cases where subId is unavailable, the caller needs to specify the phone.
551 public Phone phone;
552
vagdeviaf9a5b92018-08-15 16:01:53 -0700553 public WorkSource workSource;
554
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 public MainThreadRequest(Object argument) {
556 this.argument = argument;
557 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800558
Nathan Harold92bed182018-10-12 18:16:49 -0700559 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
560 this.argument = argument;
561 if (phone != null) {
562 this.phone = phone;
563 }
564 this.workSource = workSource;
565 }
566
vagdeviaf9a5b92018-08-15 16:01:53 -0700567 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800568 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800569 if (subId != null) {
570 this.subId = subId;
571 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700572 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574 }
575
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800576 private static final class IncomingThirdPartyCallArgs {
577 public final ComponentName component;
578 public final String callId;
579 public final String callerDisplayName;
580
581 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
582 String callerDisplayName) {
583 this.component = component;
584 this.callId = callId;
585 this.callerDisplayName = callerDisplayName;
586 }
587 }
588
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700589 /**
590 * A handler that processes messages on the main thread in the phone process. Since many
591 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
592 * inbound binder threads to the main thread in the phone process. The Binder thread
593 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
594 * on, which will be notified when the operation completes and will contain the result of the
595 * request.
596 *
597 * <p>If a MainThreadRequest object is provided in the msg.obj field,
598 * note that request.result must be set to something non-null for the calling thread to
599 * unblock.
600 */
601 private final class MainThreadHandler extends Handler {
602 @Override
603 public void handleMessage(Message msg) {
604 MainThreadRequest request;
605 Message onCompleted;
606 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000607 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800609 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700610
611 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 case CMD_HANDLE_USSD_REQUEST: {
613 request = (MainThreadRequest) msg.obj;
614 final Phone phone = getPhoneFromRequest(request);
615 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800616 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700618
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 if (!isUssdApiAllowed(request.subId)) {
620 // Carrier does not support use of this API, return failure.
621 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
622 UssdResponse response = new UssdResponse(ussdRequest, null);
623 Bundle returnData = new Bundle();
624 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
625 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700626
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 request.result = true;
628 notifyRequester(request);
629 return;
630 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700631
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 try {
633 request.result = phone != null
634 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
635 } catch (CallStateException cse) {
636 request.result = false;
637 }
638 // Wake up the requesting thread
639 notifyRequester(request);
640 break;
pkanwar32d516d2016-10-14 19:37:38 -0700641 }
642
Yorke Lee716f67e2015-06-17 15:39:16 -0700643 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700644 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700645 final Phone phone = getPhoneFromRequest(request);
646 request.result = phone != null ?
647 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
648 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700653
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000657 uiccPort = getUiccPortFromRequest(request);
658 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800660 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800664 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800666 iccArgument.channel, iccArgument.cla, iccArgument.command,
667 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
668 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 break;
671
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result;
677 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800678 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 if (ar.result == null) {
680 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800681 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800683 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
685 loge("iccTransmitApduLogicalChannel: Unknown exception");
686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
692 request = (MainThreadRequest) msg.obj;
693 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000694 uiccPort = getUiccPortFromRequest(request);
695 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800697 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700698 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 } else {
700 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800701 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000702 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800703 iccArgument.cla, iccArgument.command, iccArgument.p1,
704 iccArgument.p2,
705 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 }
707 break;
708
709 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
710 ar = (AsyncResult) msg.obj;
711 request = (MainThreadRequest) ar.userObj;
712 if (ar.exception == null && ar.result != null) {
713 request.result = ar.result;
714 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800715 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 if (ar.result == null) {
717 loge("iccTransmitApduBasicChannel: Empty response");
718 } else if (ar.exception instanceof CommandException) {
719 loge("iccTransmitApduBasicChannel: CommandException: " +
720 ar.exception);
721 } else {
722 loge("iccTransmitApduBasicChannel: Unknown exception");
723 }
724 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700725 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 break;
727
728 case CMD_EXCHANGE_SIM_IO:
729 request = (MainThreadRequest) msg.obj;
730 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000731 uiccPort = getUiccPortFromRequest(request);
732 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800734 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 } else {
737 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
738 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000739 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
741 iccArgument.data, onCompleted);
742 }
743 break;
744
745 case EVENT_EXCHANGE_SIM_IO_DONE:
746 ar = (AsyncResult) msg.obj;
747 request = (MainThreadRequest) ar.userObj;
748 if (ar.exception == null && ar.result != null) {
749 request.result = ar.result;
750 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800751 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700752 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 break;
755
Derek Tan4d5e5c12014-02-04 11:54:58 -0800756 case CMD_SEND_ENVELOPE:
757 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000758 uiccPort = getUiccPortFromRequest(request);
759 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700760 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800761 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700763 } else {
764 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800765 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800767 break;
768
769 case EVENT_SEND_ENVELOPE_DONE:
770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700772 if (ar.exception == null && ar.result != null) {
773 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800774 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800775 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700776 if (ar.result == null) {
777 loge("sendEnvelopeWithStatus: Empty response");
778 } else if (ar.exception instanceof CommandException) {
779 loge("sendEnvelopeWithStatus: CommandException: " +
780 ar.exception);
781 } else {
782 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
783 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800784 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700785 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800786 break;
787
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 case CMD_OPEN_CHANNEL:
789 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000790 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800791 IccLogicalChannelRequest openChannelRequest =
792 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000793 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800795 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800796 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700797 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 } else {
799 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800800 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
801 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700802 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 break;
804
805 case EVENT_OPEN_CHANNEL_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700808 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700809 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700810 int[] result = (int[]) ar.result;
811 int channelId = result[0];
812 byte[] selectResponse = null;
813 if (result.length > 1) {
814 selectResponse = new byte[result.length - 1];
815 for (int i = 1; i < result.length; ++i) {
816 selectResponse[i - 1] = (byte) result[i];
817 }
818 }
819 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800820 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800821
822 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700823 if (uiccPort == null) {
824 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
825 } else {
826 IccLogicalChannelRequest channelRequest =
827 (IccLogicalChannelRequest) request.argument;
828 channelRequest.channel = channelId;
829 uiccPort.onLogicalChannelOpened(channelRequest);
830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700831 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 if (ar.result == null) {
833 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700835 if (ar.exception != null) {
836 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
837 }
838
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700839 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700840 if (ar.exception instanceof CommandException) {
841 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800842 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700843 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700844 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700845 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700846 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700847 }
848 }
849 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800850 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700852 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700853 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 break;
855
856 case CMD_CLOSE_CHANNEL:
857 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000858 uiccPort = getUiccPortFromRequest(request);
859 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700860 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800861 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800862 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800863 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700864 } else {
865 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000866 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700867 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700868 break;
869
870 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null) {
874 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800875 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700876 if (uiccPort == null) {
877 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
878 } else {
879 final int channelId = (Integer) request.argument;
880 uiccPort.onLogicalChannelClosed(channelId);
881 }
Chen Xu540470b2021-12-14 17:15:47 -0800882 } else {
883 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800884 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800885 if (ar.exception instanceof CommandException) {
886 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
887 CommandException.Error error =
888 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800889 if (error == CommandException.Error.INVALID_ARGUMENTS) {
890 // should only throw exceptions from the binder threads.
891 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800892 "iccCloseLogicalChannel: invalid argument ");
893 }
894 } else {
895 loge("iccCloseLogicalChannel: Unknown exception");
896 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800897 request.result = (exception != null) ? exception :
898 new IllegalStateException(
899 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800900 }
901 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800902 break;
903
904 case CMD_NV_READ_ITEM:
905 request = (MainThreadRequest) msg.obj;
906 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800907 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
908 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800909 break;
910
911 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700912 ar = (AsyncResult) msg.obj;
913 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800914 if (ar.exception == null && ar.result != null) {
915 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700916 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800917 request.result = "";
918 if (ar.result == null) {
919 loge("nvReadItem: Empty response");
920 } else if (ar.exception instanceof CommandException) {
921 loge("nvReadItem: CommandException: " +
922 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700923 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800924 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700925 }
926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700927 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700928 break;
929
Jake Hambye994d462014-02-03 13:10:13 -0800930 case CMD_NV_WRITE_ITEM:
931 request = (MainThreadRequest) msg.obj;
932 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
933 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800934 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700935 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800936 break;
937
938 case EVENT_NV_WRITE_ITEM_DONE:
939 handleNullReturnEvent(msg, "nvWriteItem");
940 break;
941
942 case CMD_NV_WRITE_CDMA_PRL:
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800945 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800946 break;
947
948 case EVENT_NV_WRITE_CDMA_PRL_DONE:
949 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
950 break;
951
chen xu6dac5ab2018-10-26 17:39:23 -0700952 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800953 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700954 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800955 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800956 break;
957
chen xu6dac5ab2018-10-26 17:39:23 -0700958 case EVENT_RESET_MODEM_CONFIG_DONE:
959 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800960 break;
961
Sooraj Sasindran37444802020-08-11 10:40:43 -0700962 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
965 request);
966 Phone phone = getPhoneFromRequest(request);
967 if (phone != null) {
968 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
969 } else {
970 loge("isNRDualConnectivityEnabled: No phone object");
971 request.result = false;
972 notifyRequester(request);
973 }
974 break;
975 }
976
977 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
978 ar = (AsyncResult) msg.obj;
979 request = (MainThreadRequest) ar.userObj;
980 if (ar.exception == null && ar.result != null) {
981 request.result = ar.result;
982 } else {
983 // request.result must be set to something non-null
984 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700985 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700986 request.result = ar.result;
987 } else {
988 request.result = false;
989 }
990 if (ar.result == null) {
991 loge("isNRDualConnectivityEnabled: Empty response");
992 } else if (ar.exception instanceof CommandException) {
993 loge("isNRDualConnectivityEnabled: CommandException: "
994 + ar.exception);
995 } else {
996 loge("isNRDualConnectivityEnabled: Unknown exception");
997 }
998 }
999 notifyRequester(request);
1000 break;
1001
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001002 case CMD_IS_VONR_ENABLED: {
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1005 request);
1006 Phone phone = getPhoneFromRequest(request);
1007 if (phone != null) {
1008 phone.isVoNrEnabled(onCompleted, request.workSource);
1009 } else {
1010 loge("isVoNrEnabled: No phone object");
1011 request.result = false;
1012 notifyRequester(request);
1013 }
1014 break;
1015 }
1016
1017 case EVENT_IS_VONR_ENABLED_DONE:
1018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception == null && ar.result != null) {
1021 request.result = ar.result;
1022 } else {
1023 // request.result must be set to something non-null
1024 // for the calling thread to unblock
1025 if (ar.result != null) {
1026 request.result = ar.result;
1027 } else {
1028 request.result = false;
1029 }
1030 if (ar.result == null) {
1031 loge("isVoNrEnabled: Empty response");
1032 } else if (ar.exception instanceof CommandException) {
1033 loge("isVoNrEnabled: CommandException: "
1034 + ar.exception);
1035 } else {
1036 loge("isVoNrEnabled: Unknown exception");
1037 }
1038 }
1039 notifyRequester(request);
1040 break;
1041
Sooraj Sasindran37444802020-08-11 10:40:43 -07001042 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1043 request = (MainThreadRequest) msg.obj;
1044 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1045 Phone phone = getPhoneFromRequest(request);
1046 if (phone != null) {
1047 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1048 request.workSource);
1049 } else {
1050 loge("enableNrDualConnectivity: No phone object");
1051 request.result =
1052 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1053 notifyRequester(request);
1054 }
1055 break;
1056 }
1057
1058 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
1061 if (ar.exception == null) {
1062 request.result =
1063 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1064 } else {
1065 request.result =
1066 TelephonyManager
1067 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1068 if (ar.exception instanceof CommandException) {
1069 CommandException.Error error =
1070 ((CommandException) (ar.exception)).getCommandError();
1071 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1072 request.result =
1073 TelephonyManager
1074 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001075 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1076 request.result =
1077 TelephonyManager
1078 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001079 }
1080 loge("enableNrDualConnectivity" + ": CommandException: "
1081 + ar.exception);
1082 } else {
1083 loge("enableNrDualConnectivity" + ": Unknown exception");
1084 }
1085 }
1086 notifyRequester(request);
1087 break;
1088 }
1089
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001090 case CMD_ENABLE_VONR: {
1091 request = (MainThreadRequest) msg.obj;
1092 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1093 Phone phone = getPhoneFromRequest(request);
1094 if (phone != null) {
1095 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1096 request.workSource);
1097 } else {
1098 loge("setVoNrEnabled: No phone object");
1099 request.result =
1100 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1101 notifyRequester(request);
1102 }
1103 break;
1104 }
1105
1106 case EVENT_ENABLE_VONR_DONE: {
1107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null) {
1110 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1111 } else {
1112 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1113 if (ar.exception instanceof CommandException) {
1114 CommandException.Error error =
1115 ((CommandException) (ar.exception)).getCommandError();
1116 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1117 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1118 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1119 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1120 } else {
1121 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1122 }
1123 loge("setVoNrEnabled" + ": CommandException: "
1124 + ar.exception);
1125 } else {
1126 loge("setVoNrEnabled" + ": Unknown exception");
1127 }
1128 }
1129 notifyRequester(request);
1130 break;
1131 }
1132
SongFerngWang3ef3e072020-12-21 16:41:52 +08001133 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001134 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1136 request);
1137 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 break;
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 if (ar.exception == null && ar.result != null) {
1144 request.result = ar.result; // Integer
1145 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301146 // request.result must be set to something non-null
1147 // for the calling thread to unblock
1148 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001149 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001150 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 loge("getAllowedNetworkTypesBitmask: CommandException: "
1153 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001155 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 }
1157 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001158 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 break;
1160
SongFerngWang3ef3e072020-12-21 16:41:52 +08001161 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001162 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1164 request);
1165 Pair<Integer, Long> reasonWithNetworkTypes =
1166 (Pair<Integer, Long>) request.argument;
1167 getPhoneFromRequest(request).setAllowedNetworkTypes(
1168 reasonWithNetworkTypes.first,
1169 reasonWithNetworkTypes.second,
1170 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001171 break;
1172
SongFerngWang3ef3e072020-12-21 16:41:52 +08001173 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1174 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001175 break;
1176
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001177 case CMD_SET_VOICEMAIL_NUMBER:
1178 request = (MainThreadRequest) msg.obj;
1179 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1180 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001181 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1182 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001183 break;
1184
1185 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1186 handleNullReturnEvent(msg, "setVoicemailNumber");
1187 break;
1188
Stuart Scott54788802015-03-30 13:18:01 -07001189 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1192 request);
1193 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1194 break;
1195
1196 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1197 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1198 break;
1199
Shishir Agrawal302c8692015-06-19 13:49:39 -07001200 case CMD_PERFORM_NETWORK_SCAN:
1201 request = (MainThreadRequest) msg.obj;
1202 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1203 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1204 break;
1205
Hall Liu27d24262020-09-18 19:04:59 -07001206 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001209 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1210 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1211 request.argument;
1212 int callForwardingReason = args.first;
1213 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001214 break;
Hall Liu27d24262020-09-18 19:04:59 -07001215 }
1216 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001219 TelephonyManager.CallForwardingInfoCallback callback =
1220 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1221 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001222 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001223 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001224 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1225 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1226 // Service Class is a bit mask per 3gpp 27.007. Search for
1227 // any service for voice call.
1228 if ((callForwardInfo.serviceClass
1229 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001230 callForwardingInfo = new CallForwardingInfo(
1231 callForwardInfo.status
1232 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001233 callForwardInfo.reason,
1234 callForwardInfo.number,
1235 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001236 break;
1237 }
1238 }
1239 // Didn't find a call forward info for voice call.
1240 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001241 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1242 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001243 }
Hall Liu27d24262020-09-18 19:04:59 -07001244 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 } else {
1246 if (ar.result == null) {
1247 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1248 }
1249 if (ar.exception != null) {
1250 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1251 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001252 int errorCode = TelephonyManager
1253 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001254 if (ar.exception instanceof CommandException) {
1255 CommandException.Error error =
1256 ((CommandException) (ar.exception)).getCommandError();
1257 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001258 errorCode = TelephonyManager
1259 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001260 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001261 errorCode = TelephonyManager
1262 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 }
1264 }
Hall Liu27d24262020-09-18 19:04:59 -07001265 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001266 }
Shuo Qian4a594052020-01-23 11:59:30 -08001267 break;
Hall Liu27d24262020-09-18 19:04:59 -07001268 }
Shuo Qian4a594052020-01-23 11:59:30 -08001269
Hall Liu27d24262020-09-18 19:04:59 -07001270 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001271 request = (MainThreadRequest) msg.obj;
1272 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001273 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001274 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001275 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1276 request.argument).first;
1277 request.phone.setCallForwardingOption(
1278 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001279 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001280 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001281 callForwardingInfoToSet.getReason(),
1282 callForwardingInfoToSet.getNumber(),
1283 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286
Hall Liu27d24262020-09-18 19:04:59 -07001287 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 ar = (AsyncResult) msg.obj;
1289 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001290 Consumer<Integer> callback =
1291 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1292 request.argument).second;
1293 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001294 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001295 int errorCode = TelephonyManager.CallForwardingInfoCallback
1296 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001297 if (ar.exception instanceof CommandException) {
1298 CommandException.Error error =
1299 ((CommandException) (ar.exception)).getCommandError();
1300 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001301 errorCode = TelephonyManager.CallForwardingInfoCallback
1302 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001303 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001304 errorCode = TelephonyManager.CallForwardingInfoCallback
1305 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001306 }
1307 }
1308 callback.accept(errorCode);
1309 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001310 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001311 }
Shuo Qian4a594052020-01-23 11:59:30 -08001312 break;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314
Hall Liu27d24262020-09-18 19:04:59 -07001315 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 request = (MainThreadRequest) msg.obj;
1317 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1318 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1319 break;
Hall Liu27d24262020-09-18 19:04:59 -07001320 }
Shuo Qian4a594052020-01-23 11:59:30 -08001321
Hall Liu27d24262020-09-18 19:04:59 -07001322 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001325 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001326 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001327 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001328 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001329 // Service Class is a bit mask per 3gpp 27.007.
1330 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001331 if (callForwardResults.length > 1
1332 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001333 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001334 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001335 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1336 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001337 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001339 }
1340 } else {
1341 if (ar.result == null) {
1342 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1343 }
1344 if (ar.exception != null) {
1345 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1346 }
1347 if (ar.exception instanceof CommandException) {
1348 CommandException.Error error =
1349 ((CommandException) (ar.exception)).getCommandError();
1350 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001351 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001352 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1354 callWaitingStatus =
1355 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001356 }
1357 }
1358 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001359 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001360 break;
Hall Liu27d24262020-09-18 19:04:59 -07001361 }
Shuo Qian4a594052020-01-23 11:59:30 -08001362
Hall Liu27d24262020-09-18 19:04:59 -07001363 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001364 request = (MainThreadRequest) msg.obj;
1365 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001366 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1367 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001368 break;
Hall Liu27d24262020-09-18 19:04:59 -07001369 }
Shuo Qian4a594052020-01-23 11:59:30 -08001370
Hall Liu27d24262020-09-18 19:04:59 -07001371 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001372 ar = (AsyncResult) msg.obj;
1373 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001374 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1375 Consumer<Integer> callback =
1376 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1377 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001378 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001379 if (ar.exception instanceof CommandException) {
1380 CommandException.Error error =
1381 ((CommandException) (ar.exception)).getCommandError();
1382 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1383 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001384 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1385 callback.accept(
1386 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001387 } else {
1388 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1389 }
1390 } else {
1391 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1392 }
1393 } else {
1394 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1395 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001396 }
Shuo Qian4a594052020-01-23 11:59:30 -08001397 break;
Hall Liu27d24262020-09-18 19:04:59 -07001398 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001399 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 CellNetworkScanResult cellScanResult;
1403 if (ar.exception == null && ar.result != null) {
1404 cellScanResult = new CellNetworkScanResult(
1405 CellNetworkScanResult.STATUS_SUCCESS,
1406 (List<OperatorInfo>) ar.result);
1407 } else {
1408 if (ar.result == null) {
1409 loge("getCellNetworkScanResults: Empty response");
1410 }
1411 if (ar.exception != null) {
1412 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1413 }
1414 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1415 if (ar.exception instanceof CommandException) {
1416 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001417 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001418 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1419 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1420 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1421 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1422 }
1423 }
1424 cellScanResult = new CellNetworkScanResult(errorCode, null);
1425 }
1426 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001427 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001428 break;
1429
1430 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1431 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001432 ManualNetworkSelectionArgument selArg =
1433 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001434 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1435 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001436 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1437 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001438 break;
1439
1440 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001441 ar = (AsyncResult) msg.obj;
1442 request = (MainThreadRequest) ar.userObj;
1443 if (ar.exception == null) {
1444 request.result = true;
1445 } else {
1446 request.result = false;
1447 loge("setNetworkSelectionModeManual " + ar.exception);
1448 }
1449 notifyRequester(request);
1450 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001451 break;
1452
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001453 case CMD_GET_MODEM_ACTIVITY_INFO:
1454 request = (MainThreadRequest) msg.obj;
1455 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001456 if (defaultPhone != null) {
1457 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 } else {
1459 ResultReceiver result = (ResultReceiver) request.argument;
1460 Bundle bundle = new Bundle();
1461 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001462 new ModemActivityInfo(0, 0, 0,
1463 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001464 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001465 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001466 break;
1467
Hall Liud0f208c2020-10-14 16:54:44 -07001468 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001472 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001473 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001474 if (mLastModemActivityInfo == null) {
1475 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1476 mLastModemActivitySpecificInfo[0] =
1477 new ActivityStatsTechSpecificInfo(
1478 0,
1479 0,
1480 new int[ModemActivityInfo.getNumTxPowerLevels()],
1481 0);
1482 mLastModemActivityInfo =
1483 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1484 }
1485
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001486 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001487 // Update the last modem activity info and the result of the request.
1488 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1489 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001490 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001491 } else {
1492 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001493 }
Kai Shi917fdc62022-11-28 14:01:02 -08001494 // This is needed to decouple ret from mLastModemActivityInfo
1495 // We don't want to return mLastModemActivityInfo which is updated
1496 // inside mergeModemActivityInfo()
1497 ret = new ModemActivityInfo(
1498 mLastModemActivityInfo.getTimestampMillis(),
1499 mLastModemActivityInfo.getSleepTimeMillis(),
1500 mLastModemActivityInfo.getIdleTimeMillis(),
1501 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001502
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001503 } else {
1504 if (ar.result == null) {
1505 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001506 error = TelephonyManager.ModemActivityInfoException
1507 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001508 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001509 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001510 error = TelephonyManager.ModemActivityInfoException
1511 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001512 } else {
1513 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001514 error = TelephonyManager.ModemActivityInfoException
1515 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001516 }
1517 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001518 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001519 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001520 bundle.putParcelable(
1521 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001522 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001523 } else {
1524 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1525 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001526 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001527 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001528 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001529 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001530
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001531 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001532 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001533 CarrierRestrictionRules argument =
1534 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001536 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001538 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539
1540 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1541 ar = (AsyncResult) msg.obj;
1542 request = (MainThreadRequest) ar.userObj;
1543 if (ar.exception == null && ar.result != null) {
1544 request.result = ar.result;
1545 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001546 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1547 if (ar.exception instanceof CommandException) {
1548 loge("setAllowedCarriers: CommandException: " + ar.exception);
1549 CommandException.Error error =
1550 ((CommandException) (ar.exception)).getCommandError();
1551 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1552 request.result =
1553 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1554 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001555 } else {
1556 loge("setAllowedCarriers: Unknown exception");
1557 }
1558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001559 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001560 break;
1561
1562 case CMD_GET_ALLOWED_CARRIERS:
1563 request = (MainThreadRequest) msg.obj;
1564 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001565 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001566 break;
1567
1568 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 if (ar.exception == null && ar.result != null) {
1572 request.result = ar.result;
1573 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001574 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001575 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001576 if (ar.result == null) {
1577 loge("getAllowedCarriers: Empty response");
1578 } else if (ar.exception instanceof CommandException) {
1579 loge("getAllowedCarriers: CommandException: " +
1580 ar.exception);
1581 } else {
1582 loge("getAllowedCarriers: Unknown exception");
1583 }
1584 }
arunvoddud7401012022-12-15 16:08:12 +00001585 if (request.argument != null) {
1586 // This is for the implementation of carrierRestrictionStatus.
1587 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1588 Consumer<Integer> callback = callbackInfo.getConsumer();
1589 int callerCarrierId = callbackInfo.getCarrierId();
1590 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1591 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1592 CarrierRestrictionRules carrierRestrictionRules =
1593 (CarrierRestrictionRules) ar.result;
1594 int carrierId = -1;
1595 try {
1596 CarrierIdentifier carrierIdentifier =
1597 carrierRestrictionRules.getAllowedCarriers().get(0);
1598 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1599 carrierIdentifier);
1600 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1601 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1602 }
1603 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1604 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1605 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001606 lockStatus = TelephonyManager
1607 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001608 }
1609 } else {
1610 Rlog.e(LOG_TAG,
1611 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1612 }
1613 callback.accept(lockStatus);
1614 } else {
1615 // This is for the implementation of getAllowedCarriers.
1616 notifyRequester(request);
1617 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001618 break;
1619
Nathan Haroldb3014052017-01-25 15:57:32 -08001620 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 if (ar.exception == null && ar.result != null) {
1624 request.result = ar.result;
1625 } else {
1626 request.result = new IllegalArgumentException(
1627 "Failed to retrieve Forbidden Plmns");
1628 if (ar.result == null) {
1629 loge("getForbiddenPlmns: Empty response");
1630 } else {
1631 loge("getForbiddenPlmns: Unknown exception");
1632 }
1633 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001634 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001635 break;
1636
1637 case CMD_GET_FORBIDDEN_PLMNS:
1638 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001639 uiccPort = getUiccPortFromRequest(request);
1640 if (uiccPort == null) {
1641 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001642 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001643 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001644 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001645 break;
1646 }
1647 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001648 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001649 if (uiccApp == null) {
1650 loge("getForbiddenPlmns() no app with specified type -- "
1651 + appType);
1652 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 break;
1655 } else {
1656 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1657 + " specified type -- " + appType);
1658 }
1659 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1660 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001661 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001662 break;
1663
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001664 case CMD_SWITCH_SLOTS:
1665 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001666 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001667 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001668 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001669 break;
1670
1671 case EVENT_SWITCH_SLOTS_DONE:
1672 ar = (AsyncResult) msg.obj;
1673 request = (MainThreadRequest) ar.userObj;
1674 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001675 notifyRequester(request);
1676 break;
1677 case CMD_GET_NETWORK_SELECTION_MODE:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1680 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1681 break;
1682
1683 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 if (ar.exception != null) {
1687 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1688 } else {
1689 int mode = ((int[]) ar.result)[0];
1690 if (mode == 0) {
1691 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1692 } else {
1693 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1694 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001696 notifyRequester(request);
1697 break;
1698 case CMD_GET_CDMA_ROAMING_MODE:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1701 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1702 break;
1703 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 if (ar.exception != null) {
1707 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1708 } else {
1709 request.result = ((int[]) ar.result)[0];
1710 }
1711 notifyRequester(request);
1712 break;
1713 case CMD_SET_CDMA_ROAMING_MODE:
1714 request = (MainThreadRequest) msg.obj;
1715 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1716 int mode = (int) request.argument;
1717 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1718 break;
1719 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722 request.result = ar.exception == null;
1723 notifyRequester(request);
1724 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001725 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1728 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1729 break;
1730 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 if (ar.exception != null) {
1734 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1735 } else {
1736 request.result = ((int[]) ar.result)[0];
1737 }
1738 notifyRequester(request);
1739 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001740 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1743 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001744 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1745 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001746 break;
1747 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1748 ar = (AsyncResult) msg.obj;
1749 request = (MainThreadRequest) ar.userObj;
1750 request.result = ar.exception == null;
1751 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001752 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001753 case CMD_GET_ALL_CELL_INFO:
1754 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001755 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001756 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001757 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001758 case EVENT_GET_ALL_CELL_INFO_DONE:
1759 ar = (AsyncResult) msg.obj;
1760 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001761 // If a timeout occurs, the response will be null
1762 request.result = (ar.exception == null && ar.result != null)
1763 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 synchronized (request) {
1765 request.notifyAll();
1766 }
1767 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001768 case CMD_REQUEST_CELL_INFO_UPDATE:
1769 request = (MainThreadRequest) msg.obj;
1770 request.phone.requestCellInfoUpdate(request.workSource,
1771 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1772 break;
1773 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1774 ar = (AsyncResult) msg.obj;
1775 request = (MainThreadRequest) ar.userObj;
1776 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1777 try {
1778 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001779 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001780 cb.onError(
1781 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1782 ar.exception.getClass().getName(),
1783 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001784 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001785 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001786 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001787 } else {
1788 // use the result as returned
1789 cb.onCellInfo((List<CellInfo>) ar.result);
1790 }
1791 } catch (RemoteException re) {
1792 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1793 }
1794 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001795 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001796 request = (MainThreadRequest) msg.obj;
1797 WorkSource ws = (WorkSource) request.argument;
1798 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001799 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001800 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001801 }
1802 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001803 ar = (AsyncResult) msg.obj;
1804 request = (MainThreadRequest) ar.userObj;
1805 if (ar.exception == null) {
1806 request.result = ar.result;
1807 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001808 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001809 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001810 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001811 }
1812
1813 synchronized (request) {
1814 request.notifyAll();
1815 }
1816 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001817 }
chen xu6dac5ab2018-10-26 17:39:23 -07001818 case CMD_MODEM_REBOOT:
1819 request = (MainThreadRequest) msg.obj;
1820 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001821 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001822 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001823 case EVENT_CMD_MODEM_REBOOT_DONE:
1824 handleNullReturnEvent(msg, "rebootModem");
1825 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001826 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001827 request = (MainThreadRequest) msg.obj;
1828 boolean enable = (boolean) request.argument;
1829 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001830 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001831 PhoneConfigurationManager.getInstance()
1832 .enablePhone(request.phone, enable, onCompleted);
1833 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001834 }
Michele Berionne5e411512020-11-13 02:36:59 +00001835 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001839 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001840 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001841 if ((boolean) request.result) {
1842 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1843 updateModemStateMetrics();
1844 } else {
1845 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1846 + ar.exception);
1847 }
1848 notifyRequester(request);
1849 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001850 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001851 case CMD_GET_MODEM_STATUS:
1852 request = (MainThreadRequest) msg.obj;
1853 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1854 PhoneConfigurationManager.getInstance()
1855 .getPhoneStatusFromModem(request.phone, onCompleted);
1856 break;
1857 case EVENT_GET_MODEM_STATUS_DONE:
1858 ar = (AsyncResult) msg.obj;
1859 request = (MainThreadRequest) ar.userObj;
1860 int id = request.phone.getPhoneId();
1861 if (ar.exception == null && ar.result != null) {
1862 request.result = ar.result;
1863 //update the cache as modem status has changed
1864 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1865 (boolean) request.result);
1866 } else {
1867 // Return true if modem status cannot be retrieved. For most cases,
1868 // modem status is on. And for older version modems, GET_MODEM_STATUS
1869 // and disable modem are not supported. Modem is always on.
1870 // TODO: this should be fixed in R to support a third
1871 // status UNKNOWN b/131631629
1872 request.result = true;
1873 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1874 + ar.exception);
1875 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001876 notifyRequester(request);
1877 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001878 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1879 request = (MainThreadRequest) msg.obj;
1880 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1881 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1882 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1883 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1884 break;
1885 }
1886 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1887 ar = (AsyncResult) msg.obj;
1888 request = (MainThreadRequest) ar.userObj;
1889 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1890 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1891 args.second.accept(ar.exception == null);
1892 notifyRequester(request);
1893 break;
1894 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001895 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1896 request = (MainThreadRequest) msg.obj;
1897 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1898 Phone phone = getPhoneFromRequest(request);
1899 if (phone != null) {
1900 phone.getSystemSelectionChannels(onCompleted);
1901 } else {
1902 loge("getSystemSelectionChannels: No phone object");
1903 request.result = new ArrayList<RadioAccessSpecifier>();
1904 notifyRequester(request);
1905 }
1906 break;
1907 }
1908 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1909 ar = (AsyncResult) msg.obj;
1910 request = (MainThreadRequest) ar.userObj;
1911 if (ar.exception == null && ar.result != null) {
1912 request.result = ar.result;
1913 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001914 request.result = new IllegalStateException(
1915 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001916 if (ar.result == null) {
1917 loge("getSystemSelectionChannels: Empty response");
1918 } else {
1919 loge("getSystemSelectionChannels: Unknown exception");
1920 }
1921 }
1922 notifyRequester(request);
1923 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001924 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1925 ar = (AsyncResult) msg.obj;
1926 request = (MainThreadRequest) ar.userObj;
1927 if (ar.exception == null && ar.result != null) {
1928 request.result = ar.result;
1929 } else {
1930 request.result = -1;
1931 loge("Failed to set Forbidden Plmns");
1932 if (ar.result == null) {
1933 loge("setForbidenPlmns: Empty response");
1934 } else if (ar.exception != null) {
1935 loge("setForbiddenPlmns: Exception: " + ar.exception);
1936 request.result = -1;
1937 } else {
1938 loge("setForbiddenPlmns: Unknown exception");
1939 }
1940 }
1941 notifyRequester(request);
1942 break;
1943 case CMD_SET_FORBIDDEN_PLMNS:
1944 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001945 uiccPort = getUiccPortFromRequest(request);
1946 if (uiccPort == null) {
1947 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001948 request.result = -1;
1949 notifyRequester(request);
1950 break;
1951 }
1952 Pair<Integer, List<String>> setFplmnsArgs =
1953 (Pair<Integer, List<String>>) request.argument;
1954 appType = setFplmnsArgs.first;
1955 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001956 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001957 if (uiccApp == null) {
1958 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1959 request.result = -1;
1960 loge("Failed to get UICC App");
1961 notifyRequester(request);
1962 } else {
1963 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1964 ((SIMRecords) uiccApp.getIccRecords())
1965 .setForbiddenPlmns(onCompleted, fplmns);
1966 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001967 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001968 case CMD_ERASE_MODEM_CONFIG:
1969 request = (MainThreadRequest) msg.obj;
1970 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1971 defaultPhone.eraseModemConfig(onCompleted);
1972 break;
1973 case EVENT_ERASE_MODEM_CONFIG_DONE:
1974 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001975 break;
zoey chene02881a2019-12-30 16:11:23 +08001976
Kai Shif70f46f2021-03-03 13:59:46 -08001977 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1978 request = (MainThreadRequest) msg.obj;
1979 request.result = defaultPhone.eraseDataInSharedPreferences();
1980 notifyRequester(request);
1981 break;
1982
zoey chene02881a2019-12-30 16:11:23 +08001983 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1984 request = (MainThreadRequest) msg.obj;
1985 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1986 Pair<String, String> changed = (Pair<String, String>) request.argument;
1987 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1988 changed.first, changed.second, onCompleted);
1989 break;
1990 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1991 ar = (AsyncResult) msg.obj;
1992 request = (MainThreadRequest) ar.userObj;
1993 if (ar.exception == null) {
1994 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001995 // If the operation is successful, update the PIN storage
1996 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1997 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001998 UiccController.getInstance().getPinStorage()
1999 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002000 } else {
2001 request.result = msg.arg1;
2002 }
2003 notifyRequester(request);
2004 break;
2005
Michele Berionne5e411512020-11-13 02:36:59 +00002006 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002007 request = (MainThreadRequest) msg.obj;
2008 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2009 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2010 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2011 enabled.first, enabled.second, onCompleted);
2012 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002013 }
zoey chene02881a2019-12-30 16:11:23 +08002014 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2015 ar = (AsyncResult) msg.obj;
2016 request = (MainThreadRequest) ar.userObj;
2017 if (ar.exception == null) {
2018 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002019 // If the operation is successful, update the PIN storage
2020 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2021 int phoneId = getPhoneFromRequest(request).getPhoneId();
2022 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002023 UiccController.getInstance().getPinStorage()
2024 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002025 } else {
2026 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2027 }
zoey chene02881a2019-12-30 16:11:23 +08002028 } else {
2029 request.result = msg.arg1;
2030 }
Michele Berionne5e411512020-11-13 02:36:59 +00002031
2032
zoey chene02881a2019-12-30 16:11:23 +08002033 notifyRequester(request);
2034 break;
2035
Peter Wangdafb9ac2020-01-15 14:13:38 -08002036 case MSG_NOTIFY_USER_ACTIVITY:
2037 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002038 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002039 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2040 getDefaultPhone().getContext().sendBroadcastAsUser(
2041 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2042 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002043
2044 case CMD_SET_DATA_THROTTLING: {
2045 request = (MainThreadRequest) msg.obj;
2046 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2047 DataThrottlingRequest dataThrottlingRequest =
2048 (DataThrottlingRequest) request.argument;
2049 Phone phone = getPhoneFromRequest(request);
2050 if (phone != null) {
2051 phone.setDataThrottling(onCompleted,
2052 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2053 dataThrottlingRequest.getCompletionDurationMillis());
2054 } else {
2055 loge("setDataThrottling: No phone object");
2056 request.result =
2057 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2058 notifyRequester(request);
2059 }
2060
2061 break;
2062 }
2063 case EVENT_SET_DATA_THROTTLING_DONE:
2064 ar = (AsyncResult) msg.obj;
2065 request = (MainThreadRequest) ar.userObj;
2066
2067 if (ar.exception == null) {
2068 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2069 } else if (ar.exception instanceof CommandException) {
2070 loge("setDataThrottling: CommandException: " + ar.exception);
2071 CommandException.Error error =
2072 ((CommandException) (ar.exception)).getCommandError();
2073
2074 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2075 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002076 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002077 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2078 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002079 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2080 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002081 } else {
2082 request.result =
2083 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2084 }
2085 } else {
2086 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2087 }
2088 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2089 notifyRequester(request);
2090 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002091
2092 case CMD_SET_SIM_POWER: {
2093 request = (MainThreadRequest) msg.obj;
2094 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2095 request = (MainThreadRequest) msg.obj;
2096 int stateToSet =
2097 ((Pair<Integer, IIntegerConsumer>)
2098 request.argument).first;
2099 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2100 break;
2101 }
2102 case EVENT_SET_SIM_POWER_DONE: {
2103 ar = (AsyncResult) msg.obj;
2104 request = (MainThreadRequest) ar.userObj;
2105 IIntegerConsumer callback =
2106 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2107 if (ar.exception != null) {
2108 loge("setSimPower exception: " + ar.exception);
2109 int errorCode = TelephonyManager.CallForwardingInfoCallback
2110 .RESULT_ERROR_UNKNOWN;
2111 if (ar.exception instanceof CommandException) {
2112 CommandException.Error error =
2113 ((CommandException) (ar.exception)).getCommandError();
2114 if (error == CommandException.Error.SIM_ERR) {
2115 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2116 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2117 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2118 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2119 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2120 } else {
2121 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2122 }
2123 }
2124 try {
2125 callback.accept(errorCode);
2126 } catch (RemoteException e) {
2127 // Ignore if the remote process is no longer available to call back.
2128 Log.w(LOG_TAG, "setSimPower: callback not available.");
2129 }
2130 } else {
2131 try {
2132 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2133 } catch (RemoteException e) {
2134 // Ignore if the remote process is no longer available to call back.
2135 Log.w(LOG_TAG, "setSimPower: callback not available.");
2136 }
2137 }
2138 break;
2139 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002140 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2141 request = (MainThreadRequest) msg.obj;
2142
2143 final Phone phone = getPhoneFromRequest(request);
2144 if (phone == null || phone.getServiceStateTracker() == null) {
2145 request.result = new IllegalStateException("Phone or SST is null");
2146 notifyRequester(request);
2147 break;
2148 }
2149
2150 Pair<Integer, SignalStrengthUpdateRequest> pair =
2151 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2152 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2153 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002154 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002155 request.subId, pair.first /*callingUid*/,
2156 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002157 break;
2158 }
2159 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2160 ar = (AsyncResult) msg.obj;
2161 request = (MainThreadRequest) ar.userObj;
2162 // request.result will be the exception of ar if present, true otherwise.
2163 // Be cautious not to leave result null which will wait() forever
2164 request.result = ar.exception != null ? ar.exception : true;
2165 notifyRequester(request);
2166 break;
2167 }
2168 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2169 request = (MainThreadRequest) msg.obj;
2170
2171 Phone phone = getPhoneFromRequest(request);
2172 if (phone == null || phone.getServiceStateTracker() == null) {
2173 request.result = new IllegalStateException("Phone or SST is null");
2174 notifyRequester(request);
2175 break;
2176 }
2177
2178 Pair<Integer, SignalStrengthUpdateRequest> pair =
2179 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2180 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2181 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002182 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002183 request.subId, pair.first /*callingUid*/,
2184 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002185 break;
2186 }
2187 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2188 ar = (AsyncResult) msg.obj;
2189 request = (MainThreadRequest) ar.userObj;
2190 request.result = ar.exception != null ? ar.exception : true;
2191 notifyRequester(request);
2192 break;
2193 }
Jordan Liu109698e2020-11-24 14:50:34 -08002194
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002195 case CMD_GET_SLICING_CONFIG: {
2196 request = (MainThreadRequest) msg.obj;
2197 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2198 request.phone.getSlicingConfig(onCompleted);
2199 break;
2200 }
2201 case EVENT_GET_SLICING_CONFIG_DONE: {
2202 ar = (AsyncResult) msg.obj;
2203 request = (MainThreadRequest) ar.userObj;
2204 ResultReceiver result = (ResultReceiver) request.argument;
2205
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002206 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002207 Bundle bundle = new Bundle();
2208 int resultCode = 0;
2209 if (ar.exception != null) {
2210 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2211 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002212 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002213 } else if (ar.result == null) {
2214 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002215 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002216 } else {
2217 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002218 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2219 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002220 }
2221
2222 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002223 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002224 }
2225 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2226 result.send(resultCode, bundle);
2227 notifyRequester(request);
2228 break;
2229 }
2230
Sarah Chin71b3a852022-09-28 15:54:19 -07002231 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002232 request = (MainThreadRequest) msg.obj;
2233 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002234 PurchasePremiumCapabilityArgument arg =
2235 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002236 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2237 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002238 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002239 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002240
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242 ar = (AsyncResult) msg.obj;
2243 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 PurchasePremiumCapabilityArgument arg =
2245 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246 try {
2247 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002251 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252 + TelephonyManager.convertPurchaseResultToString(result));
2253 } catch (RemoteException e) {
2254 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256 + " failed: " + e;
2257 if (DBG) log(logStr);
2258 AnomalyReporter.reportAnomaly(
2259 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2260 }
2261 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002262 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002263
Michele Berionne5e411512020-11-13 02:36:59 +00002264 case CMD_PREPARE_UNATTENDED_REBOOT:
2265 request = (MainThreadRequest) msg.obj;
2266 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002267 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002268 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002269 notifyRequester(request);
2270 break;
2271
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 default:
2273 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2274 break;
2275 }
2276 }
Jake Hambye994d462014-02-03 13:10:13 -08002277
Pengquan Menga1bb6272018-09-06 09:59:22 -07002278 private void notifyRequester(MainThreadRequest request) {
2279 synchronized (request) {
2280 request.notifyAll();
2281 }
2282 }
2283
Jake Hambye994d462014-02-03 13:10:13 -08002284 private void handleNullReturnEvent(Message msg, String command) {
2285 AsyncResult ar = (AsyncResult) msg.obj;
2286 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2287 if (ar.exception == null) {
2288 request.result = true;
2289 } else {
2290 request.result = false;
2291 if (ar.exception instanceof CommandException) {
2292 loge(command + ": CommandException: " + ar.exception);
2293 } else {
2294 loge(command + ": Unknown exception");
2295 }
2296 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002297 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
2301 /**
2302 * Posts the specified command to be executed on the main thread,
2303 * waits for the request to complete, and returns the result.
2304 * @see #sendRequestAsync
2305 */
2306 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002307 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2308 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002309 }
2310
2311 /**
2312 * Posts the specified command to be executed on the main thread,
2313 * waits for the request to complete, and returns the result.
2314 * @see #sendRequestAsync
2315 */
2316 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2317 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002318 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002319 }
2320
2321 /**
2322 * Posts the specified command to be executed on the main thread,
2323 * waits for the request to complete, and returns the result.
2324 * @see #sendRequestAsync
2325 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002326 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002327 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2328 }
2329
2330 /**
2331 * Posts the specified command to be executed on the main thread,
2332 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2333 * if not timeout or null otherwise.
2334 * @see #sendRequestAsync
2335 */
2336 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2337 long timeoutInMs) {
2338 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002339 }
2340
2341 /**
2342 * Posts the specified command to be executed on the main thread,
2343 * waits for the request to complete, and returns the result.
2344 * @see #sendRequestAsync
2345 */
Nathan Harold92bed182018-10-12 18:16:49 -07002346 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002347 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002348 }
2349
2350 /**
2351 * Posts the specified command to be executed on the main thread,
2352 * waits for the request to complete, and returns the result.
2353 * @see #sendRequestAsync
2354 */
2355 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002356 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2357 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002358 }
2359
2360 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002361 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2362 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2363 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002364 * @see #sendRequestAsync
2365 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002366 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2367 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2369 throw new RuntimeException("This method will deadlock if called from the main thread.");
2370 }
2371
Nathan Harold92bed182018-10-12 18:16:49 -07002372 MainThreadRequest request = null;
2373 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2374 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2375 } else if (phone != null) {
2376 request = new MainThreadRequest(argument, phone, workSource);
2377 } else {
2378 request = new MainThreadRequest(argument, subId, workSource);
2379 }
2380
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 Message msg = mMainThreadHandler.obtainMessage(command, request);
2382 msg.sendToTarget();
2383
Rambo Wang0f050d82021-02-12 11:43:36 -08002384
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002386 if (timeoutInMs >= 0) {
2387 // Wait for at least timeoutInMs before returning null request result
2388 long now = SystemClock.elapsedRealtime();
2389 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002390 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002391 try {
2392 request.wait(deadline - now);
2393 } catch (InterruptedException e) {
2394 // Do nothing, go back and check if request is completed or timeout
2395 } finally {
2396 now = SystemClock.elapsedRealtime();
2397 }
2398 }
2399 } else {
2400 // Wait for the request to complete
2401 while (request.result == null) {
2402 try {
2403 request.wait();
2404 } catch (InterruptedException e) {
2405 // Do nothing, go back and wait until the request is complete
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 }
2408 }
2409 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002410 if (request.result == null) {
2411 Log.wtf(LOG_TAG,
2412 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 return request.result;
2415 }
2416
2417 /**
2418 * Asynchronous ("fire and forget") version of sendRequest():
2419 * Posts the specified command to be executed on the main thread, and
2420 * returns immediately.
2421 * @see #sendRequest
2422 */
2423 private void sendRequestAsync(int command) {
2424 mMainThreadHandler.sendEmptyMessage(command);
2425 }
2426
2427 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002428 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002429 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002430 */
2431 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002432 sendRequestAsync(command, argument, null, null);
2433 }
2434
2435 /**
2436 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2437 * @see {@link #sendRequest(int,Object)}
2438 */
2439 private void sendRequestAsync(
2440 int command, Object argument, Phone phone, WorkSource workSource) {
2441 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002442 Message msg = mMainThreadHandler.obtainMessage(command, request);
2443 msg.sendToTarget();
2444 }
2445
2446 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 * Initialize the singleton PhoneInterfaceManager instance.
2448 * This is only done once, at startup, from PhoneApp.onCreate().
2449 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002450 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 synchronized (PhoneInterfaceManager.class) {
2452 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002453 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 } else {
2455 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2456 }
2457 return sInstance;
2458 }
2459 }
2460
2461 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002462 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002464 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002466 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002467 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002468 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2470 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002471 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002472 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002473 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002474 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002475 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002476 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002477 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2478 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002479 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 publish();
arunvoddud7401012022-12-15 16:08:12 +00002481 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002482
2483 // Create the SatelliteEntitlementController singleton, for using the get the
2484 // entitlementStatus for satellite service.
2485 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 }
2487
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002488 @VisibleForTesting
2489 public SharedPreferences getSharedPreferences() {
2490 return mTelephonySharedPreferences;
2491 }
2492
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002493 /**
2494 * Get the default phone for this device.
2495 */
2496 @VisibleForTesting
2497 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002498 Phone thePhone = getPhone(getDefaultSubscription());
2499 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2500 }
2501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 private void publish() {
2503 if (DBG) log("publish: " + this);
2504
Peter Wangc035ce42020-01-08 21:00:22 -08002505 TelephonyFrameworkInitializer
2506 .getTelephonyServiceManager()
2507 .getTelephonyServiceRegisterer()
2508 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 }
2510
Stuart Scott584921c2015-01-15 17:10:34 -08002511 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002512 if (request.phone != null) {
2513 return request.phone;
2514 } else {
2515 return getPhoneFromSubId(request.subId);
2516 }
2517 }
2518
2519 private Phone getPhoneFromSubId(int subId) {
2520 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2521 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002522 }
2523
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002524 /**
2525 * Get phone object associated with a subscription.
2526 * Return default phone if phone object associated with subscription is null
2527 * @param subId - subscriptionId
2528 * @return phone object associated with a subscription or default phone if null.
2529 */
Ling Mac28f0212023-03-24 16:07:15 -07002530 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002531 Phone phone = getPhoneFromSubId(subId);
2532 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002533 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002534 phone = getDefaultPhone();
2535 }
2536 return phone;
2537 }
2538
Rambo Wange53e07d2022-05-10 13:01:13 -07002539 @Nullable
2540 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002541 Phone phone = getPhoneFromRequest(request);
2542 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002543 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002544 }
2545
Ling Mac28f0212023-03-24 16:07:15 -07002546 /**
2547 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2548 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2549 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2550 * @return The Phone associated the sub Id
2551 */
2552 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002553 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555
Kai Shif70f46f2021-03-03 13:59:46 -08002556 private void sendEraseModemConfig(@NonNull Phone phone) {
2557 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2558 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2559 }
2560
2561 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2562 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2563 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002564 }
2565
Peter Wang44b186e2020-01-13 23:33:09 -08002566 private boolean isImsAvailableOnDevice() {
2567 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2568 if (pm == null) {
2569 // For some reason package manger is not available.. This will fail internally anyway,
2570 // so do not throw error and allow.
2571 return true;
2572 }
2573 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2574 }
2575
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002577 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2578 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2579
Wink Savilleadd7cc52014-09-08 14:23:09 -07002580 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002581 }
2582
Wink Savilleb564aae2014-10-23 10:18:09 -07002583 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 if (DBG) log("dial: " + number);
2585 // No permission check needed here: This is just a wrapper around the
2586 // ACTION_DIAL intent, which is available to any app since it puts up
2587 // the UI before it does anything.
2588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 String url = createTelUrl(number);
2592 if (url == null) {
2593 return;
2594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 // PENDING: should we just silently fail if phone is offhook or ringing?
2597 PhoneConstants.State state = mCM.getState(subId);
2598 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2599 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2600 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2601 mApp.startActivity(intent);
2602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
2606 }
2607
2608 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002609 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002610 }
2611
Wink Savilleb564aae2014-10-23 10:18:09 -07002612 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 if (DBG) log("call: " + number);
2614
2615 // This is just a wrapper around the ACTION_CALL intent, but we still
2616 // need to do a permission check since we're calling startActivity()
2617 // from the context of the phone app.
2618 enforceCallPermission();
2619
Jordan Liu1617b712019-07-10 15:06:26 -07002620 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 != AppOpsManager.MODE_ALLOWED) {
2622 return;
2623 }
2624
joonhunshin4ac60942023-11-15 15:23:39 +00002625 enforceTelephonyFeatureWithException(callingPackage,
2626 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 String url = createTelUrl(number);
2631 if (url == null) {
2632 return;
2633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 boolean isValid = false;
2636 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2637 if (slist != null) {
2638 for (SubscriptionInfo subInfoRecord : slist) {
2639 if (subInfoRecord.getSubscriptionId() == subId) {
2640 isValid = true;
2641 break;
2642 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002643 }
Wink Saville08874612014-08-31 19:19:58 -07002644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645 if (!isValid) {
2646 return;
2647 }
Wink Saville08874612014-08-31 19:19:58 -07002648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2650 intent.putExtra(SUBSCRIPTION_KEY, subId);
2651 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2652 mApp.startActivity(intent);
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 }
2657
Wink Savilleb564aae2014-10-23 10:18:09 -07002658 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002659 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002660 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2661 }
2662
Wink Savilleb564aae2014-10-23 10:18:09 -07002663 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002664 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670
joonhunshin4ac60942023-11-15 15:23:39 +00002671 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2672 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2673 "supplyPinReportResultForSubscriber");
2674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675 final long identity = Binder.clearCallingIdentity();
2676 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002677 Phone phone = getPhone(subId);
2678 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 checkSimPin.start();
2680 return checkSimPin.unlockSim(null, pin);
2681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 }
2685
Wink Savilleb564aae2014-10-23 10:18:09 -07002686 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
joonhunshin4ac60942023-11-15 15:23:39 +00002689 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2690 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 final long identity = Binder.clearCallingIdentity();
2693 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002694 Phone phone = getPhone(subId);
2695 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 checkSimPuk.start();
2697 return checkSimPuk.unlockSim(puk, pin);
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
2700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 }
2702
2703 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002704 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 * a synchronous one.
2706 */
2707 private static class UnlockSim extends Thread {
2708
2709 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002710 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711
2712 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002713 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2714 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715
2716 // For replies from SimCard interface
2717 private Handler mHandler;
2718
2719 // For async handler to identify request type
2720 private static final int SUPPLY_PIN_COMPLETE = 100;
2721
Michele Berionne5e411512020-11-13 02:36:59 +00002722 UnlockSim(int phoneId, IccCard simCard) {
2723 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 mSimCard = simCard;
2725 }
2726
2727 @Override
2728 public void run() {
2729 Looper.prepare();
2730 synchronized (UnlockSim.this) {
2731 mHandler = new Handler() {
2732 @Override
2733 public void handleMessage(Message msg) {
2734 AsyncResult ar = (AsyncResult) msg.obj;
2735 switch (msg.what) {
2736 case SUPPLY_PIN_COMPLETE:
2737 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2738 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002739 mRetryCount = msg.arg1;
2740 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002741 CommandException.Error error = null;
2742 if (ar.exception instanceof CommandException) {
2743 error = ((CommandException) (ar.exception))
2744 .getCommandError();
2745 }
2746 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002747 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002748 } else if (error == CommandException.Error.ABORTED) {
2749 /* When UiccCardApp dispose, handle message and return
2750 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002751 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002752 } else {
2753 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2754 }
2755 } else {
2756 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 mDone = true;
2759 UnlockSim.this.notifyAll();
2760 }
2761 break;
2762 }
2763 }
2764 };
2765 UnlockSim.this.notifyAll();
2766 }
2767 Looper.loop();
2768 }
2769
2770 /*
2771 * Use PIN or PUK to unlock SIM card
2772 *
2773 * If PUK is null, unlock SIM card with PIN
2774 *
2775 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302776 *
2777 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2778 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 */
Wink Saville9de0f752013-10-22 19:04:03 -07002780 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781
2782 while (mHandler == null) {
2783 try {
2784 wait();
2785 } catch (InterruptedException e) {
2786 Thread.currentThread().interrupt();
2787 }
2788 }
2789 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2790
2791 if (puk == null) {
2792 mSimCard.supplyPin(pin, callback);
2793 } else {
2794 mSimCard.supplyPuk(puk, pin, callback);
2795 }
2796
2797 while (!mDone) {
2798 try {
2799 Log.d(LOG_TAG, "wait for done");
2800 wait();
2801 } catch (InterruptedException e) {
2802 // Restore the interrupted status
2803 Thread.currentThread().interrupt();
2804 }
2805 }
2806 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002807 int[] resultArray = new int[2];
2808 resultArray[0] = mResult;
2809 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002810
2811 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002812 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002813 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302814 // This instance is no longer reused, so quit its thread's looper.
2815 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002816
Wink Saville9de0f752013-10-22 19:04:03 -07002817 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819 }
2820
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002821 /**
2822 * This method has been removed due to privacy and stability concerns.
2823 */
2824 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002826 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2827 return;
Wink Saville36469e72014-06-11 15:17:00 -07002828 }
2829
Nathan Harold1f889d82020-06-04 17:05:26 -07002830 @Override
2831 public void updateServiceLocationWithPackageName(String callingPackage) {
2832 mApp.getSystemService(AppOpsManager.class)
2833 .checkPackage(Binder.getCallingUid(), callingPackage);
2834
Nathan Haroldf096d982020-11-18 17:18:06 -08002835 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002836 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2837 // Callers targeting S have no business invoking this method.
2838 return;
2839 }
2840
2841 LocationAccessPolicy.LocationPermissionResult locationResult =
2842 LocationAccessPolicy.checkLocationPermission(mApp,
2843 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2844 .setCallingPackage(callingPackage)
2845 .setCallingFeatureId(null)
2846 .setCallingPid(Binder.getCallingPid())
2847 .setCallingUid(Binder.getCallingUid())
2848 .setMethod("updateServiceLocation")
2849 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2850 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2851 .build());
2852 // Apps that lack location permission have no business calling this method;
2853 // however, because no permission was declared in the public API, denials must
2854 // all be "soft".
2855 switch (locationResult) {
2856 case DENIED_HARD: /* fall through */
2857 case DENIED_SOFT:
2858 return;
2859 }
2860
2861 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 final long identity = Binder.clearCallingIdentity();
2863 try {
Ling Mac28f0212023-03-24 16:07:15 -07002864 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 } finally {
2866 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 }
2869
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002870 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002871 @Override
2872 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002873 return isRadioOnWithFeature(callingPackage, null);
2874 }
2875
2876
2877 @Override
2878 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2879 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2880 callingFeatureId);
2881 }
2882
2883 @Deprecated
2884 @Override
2885 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2886 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002887 }
2888
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002889 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002890 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2891 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002893 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002894 return false;
2895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896
joonhunshin4ac60942023-11-15 15:23:39 +00002897 enforceTelephonyFeatureWithException(callingPackage,
2898 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 return isRadioOnForSubscriber(subId);
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
2905 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002906 }
2907
2908 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 if (phone != null) {
2913 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2914 } else {
2915 return false;
2916 }
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
2922 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002923 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 }
Wink Saville36469e72014-06-11 15:17:00 -07002925
Wink Savilleb564aae2014-10-23 10:18:09 -07002926 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928
joonhunshin4ac60942023-11-15 15:23:39 +00002929 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2930 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 final Phone phone = getPhone(subId);
2935 if (phone != null) {
2936 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2937 }
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002940 }
Wink Saville36469e72014-06-11 15:17:00 -07002941 }
2942
2943 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002944 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002945 }
2946
Wink Savilleb564aae2014-10-23 10:18:09 -07002947 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949
2950 final long identity = Binder.clearCallingIdentity();
2951 try {
2952 final Phone phone = getPhone(subId);
2953 if (phone == null) {
2954 return false;
2955 }
2956 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2957 toggleRadioOnOffForSubscriber(subId);
2958 }
2959 return true;
2960 } finally {
2961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002963 }
Wink Saville36469e72014-06-11 15:17:00 -07002964
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002965 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002966 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002967
2968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2969 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2970
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002971 /*
2972 * If any of the Radios are available, it will need to be
2973 * shutdown. So return true if any Radio is available.
2974 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2978 Phone phone = PhoneFactory.getPhone(i);
2979 if (phone != null && phone.isRadioAvailable()) return true;
2980 }
2981 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2982 return false;
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002985 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002986 }
2987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002989 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 enforceModifyPermission();
2991
joonhunshin4ac60942023-11-15 15:23:39 +00002992 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2993 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2998 logv("Shutting down Phone " + i);
2999 shutdownRadioUsingPhoneId(i);
3000 }
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003003 }
3004 }
3005
3006 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003007 Phone phone = PhoneFactory.getPhone(phoneId);
3008 if (phone != null && phone.isRadioAvailable()) {
3009 phone.shutdownRadio();
3010 }
3011 }
3012
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003013 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015
Ling Ma83dc5ea2023-01-12 15:06:04 -08003016 if (!turnOn) {
3017 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3018 }
3019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3023 if (defaultPhone != null) {
3024 defaultPhone.setRadioPower(turnOn);
3025 return true;
3026 } else {
3027 loge("There's no default phone.");
3028 return false;
3029 }
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003032 }
Wink Saville36469e72014-06-11 15:17:00 -07003033 }
3034
Wink Savilleb564aae2014-10-23 10:18:09 -07003035 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037
Ling Ma83dc5ea2023-01-12 15:06:04 -08003038 if (!turnOn) {
3039 log("setRadioPowerForSubscriber off: subId=" + subId
3040 + ",callingPackage=" + getCurrentPackageName());
3041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 final Phone phone = getPhone(subId);
3045 if (phone != null) {
3046 phone.setRadioPower(turnOn);
3047 return true;
3048 } else {
3049 return false;
3050 }
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 }
3055
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003056 /**
3057 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3058 * no reason to power it off. When any of the voters want to power it off, it will be turned
3059 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3060 * powering it off, and these radio off votes will be cleared.
3061 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3062 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3063 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3064 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3065 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3066 * check its vote.
3067 *
3068 * @param subId The subscription ID.
3069 * @param reason The reason for powering off radio.
3070 * @return true on success and false on failure.
3071 */
3072 public boolean requestRadioPowerOffForReason(int subId,
3073 @TelephonyManager.RadioPowerReason int reason) {
3074 enforceModifyPermission();
3075
joonhunshin4ac60942023-11-15 15:23:39 +00003076 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3077 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3078
Ling Ma83dc5ea2023-01-12 15:06:04 -08003079 log("requestRadioPowerOffForReason: subId=" + subId
3080 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003081 final long identity = Binder.clearCallingIdentity();
3082 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003083 boolean result = false;
3084 for (Phone phone : PhoneFactory.getPhones()) {
3085 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003086 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003087 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003088 if (!result) {
3089 loge("requestRadioPowerOffForReason: no phone exists");
3090 }
3091 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 }
3096
3097 /**
3098 * Remove the vote on powering off the radio for a reason, as requested by
3099 * {@link requestRadioPowerOffForReason}.
3100 *
3101 * @param subId The subscription ID.
3102 * @param reason The reason for powering off radio.
3103 * @return true on success and false on failure.
3104 */
3105 public boolean clearRadioPowerOffForReason(int subId,
3106 @TelephonyManager.RadioPowerReason int reason) {
3107 enforceModifyPermission();
3108
joonhunshin4ac60942023-11-15 15:23:39 +00003109 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3110 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3111
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003112 final long identity = Binder.clearCallingIdentity();
3113 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003114 boolean result = false;
3115 for (Phone phone : PhoneFactory.getPhones()) {
3116 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003117 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003118 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003119 if (!result) {
3120 loge("clearRadioPowerOffForReason: no phone exists");
3121 }
3122 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
3126 }
3127
3128 /**
3129 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3130 *
3131 * @param subId The subscription ID.
3132 * @param callingPackage The package making the call.
3133 * @param callingFeatureId The feature in the package.
3134 * @return List of reasons for powering off radio.
3135 */
3136 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3137 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3138
joonhunshin4ac60942023-11-15 15:23:39 +00003139 enforceTelephonyFeatureWithException(callingPackage,
3140 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3141
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003142 final long identity = Binder.clearCallingIdentity();
3143 List result = new ArrayList();
3144 try {
3145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3146 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3147 return result;
3148 }
3149
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003150 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003151 if (phone != null) {
3152 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003153 } else {
3154 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003155 }
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
3159 return result;
3160 }
3161
Wink Saville36469e72014-06-11 15:17:00 -07003162 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003163 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003164 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166
joonhunshin4ac60942023-11-15 15:23:39 +00003167 enforceTelephonyFeatureWithException(callingPackage,
3168 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
Jack Yu285100e2022-12-02 22:48:35 -08003172 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173 final Phone phone = getPhone(subId);
3174 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003175 phone.getDataSettingsManager().setDataEnabled(
3176 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 return true;
3178 } else {
3179 return false;
3180 }
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184 }
3185
Wink Saville36469e72014-06-11 15:17:00 -07003186 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003187 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003188 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190
joonhunshin4ac60942023-11-15 15:23:39 +00003191 enforceTelephonyFeatureWithException(callingPackage,
3192 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
Jack Yu285100e2022-12-02 22:48:35 -08003196 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final Phone phone = getPhone(subId);
3198 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003199 phone.getDataSettingsManager().setDataEnabled(
3200 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 return true;
3202 } else {
3203 return false;
3204 }
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 }
3209
Sanket Padawe356d7632015-06-22 14:03:32 -07003210 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003211 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003212 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3213 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 final Phone phone = getPhone(subId);
3218 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003219 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 } else {
3221 return false;
3222 }
3223 } finally {
3224 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003225 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003226 }
3227
3228 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003229 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003230 }
3231
pkanwarae03a6b2016-11-06 20:37:09 -08003232 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 enforceCallPermission();
3234
joonhunshin4ac60942023-11-15 15:23:39 +00003235 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3236 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3241 return;
3242 }
3243 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3244 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
pkanwar32d516d2016-10-14 19:37:38 -07003248 };
3249
Wink Savilleb564aae2014-10-23 10:18:09 -07003250 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252
joonhunshin4ac60942023-11-15 15:23:39 +00003253 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3254 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3259 return false;
3260 }
3261 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 }
3266
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003267 /**
3268 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3269 * tag on getCallState Binder call.
3270 */
3271 @Deprecated
3272 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003273 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003274 if (CompatChanges.isChangeEnabled(
3275 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3276 Binder.getCallingUid())) {
3277 // Do not allow this API to be called on API version 31+, it should only be
3278 // called on old apps using this Binder call directly.
3279 throw new SecurityException("This method can only be used for applications "
3280 + "targeting API version 30 or less.");
3281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 final long identity = Binder.clearCallingIdentity();
3283 try {
Ling Mac28f0212023-03-24 16:07:15 -07003284 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3285 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
3289 }
3290
3291 @Override
3292 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3293 if (CompatChanges.isChangeEnabled(
3294 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3295 Binder.getCallingUid())) {
3296 // Check READ_PHONE_STATE for API version 31+
3297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3298 featureId, "getCallStateForSubscription")) {
3299 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3300 + "targeting API level 31+.");
3301 }
3302 }
joonhunshin4ac60942023-11-15 15:23:39 +00003303
3304 enforceTelephonyFeatureWithException(callingPackage,
3305 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3306
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3311 PhoneConstantConversions.convertCallState(phone.getState());
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315 }
3316
Sanket Padawe356d7632015-06-22 14:03:32 -07003317 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003318 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003319 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003320 }
3321
3322 @Override
3323 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003324 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3325 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003329 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003331 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 } else {
3333 return PhoneConstantConversions.convertDataState(
3334 PhoneConstants.DataState.DISCONNECTED);
3335 }
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003339 }
3340
Sanket Padawe356d7632015-06-22 14:03:32 -07003341 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003342 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003343 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003344 }
3345
3346 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003347 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003348 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3349 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351 final long identity = Binder.clearCallingIdentity();
3352 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003353 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003355 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 } else {
3357 return TelephonyManager.DATA_ACTIVITY_NONE;
3358 }
3359 } finally {
3360 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003362 }
3363
3364 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003365 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003366 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003367 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003368
3369 LocationAccessPolicy.LocationPermissionResult locationResult =
3370 LocationAccessPolicy.checkLocationPermission(mApp,
3371 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3372 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003373 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003374 .setCallingPid(Binder.getCallingPid())
3375 .setCallingUid(Binder.getCallingUid())
3376 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003377 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003378 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3379 .build());
3380 switch (locationResult) {
3381 case DENIED_HARD:
3382 throw new SecurityException("Not allowed to access cell location");
3383 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003384 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3385 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386 }
3387
joonhunshin4ac60942023-11-15 15:23:39 +00003388 enforceTelephonyFeatureWithException(callingPackage,
3389 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3390
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003391 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003395 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003396 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
Svetoslav64fad262015-04-14 14:35:21 -07003400 }
3401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003403 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3405 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3406
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003407 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3408 // registered cell info, so return a NULL country instead.
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003411 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3412 // Get default phone in this case.
3413 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3414 }
Jack Yu285100e2022-12-02 22:48:35 -08003415 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003417 if (phone == null) return "";
3418 ServiceStateTracker sst = phone.getServiceStateTracker();
3419 if (sst == null) return "";
3420 LocaleTracker lt = sst.getLocaleTracker();
3421 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003422 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003426 }
3427
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003428 /**
3429 * This method was removed due to potential issues caused by performing partial
3430 * updates of service state, and lack of a credible use case.
3431 *
3432 * This has the ability to break the telephony implementation by disabling notification of
3433 * changes in device connectivity. DO NOT USE THIS!
3434 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003435 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003436 public void enableLocationUpdates() {
3437 mApp.enforceCallingOrSelfPermission(
3438 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 }
3440
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003441 /**
3442 * This method was removed due to potential issues caused by performing partial
3443 * updates of service state, and lack of a credible use case.
3444 *
3445 * This has the ability to break the telephony implementation by disabling notification of
3446 * changes in device connectivity. DO NOT USE THIS!
3447 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 @Override
3449 public void disableLocationUpdates() {
3450 mApp.enforceCallingOrSelfPermission(
3451 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 }
3453
3454 @Override
3455 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003456 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3457 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003458 try {
3459 mApp.getSystemService(AppOpsManager.class)
3460 .checkPackage(Binder.getCallingUid(), callingPackage);
3461 } catch (SecurityException e) {
3462 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3463 throw e;
3464 }
3465
Nathan Haroldf096d982020-11-18 17:18:06 -08003466 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003467 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3468 throw new SecurityException(
3469 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3470 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003471
Jordan Liu1617b712019-07-10 15:06:26 -07003472 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003473 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3474 return null;
3475 }
Svetoslav64fad262015-04-14 14:35:21 -07003476
joonhunshin4ac60942023-11-15 15:23:39 +00003477 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3478 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3479
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003480 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003481
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003482 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003483 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484
Nathan Haroldf180aac2018-06-01 18:43:55 -07003485 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3486 for (CellInfo ci : info) {
3487 if (ci instanceof CellInfoGsm) {
3488 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3489 } else if (ci instanceof CellInfoWcdma) {
3490 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003492 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003493 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494 }
3495
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003496 private List<CellInfo> getCachedCellInfo() {
3497 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3498 for (Phone phone : PhoneFactory.getPhones()) {
3499 List<CellInfo> info = phone.getAllCellInfo();
3500 if (info != null) cellInfos.addAll(info);
3501 }
3502 return cellInfos;
3503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504
3505 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003506 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003507 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003508 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003509
3510 LocationAccessPolicy.LocationPermissionResult locationResult =
3511 LocationAccessPolicy.checkLocationPermission(mApp,
3512 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3513 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003514 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003515 .setCallingPid(Binder.getCallingPid())
3516 .setCallingUid(Binder.getCallingUid())
3517 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003518 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003519 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3520 .build());
3521 switch (locationResult) {
3522 case DENIED_HARD:
3523 throw new SecurityException("Not allowed to access cell info");
3524 case DENIED_SOFT:
3525 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
Nathan Haroldf096d982020-11-18 17:18:06 -08003528 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003529 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3530 return getCachedCellInfo();
3531 }
3532
joonhunshin4ac60942023-11-15 15:23:39 +00003533 enforceTelephonyFeatureWithException(callingPackage,
3534 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3535
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003536 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003537 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3541 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003542 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003543 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544 if (info != null) cellInfos.addAll(info);
3545 }
3546 return cellInfos;
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003549 }
3550 }
3551
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003552 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003553 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3554 String callingFeatureId) {
3555 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3556 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003557 }
3558
3559 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003560 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3561 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003562 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003563 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003564 }
3565
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003566 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3567 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003568 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003569 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003570
3571 LocationAccessPolicy.LocationPermissionResult locationResult =
3572 LocationAccessPolicy.checkLocationPermission(mApp,
3573 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3574 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003575 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003576 .setCallingPid(Binder.getCallingPid())
3577 .setCallingUid(Binder.getCallingUid())
3578 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003579 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3580 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003581 .build());
3582 switch (locationResult) {
3583 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003584 if (TelephonyPermissions
3585 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003586 // Safetynet logging for b/154934934
3587 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3588 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003589 throw new SecurityException("Not allowed to access cell info");
3590 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003591 if (TelephonyPermissions
3592 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003593 // Safetynet logging for b/154934934
3594 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3595 }
Nathan Harold5320c422019-05-09 10:26:08 -07003596 try {
3597 cb.onCellInfo(new ArrayList<CellInfo>());
3598 } catch (RemoteException re) {
3599 // Drop without consequences
3600 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003601 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003602 }
3603
joonhunshin4ac60942023-11-15 15:23:39 +00003604 enforceTelephonyFeatureWithException(callingPackage,
3605 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003606
3607 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003608 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3609
3610 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3611 }
3612
3613 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003614 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003615 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003616 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617
3618 final long identity = Binder.clearCallingIdentity();
3619 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003620 Phone phone = getPhone(subId);
3621 if (phone == null) {
3622 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3623 } else {
3624 phone.setCellInfoListRate(rateInMillis, workSource);
3625 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003629 }
3630
Shishir Agrawala9f32182016-04-12 12:00:16 -07003631 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003632 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003633 Phone phone = PhoneFactory.getPhone(slotIndex);
3634 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 return null;
3636 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003637 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003638 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003639 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003640 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003641 return null;
3642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643
joonhunshin4ac60942023-11-15 15:23:39 +00003644 enforceTelephonyFeatureWithException(callingPackage,
3645 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 return phone.getImei();
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003653 }
3654
3655 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003656 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3657 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3658 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3659 callingFeatureId, "getPrimaryImei")) {
3660 throw new SecurityException("Caller does not have permission");
3661 }
joonhunshin4ac60942023-11-15 15:23:39 +00003662
3663 enforceTelephonyFeatureWithException(callingPackage,
3664 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3665
arunvoddud5c6ce02022-12-11 06:03:12 +00003666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 for (Phone phone : PhoneFactory.getPhones()) {
3669 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3670 return phone.getImei();
3671 }
3672 }
3673 throw new UnsupportedOperationException("Operation not supported");
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
3677 }
3678
3679 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003680 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003681 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3682 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3683
David Kelly5e06a7f2018-03-12 14:10:59 +00003684 Phone phone = PhoneFactory.getPhone(slotIndex);
3685 String tac = null;
3686 if (phone != null) {
3687 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003688 try {
3689 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3690 } catch (IndexOutOfBoundsException e) {
3691 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3692 return null;
3693 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003694 }
3695 return tac;
3696 }
3697
3698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003700 try {
3701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3702 } catch (SecurityException se) {
3703 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3704 throw new SecurityException("Package " + callingPackage + " does not belong to "
3705 + Binder.getCallingUid());
3706 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003707 Phone phone = PhoneFactory.getPhone(slotIndex);
3708 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003709 return null;
3710 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711
Jeff Davidson913390f2018-02-23 17:11:49 -08003712 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003713 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003714 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003715 return null;
3716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717
joonhunshin4ac60942023-11-15 15:23:39 +00003718 enforceTelephonyFeatureWithException(callingPackage,
3719 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 return phone.getMeid();
3724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
Jack Yu2af8d712017-03-15 17:14:14 -07003727 }
3728
3729 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003730 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003731 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3732 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3733
David Kelly5e06a7f2018-03-12 14:10:59 +00003734 Phone phone = PhoneFactory.getPhone(slotIndex);
3735 String manufacturerCode = null;
3736 if (phone != null) {
3737 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003738 try {
3739 manufacturerCode =
3740 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3741 } catch (IndexOutOfBoundsException e) {
3742 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3743 return null;
3744 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003745 }
3746 return manufacturerCode;
3747 }
3748
3749 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003750 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3751 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003752 Phone phone = PhoneFactory.getPhone(slotIndex);
3753 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003754 return null;
3755 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003756 int subId = phone.getSubId();
3757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003758 mApp, subId, callingPackage, callingFeatureId,
3759 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003760 return null;
3761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762
joonhunshin4ac60942023-11-15 15:23:39 +00003763 enforceTelephonyFeatureWithException(callingPackage,
3764 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 return phone.getDeviceSvn();
3769 } finally {
3770 Binder.restoreCallingIdentity(identity);
3771 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003772 }
3773
fionaxu43304da2017-11-27 22:51:16 -08003774 @Override
3775 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003776 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3777 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779 final long identity = Binder.clearCallingIdentity();
3780 try {
3781 final Phone phone = getPhone(subId);
3782 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
fionaxu43304da2017-11-27 22:51:16 -08003786 }
3787
3788 @Override
3789 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003790 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3791 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 final Phone phone = getPhone(subId);
3796 return phone == null ? null : phone.getCarrierName();
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
fionaxu43304da2017-11-27 22:51:16 -08003800 }
3801
calvinpanffe225e2018-11-01 19:43:06 +08003802 @Override
chen xu0026ca62019-03-06 15:28:50 -08003803 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3805 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3806
chen xu25637222018-11-04 17:17:00 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 final Phone phone = getPhone(subId);
3810 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003811 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003812 } finally {
3813 Binder.restoreCallingIdentity(identity);
3814 }
3815 }
3816
3817 @Override
chen xu0026ca62019-03-06 15:28:50 -08003818 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003819 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3820 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3821 "getSubscriptionSpecificCarrierName");
3822
chen xu25637222018-11-04 17:17:00 -08003823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003826 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
3830 }
3831
chen xu651eec72018-11-11 19:03:44 -08003832 @Override
chen xu864e11c2018-12-06 22:10:03 -08003833 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3834 if (!isSubscriptionMccMnc) {
3835 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3836 }
chen xu651eec72018-11-11 19:03:44 -08003837 final Phone phone = PhoneFactory.getPhone(slotIndex);
3838 if (phone == null) {
3839 return TelephonyManager.UNKNOWN_CARRIER_ID;
3840 }
joonhunshin4ac60942023-11-15 15:23:39 +00003841
3842 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3843 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3844
chen xu651eec72018-11-11 19:03:44 -08003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
3850 }
3851 }
3852
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003853 //
3854 // Internal helper methods.
3855 //
3856
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003857 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003858 * Make sure the caller is the calling package itself
3859 *
3860 * @throws SecurityException if the caller is not the calling package
3861 */
3862 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3863 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003864 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3865 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003866 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003867 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003868 } catch (PackageManager.NameNotFoundException e) {
3869 // packageUid is -1
3870 }
3871 if (packageUid != callingUid) {
3872 throw new SecurityException(message + ": Package " + callingPackage
3873 + " does not belong to " + callingUid);
3874 }
3875 }
3876
3877 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003878 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3879 *
3880 * @throws SecurityException if the caller does not have the required permission
3881 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003882 @VisibleForTesting
3883 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003884 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3885 }
3886
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003887 /**
arunvoddud7401012022-12-15 16:08:12 +00003888 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003889 *
3890 * @throws SecurityException if the caller does not have the required permission
3891 */
3892 @VisibleForTesting
3893 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003894 enforceReadPermission(null);
3895 }
3896
3897 /**
3898 * Make sure the caller has the READ_PHONE_STATE permissions.
3899 *
3900 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3901 */
3902 @VisibleForTesting
3903 public void enforceReadPermission(String msg) {
3904 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003905 }
3906
Shuo Qian3b6ee772019-11-13 17:43:31 -08003907 private void enforceActiveEmergencySessionPermission() {
3908 mApp.enforceCallingOrSelfPermission(
3909 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3910 }
3911
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003912 /**
3913 * Make sure the caller has the CALL_PHONE permission.
3914 *
3915 * @throws SecurityException if the caller does not have the required permission
3916 */
3917 private void enforceCallPermission() {
3918 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3919 }
3920
paulhu5a773602019-08-23 19:17:33 +08003921 private void enforceSettingsPermission() {
3922 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003923 }
3924
Michele Berionne5e411512020-11-13 02:36:59 +00003925 private void enforceRebootPermission() {
3926 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3927 }
3928
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003929 /**
3930 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3931 * @param message - log message to print.
3932 * @throws SecurityException if the caller does not have the required permission
3933 */
3934 private void enforceSatelliteCommunicationPermission(String message) {
3935 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3936 }
3937
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003938 private String createTelUrl(String number) {
3939 if (TextUtils.isEmpty(number)) {
3940 return null;
3941 }
3942
Jake Hambye994d462014-02-03 13:10:13 -08003943 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003944 }
3945
Ihab Awadf9e92732013-12-05 18:02:52 -08003946 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003947 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003948 }
3949
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003950 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003951 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003952 }
3953
Ihab Awadf9e92732013-12-05 18:02:52 -08003954 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003955 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003956 }
3957
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003958 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003959 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003960 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003961 }
3962
Sanket Padawe356d7632015-06-22 14:03:32 -07003963 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003964 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003965 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3966 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 final Phone phone = PhoneFactory.getPhone(slotIndex);
3971 if (phone == null) {
3972 return PhoneConstants.PHONE_TYPE_NONE;
3973 } else {
3974 return phone.getPhoneType();
3975 }
3976 } finally {
3977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003979 }
3980
3981 /**
3982 * Returns the CDMA ERI icon index to display
3983 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003984 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003985 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3986 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3987 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003988 }
3989
Sanket Padawe356d7632015-06-22 14:03:32 -07003990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003991 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3992 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003994 mApp, subId, callingPackage, callingFeatureId,
3995 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003996 return -1;
3997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998
joonhunshin4ac60942023-11-15 15:23:39 +00003999 enforceTelephonyFeatureWithException(callingPackage,
4000 PackageManager.FEATURE_TELEPHONY_CDMA,
4001 "getCdmaEriIconIndexForSubscriber");
4002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 final Phone phone = getPhone(subId);
4006 if (phone != null) {
4007 return phone.getCdmaEriIconIndex();
4008 } else {
4009 return -1;
4010 }
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004014 }
4015
4016 /**
4017 * Returns the CDMA ERI icon mode,
4018 * 0 - ON
4019 * 1 - FLASHING
4020 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004021 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004022 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4023 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4024 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004025 }
4026
Sanket Padawe356d7632015-06-22 14:03:32 -07004027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004028 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4029 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004031 mApp, subId, callingPackage, callingFeatureId,
4032 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004033 return -1;
4034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035
4036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 final Phone phone = getPhone(subId);
4039 if (phone != null) {
4040 return phone.getCdmaEriIconMode();
4041 } else {
4042 return -1;
4043 }
4044 } finally {
4045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004047 }
4048
4049 /**
4050 * Returns the CDMA ERI text,
4051 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004052 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004053 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4054 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4055 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004056 }
4057
Sanket Padawe356d7632015-06-22 14:03:32 -07004058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004059 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4060 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004062 mApp, subId, callingPackage, callingFeatureId,
4063 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004064 return null;
4065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004066
4067 final long identity = Binder.clearCallingIdentity();
4068 try {
4069 final Phone phone = getPhone(subId);
4070 if (phone != null) {
4071 return phone.getCdmaEriText();
4072 } else {
4073 return null;
4074 }
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004077 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004078 }
4079
4080 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004081 * Returns the CDMA MDN.
4082 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004083 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004084 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4086 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087
joonhunshin4ac60942023-11-15 15:23:39 +00004088 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4089 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 return phone.getLine1Number();
4096 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 return null;
4099 }
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004102 }
4103 }
4104
4105 /**
4106 * Returns the CDMA MIN.
4107 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004108 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004109 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4111 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112
joonhunshin4ac60942023-11-15 15:23:39 +00004113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4114 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 final Phone phone = getPhone(subId);
4119 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4120 return phone.getCdmaMin();
4121 } else {
4122 return null;
4123 }
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004126 }
4127 }
4128
Hall Liud892bec2018-11-30 14:51:45 -08004129 @Override
4130 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4131 INumberVerificationCallback callback, String callingPackage) {
4132 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4133 != PERMISSION_GRANTED) {
4134 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4135 }
4136 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4137
4138 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4139 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004140 throw new SecurityException("Calling package must be configured in the device config: "
4141 + "calling package: " + callingPackage
4142 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004143 }
4144
joonhunshin4ac60942023-11-15 15:23:39 +00004145 enforceTelephonyFeatureWithException(callingPackage,
4146 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4147
Hall Liud892bec2018-11-30 14:51:45 -08004148 if (range == null) {
4149 throw new NullPointerException("Range must be non-null");
4150 }
4151
4152 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004153 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004154
4155 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4156 }
4157
Junda Liuca05d5d2014-08-14 22:36:34 -07004158 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004159 * Returns true if CDMA provisioning needs to run.
4160 */
4161 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004162 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4163 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 final long identity = Binder.clearCallingIdentity();
4166 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004167 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004171 }
4172
4173 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004174 * Sets the voice mail number of a given subId.
4175 */
4176 @Override
4177 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004178 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4179 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180
joonhunshin4ac60942023-11-15 15:23:39 +00004181 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4182 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184 final long identity = Binder.clearCallingIdentity();
4185 try {
4186 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4187 new Pair<String, String>(alphaTag, number), new Integer(subId));
4188 return success;
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004192 }
4193
Ta-wei Yen87c49842016-05-13 21:19:52 -07004194 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004195 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4196 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004197 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4198 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004199 if (!TextUtils.equals(callingPackage, systemDialer)) {
4200 throw new SecurityException("caller must be system dialer");
4201 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004202
joonhunshin4ac60942023-11-15 15:23:39 +00004203 enforceTelephonyFeatureWithException(callingPackage,
4204 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004206 final long identity = Binder.clearCallingIdentity();
4207 try {
4208 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4209 if (phoneAccountHandle == null) {
4210 return null;
4211 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004212 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 } finally {
4214 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004215 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004216 }
4217
4218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004219 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4220 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004221 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004223 mApp, subId, callingPackage, callingFeatureId,
4224 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004225 return null;
4226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227
joonhunshin4ac60942023-11-15 15:23:39 +00004228 enforceTelephonyFeatureWithException(callingPackage,
4229 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4230
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004231 final long identity = Binder.clearCallingIdentity();
4232 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004233 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004234 } finally {
4235 Binder.restoreCallingIdentity(identity);
4236 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004237 }
4238
4239 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004240 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4241 VisualVoicemailSmsFilterSettings settings) {
4242 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243
joonhunshin4ac60942023-11-15 15:23:39 +00004244 enforceTelephonyFeatureWithException(callingPackage,
4245 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 final long identity = Binder.clearCallingIdentity();
4248 try {
4249 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004250 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004254 }
4255
4256 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004257 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259
joonhunshin4ac60942023-11-15 15:23:39 +00004260 enforceTelephonyFeatureWithException(callingPackage,
4261 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004266 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004270 }
4271
4272 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004273 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4274 String callingPackage, int subId) {
4275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004280 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004284 }
4285
4286 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004287 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289
4290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004293 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004297 }
4298
4299 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004300 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4301 String callingAttributionTag, int subId, String number, int port, String text,
4302 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004304 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004305 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004306
4307 enforceTelephonyFeatureWithException(callingPackage,
4308 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4309
Amit Mahajandccb3f12019-05-13 13:48:32 -07004310 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004311 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4312 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004313 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004314
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004315 /**
fionaxu0152e512016-11-14 13:36:14 -08004316 * Sets the voice activation state of a given subId.
4317 */
4318 @Override
4319 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4321 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322
joonhunshin4ac60942023-11-15 15:23:39 +00004323 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4324 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 final Phone phone = getPhone(subId);
4329 if (phone != null) {
4330 phone.setVoiceActivationState(activationState);
4331 } else {
4332 loge("setVoiceActivationState fails with invalid subId: " + subId);
4333 }
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004336 }
4337 }
4338
4339 /**
4340 * Sets the data activation state of a given subId.
4341 */
4342 @Override
4343 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4345 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346
joonhunshin4ac60942023-11-15 15:23:39 +00004347 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4348 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 final Phone phone = getPhone(subId);
4353 if (phone != null) {
4354 phone.setDataActivationState(activationState);
4355 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004356 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 }
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004360 }
4361 }
4362
4363 /**
4364 * Returns the voice activation state of a given subId.
4365 */
4366 @Override
4367 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369
joonhunshin4ac60942023-11-15 15:23:39 +00004370 enforceTelephonyFeatureWithException(callingPackage,
4371 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4372
fionaxu0152e512016-11-14 13:36:14 -08004373 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 if (phone != null) {
4377 return phone.getVoiceActivationState();
4378 } else {
4379 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4380 }
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004383 }
4384 }
4385
4386 /**
4387 * Returns the data activation state of a given subId.
4388 */
4389 @Override
4390 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392
joonhunshin4ac60942023-11-15 15:23:39 +00004393 enforceTelephonyFeatureWithException(callingPackage,
4394 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4395
fionaxu0152e512016-11-14 13:36:14 -08004396 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 final long identity = Binder.clearCallingIdentity();
4398 try {
4399 if (phone != null) {
4400 return phone.getDataActivationState();
4401 } else {
4402 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4403 }
4404 } finally {
4405 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004406 }
4407 }
4408
4409 /**
Wink Saville36469e72014-06-11 15:17:00 -07004410 * Returns the unread count of voicemails for a subId
4411 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004413 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4414 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004415 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004416 mApp, subId, callingPackage, callingFeatureId,
4417 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004418 return 0;
4419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 final Phone phone = getPhone(subId);
4423 if (phone != null) {
4424 return phone.getVoiceMessageCount();
4425 } else {
4426 return 0;
4427 }
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004431 }
4432
4433 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004434 * returns true, if the device is in a state where both voice and data
4435 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004436 */
4437 @Override
4438 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4440 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
Ling Mac28f0212023-03-24 16:07:15 -07004444 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 } finally {
4446 Binder.restoreCallingIdentity(identity);
4447 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004448 }
4449
4450 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004451 * Send the dialer code if called from the current default dialer or the caller has
4452 * carrier privilege.
4453 * @param inputCode The dialer code to send
4454 */
4455 @Override
4456 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004457 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004459 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4460 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004461 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004462 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004463 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465
joonhunshin4ac60942023-11-15 15:23:39 +00004466 enforceTelephonyFeatureWithException(callingPackage,
4467 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 final long identity = Binder.clearCallingIdentity();
4470 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004471 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
fionaxu235cc5e2017-03-06 22:25:57 -08004475 }
4476
Pengquan Menga1bb6272018-09-06 09:59:22 -07004477 @Override
4478 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004479 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004480 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4481 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004482
4483 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4484 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4485
shilufc958392020-01-20 11:36:01 -08004486 final long identity = Binder.clearCallingIdentity();
4487 try {
4488 if (!isActiveSubscription(subId)) {
4489 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4490 }
4491 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4492 } finally {
4493 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004495 }
4496
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004498 public boolean isInEmergencySmsMode() {
4499 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004500
4501 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4502 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4503
Brad Ebingerb2b65522019-03-15 13:48:47 -07004504 final long identity = Binder.clearCallingIdentity();
4505 try {
4506 for (Phone phone : PhoneFactory.getPhones()) {
4507 if (phone.isInEmergencySmsMode()) {
4508 return true;
4509 }
4510 }
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
4514 return false;
4515 }
4516
shilu366312e2019-12-17 09:28:10 -08004517 /**
4518 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4519 * @param subId The subscription to use to check the configuration.
4520 * @param c The callback that will be used to send the result.
4521 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004522 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004523 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4524 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004525 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004526 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004527
4528 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4529 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4530 "IMS not available on device.");
4531 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 final long token = Binder.clearCallingIdentity();
4533 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004534 int slotId = getSlotIndexOrException(subId);
4535 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004536
4537 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4538 if (controller != null) {
4539 ImsManager imsManager = controller.getImsManager(subId);
4540 if (imsManager != null) {
4541 imsManager.addRegistrationCallbackForSubscription(c, subId);
4542 } else {
4543 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4544 }
4545 } else {
4546 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4547 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004548 } catch (ImsException e) {
4549 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 } finally {
4551 Binder.restoreCallingIdentity(token);
4552 }
4553 }
4554
shilu366312e2019-12-17 09:28:10 -08004555 /**
4556 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4557 * @param subId The subscription to use to check the configuration.
4558 * @param c The callback that will be used to send the result.
4559 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004560 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004561 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004562 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004563 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004564 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4565 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4566 }
Meng Wangafbc5852019-09-19 17:37:13 -07004567 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004568
Meng Wangafbc5852019-09-19 17:37:13 -07004569 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004570 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4571 if (controller != null) {
4572 ImsManager imsManager = controller.getImsManager(subId);
4573 if (imsManager != null) {
4574 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4575 } else {
4576 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4577 + "is inactive, ignoring unregister.");
4578 // If the ImsManager is not valid, just return, since the callback
4579 // will already have been removed internally.
4580 }
4581 }
Meng Wangafbc5852019-09-19 17:37:13 -07004582 } finally {
4583 Binder.restoreCallingIdentity(token);
4584 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004585 }
4586
Brad Ebingera34a6c22019-10-22 17:36:18 -07004587 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004588 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4589 * @param subId The subscription to use to check the configuration.
4590 * @param c The callback that will be used to send the result.
4591 */
4592 @Override
4593 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4594 throws RemoteException {
4595 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4596 mApp, subId, "registerImsEmergencyRegistrationCallback");
4597
4598 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4599 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4600 "IMS not available on device.");
4601 }
4602 final long token = Binder.clearCallingIdentity();
4603 try {
4604 int slotId = getSlotIndexOrException(subId);
4605 verifyImsMmTelConfiguredOrThrow(slotId);
4606
4607 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4608 if (controller != null) {
4609 ImsManager imsManager = controller.getImsManager(subId);
4610 if (imsManager != null) {
4611 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4612 } else {
4613 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4614 }
4615 } else {
4616 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4617 }
4618 } catch (ImsException e) {
4619 throw new ServiceSpecificException(e.getCode());
4620 } finally {
4621 Binder.restoreCallingIdentity(token);
4622 }
4623 }
4624
4625 /**
4626 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4627 * @param subId The subscription to use to check the configuration.
4628 * @param c The callback that will be used to send the result.
4629 */
4630 @Override
4631 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4632 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4633 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4634 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4635 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4636 }
4637 final long token = Binder.clearCallingIdentity();
4638
4639 try {
4640 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4641 if (controller != null) {
4642 ImsManager imsManager = controller.getImsManager(subId);
4643 if (imsManager != null) {
4644 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4645 } else {
4646 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4647 + "is inactive, ignoring unregister.");
4648 // If the ImsManager is not valid, just return, since the callback
4649 // will already have been removed internally.
4650 }
4651 }
4652 } finally {
4653 Binder.restoreCallingIdentity(token);
4654 }
4655 }
4656
4657 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004658 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4659 */
4660 @Override
4661 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4662 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4663 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4664 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4665 "IMS not available on device.");
4666 }
4667 final long token = Binder.clearCallingIdentity();
4668 try {
4669 Phone phone = getPhone(subId);
4670 if (phone == null) {
4671 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4672 + subId + "'");
4673 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4674 }
4675 phone.getImsRegistrationState(regState -> {
4676 try {
4677 consumer.accept((regState == null)
4678 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4679 } catch (RemoteException e) {
4680 // Ignore if the remote process is no longer available to call back.
4681 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4682 }
4683 });
4684 } finally {
4685 Binder.restoreCallingIdentity(token);
4686 }
4687 }
4688
4689 /**
4690 * Get the transport type for the IMS service registration state.
4691 */
4692 @Override
4693 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004694 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004695 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004696 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4697 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4698 "IMS not available on device.");
4699 }
4700 final long token = Binder.clearCallingIdentity();
4701 try {
4702 Phone phone = getPhone(subId);
4703 if (phone == null) {
4704 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4705 + subId + "'");
4706 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4707 }
4708 phone.getImsRegistrationTech(regTech -> {
4709 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4710 int regTechConverted = (regTech == null)
4711 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4712 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4713 regTechConverted);
4714 try {
4715 consumer.accept(regTechConverted);
4716 } catch (RemoteException e) {
4717 // Ignore if the remote process is no longer available to call back.
4718 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4719 }
4720 });
4721 } finally {
4722 Binder.restoreCallingIdentity(token);
4723 }
4724 }
4725
shilu366312e2019-12-17 09:28:10 -08004726 /**
4727 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4728 * @param subId The subscription to use to check the configuration.
4729 * @param c The callback that will be used to send the result.
4730 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004731 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004732 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4733 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004734 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004735 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004736 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4737 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4738 "IMS not available on device.");
4739 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004740 final long token = Binder.clearCallingIdentity();
4741 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004742 int slotId = getSlotIndexOrException(subId);
4743 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004744
4745 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4746 if (controller != null) {
4747 ImsManager imsManager = controller.getImsManager(subId);
4748 if (imsManager != null) {
4749 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4750 } else {
4751 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4752 }
4753 } else {
4754 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4755 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004756 } catch (ImsException e) {
4757 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004758 } finally {
4759 Binder.restoreCallingIdentity(token);
4760 }
4761 }
4762
shilu366312e2019-12-17 09:28:10 -08004763 /**
4764 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4765 * @param subId The subscription to use to check the configuration.
4766 * @param c The callback that will be used to send the result.
4767 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004769 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004770 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004771 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004772 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4773 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4774 }
Meng Wangafbc5852019-09-19 17:37:13 -07004775
4776 final long token = Binder.clearCallingIdentity();
4777 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004778 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4779 if (controller != null) {
4780 ImsManager imsManager = controller.getImsManager(subId);
4781 if (imsManager != null) {
4782 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4783 } else {
4784 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4785 + " is inactive, ignoring unregister.");
4786 // If the ImsManager is not valid, just return, since the callback
4787 // will already have been removed internally.
4788 }
4789 }
Meng Wangafbc5852019-09-19 17:37:13 -07004790 } finally {
4791 Binder.restoreCallingIdentity(token);
4792 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004793 }
4794
4795 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004796 public boolean isCapable(int subId, int capability, int regTech) {
4797 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004798
4799 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4800 FEATURE_TELEPHONY_IMS, "isCapable");
4801
Brad Ebinger35c841c2018-10-01 10:40:55 -07004802 final long token = Binder.clearCallingIdentity();
4803 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004804 int slotId = getSlotIndexOrException(subId);
4805 verifyImsMmTelConfiguredOrThrow(slotId);
4806 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4807 } catch (com.android.ims.ImsException e) {
4808 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4809 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004810 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004811 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4812 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 } finally {
4814 Binder.restoreCallingIdentity(token);
4815 }
4816 }
4817
4818 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004819 public boolean isAvailable(int subId, int capability, int regTech) {
4820 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004821
4822 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4823 FEATURE_TELEPHONY_IMS, "isAvailable");
4824
Brad Ebinger35c841c2018-10-01 10:40:55 -07004825 final long token = Binder.clearCallingIdentity();
4826 try {
4827 Phone phone = getPhone(subId);
4828 if (phone == null) return false;
4829 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004830 } catch (com.android.ims.ImsException e) {
4831 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4832 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004833 } finally {
4834 Binder.restoreCallingIdentity(token);
4835 }
4836 }
4837
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004838 /**
4839 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4840 * subscription.
4841 * @param subId The subscription to use to check the configuration.
4842 * @param callback The callback that will be used to send the result.
4843 * @param capability The MmTelFeature capability that will be used to send the result.
4844 * @param transportType The transport type of the MmTelFeature capability.
4845 */
4846 @Override
4847 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4848 int transportType) {
4849 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004850 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4851 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4852 "IMS not available on device.");
4853 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004854 final long token = Binder.clearCallingIdentity();
4855 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004856 int slotId = getSlotIndex(subId);
4857 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4858 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4859 + subId + "'");
4860 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4861 }
4862 verifyImsMmTelConfiguredOrThrow(slotId);
4863 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4864 transportType, aBoolean -> {
4865 try {
4866 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4867 } catch (RemoteException e) {
4868 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4869 + "running. Ignore");
4870 }
4871 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004872 } catch (ImsException e) {
4873 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004874 } finally {
4875 Binder.restoreCallingIdentity(token);
4876 }
4877 }
4878
shilu366312e2019-12-17 09:28:10 -08004879 /**
4880 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4881 * @param subId The subscription to use to check the configuration.
4882 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 @Override
4884 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004885 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004886 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004887
joonhunshin4ac60942023-11-15 15:23:39 +00004888 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4889 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4890
Brad Ebinger35c841c2018-10-01 10:40:55 -07004891 final long token = Binder.clearCallingIdentity();
4892 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004893 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004894 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004895 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004896 } catch (ImsException e) {
4897 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004898 } finally {
4899 Binder.restoreCallingIdentity(token);
4900 }
4901 }
4902
4903 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004904 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004906 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004907
4908 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4909 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4910
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 final long identity = Binder.clearCallingIdentity();
4912 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004913 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004914 // This setting doesn't require an active ImsService connection, so do not verify. The
4915 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004916 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004917 } catch (ImsException e) {
4918 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
4922 }
4923
shilu366312e2019-12-17 09:28:10 -08004924 /**
4925 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4926 * @param subId The subscription to use to check the configuration.
4927 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004928 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004929 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004930 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004931 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004932
4933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4934 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4935
Brad Ebinger35c841c2018-10-01 10:40:55 -07004936 final long identity = Binder.clearCallingIdentity();
4937 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004938 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004939 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004940 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004941 } catch (ImsException e) {
4942 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004943 } finally {
4944 Binder.restoreCallingIdentity(identity);
4945 }
4946 }
4947
4948 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004949 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004951 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004952
4953 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4954 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4955
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 final long identity = Binder.clearCallingIdentity();
4957 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004958 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004959 // This setting doesn't require an active ImsService connection, so do not verify. The
4960 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004961 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004962 } catch (ImsException e) {
4963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
4967 }
4968
shilu366312e2019-12-17 09:28:10 -08004969 /**
4970 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4971 * @param subId The subscription to use to check the configuration.
4972 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004973 @Override
4974 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004975 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004976 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004977
4978 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4979 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4980
Brad Ebinger35c841c2018-10-01 10:40:55 -07004981 final long identity = Binder.clearCallingIdentity();
4982 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004983 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004984 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004985 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004986 } catch (ImsException e) {
4987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
4991 }
4992
4993 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004994 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004996 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004997
4998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4999 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5000
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 final long identity = Binder.clearCallingIdentity();
5002 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005003 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005004 // This setting doesn't require an active ImsService connection, so do not verify. The
5005 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005006 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005007 } catch (ImsException e) {
5008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
5012 }
5013
shilu366312e2019-12-17 09:28:10 -08005014 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005015 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5016 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5017 * @param subId The subscription to use to check the configuration.
5018 */
5019 @Override
5020 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005021 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005022 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005023
5024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5025 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5026
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005027 final long identity = Binder.clearCallingIdentity();
5028 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005029 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005030 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005031 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005032 } catch (ImsException e) {
5033 throw new ServiceSpecificException(e.getCode());
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
5037 }
5038
5039 /**
5040 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5041 * Requires MODIFY_PHONE_STATE permission.
5042 * @param subId The subscription to use to check the configuration.
5043 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5044 * false otherwise
5045 */
5046 @Override
5047 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5049 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005050
5051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5052 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5053
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005056 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005057 // This setting doesn't require an active ImsService connection, so do not verify. The
5058 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005059 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005060 } catch (ImsException e) {
5061 throw new ServiceSpecificException(e.getCode());
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
5064 }
5065 }
5066
5067 /**
shilu366312e2019-12-17 09:28:10 -08005068 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5069 * @param subId The subscription to use to check the configuration.
5070 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005071 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005072
Brad Ebinger35c841c2018-10-01 10:40:55 -07005073 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005074 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005075 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005076
5077 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5078 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5079
Brad Ebinger35c841c2018-10-01 10:40:55 -07005080 final long identity = Binder.clearCallingIdentity();
5081 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005082 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005083 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005084 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005085 } catch (ImsException e) {
5086 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
5089 }
5090 }
5091
5092 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005093 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005095 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005096
5097 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5098 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5099
Brad Ebinger35c841c2018-10-01 10:40:55 -07005100 final long identity = Binder.clearCallingIdentity();
5101 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005102 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005103 // This setting doesn't require an active ImsService connection, so do not verify. The
5104 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005105 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005106 } catch (ImsException e) {
5107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005108 } finally {
5109 Binder.restoreCallingIdentity(identity);
5110 }
5111 }
5112
5113 @Override
5114 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5116 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005117
5118 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5119 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5120
Brad Ebinger35c841c2018-10-01 10:40:55 -07005121 final long identity = Binder.clearCallingIdentity();
5122 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005123 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005124 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005125 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005126 } catch (ImsException e) {
5127 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005128 } finally {
5129 Binder.restoreCallingIdentity(identity);
5130 }
5131 }
5132
shilu366312e2019-12-17 09:28:10 -08005133 /**
5134 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5135 * @param subId The subscription to use to check the configuration.
5136 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005137 @Override
5138 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005139 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005140 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005141
5142 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5143 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5144
Brad Ebinger35c841c2018-10-01 10:40:55 -07005145 final long identity = Binder.clearCallingIdentity();
5146 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005147 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005148 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005149 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005150 } catch (ImsException e) {
5151 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
5155 }
5156
5157 @Override
5158 public void setVoWiFiModeSetting(int subId, int mode) {
5159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5160 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005161
5162 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5163 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5164
Brad Ebinger35c841c2018-10-01 10:40:55 -07005165 final long identity = Binder.clearCallingIdentity();
5166 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005167 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005168 // This setting doesn't require an active ImsService connection, so do not verify. The
5169 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005170 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005171 } catch (ImsException e) {
5172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
5176 }
5177
5178 @Override
5179 public int getVoWiFiRoamingModeSetting(int subId) {
5180 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005181
5182 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5183 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5184
Brad Ebinger35c841c2018-10-01 10:40:55 -07005185 final long identity = Binder.clearCallingIdentity();
5186 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005187 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005188 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005189 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005190 } catch (ImsException e) {
5191 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
5195 }
5196
5197 @Override
5198 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5200 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005201
5202 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5203 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5204
Brad Ebinger35c841c2018-10-01 10:40:55 -07005205 final long identity = Binder.clearCallingIdentity();
5206 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005207 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005208 // This setting doesn't require an active ImsService connection, so do not verify. The
5209 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005210 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005211 } catch (ImsException e) {
5212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
5216 }
5217
5218 @Override
5219 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5221 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005222
5223 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5224 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5225
Brad Ebinger35c841c2018-10-01 10:40:55 -07005226 final long identity = Binder.clearCallingIdentity();
5227 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005228 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005229 // This setting doesn't require an active ImsService connection, so do not verify. The
5230 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005231 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005232 } catch (ImsException e) {
5233 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
5237 }
5238
shilu366312e2019-12-17 09:28:10 -08005239 /**
5240 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5241 * @param subId The subscription to use to check the configuration.
5242 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005243 @Override
5244 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005245 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005246 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005247
5248 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5249 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5250
Brad Ebinger35c841c2018-10-01 10:40:55 -07005251 final long identity = Binder.clearCallingIdentity();
5252 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005253 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005254 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005255 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005256 } catch (ImsException e) {
5257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
5261 }
5262
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005263 @Override
5264 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5265 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005266
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005267 final long identity = Binder.clearCallingIdentity();
5268 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005269 if (!isImsAvailableOnDevice()) {
5270 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5271 "IMS not available on device.");
5272 }
5273 int slotId = getSlotIndexOrException(subId);
5274 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005275
5276 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5277 if (controller != null) {
5278 ImsManager imsManager = controller.getImsManager(subId);
5279 if (imsManager != null) {
5280 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5281 } else {
5282 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5283 }
5284 } else {
5285 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5286 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005287 } catch (ImsException e) {
5288 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
5292 }
5293
5294 @Override
5295 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5296 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005297
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005298 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005299 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5300 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5301 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005302 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005303 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5304 if (controller != null) {
5305 ImsManager imsManager = controller.getImsManager(subId);
5306 if (imsManager != null) {
5307 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5308 } else {
5309 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5310 + " is inactive, ignoring unregister.");
5311 // If the ImsManager is not valid, just return, since the callback will already
5312 // have been removed internally.
5313 }
5314 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
5318 }
5319
joonhunshincffb7fc2021-11-28 07:32:01 +00005320 @Override
5321 public void registerFeatureProvisioningChangedCallback(int subId,
5322 IFeatureProvisioningCallback callback) {
5323 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5324 mApp, subId, "registerFeatureProvisioningChangedCallback");
5325
5326 final long identity = Binder.clearCallingIdentity();
5327 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5328 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5329 }
5330
joonhunshin91bc1952022-04-29 08:47:15 +00005331 try {
5332 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5333 if (controller == null) {
5334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5335 "Device does not support IMS");
5336 }
5337 controller.addFeatureProvisioningChangedCallback(subId, callback);
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005341 }
5342
5343 @Override
5344 public void unregisterFeatureProvisioningChangedCallback(int subId,
5345 IFeatureProvisioningCallback callback) {
5346 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5347 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5348
5349 final long identity = Binder.clearCallingIdentity();
5350 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5351 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5352 }
5353
joonhunshin91bc1952022-04-29 08:47:15 +00005354 try {
5355 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5356 if (controller == null) {
5357 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5358 return;
5359 }
5360 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5361 } finally {
5362 Binder.restoreCallingIdentity(identity);
5363 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005364 }
allenwtsu99c623b2020-01-03 18:24:23 +08005365
5366 private void checkModifyPhoneStatePermission(int subId, String message) {
5367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5368 message);
5369 }
5370
allenwtsu99c623b2020-01-03 18:24:23 +08005371 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005372 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005373 boolean isProvisioned) {
5374 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5375
joonhunshin4ac60942023-11-15 15:23:39 +00005376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5377 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5378
allenwtsu99c623b2020-01-03 18:24:23 +08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005381 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5382 if (controller == null) {
5383 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5384 return;
5385 }
5386 controller.setRcsProvisioningStatusForCapability(
5387 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005388 } finally {
5389 Binder.restoreCallingIdentity(identity);
5390 }
allenwtsu99c623b2020-01-03 18:24:23 +08005391 }
5392
5393
5394 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005395 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5396 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5397 mApp, subId, "getRcsProvisioningStatusForCapability");
5398
joonhunshin4ac60942023-11-15 15:23:39 +00005399 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5400 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5401
allenwtsu99c623b2020-01-03 18:24:23 +08005402 final long identity = Binder.clearCallingIdentity();
5403 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005404 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5405 if (controller == null) {
5406 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5407
5408 // device does not support IMS, this method will return true always.
5409 return true;
5410 }
5411 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
5415 }
5416
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005417 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005418 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5419 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005420 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005421
joonhunshin4ac60942023-11-15 15:23:39 +00005422 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5423 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5424
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005427 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5428 if (controller == null) {
5429 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5430 return;
5431 }
5432 controller.setImsProvisioningStatusForCapability(
5433 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005434 } finally {
5435 Binder.restoreCallingIdentity(identity);
5436 }
5437 }
5438
5439 @Override
5440 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005441 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5442 mApp, subId, "getProvisioningStatusForCapability");
5443
joonhunshin4ac60942023-11-15 15:23:39 +00005444 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5445 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5446
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005449 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5450 if (controller == null) {
5451 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005452
joonhunshin91bc1952022-04-29 08:47:15 +00005453 // device does not support IMS, this method will return true always.
5454 return true;
5455 }
5456 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
5460 }
5461
5462 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005463 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5464 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5465 mApp, subId, "isProvisioningRequiredForCapability");
5466
joonhunshin4ac60942023-11-15 15:23:39 +00005467 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5468 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5469
joonhunshincffb7fc2021-11-28 07:32:01 +00005470 final long identity = Binder.clearCallingIdentity();
5471 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005472 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5473 if (controller == null) {
5474 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5475
5476 // device does not support IMS, this method will return false
5477 return false;
5478 }
5479 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005482 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005483 }
5484
5485 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005486 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5487 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5488 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005489
joonhunshin4ac60942023-11-15 15:23:39 +00005490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5491 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5492
joonhunshincffb7fc2021-11-28 07:32:01 +00005493 final long identity = Binder.clearCallingIdentity();
5494 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005495 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5496 if (controller == null) {
5497 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5498
5499 // device does not support IMS, this method will return false
5500 return false;
5501 }
5502 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005503 } finally {
5504 Binder.restoreCallingIdentity(identity);
5505 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005506 }
5507
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005508 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005509 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005510 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5511 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5512 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005513 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5514 mApp, subId, "getImsProvisioningInt");
5515
joonhunshin4ac60942023-11-15 15:23:39 +00005516 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5517 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5518
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005522 int slotId = getSlotIndex(subId);
5523 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5524 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5525 + subId + "' for key:" + key);
5526 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5527 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005528
joonhunshin91bc1952022-04-29 08:47:15 +00005529 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5530 if (controller == null) {
5531 loge("getImsProvisioningInt: Device does not support IMS");
5532
5533 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5534 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5535 }
5536 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005537 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5538 return retVal;
5539 }
5540
calvinpanb5a34062021-02-08 19:59:36 +08005541 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005542 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005543 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5544 + subId + "' for key:" + key);
5545 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
5549 }
5550
5551 @Override
5552 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005553 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5554 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5555 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005556 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5557 mApp, subId, "getImsProvisioningString");
5558
joonhunshin4ac60942023-11-15 15:23:39 +00005559 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5560 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5561
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005565 int slotId = getSlotIndex(subId);
5566 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5567 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5568 + subId + "' for key:" + key);
5569 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5570 }
calvinpanb5a34062021-02-08 19:59:36 +08005571 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005572 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005573 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5574 + subId + "' for key:" + key);
5575 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
5579 }
5580
5581 @Override
5582 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005583 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5584 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5585 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5587 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005588
joonhunshin4ac60942023-11-15 15:23:39 +00005589 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5590 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5591
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005595 int slotId = getSlotIndex(subId);
5596 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5597 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5598 + subId + "' for key:" + key);
5599 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5600 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005601
joonhunshin91bc1952022-04-29 08:47:15 +00005602 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5603 if (controller == null) {
5604 loge("setImsProvisioningInt: Device does not support IMS");
5605
5606 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5607 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5608 }
5609 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005610 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5611 return retVal;
5612 }
5613
calvinpanb5a34062021-02-08 19:59:36 +08005614 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5615 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005616 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005617 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005618 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
5622 }
5623
5624 @Override
5625 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005626 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5627 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5628 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5630 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005631
5632 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5633 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5634
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005638 int slotId = getSlotIndex(subId);
5639 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5640 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5641 + subId + "' for key:" + key);
5642 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5643 }
calvinpanb5a34062021-02-08 19:59:36 +08005644 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5645 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005646 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005647 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005648 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
5652 }
5653
Brad Ebinger919631e2021-06-02 17:46:35 -07005654 /**
5655 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5656 * for the given slot ID or no ImsResolver instance has been created.
5657 * @param slotId The slot ID that the IMS service is created for.
5658 * @throws ImsException If there is no ImsService configured for this slot.
5659 */
5660 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5661 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5662 ImsFeature.FEATURE_MMTEL)) {
5663 throw new ImsException("This subscription does not support MMTEL over IMS",
5664 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5665 }
5666 }
5667
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005668 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005669 int slotId = SubscriptionManager.getSlotIndex(subId);
5670 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005671 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5672 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005673 }
5674 return slotId;
5675 }
5676
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005677 private int getSlotIndex(int subId) {
5678 int slotId = SubscriptionManager.getSlotIndex(subId);
5679 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5680 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5681 }
5682 return slotId;
5683 }
5684
Wink Saville36469e72014-06-11 15:17:00 -07005685 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005686 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005687 */
5688 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005689 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5690 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005691 try {
5692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5693 } catch (SecurityException se) {
5694 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5695 throw new SecurityException("Package " + callingPackage + " does not belong to "
5696 + Binder.getCallingUid());
5697 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005698 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005699 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005700 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005701 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005702 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005703 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005704 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005705 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5706 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005707
joonhunshin4ac60942023-11-15 15:23:39 +00005708 enforceTelephonyFeatureWithException(callingPackage,
5709 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 final long identity = Binder.clearCallingIdentity();
5712 try {
5713 final Phone phone = getPhone(subId);
5714 if (phone != null) {
5715 return phone.getServiceState().getDataNetworkType();
5716 } else {
5717 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5718 }
5719 } finally {
5720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005722 }
5723
5724 /**
5725 * Returns the data network type
5726 */
5727 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005728 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005729 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005730 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005731 }
5732
5733 /**
5734 * Returns the data network type for a subId
5735 */
5736 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005737 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5738 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005739 String functionName = "getDataNetworkTypeForSubscriber";
5740 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5741 mApp, functionName)) {
5742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5743 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5744 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5745 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005746 }
5747
joonhunshin4ac60942023-11-15 15:23:39 +00005748 enforceTelephonyFeatureWithException(callingPackage,
5749 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 final long identity = Binder.clearCallingIdentity();
5752 try {
5753 final Phone phone = getPhone(subId);
5754 if (phone != null) {
5755 return phone.getServiceState().getDataNetworkType();
5756 } else {
5757 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5758 }
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005762 }
5763
5764 /**
Wink Saville36469e72014-06-11 15:17:00 -07005765 * Returns the Voice network type for a subId
5766 */
5767 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005768 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5769 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005770 String functionName = "getVoiceNetworkTypeForSubscriber";
5771 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5772 mApp, functionName)) {
5773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5774 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5775 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5776 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005777 }
5778
joonhunshin4ac60942023-11-15 15:23:39 +00005779 enforceTelephonyFeatureWithException(callingPackage,
5780 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 final Phone phone = getPhone(subId);
5785 if (phone != null) {
5786 return phone.getServiceState().getVoiceNetworkType();
5787 } else {
5788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5789 }
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005793 }
5794
5795 /**
5796 * @return true if a ICC card is present
5797 */
5798 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005799 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005800 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005801 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005802 }
5803
5804 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005805 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005806 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005807 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005808 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5810 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 final Phone phone = PhoneFactory.getPhone(slotIndex);
5815 if (phone != null) {
5816 return phone.getIccCard().hasIccCard();
5817 } else {
5818 return false;
5819 }
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005823 }
5824
5825 /**
5826 * Return if the current radio is LTE on CDMA. This
5827 * is a tri-state return value as for a period of time
5828 * the mode may be unknown.
5829 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005830 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005831 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005832 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005833 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005834 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005835 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5836 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5837 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005838 }
5839
Sanket Padawe356d7632015-06-22 14:03:32 -07005840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005841 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5842 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005843 try {
5844 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5845 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005846 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5847 }
5848
joonhunshin4ac60942023-11-15 15:23:39 +00005849 enforceTelephonyFeatureWithException(callingPackage,
5850 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 final long identity = Binder.clearCallingIdentity();
5853 try {
5854 final Phone phone = getPhone(subId);
5855 if (phone == null) {
5856 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5857 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005858 return TelephonyProperties.lte_on_cdma_device()
5859 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 }
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005863 }
Wink Saville36469e72014-06-11 15:17:00 -07005864 }
5865
Wink Saville36469e72014-06-11 15:17:00 -07005866 /**
5867 * {@hide}
5868 * Returns Default subId, 0 in the case of single standby.
5869 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005870 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005871 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005872 }
5873
Shishir Agrawala9f32182016-04-12 12:00:16 -07005874 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005875 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005876 }
5877
Wink Savilleb564aae2014-10-23 10:18:09 -07005878 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005879 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005880 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005881
Pengquan Menge92a50d2018-09-21 15:54:48 -07005882 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005883 return getSubscriptionManagerService().isActiveSubId(subId,
5884 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005885 }
5886
Ihab Awadf2177b72013-11-25 13:33:23 -08005887 /**
5888 * @see android.telephony.TelephonyManager.WifiCallingChoices
5889 */
5890 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 final long identity = Binder.clearCallingIdentity();
5892 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005893 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5895 getWhenToMakeWifiCallsDefaultPreference());
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005899 }
5900
5901 /**
5902 * @see android.telephony.TelephonyManager.WifiCallingChoices
5903 */
5904 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 final long identity = Binder.clearCallingIdentity();
5906 try {
5907 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005908 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005913 }
5914
Sailesh Nepald1e68152013-12-12 19:08:02 -08005915 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005916 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005917 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005918 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005919
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005920 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5921 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5922 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005923 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005924 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005925 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005926 }
5927 return PhoneFactory.getPhone(phoneId);
5928 }
5929
Shishir Agrawal566b7612013-10-28 14:41:00 -07005930 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005931 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005932 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005933
Rambo Wanga1782702021-11-10 20:15:19 -08005934 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5935 /*message=*/ "iccOpenLogicalChannel");
5936
5937 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5938 // Verify that the callingPackage in the request belongs to the calling UID
5939 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5940
joonhunshin4ac60942023-11-15 15:23:39 +00005941 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5942 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5943
Rambo Wanga1782702021-11-10 20:15:19 -08005944 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005945 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005946
Rambo Wanga1782702021-11-10 20:15:19 -08005947 private Phone getPhoneFromValidIccLogicalChannelRequest(
5948 @NonNull IccLogicalChannelRequest request, String message) {
5949 Phone phone;
5950 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5952 mApp, request.subId, message);
5953 phone = getPhoneFromSubId(request.subId);
5954 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5955 enforceModifyPermission();
5956 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5957 } else {
5958 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005959 }
Rambo Wanga1782702021-11-10 20:15:19 -08005960 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005961 }
5962
5963 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005964 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 final long identity = Binder.clearCallingIdentity();
5966 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005967 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005969 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5970 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005971 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5972 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 loge("The calling package is not allowed to access ISD-R.");
5974 throw new SecurityException(
5975 "The calling package is not allowed to access ISD-R.");
5976 }
Derek Tan740e1672017-06-27 14:56:27 -07005977 }
Derek Tan740e1672017-06-27 14:56:27 -07005978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005980 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5981 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 return response;
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005986 }
5987
5988 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005989 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005990 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5991 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5992
Rambo Wanga1782702021-11-10 20:15:19 -08005993 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5994 /*message=*/"iccCloseLogicalChannel");
5995
5996 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5997
5998 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005999 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006000
Rambo Wanga1782702021-11-10 20:15:19 -08006001 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6002 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006003 // before this feature is enabled, this API should only return false if
6004 // the operation fails instead of throwing runtime exception for
6005 // backward-compatibility.
6006 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6007 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 final long identity = Binder.clearCallingIdentity();
6009 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006010 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006011 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 }
Chen Xue9d737e2022-01-01 23:41:31 -08006013 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006014 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006015 Boolean success = false;
6016 if (result instanceof RuntimeException) {
6017 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006018 if (shouldThrowExceptionOnFailure) {
6019 throw (RuntimeException) result;
6020 } else {
6021 return false;
6022 }
Chen Xue9d737e2022-01-01 23:41:31 -08006023 } else if (result instanceof Boolean) {
6024 success = (Boolean) result;
6025 } else {
6026 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6027 }
Rambo Wanga1782702021-11-10 20:15:19 -08006028 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 return success;
6030 } finally {
6031 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006032 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006033 }
6034
6035 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006036 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006037 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6039 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006040
6041 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6042 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6043
Jordan Liu4c733742019-02-28 12:03:40 -08006044 if (DBG) {
6045 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6046 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6047 + p3 + " data=" + data);
6048 }
6049 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6050 command, p1, p2, p3, data);
6051 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006052
Jordan Liu4c733742019-02-28 12:03:40 -08006053 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006054 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006055 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006056 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006057
6058 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6059 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6060 "iccTransmitApduLogicalChannelBySlot");
6061
Jordan Liu4c733742019-02-28 12:03:40 -08006062 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006063 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006064 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6065 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006066 }
6067 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006068 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6069 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006070 }
6071
6072 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6073 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 final long identity = Binder.clearCallingIdentity();
6075 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006076 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 return "";
6078 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006081 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6082 null /* workSource */);
6083 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 // Append the returned status code to the end of the response payload.
6086 String s = Integer.toHexString(
6087 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6088 if (response.payload != null) {
6089 s = IccUtils.bytesToHexString(response.payload) + s;
6090 }
6091 return s;
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006094 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006095 }
Jake Hambye994d462014-02-03 13:10:13 -08006096
Evan Charltonc66da362014-05-16 14:06:40 -07006097 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006098 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6099 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6101 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006103
6104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6105 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6106
Jordan Liu4c733742019-02-28 12:03:40 -08006107 if (DBG) {
6108 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6109 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6110 }
6111 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6112 cla, command, p1, p2, p3, data);
6113 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006114
Jordan Liu4c733742019-02-28 12:03:40 -08006115 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006116 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006117 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006118 enforceModifyPermission();
6119 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006120
6121 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6122 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6123
Jordan Liu4c733742019-02-28 12:03:40 -08006124 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006125 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006126 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6127 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006128 }
6129
6130 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006131 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6132 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006133 }
6134
6135 // open APDU basic channel assuming the caller has sufficient permissions
6136 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6137 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6141 && TextUtils.equals(ISDR_AID, data)) {
6142 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006143 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6144 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145 if (bestComponent == null
6146 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6147 loge("The calling package is not allowed to select ISD-R.");
6148 throw new SecurityException(
6149 "The calling package is not allowed to select ISD-R.");
6150 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006151 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006154 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6155 null /* workSource */);
6156 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 // Append the returned status code to the end of the response payload.
6159 String s = Integer.toHexString(
6160 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6161 if (response.payload != null) {
6162 s = IccUtils.bytesToHexString(response.payload) + s;
6163 }
6164 return s;
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006167 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006168 }
6169
6170 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006171 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006172 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6174 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006175
joonhunshin4ac60942023-11-15 15:23:39 +00006176 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6177 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179 final long identity = Binder.clearCallingIdentity();
6180 try {
6181 if (DBG) {
6182 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6183 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6184 }
6185
6186 IccIoResult response =
6187 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6188 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6189 subId);
6190
6191 if (DBG) {
6192 log("Exchange SIM_IO [R]" + response);
6193 }
6194
6195 byte[] result = null;
6196 int length = 2;
6197 if (response.payload != null) {
6198 length = 2 + response.payload.length;
6199 result = new byte[length];
6200 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6201 } else {
6202 result = new byte[length];
6203 }
6204
6205 result[length - 1] = (byte) response.sw2;
6206 result[length - 2] = (byte) response.sw1;
6207 return result;
6208 } finally {
6209 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006210 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006211 }
6212
Nathan Haroldb3014052017-01-25 15:57:32 -08006213 /**
6214 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6215 * on a particular subscription
6216 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006217 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6218 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006220 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006221 return null;
6222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223
joonhunshin4ac60942023-11-15 15:23:39 +00006224 enforceTelephonyFeatureWithException(callingPackage,
6225 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 if (appType != TelephonyManager.APPTYPE_USIM
6230 && appType != TelephonyManager.APPTYPE_SIM) {
6231 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6232 return null;
6233 }
6234 Object response = sendRequest(
6235 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6236 if (response instanceof String[]) {
6237 return (String[]) response;
6238 }
yincheng zhao2737e882019-09-06 17:06:54 -07006239 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006241 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 } finally {
6243 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006244 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006245 }
6246
yincheng zhao2737e882019-09-06 17:06:54 -07006247 /**
6248 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6249 * subscription.
6250 *
6251 * @param subId the id of the subscription.
6252 * @param appType the uicc app type, must be USIM or SIM.
6253 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6254 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006255 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006256 * @return number of fplmns that is successfully written to the SIM.
6257 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006258 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6259 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6261 mApp, subId, "setForbiddenPlmns");
6262
joonhunshin4ac60942023-11-15 15:23:39 +00006263 enforceTelephonyFeatureWithException(callingPackage,
6264 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6265
yincheng zhao2737e882019-09-06 17:06:54 -07006266 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6267 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6268 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6269 }
6270 if (fplmns == null) {
6271 throw new IllegalArgumentException("Fplmn List provided is null");
6272 }
6273 for (String fplmn : fplmns) {
6274 if (!CellIdentity.isValidPlmn(fplmn)) {
6275 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6276 }
6277 }
6278 final long identity = Binder.clearCallingIdentity();
6279 try {
6280 Object response = sendRequest(
6281 CMD_SET_FORBIDDEN_PLMNS,
6282 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6283 subId);
6284 return (int) response;
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
6287 }
6288 }
6289
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006290 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006291 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6293 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006294
joonhunshin4ac60942023-11-15 15:23:39 +00006295 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6296 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 final long identity = Binder.clearCallingIdentity();
6299 try {
6300 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6301 if (response.payload == null) {
6302 return "";
6303 }
Evan Charltonc66da362014-05-16 14:06:40 -07006304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 // Append the returned status code to the end of the response payload.
6306 String s = Integer.toHexString(
6307 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6308 s = IccUtils.bytesToHexString(response.payload) + s;
6309 return s;
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
Evan Charltonc66da362014-05-16 14:06:40 -07006313 }
6314
Jake Hambye994d462014-02-03 13:10:13 -08006315 /**
6316 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6317 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6318 *
6319 * @param itemID the ID of the item to read
6320 * @return the NV item as a String, or null on error.
6321 */
6322 @Override
6323 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006324 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6326 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
6330 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006331 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6333 return value;
6334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
Jake Hambye994d462014-02-03 13:10:13 -08006337 }
6338
6339 /**
6340 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6341 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6342 *
6343 * @param itemID the ID of the item to read
6344 * @param itemValue the value to write, as a String
6345 * @return true on success; false on any failure
6346 */
6347 @Override
6348 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6351 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6356 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006357 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6359 return success;
6360 } finally {
6361 Binder.restoreCallingIdentity(identity);
6362 }
Jake Hambye994d462014-02-03 13:10:13 -08006363 }
6364
6365 /**
6366 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6367 * Used for device configuration by some CDMA operators.
6368 *
6369 * @param preferredRoamingList byte array containing the new PRL
6370 * @return true on success; false on any failure
6371 */
6372 @Override
6373 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6375 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376
6377 final long identity = Binder.clearCallingIdentity();
6378 try {
6379 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6380 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6381 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6382 return success;
6383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
Jake Hambye994d462014-02-03 13:10:13 -08006386 }
6387
6388 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006389 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006390 * Used for device configuration by some CDMA operators.
6391 *
chen xu6dac5ab2018-10-26 17:39:23 -07006392 * @param slotIndex - device slot.
6393 *
Jake Hambye994d462014-02-03 13:10:13 -08006394 * @return true on success; false on any failure
6395 */
6396 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006397 public boolean resetModemConfig(int slotIndex) {
6398 Phone phone = PhoneFactory.getPhone(slotIndex);
6399 if (phone != null) {
6400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6401 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402
joonhunshin4ac60942023-11-15 15:23:39 +00006403 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6404 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6405
chen xu6dac5ab2018-10-26 17:39:23 -07006406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6409 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6410 return success;
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 }
chen xu6dac5ab2018-10-26 17:39:23 -07006415 return false;
6416 }
6417
6418 /**
6419 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6420 *
6421 * @param slotIndex - device slot.
6422 *
6423 * @return true on success; false on any failure
6424 */
6425 @Override
6426 public boolean rebootModem(int slotIndex) {
6427 Phone phone = PhoneFactory.getPhone(slotIndex);
6428 if (phone != null) {
6429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6430 mApp, phone.getSubId(), "rebootModem");
6431
joonhunshin4ac60942023-11-15 15:23:39 +00006432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6433 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6434
chen xu6dac5ab2018-10-26 17:39:23 -07006435 final long identity = Binder.clearCallingIdentity();
6436 try {
6437 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6438 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6439 return success;
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
6443 }
6444 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006445 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006446
Brad Ebinger51f743a2017-01-23 13:50:20 -08006447 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006448 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6449 * {@link #disableIms(int)}.
6450 * @param slotIndex device slot.
6451 */
6452 public void resetIms(int slotIndex) {
6453 enforceModifyPermission();
6454
joonhunshin4ac60942023-11-15 15:23:39 +00006455 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6456 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6457
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006458 final long identity = Binder.clearCallingIdentity();
6459 try {
6460 if (mImsResolver == null) {
6461 // may happen if the does not support IMS.
6462 return;
6463 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006464 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006465 } finally {
6466 Binder.restoreCallingIdentity(identity);
6467 }
6468 }
6469
6470 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006471 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6472 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006473 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006474 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006475 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476
6477 final long identity = Binder.clearCallingIdentity();
6478 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006479 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006480 // may happen if the device does not support IMS.
6481 return;
6482 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006483 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006487 }
6488
6489 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006490 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6491 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006492 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006493 public void disableIms(int slotId) {
6494 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006498 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006499 // may happen if the device does not support IMS.
6500 return;
6501 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006502 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006506 }
6507
6508 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006509 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6510 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006511 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006512 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006513 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006514 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515
6516 final long identity = Binder.clearCallingIdentity();
6517 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006518 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006519 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6520 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006521 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006522 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006526 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006527 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006528 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6529 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006530 @Override
6531 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006532 enforceModifyPermission();
6533
6534 final long identity = Binder.clearCallingIdentity();
6535 try {
6536 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006537 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
6541 }
6542
6543 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006544 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006545 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006546 */
6547 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549
6550 final long identity = Binder.clearCallingIdentity();
6551 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006552 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006553 // may happen if the device does not support IMS.
6554 return null;
6555 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006556 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
6559 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006560 }
6561
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006562 /**
6563 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006564 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006565 */
6566 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568
6569 final long identity = Binder.clearCallingIdentity();
6570 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006571 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006572 // may happen if the device does not support IMS.
6573 return null;
6574 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006575 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 } finally {
6577 Binder.restoreCallingIdentity(identity);
6578 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006579 }
6580
Brad Ebinger884c07b2018-02-15 16:17:40 -08006581 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006582 * Sets the ImsService Package Name that Telephony will bind to.
6583 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006584 * @param slotIndex the slot ID that the ImsService should bind for.
6585 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006586 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006587 * @param featureTypes An integer array of feature types associated with a packageName.
6588 * @param packageName The name of the package that the current configuration will be replaced
6589 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006590 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006591 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006592 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6593 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006594 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006596 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 final long identity = Binder.clearCallingIdentity();
6599 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006600 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006601 // may happen if the device does not support IMS.
6602 return false;
6603 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006604 Map<Integer, String> featureConfig = new HashMap<>();
6605 for (int featureType : featureTypes) {
6606 featureConfig.put(featureType, packageName);
6607 }
6608 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6609 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006613 }
6614
6615 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006616 * Clears any carrier ImsService overrides for the slot index specified that were previously
6617 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6618 *
6619 * This should only be used for testing.
6620 *
6621 * @param slotIndex the slot ID that the ImsService should bind for.
6622 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6623 */
6624 @Override
6625 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6627 "clearCarrierImsServiceOverride");
6628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006629 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006630
6631 final long identity = Binder.clearCallingIdentity();
6632 try {
6633 if (mImsResolver == null) {
6634 // may happen if the device does not support IMS.
6635 return false;
6636 }
6637 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6638 } finally {
6639 Binder.restoreCallingIdentity(identity);
6640 }
6641 }
6642
6643 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006644 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006645 *
6646 * @param slotId The slot that the ImsService is associated with.
6647 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6648 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006649 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006650 * @return the package name of the ImsService configuration.
6651 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6653 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006655 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6656 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 final long identity = Binder.clearCallingIdentity();
6659 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006660 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006661 // may happen if the device does not support IMS.
6662 return "";
6663 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006664 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006665 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6666 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667 } finally {
6668 Binder.restoreCallingIdentity(identity);
6669 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006670 }
6671
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006672 /**
6673 * Get the MmTelFeature state associated with the requested subscription id.
6674 * @param subId The subscription that the MmTelFeature is associated with.
6675 * @param callback A callback with an integer containing the
6676 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6677 */
6678 @Override
6679 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6680 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006681 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6682 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6683 "IMS not available on device.");
6684 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006685 final long token = Binder.clearCallingIdentity();
6686 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006687 int slotId = getSlotIndex(subId);
6688 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6689 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6690 + subId + "'");
6691 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6692 }
6693 verifyImsMmTelConfiguredOrThrow(slotId);
6694 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6695 try {
6696 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6697 } catch (RemoteException e) {
6698 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6699 + "Ignore");
6700 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006701 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006702 } catch (ImsException e) {
6703 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006704 } finally {
6705 Binder.restoreCallingIdentity(token);
6706 }
6707 }
6708
Daniel Brightbb5840b2021-01-12 15:48:18 -08006709 /**
6710 * Sets the ims registration state on all valid {@link Phone}s.
6711 */
6712 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714
6715 final long identity = Binder.clearCallingIdentity();
6716 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006717 // NOTE: Before S, this method only set the default phone.
6718 for (final Phone phone : PhoneFactory.getPhones()) {
6719 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6720 phone.setImsRegistrationState(registered);
6721 }
6722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
Wink Saville36469e72014-06-11 15:17:00 -07006726 }
6727
6728 /**
Stuart Scott54788802015-03-30 13:18:01 -07006729 * Set the network selection mode to automatic.
6730 *
6731 */
6732 @Override
6733 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6735 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736
joonhunshin4ac60942023-11-15 15:23:39 +00006737 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6738 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 final long identity = Binder.clearCallingIdentity();
6741 try {
shilufc958392020-01-20 11:36:01 -08006742 if (!isActiveSubscription(subId)) {
6743 return;
6744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006746 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6747 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 } finally {
6749 Binder.restoreCallingIdentity(identity);
6750 }
Stuart Scott54788802015-03-30 13:18:01 -07006751 }
6752
Jack Yud10cdd42020-09-28 20:28:01 -07006753 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006754 * Ask the radio to connect to the input network and change selection mode to manual.
6755 *
6756 * @param subId the id of the subscription.
6757 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6758 * the operator to attach to.
6759 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6760 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6761 * normal network selection next time.
6762 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006763 */
6764 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006765 public boolean setNetworkSelectionModeManual(
6766 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6768 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006769
joonhunshin4ac60942023-11-15 15:23:39 +00006770 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6771 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6772
Jack Yu285100e2022-12-02 22:48:35 -08006773 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006774 if (!isActiveSubscription(subId)) {
6775 return false;
6776 }
6777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006779 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006781 if (DBG) {
6782 log("setNetworkSelectionModeManual: subId: " + subId
6783 + " operator: " + operatorInfo);
6784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6786 } finally {
6787 Binder.restoreCallingIdentity(identity);
6788 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006789 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006790 /**
shilu84f6e8b2019-12-19 13:58:01 -08006791 * Get the manual network selection
6792 *
6793 * @param subId the id of the subscription.
6794 *
6795 * @return the previously saved user selected PLMN
6796 */
6797 @Override
6798 public String getManualNetworkSelectionPlmn(int subId) {
6799 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006800 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6801 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006802
joonhunshin4ac60942023-11-15 15:23:39 +00006803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6804 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6805
shilu84f6e8b2019-12-19 13:58:01 -08006806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006809 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006810 }
6811
6812 final Phone phone = getPhone(subId);
6813 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006814 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006815 }
6816 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6817 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006818 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
6822 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006823
6824 /**
6825 * Scans for available networks.
6826 */
6827 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006828 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6829 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6831 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006832 LocationAccessPolicy.LocationPermissionResult locationResult =
6833 LocationAccessPolicy.checkLocationPermission(mApp,
6834 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6835 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006836 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006837 .setCallingPid(Binder.getCallingPid())
6838 .setCallingUid(Binder.getCallingUid())
6839 .setMethod("getCellNetworkScanResults")
6840 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006841 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6842 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006843 .build());
6844 switch (locationResult) {
6845 case DENIED_HARD:
6846 throw new SecurityException("Not allowed to access scan results -- location");
6847 case DENIED_SOFT:
6848 return null;
6849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850
Pengquan Menga1bb6272018-09-06 09:59:22 -07006851 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 try {
6853 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006854 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006859 }
6860
6861 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006862 * Get the call forwarding info, given the call forwarding reason.
6863 */
6864 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006865 public void getCallForwarding(int subId, int callForwardingReason,
6866 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006867 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006868
6869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6870 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6871
Shuo Qian4a594052020-01-23 11:59:30 -08006872 long identity = Binder.clearCallingIdentity();
6873 try {
6874 if (DBG) {
6875 log("getCallForwarding: subId " + subId
6876 + " callForwardingReason" + callForwardingReason);
6877 }
Hall Liu27d24262020-09-18 19:04:59 -07006878
6879 Phone phone = getPhone(subId);
6880 if (phone == null) {
6881 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006882 callback.onError(
6883 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006884 } catch (RemoteException e) {
6885 // ignore
6886 }
6887 return;
6888 }
6889
6890 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6891 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6892 @Override
6893 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6894 try {
6895 callback.onCallForwardingInfoAvailable(info);
6896 } catch (RemoteException e) {
6897 // ignore
6898 }
6899 }
6900
6901 @Override
6902 public void onError(int error) {
6903 try {
6904 callback.onError(error);
6905 } catch (RemoteException e) {
6906 // ignore
6907 }
6908 }
6909 });
6910 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006911 } finally {
6912 Binder.restoreCallingIdentity(identity);
6913 }
6914 }
6915
6916 /**
6917 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6918 * reason, the number to forward, and the timeout before the forwarding is attempted.
6919 */
6920 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006921 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6922 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006923 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006924
6925 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6926 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6927
Shuo Qian4a594052020-01-23 11:59:30 -08006928 long identity = Binder.clearCallingIdentity();
6929 try {
6930 if (DBG) {
6931 log("setCallForwarding: subId " + subId
6932 + " callForwardingInfo" + callForwardingInfo);
6933 }
Hall Liu27d24262020-09-18 19:04:59 -07006934
6935 Phone phone = getPhone(subId);
6936 if (phone == null) {
6937 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006938 callback.accept(
6939 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006940 } catch (RemoteException e) {
6941 // ignore
6942 }
6943 return;
6944 }
6945
6946 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6947 FunctionalUtils.ignoreRemoteException(callback::accept));
6948
6949 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006950 } finally {
6951 Binder.restoreCallingIdentity(identity);
6952 }
6953 }
6954
6955 /**
Hall Liu27d24262020-09-18 19:04:59 -07006956 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006957 */
6958 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006959 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006960 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006961
6962 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6963 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6964
Shuo Qian4a594052020-01-23 11:59:30 -08006965 long identity = Binder.clearCallingIdentity();
6966 try {
Hall Liu27d24262020-09-18 19:04:59 -07006967 Phone phone = getPhone(subId);
6968 if (phone == null) {
6969 try {
6970 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6971 } catch (RemoteException e) {
6972 // ignore
6973 }
6974 return;
6975 }
SongFerngWang0e767992021-03-31 22:08:45 +08006976 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6977 PersistableBundle c = configManager.getConfigForSubId(subId);
6978 boolean requireUssd = c.getBoolean(
6979 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006980
Shuo Qian4a594052020-01-23 11:59:30 -08006981 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006982 if (requireUssd) {
6983 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6984 getSubscriptionCarrierId(subId));
6985 String newUssdCommand = "";
6986 try {
6987 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006988 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006989 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6990 } catch (NullPointerException e) {
6991 loge("Failed to generate USSD number" + e);
6992 }
6993 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6994 mMainThreadHandler, callback, carrierXmlParser,
6995 CarrierXmlParser.SsEntry.SSAction.QUERY);
6996 final String ussdCommand = newUssdCommand;
6997 Executors.newSingleThreadExecutor().execute(() -> {
6998 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6999 });
7000 } else {
7001 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7002 callback::accept);
7003 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7004 }
Shuo Qian4a594052020-01-23 11:59:30 -08007005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
7008 }
7009
7010 /**
Hall Liu27d24262020-09-18 19:04:59 -07007011 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007012 */
7013 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007014 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007015 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007016
7017 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7018 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7019
Shuo Qian4a594052020-01-23 11:59:30 -08007020 long identity = Binder.clearCallingIdentity();
7021 try {
Hall Liu27d24262020-09-18 19:04:59 -07007022 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7023
7024 Phone phone = getPhone(subId);
7025 if (phone == null) {
7026 try {
7027 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7028 } catch (RemoteException e) {
7029 // ignore
7030 }
7031 return;
7032 }
7033
SongFerngWang0e767992021-03-31 22:08:45 +08007034 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7035 PersistableBundle c = configManager.getConfigForSubId(subId);
7036 boolean requireUssd = c.getBoolean(
7037 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007038
SongFerngWang0e767992021-03-31 22:08:45 +08007039 if (DBG) log("getCallWaitingStatus: subId " + subId);
7040 if (requireUssd) {
7041 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7042 getSubscriptionCarrierId(subId));
7043 CarrierXmlParser.SsEntry.SSAction ssAction =
7044 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7045 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7046 String newUssdCommand = "";
7047 try {
7048 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007049 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007050 .makeCommand(ssAction, null);
7051 } catch (NullPointerException e) {
7052 loge("Failed to generate USSD number" + e);
7053 }
7054 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7055 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7056 final String ussdCommand = newUssdCommand;
7057 Executors.newSingleThreadExecutor().execute(() -> {
7058 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7059 });
7060 } else {
7061 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7062 FunctionalUtils.ignoreRemoteException(callback::accept));
7063
7064 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7065 }
Shuo Qian4a594052020-01-23 11:59:30 -08007066 } finally {
7067 Binder.restoreCallingIdentity(identity);
7068 }
7069 }
7070
7071 /**
yinxub1bed742017-04-17 11:45:04 -07007072 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007073 *
yinxub1bed742017-04-17 11:45:04 -07007074 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007075 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7076 * location related information which will be sent if the caller already possess
7077 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007078 * @param request contains the radio access networks with bands/channels to scan
7079 * @param messenger callback messenger for scan results or errors
7080 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007081 * @return the id of the requested scan which can be used to stop the scan.
7082 */
7083 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007084 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7085 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007086 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7088 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007089 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007090 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7091 if (!renounceFineLocationAccess) {
7092 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007093 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7094 .setCallingPackage(callingPackage)
7095 .setCallingFeatureId(callingFeatureId)
7096 .setCallingPid(Binder.getCallingPid())
7097 .setCallingUid(Binder.getCallingUid())
7098 .setMethod("requestNetworkScan")
7099 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7100 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7101 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7102 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007103 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007104 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007105 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7106 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007107 if (e != null) {
7108 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7109 throw e;
7110 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007111 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007112 return TelephonyScanManager.INVALID_SCAN_ID;
7113 }
7114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 }
joonhunshin4ac60942023-11-15 15:23:39 +00007116
7117 enforceTelephonyFeatureWithException(callingPackage,
7118 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7119
Hall Liu912dfd32019-04-25 14:02:26 -07007120 int callingUid = Binder.getCallingUid();
7121 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007122 final long identity = Binder.clearCallingIdentity();
7123 try {
7124 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007125 renounceFineLocationAccess, request, messenger, binder,
7126 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007127 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
yinxu504e1392017-04-12 16:03:22 -07007131 }
7132
Hall Liub2ac8ef2019-02-28 15:56:23 -08007133 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007134 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007135 boolean hasCarrierPriv;
7136 final long identity = Binder.clearCallingIdentity();
7137 try {
7138 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7139 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
Hall Liu558027f2019-05-15 19:14:05 -07007143 boolean hasNetworkScanPermission =
7144 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007145 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007146
7147 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7148 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7149 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007150 }
7151
7152 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7153 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007154 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7155 return new SecurityException("Specific channels must not be"
7156 + " scanned without location access.");
7157 }
7158 }
7159 }
7160
Hall Liub2ac8ef2019-02-28 15:56:23 -08007161 return null;
7162 }
7163
yinxu504e1392017-04-12 16:03:22 -07007164 /**
7165 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007166 *
7167 * @param subId id of the subscription
7168 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007169 */
7170 @Override
7171 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7173 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174
Hall Liu912dfd32019-04-25 14:02:26 -07007175 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 final long identity = Binder.clearCallingIdentity();
7177 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007178 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 } finally {
7180 Binder.restoreCallingIdentity(identity);
7181 }
yinxu504e1392017-04-12 16:03:22 -07007182 }
7183
7184 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007185 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007186 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007187 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007188 */
7189 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007190 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007191 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007192 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007193 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194
joonhunshin4ac60942023-11-15 15:23:39 +00007195 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7196 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198 final long identity = Binder.clearCallingIdentity();
7199 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007200 if (DBG) log("getAllowedNetworkTypesBitmask");
7201 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7202 int networkTypesBitmask = (result != null ? result[0] : -1);
7203 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7204 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 } finally {
7206 Binder.restoreCallingIdentity(identity);
7207 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007208 }
7209
7210 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007211 * Get the allowed network types for certain reason.
7212 *
7213 * @param subId the id of the subscription.
7214 * @param reason the reason the allowed network type change is taking place
7215 * @return the allowed network types.
7216 */
7217 @Override
7218 public long getAllowedNetworkTypesForReason(int subId,
7219 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007220 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007221 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007222
7223 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7224 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7225
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007226 final long identity = Binder.clearCallingIdentity();
7227 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007228 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007229 } finally {
7230 Binder.restoreCallingIdentity(identity);
7231 }
7232 }
7233
7234 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007235 * Enable/Disable E-UTRA-NR Dual Connectivity
7236 * @param subId subscription id of the sim card
7237 * @param nrDualConnectivityState expected NR dual connectivity state
7238 * This can be passed following states
7239 * <ol>
7240 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7241 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7242 * <li>Disable NR dual connectivity and force secondary cell to be released
7243 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7244 * </ol>
7245 * @return operation result.
7246 */
7247 @Override
7248 public int setNrDualConnectivityState(int subId,
7249 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7251 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007252 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007253 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7254 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7255 }
7256
Sooraj Sasindran37444802020-08-11 10:40:43 -07007257 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7258 final long identity = Binder.clearCallingIdentity();
7259 try {
7260 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7261 nrDualConnectivityState, subId,
7262 workSource);
7263 if (DBG) log("enableNRDualConnectivity result: " + result);
7264 return result;
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
7268 }
7269
7270 /**
7271 * Is E-UTRA-NR Dual Connectivity enabled
7272 * @return true if dual connectivity is enabled else false
7273 */
7274 @Override
7275 public boolean isNrDualConnectivityEnabled(int subId) {
7276 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007277 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007278 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007279 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007280 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7281 return false;
7282 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007283 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7284 final long identity = Binder.clearCallingIdentity();
7285 try {
7286 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7287 null, subId, workSource);
7288 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7289 return isEnabled;
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
7295 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007296 * Set the allowed network types of the device and
7297 * provide the reason triggering the allowed network change.
7298 *
7299 * @param subId the id of the subscription.
7300 * @param reason the reason the allowed network type change is taking place
7301 * @param allowedNetworkTypes the allowed network types.
7302 * @return true on success; false on any failure.
7303 */
7304 @Override
7305 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007306 @TelephonyManager.AllowedNetworkTypesReason int reason,
7307 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7309 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007310 // If the caller only has carrier privileges, then they should not be able to override
7311 // any network types which were set for security reasons.
7312 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7313 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007314 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007315 throw new SecurityException(
7316 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007317 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007318 }
joonhunshin4ac60942023-11-15 15:23:39 +00007319
7320 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7321 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7322
SongFerngWang3ef3e072020-12-21 16:41:52 +08007323 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007324 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007325 return false;
7326 }
7327 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7328 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007329 return false;
7330 }
7331
Jack Yu5b494332023-01-23 18:18:04 +00007332 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7333 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007334
Jack Yue37dd262022-12-16 11:53:37 -08007335 Phone phone = getPhone(subId);
7336 if (phone == null) {
7337 return false;
7338 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007339
Jack Yue37dd262022-12-16 11:53:37 -08007340 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007341 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007342 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007343 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007344
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007345 final long identity = Binder.clearCallingIdentity();
7346 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007347 Boolean success = (Boolean) sendRequest(
7348 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7349 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7350
7351 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7352 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
7356 }
7357
7358 /**
Miaoa84611c2019-03-15 09:21:10 +08007359 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007360 *
Miaoa84611c2019-03-15 09:21:10 +08007361 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007362 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007363 * @hide
7364 */
7365 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007366 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007367 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007368
7369 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7370 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007373 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 try {
Miaoa84611c2019-03-15 09:21:10 +08007375 if (phone != null) {
7376 return phone.hasMatchedTetherApnSetting();
7377 } else {
7378 return false;
7379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 } finally {
7381 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007382 }
Junda Liu475951f2014-11-07 16:45:03 -08007383 }
7384
7385 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007386 * Get the user enabled state of Mobile Data.
7387 *
7388 * TODO: remove and use isUserDataEnabled.
7389 * This can't be removed now because some vendor codes
7390 * calls through ITelephony directly while they should
7391 * use TelephonyManager.
7392 *
7393 * @return true on enabled
7394 */
7395 @Override
7396 public boolean getDataEnabled(int subId) {
7397 return isUserDataEnabled(subId);
7398 }
7399
7400 /**
7401 * Get whether mobile data is enabled per user setting.
7402 *
7403 * There are other factors deciding whether mobile data is actually enabled, but they are
7404 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007405 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007406 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7407 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007408 *
7409 * @return {@code true} if data is enabled else {@code false}
7410 */
7411 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007412 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007413 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007414 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007415 try {
7416 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7417 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007418 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007419 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7420 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007421 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007423 mApp, subId, functionName);
7424
Robert Greenwalt646120a2014-05-23 11:54:03 -07007425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426
7427 final long identity = Binder.clearCallingIdentity();
7428 try {
Jack Yu285100e2022-12-02 22:48:35 -08007429 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7431 Phone phone = PhoneFactory.getPhone(phoneId);
7432 if (phone != null) {
7433 boolean retVal = phone.isUserDataEnabled();
7434 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7435 return retVal;
7436 } else {
7437 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7438 return false;
7439 }
7440 } finally {
7441 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007442 }
7443 }
7444
7445 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007446 * Checks if the device is capable of mobile data by considering whether whether the
7447 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7448 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007449 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007450 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007451 */
7452 @Override
7453 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007454 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007455 try {
7456 try {
7457 mApp.enforceCallingOrSelfPermission(
7458 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007459 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007460 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007461 try {
7462 mApp.enforceCallingOrSelfPermission(
7463 android.Manifest.permission.READ_PHONE_STATE,
7464 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007465 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007466 mApp.enforceCallingOrSelfPermission(
7467 permission.READ_BASIC_PHONE_STATE, functionName);
7468 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007469 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007470 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007471 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473
joonhunshin4ac60942023-11-15 15:23:39 +00007474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7475 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 final long identity = Binder.clearCallingIdentity();
7478 try {
Jack Yu285100e2022-12-02 22:48:35 -08007479 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 Phone phone = PhoneFactory.getPhone(phoneId);
7481 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007482 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007483 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 return retVal;
7485 } else {
7486 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7487 return false;
7488 }
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007491 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007492 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007493
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007494 /**
7495 * Check if data is enabled for a specific reason
7496 * @param subId Subscription index
7497 * @param reason the reason the data enable change is taking place
7498 * @return {@code true} if the overall data is enabled; {@code false} if not.
7499 */
7500 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007501 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007502 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007503 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007504 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007505 try {
7506 mApp.enforceCallingOrSelfPermission(
7507 android.Manifest.permission.ACCESS_NETWORK_STATE,
7508 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007509 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007510 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7511 functionName);
7512 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007513 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007514 try {
7515 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007517 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007519 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007520 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007521 }
7522
joonhunshin4ac60942023-11-15 15:23:39 +00007523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7524 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007525
7526 final long identity = Binder.clearCallingIdentity();
7527 try {
Jack Yu285100e2022-12-02 22:48:35 -08007528 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007529 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007530 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007531 + " reason=" + reason);
7532 }
7533 Phone phone = PhoneFactory.getPhone(phoneId);
7534 if (phone != null) {
7535 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007536 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007537 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007538 return retVal;
7539 } else {
7540 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007541 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007542 + subId + " retVal=false");
7543 }
7544 return false;
7545 }
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
7549 }
7550
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007551 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007552 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007553 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7554 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7555
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007556 // No permission needed; this only lets the caller inspect their own status.
7557 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007558 }
Junda Liu29340342014-07-10 15:23:27 -07007559
7560 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007561 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007562 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007563
7564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7565 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7566
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007567 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7568 }
7569
7570 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7571 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007572 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007573 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7575 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007576 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7577 if (cpt == null) {
7578 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007579 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7580 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007581 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007582 }
7583
7584 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007585 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007586 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007587
7588 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7589 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7590
chen xuf7e9fe82019-05-09 19:31:02 -07007591 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007592 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007593 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007594 Phone phone = getPhone(subId);
7595 if (phone == null) {
7596 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7597 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7598 }
7599 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7600 if (cpt == null) {
7601 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007602 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7603 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007604 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007605 }
7606
7607 @Override
7608 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007609 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007610
7611 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7612 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7613 "checkCarrierPrivilegesForPackageAnyPhone");
7614
Rambo Wange7209ce2022-02-23 13:41:02 -08007615 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7616 }
7617
7618 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007619 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007620 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007621 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007622 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007623 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7624 Phone phone = PhoneFactory.getPhone(phoneId);
7625 if (phone == null) {
7626 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007627 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007628 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7629 if (cpt == null) {
7630 continue;
7631 }
7632 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007633 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7634 break;
7635 }
7636 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007637 return result;
Junda Liu29340342014-07-10 15:23:27 -07007638 }
Derek Tan89e89d42014-07-08 17:00:10 -07007639
7640 @Override
Junda Liue64de782015-04-16 17:19:16 -07007641 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007642 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007643
7644 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7645 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7646 "getCarrierPackageNamesForIntentAndPhone");
7647
Rambo Wang8a247eb2022-02-08 21:11:18 +00007648 Phone phone = PhoneFactory.getPhone(phoneId);
7649 if (phone == null) {
7650 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007651 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007652 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7653 if (cpt == null) {
7654 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007655 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007656 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007657 }
7658
Amith Yamasani6e118872016-02-19 12:53:51 -08007659 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007660 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007661 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007662 Phone phone = PhoneFactory.getPhone(phoneId);
7663 if (phone == null) {
7664 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007665 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007666 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7667 if (cpt == null) {
7668 return Collections.emptyList();
7669 }
7670 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007671 }
7672
chen xuf7e9fe82019-05-09 19:31:02 -07007673 @Override
7674 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007675 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007676
7677 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7678 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7679 "getPackagesWithCarrierPrivilegesForAllPhones");
7680
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007681 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007682 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007683 try {
7684 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7685 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7686 }
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007689 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007690 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007691 }
7692
Rambo Wang6812ffb2022-03-15 16:54:17 -07007693 @Override
7694 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7695 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7696
joonhunshin4ac60942023-11-15 15:23:39 +00007697 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7698 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7699 "getCarrierServicePackageNameForLogicalSlot");
7700
Rambo Wang6812ffb2022-03-15 16:54:17 -07007701 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7702 if (phone == null) {
7703 return null;
7704 }
7705 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7706 if (cpt == null) {
7707 return null;
7708 }
7709 return cpt.getCarrierServicePackageName();
7710 }
7711
Wink Savilleb564aae2014-10-23 10:18:09 -07007712 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007713 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007714 UiccPort port = phone == null ? null : phone.getUiccPort();
7715 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007716 return null;
7717 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007718 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007719 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007720 return null;
7721 }
7722 return iccId;
7723 }
7724
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007725 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007726 public void setCallComposerStatus(int subId, int status) {
7727 enforceModifyPermission();
7728
joonhunshin4ac60942023-11-15 15:23:39 +00007729 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7730 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7731
Shuo Qiane4e11672020-12-15 22:15:33 -08007732 final long identity = Binder.clearCallingIdentity();
7733 try {
7734 Phone phone = getPhone(subId);
7735 if (phone != null) {
7736 Phone defaultPhone = phone.getImsPhone();
7737 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7738 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7739 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007740 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7741 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007742 }
7743 }
Shuo Qian284ae752020-12-22 19:10:14 -08007744 } catch (ImsException e) {
7745 throw new ServiceSpecificException(e.getCode());
7746 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007747 Binder.restoreCallingIdentity(identity);
7748 }
7749 }
7750
7751 @Override
7752 public int getCallComposerStatus(int subId) {
7753 enforceReadPrivilegedPermission("getCallComposerStatus");
7754
joonhunshin4ac60942023-11-15 15:23:39 +00007755 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7756 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7757
Shuo Qiane4e11672020-12-15 22:15:33 -08007758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 Phone phone = getPhone(subId);
7761 if (phone != null) {
7762 Phone defaultPhone = phone.getImsPhone();
7763 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7764 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7765 return imsPhone.getCallComposerStatus();
7766 }
7767 }
7768 } finally {
7769 Binder.restoreCallingIdentity(identity);
7770 }
7771 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7772 }
7773
7774 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007775 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7776 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007777 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007778 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007779
joonhunshin4ac60942023-11-15 15:23:39 +00007780 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7781 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7782 "setLine1NumberForDisplayForSubscriber");
7783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 final long identity = Binder.clearCallingIdentity();
7785 try {
7786 final String iccId = getIccId(subId);
7787 final Phone phone = getPhone(subId);
7788 if (phone == null) {
7789 return false;
7790 }
7791 final String subscriberId = phone.getSubscriberId();
7792
7793 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007794 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 + subscriberId + " to " + number);
7796 }
7797
7798 if (TextUtils.isEmpty(iccId)) {
7799 return false;
7800 }
7801
7802 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7803
7804 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7805 if (alphaTag == null) {
7806 editor.remove(alphaTagPrefKey);
7807 } else {
7808 editor.putString(alphaTagPrefKey, alphaTag);
7809 }
7810
7811 // Record both the line number and IMSI for this ICCID, since we need to
7812 // track all merged IMSIs based on line number
7813 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7814 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7815 if (number == null) {
7816 editor.remove(numberPrefKey);
7817 editor.remove(subscriberPrefKey);
7818 } else {
7819 editor.putString(numberPrefKey, number);
7820 editor.putString(subscriberPrefKey, subscriberId);
7821 }
7822
7823 editor.commit();
7824 return true;
7825 } finally {
7826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007827 }
Derek Tan7226c842014-07-02 17:42:23 -07007828 }
7829
7830 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007831 public String getLine1NumberForDisplay(int subId, String callingPackage,
7832 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007833 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007835 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007836 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007837 return null;
7838 }
Derek Tan97ebb422014-09-05 16:55:38 -07007839
joonhunshin4ac60942023-11-15 15:23:39 +00007840 enforceTelephonyFeatureWithException(callingPackage,
7841 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007843 final long identity = Binder.clearCallingIdentity();
7844 try {
7845 String iccId = getIccId(subId);
7846 if (iccId != null) {
7847 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7848 if (DBG_MERGE) {
7849 log("getLine1NumberForDisplay returning "
7850 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7851 }
7852 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7855 return null;
7856 } finally {
7857 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007858 }
Derek Tan7226c842014-07-02 17:42:23 -07007859 }
7860
7861 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007862 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7863 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007865 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007866 return null;
7867 }
Derek Tan97ebb422014-09-05 16:55:38 -07007868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 String iccId = getIccId(subId);
7872 if (iccId != null) {
7873 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7874 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7875 }
7876 return null;
7877 } finally {
7878 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007879 }
Derek Tan7226c842014-07-02 17:42:23 -07007880 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007881
7882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007883 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7884 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007885 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7886 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007888 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007889 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007890 return null;
7891 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007892
Jordan Liub49b04b2019-05-06 14:45:15 -07007893 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7894 // the process, where TelephonyManager was instantiated.
7895 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007896 final long identity = Binder.clearCallingIdentity();
7897 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007898 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 final TelephonyManager tele = TelephonyManager.from(context);
7900 final SubscriptionManager sub = SubscriptionManager.from(context);
7901
7902 // Figure out what subscribers are currently active
7903 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904
Jordan Liub49b04b2019-05-06 14:45:15 -07007905 // Only consider subs which match the current subId
7906 // This logic can be simplified. See b/131189269 for progress.
7907 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007908 activeSubscriberIds.add(tele.getSubscriberId(subId));
7909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910
7911 // First pass, find a number override for an active subscriber
7912 String mergeNumber = null;
7913 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7914 for (String key : prefs.keySet()) {
7915 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7916 final String subscriberId = (String) prefs.get(key);
7917 if (activeSubscriberIds.contains(subscriberId)) {
7918 final String iccId = key.substring(
7919 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7920 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7921 mergeNumber = (String) prefs.get(numberKey);
7922 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007923 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 + " for active subscriber " + subscriberId);
7925 }
7926 if (!TextUtils.isEmpty(mergeNumber)) {
7927 break;
7928 }
7929 }
7930 }
7931 }
7932
7933 // Shortcut when no active merged subscribers
7934 if (TextUtils.isEmpty(mergeNumber)) {
7935 return null;
7936 }
7937
7938 // Second pass, find all subscribers under that line override
7939 final ArraySet<String> result = new ArraySet<>();
7940 for (String key : prefs.keySet()) {
7941 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7942 final String number = (String) prefs.get(key);
7943 if (mergeNumber.equals(number)) {
7944 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7945 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7946 final String subscriberId = (String) prefs.get(subscriberKey);
7947 if (!TextUtils.isEmpty(subscriberId)) {
7948 result.add(subscriberId);
7949 }
7950 }
7951 }
7952 }
7953
7954 final String[] resultArray = result.toArray(new String[result.size()]);
7955 Arrays.sort(resultArray);
7956 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007957 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7959 }
7960 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007961 } finally {
7962 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007963 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007964 }
7965
7966 @Override
zoey chen38003472019-12-13 17:16:31 +08007967 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7968 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007969
joonhunshin4ac60942023-11-15 15:23:39 +00007970 enforceTelephonyFeatureWithException(callingPackage,
7971 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7972
Malcolm Chen6ca97372019-07-01 16:28:21 -07007973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 final TelephonyManager telephonyManager = mApp.getSystemService(
7976 TelephonyManager.class);
7977 String subscriberId = telephonyManager.getSubscriberId(subId);
7978 if (subscriberId == null) {
7979 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007980 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007981 + subId);
7982 }
7983 return null;
7984 }
7985
Jack Yu3beaf9d2023-04-14 09:17:27 -07007986 final SubscriptionInfo info = getSubscriptionManagerService()
7987 .getSubscriptionInfo(subId);
7988 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007989 // If it doesn't belong to any group, return just subscriberId of itself.
7990 if (groupUuid == null) {
7991 return new String[]{subscriberId};
7992 }
7993
7994 // Get all subscriberIds from the group.
7995 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007996 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7997 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7998 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007999 for (SubscriptionInfo subInfo : groupInfos) {
8000 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8001 if (subscriberId != null) {
8002 mergedSubscriberIds.add(subscriberId);
8003 }
8004 }
8005
8006 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8007 } finally {
8008 Binder.restoreCallingIdentity(identity);
8009
8010 }
8011 }
8012
8013 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008014 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008015 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008016 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017
joonhunshin4ac60942023-11-15 15:23:39 +00008018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8019 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 final long identity = Binder.clearCallingIdentity();
8022 try {
8023 final Phone phone = getPhone(subId);
8024 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008028 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008029
8030 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008031 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008032 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8033 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008034 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8035 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036
8037 final long identity = Binder.clearCallingIdentity();
8038 try {
8039 final Phone phone = getPhone(subId);
8040 if (phone == null) {
8041 return false;
8042 }
8043 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8044 cdmaNonRoamingList);
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008047 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008048 }
8049
8050 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008051 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008052 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008053 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008054 if (phone == null) {
8055 return raf;
8056 }
8057
Shuo Qiandee53402020-05-29 14:08:15 -07008058 try {
8059 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008060 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008061 mApp, phone.getSubId(), "getRadioAccessFamily");
8062 } catch (SecurityException e) {
8063 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8064 throw e;
8065 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008066
joonhunshin4ac60942023-11-15 15:23:39 +00008067 enforceTelephonyFeatureWithException(callingPackage,
8068 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 final long identity = Binder.clearCallingIdentity();
8071 try {
chen xub97461a2018-10-26 14:17:57 -07008072 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008073 } finally {
8074 Binder.restoreCallingIdentity(identity);
8075 }
chen xub97461a2018-10-26 14:17:57 -07008076 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008077 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008078
8079 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008080 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008081 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008082 try {
8083 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8084 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008085 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008086 }
8087 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008088 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008089 }
joonhunshin4ac60942023-11-15 15:23:39 +00008090
8091 enforceTelephonyFeatureWithException(callingPackage,
8092 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8093
Hall Liu82694d52020-12-11 18:22:04 -08008094 RoleManager rm = mApp.getSystemService(RoleManager.class);
8095 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8096 if (!dialerRoleHolders.contains(callingPackage)) {
8097 throw new SecurityException("App must be the dialer role holder to"
8098 + " upload a call composer pic");
8099 }
8100
8101 Executors.newSingleThreadExecutor().execute(() -> {
8102 ByteArrayOutputStream output = new ByteArrayOutputStream(
8103 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8104 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8105 boolean readUntilEnd = false;
8106 int totalBytesRead = 0;
8107 byte[] buffer = new byte[16 * 1024];
8108 while (true) {
8109 int numRead;
8110 try {
8111 numRead = input.read(buffer);
8112 } catch (IOException e) {
8113 try {
8114 fd.checkError();
8115 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8116 null);
8117 } catch (IOException e1) {
8118 // This means that the other side closed explicitly with an error. If this
8119 // happens, log and ignore.
8120 loge("Remote end of call composer picture pipe closed: " + e1);
8121 }
8122 break;
8123 }
8124 if (numRead == -1) {
8125 readUntilEnd = true;
8126 break;
8127 }
8128 totalBytesRead += numRead;
8129 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8130 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8131 try {
8132 input.close();
8133 } catch (IOException e) {
8134 // ignore
8135 }
8136 break;
8137 }
8138 output.write(buffer, 0, numRead);
8139 }
8140 // Generally, the remote end will close the file descriptors. The only case where we
8141 // close is above, where the picture size is too big.
8142
8143 try {
8144 fd.checkError();
8145 } catch (IOException e) {
8146 loge("Remote end for call composer closed with an error: " + e);
8147 return;
8148 }
8149
Hall Liuaa4211e2021-01-20 15:43:39 -08008150 if (!readUntilEnd) {
8151 loge("Did not finish reading entire image; aborting");
8152 return;
8153 }
Hall Liu82694d52020-12-11 18:22:04 -08008154
Hall Liuaa4211e2021-01-20 15:43:39 -08008155 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8156 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8157 new CallComposerPictureTransfer.Factory() {},
8158 imageData,
8159 (result) -> {
8160 if (result.first != null) {
8161 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8162 Bundle outputResult = new Bundle();
8163 outputResult.putParcelable(
8164 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8165 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8166 outputResult);
8167 } else {
8168 callback.send(result.second, null);
8169 }
8170 }
8171 );
Hall Liu82694d52020-12-11 18:22:04 -08008172 });
8173 }
8174
8175 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008176 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008177 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008178 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179
joonhunshin4ac60942023-11-15 15:23:39 +00008180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8181 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183 final long identity = Binder.clearCallingIdentity();
8184 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008185 ImsManager.getInstance(defaultPhone.getContext(),
8186 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187 } finally {
8188 Binder.restoreCallingIdentity(identity);
8189 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008190 }
8191
8192 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008193 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008194 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8196 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008197 return false;
8198 }
Svet Ganovb320e182015-04-16 12:30:10 -07008199
joonhunshin4ac60942023-11-15 15:23:39 +00008200 enforceTelephonyFeatureWithException(callingPackage,
8201 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8202
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008203 final long identity = Binder.clearCallingIdentity();
8204 try {
8205 // Check the user preference and the system-level IMS setting. Even if the user has
8206 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8207 // In the long run, we may instead need to check if there exists a connection service
8208 // which can support video calling.
8209 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008210 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008211 return imsManager.isVtEnabledByPlatform()
8212 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8213 && imsManager.isVtEnabledByUser();
8214 } finally {
8215 Binder.restoreCallingIdentity(identity);
8216 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008217 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008218
Andrew Leea1239f22015-03-02 17:44:07 -08008219 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008220 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8221 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008223 mApp, subId, callingPackage, callingFeatureId,
8224 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 return false;
8226 }
8227
joonhunshin4ac60942023-11-15 15:23:39 +00008228 enforceTelephonyFeatureWithException(callingPackage,
8229 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 final long identity = Binder.clearCallingIdentity();
8232 try {
8233 CarrierConfigManager configManager =
8234 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008235 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
Andrew Leea1239f22015-03-02 17:44:07 -08008240 }
8241
8242 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008243 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008245 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 return false;
8247 }
8248
joonhunshin4ac60942023-11-15 15:23:39 +00008249 enforceTelephonyFeatureWithException(callingPackage,
8250 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 final long identity = Binder.clearCallingIdentity();
8253 try {
8254 CarrierConfigManager configManager =
8255 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008256 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8258 } finally {
8259 Binder.restoreCallingIdentity(identity);
8260 }
Andrew Leea1239f22015-03-02 17:44:07 -08008261 }
8262
Andrew Lee9431b832015-03-09 18:46:45 -07008263 @Override
8264 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008265 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008266 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008267 }
8268
8269 @Override
8270 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8272 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 final long identity = Binder.clearCallingIdentity();
8275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008276 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
Andrew Lee9431b832015-03-09 18:46:45 -07008280 }
8281
Hall Liuf6668912018-10-31 17:05:23 -07008282 /**
8283 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8284 * support for the feature and device firmware support.
8285 *
8286 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8287 */
8288 @Override
8289 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008290 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8291 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008294 final Phone phone = getPhone(subscriptionId);
8295 if (phone == null) {
8296 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8297 return false;
8298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008300 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008302 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8303 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8304 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 return isCarrierSupported && isDeviceSupported;
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
Hall Liu98187582018-01-22 19:15:32 -08008309 }
8310
Hall Liuf6668912018-10-31 17:05:23 -07008311 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008312 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8313 * RTT setting, will return true if the device and carrier both support RTT.
8314 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008315 */
8316 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 final long identity = Binder.clearCallingIdentity();
8318 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008319 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8320 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8321 return false;
8322 }
8323 }
8324
Hall Liu5bab75c2019-12-11 23:58:20 +00008325 boolean isRttSupported = isRttSupported(subscriptionId);
8326 boolean isUserRttSettingOn = Settings.Secure.getInt(
8327 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8328 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8329 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8330 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008334 }
8335
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008336 @Deprecated
8337 @Override
8338 public String getDeviceId(String callingPackage) {
8339 return getDeviceIdWithFeature(callingPackage, null);
8340 }
8341
Sanket Padawe7310cc72015-01-14 09:53:20 -08008342 /**
8343 * Returns the unique device ID of phone, for example, the IMEI for
8344 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8345 *
8346 * <p>Requires Permission:
8347 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8348 */
8349 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008350 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008351 try {
8352 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8353 } catch (SecurityException se) {
8354 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8355 throw new SecurityException("Package " + callingPackage + " does not belong to "
8356 + Binder.getCallingUid());
8357 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008358 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008359 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008360 return null;
8361 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008362 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008363 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008364 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008365 return null;
8366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 return phone.getDeviceId();
8371 } finally {
8372 Binder.restoreCallingIdentity(identity);
8373 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008374 }
8375
Ping Sunc67b7c22016-03-02 19:16:45 +08008376 /**
8377 * {@hide}
8378 * Returns the IMS Registration Status on a particular subid
8379 *
8380 * @param subId
8381 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008382 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008383 Phone phone = getPhone(subId);
8384 if (phone != null) {
8385 return phone.isImsRegistered();
8386 } else {
8387 return false;
8388 }
8389 }
8390
Santos Cordon7a1885b2015-02-03 11:15:19 -08008391 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008392 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008393 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008395 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008396 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8397 }
8398 final long identity = Binder.clearCallingIdentity();
8399 try {
8400 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8401 } finally {
8402 Binder.restoreCallingIdentity(identity);
8403 }
8404 }
8405
8406 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008407 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008408 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008409 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008410 mApp,
8411 subscriptionId,
8412 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8413 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008414
8415 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8416 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8417
Tyler Gunnf70ed162019-04-03 15:28:53 -07008418 final long identity = Binder.clearCallingIdentity();
8419 try {
8420 Phone phone = getPhone(subscriptionId);
8421 if (phone == null) {
8422 return null;
8423 }
8424 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8425 } finally {
8426 Binder.restoreCallingIdentity(identity);
8427 }
8428 }
8429
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008430 /**
8431 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008432 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008433 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 final long identity = Binder.clearCallingIdentity();
8435 try {
8436 Phone phone = getPhone(subId);
8437 if (phone != null) {
8438 return phone.isWifiCallingEnabled();
8439 } else {
8440 return false;
8441 }
8442 } finally {
8443 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008444 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008445 }
8446
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008447 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008448 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008449 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008450 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451 final long identity = Binder.clearCallingIdentity();
8452 try {
8453 Phone phone = getPhone(subId);
8454 if (phone != null) {
8455 return phone.isVideoEnabled();
8456 } else {
8457 return false;
8458 }
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008461 }
8462 }
8463
8464 /**
8465 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8466 * defined in {@link ImsRegistrationImplBase}.
8467 */
8468 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469 final long identity = Binder.clearCallingIdentity();
8470 try {
8471 Phone phone = getPhone(subId);
8472 if (phone != null) {
8473 return phone.getImsRegistrationTech();
8474 } else {
8475 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8476 }
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008479 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008480 }
8481
Stuart Scott8eef64f2015-04-08 15:13:54 -07008482 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008483 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008484 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008485
8486 enforceTelephonyFeatureWithException(callingPackage,
8487 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8488
Stuart Scott981d8582015-04-21 14:09:50 -07008489 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8490 return;
8491 }
Kai Shif70f46f2021-03-03 13:59:46 -08008492 Phone defaultPhone = getDefaultPhone();
8493 if (defaultPhone != null) {
8494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8495 mApp, getDefaultPhone().getSubId(), "factoryReset");
8496 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008497 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008498
Svet Ganovcc087f82015-05-12 20:35:54 -07008499 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008500 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8501 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008502 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008503 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008504 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008505 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008506 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008507 setDataRoamingEnabled(subId, phone == null ? false
8508 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008509 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008510 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008511 // There has been issues when Sms raw table somehow stores orphan
8512 // fragments. They lead to garbled message when new fragments come
8513 // in and combined with those stale ones. In case this happens again,
8514 // user can reset all network settings which will clean up this table.
8515 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008516 // Clean up IMS settings as well here.
8517 int slotId = getSlotIndex(subId);
8518 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8519 ImsManager.getInstance(mApp, slotId).factoryReset();
8520 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008521
Kai Shif70f46f2021-03-03 13:59:46 -08008522 if (defaultPhone == null) {
8523 return;
8524 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008525 // Erase modem config if erase modem on network setting is enabled.
8526 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8527 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8528 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008529 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008530 }
Kai Shif70f46f2021-03-03 13:59:46 -08008531
8532 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008533 } finally {
8534 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008535 }
8536 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008537
SongFerngWangfd89b102021-05-27 22:44:54 +08008538 @VisibleForTesting
8539 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8540 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8541 return;
8542 }
8543 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8544 RILConstants.PREFERRED_NETWORK_MODE);
8545 SubscriptionManager.setSubscriptionProperty(subId,
8546 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8547 "user=" + defaultNetworkType);
8548 phone.loadAllowedNetworksFromSubscriptionDatabase();
8549 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8550 defaultNetworkType, null);
8551 }
8552
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008553 private void cleanUpSmsRawTable(Context context) {
8554 ContentResolver resolver = context.getContentResolver();
8555 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8556 resolver.delete(uri, null, null);
8557 }
8558
Narayan Kamath1c496c22015-04-16 14:40:19 +01008559 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008560 public String getSimLocaleForSubscriber(int subId) {
8561 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008562
8563 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8564 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8565
chen xu5d3637b2019-01-21 23:31:38 -08008566 final Phone phone = getPhone(subId);
8567 if (phone == null) {
8568 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008569 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 final long identity = Binder.clearCallingIdentity();
8572 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008573 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8574 phone.getContext().getOpPackageName(),
8575 phone.getContext().getAttributionTag());
8576 if (info == null) {
8577 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8578 return null;
chen xu6291c472019-02-04 12:55:53 -08008579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008580 // Try and fetch the locale from the carrier properties or from the SIM language
8581 // preferences (EF-PL and EF-LI)...
8582 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008584 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8585 if (localeFromDefaultSim != null) {
8586 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8587 if (DBG) log("Using locale from subId: " + subId + " locale: "
8588 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008589 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008590 } else {
8591 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008592 }
8593 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008595 // The SIM language preferences only store a language (e.g. fr = French), not an
8596 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8597 // the SIM and carrier preferences does not include a country we add the country
8598 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008599 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008601 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008602 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 }
8604
8605 if (DBG) log("No locale found - returning null");
8606 return null;
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008610 }
8611
tom hsu0b59d292022-09-29 23:49:21 +08008612 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008613 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008614 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008615 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008616 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008617 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8618 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008619 Locale.forLanguageTag(localeTag).getCountry())) {
8620 return localeTag;
8621 }
8622 }
8623 return inputLocale.toLanguageTag();
8624 }
8625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008626 /**
8627 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8628 */
8629 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008630 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008631 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008632 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008633
Gary Jian3aa9a762022-01-24 16:41:19 +08008634 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8635 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008636
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008637 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008638 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8639 * representing the state of the modem.
8640 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008641 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8642 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008643 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008644 */
8645 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008646 public void requestModemActivityInfo(ResultReceiver result) {
8647 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008648
8649 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8650 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8651
vagdeviaf9a5b92018-08-15 16:01:53 -07008652 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653
8654 final long identity = Binder.clearCallingIdentity();
8655 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008656 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008657 } finally {
8658 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008659 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008660 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008661
Gary Jian76280a42022-12-07 16:18:33 +08008662 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008663 // less than total activity duration.
8664 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8665 if (info == null) {
8666 return false;
8667 }
8668 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008669 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008670 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8671
Hall Liu49656c02020-10-09 19:00:11 -07008672 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8673
Siddharth Rayb8114062018-06-17 15:02:38 -07008674 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008675 && (info.getSleepTimeMillis() <= activityDurationMs)
8676 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008677 }
8678
Gary Jian3aa9a762022-01-24 16:41:19 +08008679 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8680 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8681 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8682 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8683
8684 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8685 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8686 }
8687
8688 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8689 mLastModemActivityInfo.setReceiveTimeMillis(
8690 rat,
8691 freq,
8692 info.getReceiveTimeMillis(rat, freq)
8693 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8694 }
8695
8696 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8697 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8698 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8699 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8700
8701 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8702 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8703 }
8704 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8705 mLastModemActivityInfo.setReceiveTimeMillis(
8706 rat,
8707 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8708 }
8709
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008710 /**
8711 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8712 * @param info recent ModemActivityInfo
8713 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008714 private void mergeModemActivityInfo(ModemActivityInfo info) {
8715 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008716 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008717 boolean matched;
8718 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8719 matched = false;
8720 int rat = info.getSpecificInfoRat(i);
8721 int freq = info.getSpecificInfoFrequencyRange(i);
8722 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8723 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8724 //if it already exists
8725 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8726 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8727 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8728 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8729 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8730 updateLastModemActivityInfo(info, rat, freq);
8731 matched = true;
8732 }
8733 } else {
8734 updateLastModemActivityInfo(info, rat);
8735 matched = true;
8736 }
8737 }
8738 }
8739
8740 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008741 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008742 new ActivityStatsTechSpecificInfo(
8743 rat,
8744 freq,
8745 info.getTransmitTimeMillis(rat, freq),
8746 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008747 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008748 }
8749 }
8750 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8751 mLastModemActivitySpecificInfo =
8752 new ActivityStatsTechSpecificInfo[merged.size()];
8753 merged.toArray(mLastModemActivitySpecificInfo);
8754
8755 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8756 mLastModemActivityInfo.setSleepTimeMillis(
8757 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008758 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008759 mLastModemActivityInfo.setIdleTimeMillis(
8760 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008761 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008762
8763 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008764 new ModemActivityInfo(
8765 mLastModemActivityInfo.getTimestampMillis(),
8766 mLastModemActivityInfo.getSleepTimeMillis(),
8767 mLastModemActivityInfo.getIdleTimeMillis(),
8768 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008769 }
8770
8771 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8772 ActivityStatsTechSpecificInfo[] info) {
8773 int infoSize = info.length;
8774 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8775 for (int i = 0; i < infoSize; i++) {
8776 ret[i] = new ActivityStatsTechSpecificInfo(
8777 info[i].getRat(), info[i].getFrequencyRange(),
8778 info[i].getTransmitTimeMillis(),
8779 (int) info[i].getReceiveTimeMillis());
8780 }
8781 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008782 }
8783
Jack Yu85bd38a2015-11-09 11:34:32 -08008784 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008785 * Returns the service state information on specified subscription.
8786 */
8787 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008788 public ServiceState getServiceStateForSubscriber(int subId,
8789 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8790 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008792 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008793 return null;
8794 }
8795
joonhunshin4ac60942023-11-15 15:23:39 +00008796 enforceTelephonyFeatureWithException(callingPackage,
8797 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8798
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008799 boolean hasFinePermission = false;
8800 boolean hasCoarsePermission = false;
8801 if (!renounceFineLocationAccess) {
8802 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8803 LocationAccessPolicy.checkLocationPermission(mApp,
8804 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8805 .setCallingPackage(callingPackage)
8806 .setCallingFeatureId(callingFeatureId)
8807 .setCallingPid(Binder.getCallingPid())
8808 .setCallingUid(Binder.getCallingUid())
8809 .setMethod("getServiceStateForSubscriber")
8810 .setLogAsInfo(true)
8811 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8812 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8813 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8814 .build());
8815 hasFinePermission =
8816 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8817 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008818
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008819 if (!renounceCoarseLocationAccess) {
8820 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8821 LocationAccessPolicy.checkLocationPermission(mApp,
8822 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8823 .setCallingPackage(callingPackage)
8824 .setCallingFeatureId(callingFeatureId)
8825 .setCallingPid(Binder.getCallingPid())
8826 .setCallingUid(Binder.getCallingUid())
8827 .setMethod("getServiceStateForSubscriber")
8828 .setLogAsInfo(true)
8829 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8830 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8831 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8832 .build());
8833 hasCoarsePermission =
8834 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8835 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008836
Jack Yu479f40e2020-10-27 21:29:25 -07008837 final Phone phone = getPhone(subId);
8838 if (phone == null) {
8839 return null;
8840 }
8841
Jordan Liu0f2bc442020-11-18 16:47:37 -08008842 final long identity = Binder.clearCallingIdentity();
8843
Jack Yu479f40e2020-10-27 21:29:25 -07008844 boolean isCallingPackageDataService = phone.getDataServicePackages()
8845 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008846 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008847 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008848 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8849 .getSubscriptionInfoInternal(subId);
8850 if (subInfo == null || !subInfo.isActive()) {
8851 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8852 + "subId=" + subId);
8853 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008854 }
8855
Hall Liuf19c44f2018-11-27 14:38:17 -08008856 ServiceState ss = phone.getServiceState();
8857
8858 // Scrub out the location info in ServiceState depending on what level of access
8859 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008860 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008861 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8862 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008863 } finally {
8864 Binder.restoreCallingIdentity(identity);
8865 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008866 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008867
8868 /**
8869 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8870 *
8871 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8872 * voicemail ringtone.
8873 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8874 * PhoneAccount.
8875 */
8876 @Override
8877 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008878 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8879 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 final long identity = Binder.clearCallingIdentity();
8882 try {
8883 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8884 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008885 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8889 } finally {
8890 Binder.restoreCallingIdentity(identity);
8891 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008892 }
8893
8894 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008895 * Sets the per-account voicemail ringtone.
8896 *
8897 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8898 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8899 *
8900 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8901 * voicemail ringtone.
8902 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8903 * PhoneAccount.
8904 */
8905 @Override
8906 public void setVoicemailRingtoneUri(String callingPackage,
8907 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008908 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008910 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8911 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8913 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8914 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008916
joonhunshin4ac60942023-11-15 15:23:39 +00008917 enforceTelephonyFeatureWithException(callingPackage,
8918 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 final long identity = Binder.clearCallingIdentity();
8921 try {
8922 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8923 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008924 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925 }
8926 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8927 } finally {
8928 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008929 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008930 }
8931
8932 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008933 * Returns whether vibration is set for voicemail notification in Phone settings.
8934 *
8935 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8936 * voicemail vibration setting.
8937 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8938 */
8939 @Override
8940 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008941 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8942 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008944 final long identity = Binder.clearCallingIdentity();
8945 try {
8946 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8947 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008948 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008951 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
8954 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008955 }
8956
Youhan Wange64578a2016-05-02 15:32:42 -07008957 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008958 * Sets the per-account voicemail vibration.
8959 *
8960 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8961 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8962 *
8963 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8964 * voicemail vibration setting.
8965 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8966 * specific PhoneAccount.
8967 */
8968 @Override
8969 public void setVoicemailVibrationEnabled(String callingPackage,
8970 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008971 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008973 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8974 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8976 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8977 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008978 }
8979
joonhunshin4ac60942023-11-15 15:23:39 +00008980 enforceTelephonyFeatureWithException(callingPackage,
8981 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008983 final long identity = Binder.clearCallingIdentity();
8984 try {
8985 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8986 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008987 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008988 }
8989 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8990 } finally {
8991 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008992 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008993 }
8994
8995 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008996 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8997 *
8998 * @throws SecurityException if the caller does not have the required permission
8999 */
arunvoddud7401012022-12-15 16:08:12 +00009000 @VisibleForTesting
9001 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009002 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009003 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009004 }
9005
9006 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009007 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9008 * permission.
9009 *
9010 * @throws SecurityException if the caller does not have the required permission
9011 */
9012 private void enforceSendSmsPermission() {
9013 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9014 }
9015
9016 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009017 * Make sure either called from same process as self (phone) or IPC caller has interact across
9018 * users permission.
9019 *
9020 * @throws SecurityException if the caller does not have the required permission
9021 */
9022 private void enforceInteractAcrossUsersPermission(String message) {
9023 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9024 }
9025
9026 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009027 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009028 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009029 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009030 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009031 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009032 final long identity = Binder.clearCallingIdentity();
9033 try {
9034 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009035 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009036 if (componentName == null) {
9037 throw new SecurityException(
9038 "Caller not current active visual voicemail package[null]");
9039 }
9040 String vvmPackage = componentName.getPackageName();
9041 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009042 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 }
9044 } finally {
9045 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009046 }
9047 }
9048
9049 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009050 * Return the application ID for the app type.
9051 *
9052 * @param subId the subscription ID that this request applies to.
9053 * @param appType the uicc app type.
9054 * @return Application ID for specificied app type, or null if no uicc.
9055 */
9056 @Override
9057 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009058 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009059
9060 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9061 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9062
Youhan Wange64578a2016-05-02 15:32:42 -07009063 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009064
9065 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009066 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009067 if (phone == null) {
9068 return null;
9069 }
9070 String aid = null;
9071 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009072 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009073 .getApplicationByType(appType).getAid();
9074 } catch (Exception e) {
9075 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9076 }
9077 return aid;
9078 } finally {
9079 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009080 }
Youhan Wange64578a2016-05-02 15:32:42 -07009081 }
9082
Youhan Wang4001d252016-05-11 10:29:41 -07009083 /**
9084 * Return the Electronic Serial Number.
9085 *
9086 * @param subId the subscription ID that this request applies to.
9087 * @return ESN or null if error.
9088 */
9089 @Override
9090 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009091 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009092 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009093
9094 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009095 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009096 if (phone == null) {
9097 return null;
9098 }
9099 String esn = null;
9100 try {
9101 esn = phone.getEsn();
9102 } catch (Exception e) {
9103 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9104 }
9105 return esn;
9106 } finally {
9107 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009108 }
Youhan Wang4001d252016-05-11 10:29:41 -07009109 }
9110
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009111 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009112 * Return the Preferred Roaming List Version.
9113 *
9114 * @param subId the subscription ID that this request applies to.
9115 * @return PRLVersion or null if error.
9116 */
9117 @Override
9118 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009119 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009120
9121 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9122 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9123
Youhan Wang66ad5d72016-07-18 17:56:58 -07009124 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009125
9126 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009127 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009128 if (phone == null) {
9129 return null;
9130 }
9131 String cdmaPrlVersion = null;
9132 try {
9133 cdmaPrlVersion = phone.getCdmaPrlVersion();
9134 } catch (Exception e) {
9135 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9136 }
9137 return cdmaPrlVersion;
9138 } finally {
9139 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009140 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009141 }
9142
9143 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009144 * Get snapshot of Telephony histograms
9145 * @return List of Telephony histograms
9146 * @hide
9147 */
9148 @Override
9149 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9151 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009152
9153 final long identity = Binder.clearCallingIdentity();
9154 try {
9155 return RIL.getTelephonyRILTimingHistograms();
9156 } finally {
9157 Binder.restoreCallingIdentity(identity);
9158 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009159 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009160
9161 /**
9162 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009163 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9164 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009165 * Require system privileges. In the future we may add this to carrier APIs.
9166 *
Michele Berionne482f8202018-11-27 18:57:59 -08009167 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009168 */
9169 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009170 @TelephonyManager.SetCarrierRestrictionResult
9171 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009172 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009173
9174 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9175 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9176
vagdeviaf9a5b92018-08-15 16:01:53 -07009177 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009178
Michele Berionne482f8202018-11-27 18:57:59 -08009179 if (carrierRestrictionRules == null) {
9180 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009181 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009183 final long identity = Binder.clearCallingIdentity();
9184 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009185 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009186 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009190 }
9191
9192 /**
9193 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009194 * Get the allowed carrier list and the excluded carrier list, including the priority between
9195 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009196 * Require system privileges. In the future we may add this to carrier APIs.
9197 *
Michele Berionne482f8202018-11-27 18:57:59 -08009198 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009199 */
9200 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009201 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009202 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009203
9204 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9205 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9206
vagdeviaf9a5b92018-08-15 16:01:53 -07009207 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009208
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009211 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9212 if (response instanceof CarrierRestrictionRules) {
9213 return (CarrierRestrictionRules) response;
9214 }
9215 // Response is an Exception of some kind,
9216 // which is signalled to the user as a NULL retval
9217 return null;
9218 } catch (Exception e) {
9219 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9220 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009224 }
9225
fionaxu59545b42016-05-25 15:53:37 -07009226 /**
arunvoddud7401012022-12-15 16:08:12 +00009227 * Fetches the carrier restriction status of the device and sends the status to the caller
9228 * through the callback.
9229 *
9230 * @param callback The callback that will be used to send the result.
9231 * @throws SecurityException if the caller does not have the required permission/privileges or
9232 * the caller is not allowlisted.
9233 */
9234 @Override
9235 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9236 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009237
9238 enforceTelephonyFeatureWithException(packageName,
9239 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9240
arunvoddud7401012022-12-15 16:08:12 +00009241 int carrierId = validateCallerAndGetCarrierId(packageName);
9242 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9243 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9244 throw new SecurityException("Not an authorized caller");
9245 }
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9249 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9250 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9251 } finally {
9252 Binder.restoreCallingIdentity(identity);
9253 }
9254 }
9255
arunvoddu567f2b42023-04-25 17:22:00 +00009256 @Override
9257 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9258 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9259 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9260 return allowListInfo.getShaIdList(pkgName, carrierId);
9261 }
9262
arunvoddud7401012022-12-15 16:08:12 +00009263 @VisibleForTesting
9264 public int validateCallerAndGetCarrierId(String packageName) {
9265 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9266 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9267 }
9268
9269 /**
fionaxu59545b42016-05-25 15:53:37 -07009270 * Action set from carrier signalling broadcast receivers to enable/disable radio
9271 * @param subId the subscription ID that this action applies to.
9272 * @param enabled control enable or disable radio.
9273 * {@hide}
9274 */
9275 @Override
9276 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9277 enforceModifyPermission();
9278 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009279
9280 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009281 if (phone == null) {
9282 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9283 return;
9284 }
9285 try {
9286 phone.carrierActionSetRadioEnabled(enabled);
9287 } catch (Exception e) {
9288 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009289 } finally {
9290 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009291 }
9292 }
9293
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009294 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009295 * Enable or disable Voice over NR (VoNR)
9296 * @param subId the subscription ID that this action applies to.
9297 * @param enabled enable or disable VoNR.
9298 * @return operation result.
9299 */
9300 @Override
9301 public int setVoNrEnabled(int subId, boolean enabled) {
9302 enforceModifyPermission();
9303 final Phone phone = getPhone(subId);
9304
9305 final long identity = Binder.clearCallingIdentity();
9306 if (phone == null) {
9307 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9308 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9309 }
9310
9311 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9312 try {
9313 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9314 workSource);
9315 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009316
9317 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9318 if (DBG) {
9319 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9320 }
9321 SubscriptionManager.setSubscriptionProperty(
9322 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9323 (enabled ? "1" : "0"));
9324 }
9325
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009326 return result;
9327 } finally {
9328 Binder.restoreCallingIdentity(identity);
9329 }
9330 }
9331
9332 /**
9333 * Is voice over NR enabled
9334 * @return true if VoNR is enabled else false
9335 */
9336 @Override
9337 public boolean isVoNrEnabled(int subId) {
9338 enforceReadPrivilegedPermission("isVoNrEnabled");
9339 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9343 null, subId, workSource);
9344 if (DBG) log("isVoNrEnabled: " + isEnabled);
9345 return isEnabled;
9346 } finally {
9347 Binder.restoreCallingIdentity(identity);
9348 }
9349 }
9350
9351 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009352 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9353 * network status based on which carrier apps could apply actions accordingly,
9354 * enable/disable default url handler for example.
9355 *
9356 * @param subId the subscription ID that this action applies to.
9357 * @param report control start/stop reporting the default network status.
9358 * {@hide}
9359 */
9360 @Override
9361 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9362 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009363
9364 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9365 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9366 "carrierActionReportDefaultNetworkStatus");
9367
fionaxu8da9cb12017-05-23 15:02:46 -07009368 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009369
9370 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009371 if (phone == null) {
9372 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9373 return;
9374 }
9375 try {
9376 phone.carrierActionReportDefaultNetworkStatus(report);
9377 } catch (Exception e) {
9378 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009379 } finally {
9380 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009381 }
9382 }
9383
9384 /**
fionaxud9622282017-07-17 17:51:30 -07009385 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9386 * @param subId the subscription ID that this action applies to.
9387 * {@hide}
9388 */
9389 @Override
9390 public void carrierActionResetAll(int subId) {
9391 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009392
9393 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9394 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9395
fionaxud9622282017-07-17 17:51:30 -07009396 final Phone phone = getPhone(subId);
9397 if (phone == null) {
9398 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9399 return;
9400 }
9401 try {
9402 phone.carrierActionResetAll();
9403 } catch (Exception e) {
9404 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9405 }
9406 }
9407
9408 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009409 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9410 * bug report is being generated.
9411 */
9412 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009413 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009414 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9415 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009416 writer.println("Permission Denial: can't dump Phone from pid="
9417 + Binder.getCallingPid()
9418 + ", uid=" + Binder.getCallingUid()
9419 + "without permission "
9420 + android.Manifest.permission.DUMP);
9421 return;
9422 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009423 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009424 }
Jack Yueb89b242016-06-22 13:27:47 -07009425
Brad Ebingerdac2f002018-04-03 15:17:52 -07009426 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009427 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9428 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9429 @NonNull String[] args) {
9430 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9431 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009432 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009433 }
9434
Jack Yueb89b242016-06-22 13:27:47 -07009435 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009436 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009437 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009438 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009439 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009440 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009441 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009442 */
9443 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009444 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009445 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009446 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9447 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9448 try {
9449 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009450 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009451 } catch (SecurityException se) {
9452 enforceModifyPermission();
9453 }
9454 } else {
9455 enforceModifyPermission();
9456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009457
joonhunshin4ac60942023-11-15 15:23:39 +00009458 enforceTelephonyFeatureWithException(callingPackage,
9459 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9460
Nate Myren116695d2024-02-09 09:36:01 -08009461 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009462 final long identity = Binder.clearCallingIdentity();
9463 try {
Nate Myren116695d2024-02-09 09:36:01 -08009464 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9465 && null != callingPackage && opEnableMobileDataByUser()) {
9466 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
9467 callingUid, callingPackage, null, null);
9468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009469 Phone phone = getPhone(subId);
9470 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009471 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9472 phone.carrierActionSetMeteredApnsEnabled(enabled);
9473 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009474 phone.getDataSettingsManager().setDataEnabled(
9475 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009477 }
9478 } finally {
9479 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009480 }
9481 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009482
9483 /**
9484 * Get Client request stats
9485 * @return List of Client Request Stats
9486 * @hide
9487 */
9488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009489 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9490 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009492 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009493 return null;
9494 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009495 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009497 final long identity = Binder.clearCallingIdentity();
9498 try {
9499 if (phone != null) {
9500 return phone.getClientRequestStats();
9501 }
9502
9503 return null;
9504 } finally {
9505 Binder.restoreCallingIdentity(identity);
9506 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009507 }
9508
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009509 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009510 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009511 if (uid == Process.ROOT_UID && packageName == null) {
9512 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9513 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9514 // exception. ROOT_UID seems not to have a valid package name returned by
9515 // PackageManager, so just fake it here to avoid issues when running telephony shell
9516 // commands that plumb through the RIL as root, like so:
9517 // $ adb root
9518 // $ adb shell cmd phone ...
9519 packageName = "root";
9520 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009521 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009522 }
Jack Yueb4124c2017-02-16 15:32:43 -08009523
9524 /**
Grace Chen70990072017-03-24 17:21:30 -07009525 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009526 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009527 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009528 * @param state State of SIM (power down, power up, pass through)
9529 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9531 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009532 *
9533 **/
9534 @Override
Grace Chen70990072017-03-24 17:21:30 -07009535 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009536 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009537
9538 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9539 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9540
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009541 Phone phone = PhoneFactory.getPhone(slotIndex);
9542
vagdeviaf9a5b92018-08-15 16:01:53 -07009543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009545 final long identity = Binder.clearCallingIdentity();
9546 try {
9547 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009548 phone.setSimPowerState(state, null, workSource);
9549 }
9550 } finally {
9551 Binder.restoreCallingIdentity(identity);
9552 }
9553 }
9554
9555 /**
9556 * Set SIM card power state.
9557 *
9558 * @param slotIndex SIM slot id.
9559 * @param state State of SIM (power down, power up, pass through)
9560 * @param callback callback to trigger after success or failure
9561 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9562 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9563 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9564 *
9565 **/
9566 @Override
9567 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9568 IIntegerConsumer callback) {
9569 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009570
9571 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9572 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9573 "setSimPowerStateForSlotWithCallback");
9574
Jordan Liu109698e2020-11-24 14:50:34 -08009575 Phone phone = PhoneFactory.getPhone(slotIndex);
9576
9577 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9578
9579 final long identity = Binder.clearCallingIdentity();
9580 try {
9581 if (phone != null) {
9582 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9583 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009584 }
9585 } finally {
9586 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009587 }
9588 }
Shuo Qiandd210312017-04-12 22:11:33 +00009589
Tyler Gunn65d45c22017-06-05 11:22:26 -07009590 private boolean isUssdApiAllowed(int subId) {
9591 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009592 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009593 if (configManager == null) {
9594 return false;
9595 }
9596 PersistableBundle pb = configManager.getConfigForSubId(subId);
9597 if (pb == null) {
9598 return false;
9599 }
9600 return pb.getBoolean(
9601 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9602 }
9603
Shuo Qiandd210312017-04-12 22:11:33 +00009604 /**
Ling Mac28f0212023-03-24 16:07:15 -07009605 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009606 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009607 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009608 */
goneil9c5f4872017-12-05 14:07:56 -08009609 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009610 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009611 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009612
9613 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9614 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009616 final long identity = Binder.clearCallingIdentity();
9617 try {
Ling Mac28f0212023-03-24 16:07:15 -07009618 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009619 } finally {
9620 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009621 }
9622 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009623
9624 /**
9625 * Get the current signal strength information for the given subscription.
9626 * Because this information is not updated when the device is in a low power state
9627 * it should not be relied-upon to be current.
9628 * @param subId Subscription index
9629 * @return the most recent cached signal strength info from the modem
9630 */
9631 @Override
9632 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009633 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9634 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009636 final long identity = Binder.clearCallingIdentity();
9637 try {
9638 Phone p = getPhone(subId);
9639 if (p == null) {
9640 return null;
9641 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009643 return p.getSignalStrength();
9644 } finally {
9645 Binder.restoreCallingIdentity(identity);
9646 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009647 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009648
Pengquan Meng77b7f132018-08-22 14:49:57 -07009649 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009650 * Get the current modem radio state for the given slot.
9651 * @param slotIndex slot index.
9652 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009653 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009654 * @return the current radio power state from the modem
9655 */
9656 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009657 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009658 Phone phone = PhoneFactory.getPhone(slotIndex);
9659 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9661 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009662 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9663 }
9664
joonhunshin4ac60942023-11-15 15:23:39 +00009665 enforceTelephonyFeatureWithException(callingPackage,
9666 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9667
Chen Xuf792fd62018-10-17 17:54:36 +00009668 final long identity = Binder.clearCallingIdentity();
9669 try {
9670 return phone.getRadioPowerState();
9671 } finally {
9672 Binder.restoreCallingIdentity(identity);
9673 }
9674 }
9675 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9676 }
9677
9678 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009679 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9680 *
9681 * <p>Requires one of the following permissions:
9682 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009683 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009684 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9685 * privileges.
9686 *
9687 * @param subId subscription id
9688 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9689 * {@code false}.
9690 */
9691 @Override
9692 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009693 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009694 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009695 try {
9696 mApp.enforceCallingOrSelfPermission(
9697 android.Manifest.permission.ACCESS_NETWORK_STATE,
9698 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009699 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009700 mApp.enforceCallingOrSelfPermission(
9701 permission.READ_BASIC_PHONE_STATE, functionName);
9702 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009703 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009704 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009705 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009706 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009707
joonhunshin4ac60942023-11-15 15:23:39 +00009708 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9709 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9710
Pengquan Menga1bb6272018-09-06 09:59:22 -07009711 boolean isEnabled = false;
9712 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009713 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009714 Phone phone = getPhone(subId);
9715 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009716 } finally {
9717 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009719 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009720 }
9721
9722
9723 /**
9724 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9725 *
9726 * <p> Requires permission:
9727 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9728 * privileges.
9729 *
9730 * @param subId subscription id
9731 * @param isEnabled {@code true} means enable, {@code false} means disable.
9732 */
9733 @Override
9734 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9736 mApp, subId, "setDataRoamingEnabled");
9737
joonhunshin4ac60942023-11-15 15:23:39 +00009738 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9739 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9740
Pengquan Menga1bb6272018-09-06 09:59:22 -07009741 final long identity = Binder.clearCallingIdentity();
9742 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009743 Phone phone = getPhone(subId);
9744 if (phone != null) {
9745 phone.setDataRoamingEnabled(isEnabled);
9746 }
9747 } finally {
9748 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009749 }
9750 }
9751
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009752 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009753 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009754 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009755 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009756 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009757
joonhunshin4ac60942023-11-15 15:23:39 +00009758 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9759 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9760
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009761 boolean isAllowed = true;
9762 final long identity = Binder.clearCallingIdentity();
9763 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009764 Phone phone = getPhone(subId);
9765 if (phone != null) {
9766 isAllowed = phone.isCspPlmnEnabled();
9767 }
9768 } finally {
9769 Binder.restoreCallingIdentity(identity);
9770 }
9771 return isAllowed;
9772 }
9773
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009774 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9775 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009776 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009777 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009778 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009779 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9780 if (phone == null) {
9781 return false;
9782 }
9783 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9784 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9785 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009786 }
9787
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009788 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009789 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009790 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009791 mApp.getSystemService(AppOpsManager.class)
9792 .checkPackage(Binder.getCallingUid(), callingPackage);
9793
Jordan Liu1e142fc2019-04-22 15:10:43 -07009794 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009795 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009796 try {
9797 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009798 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009799 } catch (SecurityException e) {
9800 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9801 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009802 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009803 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009804 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009805 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009806 }
joonhunshin4ac60942023-11-15 15:23:39 +00009807
9808 enforceTelephonyFeatureWithException(callingPackage,
9809 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9810
sandeepjsb6c87872021-09-27 15:34:44 +00009811 // checking compatibility, if calling app's target SDK is T and beyond.
9812 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9813 Binder.getCallingUid())) {
9814 isIccIdAccessRestricted = true;
9815 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009816 final long identity = Binder.clearCallingIdentity();
9817 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009818 UiccController uiccController = UiccController.getInstance();
9819 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009820 if (hasReadPermission) {
9821 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009822 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009823
9824 // Remove private info if the caller doesn't have access
9825 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9826 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009827 //setting the value after compatibility check
9828 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009829 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9830 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009831 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009832 if (card == null) {
9833 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009834 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009835 continue;
9836 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009837 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9838 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009839 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009840 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009841 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009842 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9843 for (UiccPortInfo portInfo : portInfos) {
9844 UiccPort port = uiccController.getUiccPortForSlot(
9845 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9846 if (port == null) {
9847 // assume no access if port is null
9848 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9849 continue;
9850 }
9851 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9852 uiccPortInfos.add(portInfo);
9853 } else {
9854 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9855 }
9856 }
9857 filteredInfos.add(new UiccCardInfo(
9858 cardInfo.isEuicc(),
9859 cardInfo.getCardId(),
9860 null,
9861 cardInfo.getPhysicalSlotIndex(),
9862 cardInfo.isRemovable(),
9863 cardInfo.isMultipleEnabledProfilesSupported(),
9864 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009865 }
9866 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009867 } finally {
9868 Binder.restoreCallingIdentity(identity);
9869 }
9870 }
9871
sandeepjsb6c87872021-09-27 15:34:44 +00009872 /**
9873 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9874 * generally private and require carrier privileges to view.
9875 *
9876 * @hide
9877 */
9878 @NonNull
9879 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9880 List<UiccPortInfo> portinfo = new ArrayList<>();
9881 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9882 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9883 }
9884 return new UiccCardInfo(
9885 cardInfo.isEuicc(),
9886 cardInfo.getCardId(),
9887 null,
9888 cardInfo.getPhysicalSlotIndex(),
9889 cardInfo.isRemovable(),
9890 cardInfo.isMultipleEnabledProfilesSupported(),
9891 portinfo
9892 );
9893 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009894
sandeepjsb6c87872021-09-27 15:34:44 +00009895 /**
9896 * @hide
9897 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9898 * These values are generally private and require carrier privileges to view.
9899 */
9900 @NonNull
9901 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9902 return new UiccPortInfo(
9903 UiccPortInfo.ICCID_REDACTED,
9904 portInfo.getPortIndex(),
9905 portInfo.getLogicalSlotIndex(),
9906 portInfo.isActive()
9907 );
9908 }
9909 @Override
9910 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009911 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009912 mApp.getSystemService(AppOpsManager.class)
9913 .checkPackage(Binder.getCallingUid(), callingPackage);
9914
sandeepjsb6c87872021-09-27 15:34:44 +00009915 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009916
Aman Guptaf3c90b32022-03-17 04:54:16 +00009917 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9918 // we are reading iccId which is PII data.
9919 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009920
joonhunshin4ac60942023-11-15 15:23:39 +00009921 enforceTelephonyFeatureWithException(callingPackage,
9922 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9923
sandeepjsb6c87872021-09-27 15:34:44 +00009924 // checking compatibility, if calling app's target SDK is T and beyond.
9925 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9926 Binder.getCallingUid())) {
9927 isLogicalSlotAccessRestricted = true;
9928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009929 final long identity = Binder.clearCallingIdentity();
9930 try {
9931 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009932 if (slots == null || slots.length == 0) {
9933 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009934 return null;
9935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009936 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9937 for (int i = 0; i < slots.length; i++) {
9938 UiccSlot slot = slots[i];
9939 if (slot == null) {
9940 continue;
9941 }
9942
Jordan Liu7be7e652019-05-06 18:55:02 +00009943 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009944 UiccCard card = slot.getUiccCard();
9945 if (card != null) {
9946 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009947 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009948 cardId = slot.getEid();
9949 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009950 // If cardId is null, use iccId of default port as cardId.
9951 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009953 }
9954
Jordan Liu857451f2019-05-09 16:35:35 -07009955 if (cardId != null) {
9956 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9957 // if cardId is an EID, it's all digits so this is fine
9958 cardId = IccUtils.stripTrailingFs(cardId);
9959 }
9960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009961 int cardState = 0;
9962 switch (slot.getCardState()) {
9963 case CARDSTATE_ABSENT:
9964 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9965 break;
9966 case CARDSTATE_PRESENT:
9967 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9968 break;
9969 case CARDSTATE_ERROR:
9970 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9971 break;
9972 case CARDSTATE_RESTRICTED:
9973 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9974 break;
9975 default:
9976 break;
9977
9978 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009979 List<UiccPortInfo> portInfos = new ArrayList<>();
9980 int[] portIndexes = slot.getPortList();
9981 for (int portIdx : portIndexes) {
9982 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009983 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009984 portInfos.add(new UiccPortInfo(iccId, portIdx,
9985 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009987 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009988 slot.isEuicc(),
9989 cardId,
9990 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009991 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009992 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009993 //setting the value after compatibility check
9994 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009995 }
9996 return infos;
9997 } finally {
9998 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010000 }
10001
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010002 /* Returns null if doesn't have read permission or carrier privilege access. */
10003 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10004 boolean hasReadPermission) {
10005 String iccId = slot.getIccId(portIndex);
10006 if (hasReadPermission) { // if has read permission
10007 return iccId;
10008 } else {
10009 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10010 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10011 // if no read permission, checking carrier privilege access
10012 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10013 return iccId;
10014 }
10015 }
10016 }
10017 // No read permission or carrier privilege access.
10018 return UiccPortInfo.ICCID_REDACTED;
10019 }
10020
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010021 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010022 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010023 public boolean switchSlots(int[] physicalSlots) {
10024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010025
joonhunshin4ac60942023-11-15 15:23:39 +000010026 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10027 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10028
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010029 final long identity = Binder.clearCallingIdentity();
10030 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010031 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10032 for (int i = 0; i < physicalSlots.length; i++) {
10033 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10034 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10035 physicalSlots[i], i));
10036 }
10037 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010038 } finally {
10039 Binder.restoreCallingIdentity(identity);
10040 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010041 }
Jack Yu4c988042018-02-27 15:30:01 -080010042
10043 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010044 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10045 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10046 enforceModifyPermission();
10047
joonhunshin4ac60942023-11-15 15:23:39 +000010048 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10049 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10050
sandeepjsb6c87872021-09-27 15:34:44 +000010051 final long identity = Binder.clearCallingIdentity();
10052 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010053 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010054 } finally {
10055 Binder.restoreCallingIdentity(identity);
10056 }
10057 }
10058
10059 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010060 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010061 enforceTelephonyFeatureWithException(callingPackage,
10062 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10063
Jordan Liu7de49fa2018-12-06 14:48:49 -080010064 final long identity = Binder.clearCallingIdentity();
10065 try {
10066 return UiccController.getInstance().getCardIdForDefaultEuicc();
10067 } finally {
10068 Binder.restoreCallingIdentity(identity);
10069 }
10070 }
10071
Pengquan Meng85728fb2018-03-12 16:31:21 -070010072 /**
goneil47ffb6e2018-04-06 15:40:58 -070010073 * A test API to reload the UICC profile.
10074 *
10075 * <p>Requires that the calling app has permission
10076 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10077 * @hide
10078 */
10079 @Override
10080 public void refreshUiccProfile(int subId) {
10081 enforceModifyPermission();
10082
10083 final long identity = Binder.clearCallingIdentity();
10084 try {
10085 Phone phone = getPhone(subId);
10086 if (phone == null) {
10087 return;
10088 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010089 UiccPort uiccPort = phone.getUiccPort();
10090 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010091 return;
10092 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010093 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010094 if (uiccProfile == null) {
10095 return;
10096 }
10097 uiccProfile.refresh();
10098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
10102
10103 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010104 * Returns false if the mobile data is disabled by default, otherwise return true.
10105 */
10106 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010107 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010108 }
10109
10110 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010111 * Returns the default network type for the given {@code subId}, if the default network type is
10112 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10113 */
10114 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010115 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010116 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010117 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10118 return list.get(phoneId);
10119 }
10120 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010121 }
fionaxua13278b2018-03-21 00:08:13 -070010122
10123 @Override
10124 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010125 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010126 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010127
10128 final long identity = Binder.clearCallingIdentity();
10129 try {
10130 final Phone phone = getPhone(subId);
10131 if (phone == null) {
10132 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10133 return;
10134 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010135 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10136 if (cpt != null) {
10137 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10138 }
10139 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010140 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10141 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010142 if (carrierPrivilegeRules == null) {
10143 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10144 } else {
10145 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010147 } finally {
10148 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010149 }
fionaxua13278b2018-03-21 00:08:13 -070010150 }
10151
10152 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010153 public void setCarrierServicePackageOverride(
10154 int subId, String carrierServicePackage, String callingPackage) {
10155 TelephonyPermissions.enforceShellOnly(
10156 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10157
Benedict Wong66477622023-02-03 23:30:57 +000010158 final long identity = Binder.clearCallingIdentity();
10159 try {
10160 final Phone phone = getPhone(subId);
10161 if (phone == null || phone.getSubId() != subId) {
10162 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10163 throw new IllegalArgumentException("No phone for subid");
10164 }
10165 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10166 if (cpt == null) {
10167 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10168 throw new IllegalStateException("No CPT for phone");
10169 }
10170 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10171 } finally {
10172 Binder.restoreCallingIdentity(identity);
10173 }
10174 }
10175
10176 @Override
fionaxua13278b2018-03-21 00:08:13 -070010177 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010178 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010179
10180 final long identity = Binder.clearCallingIdentity();
10181 try {
10182 final Phone phone = getPhone(subId);
10183 if (phone == null) {
10184 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10185 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10186 }
10187 return phone.getCarrierIdListVersion();
10188 } finally {
10189 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010190 }
fionaxua13278b2018-03-21 00:08:13 -070010191 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010192
10193 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010194 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10195 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010197 mApp, subId, callingPackage, callingFeatureId,
10198 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010199 return -1;
10200 }
10201
10202 final long identity = Binder.clearCallingIdentity();
10203 try {
10204 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10205 } finally {
10206 Binder.restoreCallingIdentity(identity);
10207 }
10208 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010209
10210 @Override
10211 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010212 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010213 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010214 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010215
joonhunshin4ac60942023-11-15 15:23:39 +000010216 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10217 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10218
Pengquan Menga1bb6272018-09-06 09:59:22 -070010219 final long identity = Binder.clearCallingIdentity();
10220 try {
10221 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10222 } finally {
10223 Binder.restoreCallingIdentity(identity);
10224 }
10225 }
10226
10227 @Override
10228 public boolean setCdmaRoamingMode(int subId, int mode) {
10229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10230 mApp, subId, "setCdmaRoamingMode");
10231
joonhunshin4ac60942023-11-15 15:23:39 +000010232 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10233 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10234
Pengquan Menga1bb6272018-09-06 09:59:22 -070010235 final long identity = Binder.clearCallingIdentity();
10236 try {
10237 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
10242
10243 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010244 public int getCdmaSubscriptionMode(int subId) {
10245 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010246 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010247 mApp, subId, "getCdmaSubscriptionMode");
10248
joonhunshin4ac60942023-11-15 15:23:39 +000010249 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10250 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10251
Sarah Chinbaab1432020-10-28 13:46:24 -070010252 final long identity = Binder.clearCallingIdentity();
10253 try {
10254 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10255 } finally {
10256 Binder.restoreCallingIdentity(identity);
10257 }
10258 }
10259
10260 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010261 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10263 mApp, subId, "setCdmaSubscriptionMode");
10264
joonhunshin4ac60942023-11-15 15:23:39 +000010265 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10266 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10267
Pengquan Menga1bb6272018-09-06 09:59:22 -070010268 final long identity = Binder.clearCallingIdentity();
10269 try {
10270 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10271 } finally {
10272 Binder.restoreCallingIdentity(identity);
10273 }
10274 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010275
sqianc5eccab2018-10-19 18:46:41 -070010276 @Override
sqian8c685422019-02-22 15:55:18 -080010277 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010278 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010280 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10281 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010282 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10283 }
joonhunshin4ac60942023-11-15 15:23:39 +000010284
10285 enforceTelephonyFeatureWithException(callingPackage,
10286 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10287
sqian11b7a0e2018-12-05 18:48:28 -080010288 final long identity = Binder.clearCallingIdentity();
10289 try {
sqian854d44b2018-12-12 16:48:18 -080010290 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10291 for (Phone phone: PhoneFactory.getPhones()) {
10292 if (phone.getEmergencyNumberTracker() != null
10293 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10294 emergencyNumberListInternal.put(
10295 phone.getSubId(),
10296 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10297 }
sqian11b7a0e2018-12-05 18:48:28 -080010298 }
sqian854d44b2018-12-12 16:48:18 -080010299 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010300 } finally {
10301 Binder.restoreCallingIdentity(identity);
10302 }
sqianc5eccab2018-10-19 18:46:41 -070010303 }
10304
10305 @Override
sqian8c685422019-02-22 15:55:18 -080010306 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010307 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010308 if (!exactMatch) {
10309 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010310 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010311 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010312 }
joonhunshin4ac60942023-11-15 15:23:39 +000010313
10314 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10315 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10316
sqian11b7a0e2018-12-05 18:48:28 -080010317 final long identity = Binder.clearCallingIdentity();
10318 try {
sqian854d44b2018-12-12 16:48:18 -080010319 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010320 //Note: we ignore passed in param exactMatch. We can remove it once
10321 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010322 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010323 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010324 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010325 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010326 }
sqian11b7a0e2018-12-05 18:48:28 -080010327 }
10328 return false;
10329 } finally {
10330 Binder.restoreCallingIdentity(identity);
10331 }
10332 }
10333
sqianf4ca7ed2019-01-15 18:32:07 -080010334 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010335 * Start emergency callback mode for GsmCdmaPhone for testing.
10336 */
10337 @Override
10338 public void startEmergencyCallbackMode() {
10339 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10340 "startEmergencyCallbackMode");
10341 enforceModifyPermission();
10342 final long identity = Binder.clearCallingIdentity();
10343 try {
10344 for (Phone phone : PhoneFactory.getPhones()) {
10345 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10346 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10347 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10348 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10349 gsmCdmaPhone.obtainMessage(
10350 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10351 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10352 }
10353 }
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
10358
10359 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010360 * Update emergency number list for test mode.
10361 */
10362 @Override
10363 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10364 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10365 "updateEmergencyNumberListTestMode");
10366
10367 final long identity = Binder.clearCallingIdentity();
10368 try {
10369 for (Phone phone: PhoneFactory.getPhones()) {
10370 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10371 if (tracker != null) {
10372 tracker.executeEmergencyNumberTestModeCommand(action, num);
10373 }
10374 }
10375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 }
10379
10380 /**
10381 * Get the full emergency number list for test mode.
10382 */
10383 @Override
10384 public List<String> getEmergencyNumberListTestMode() {
10385 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10386 "getEmergencyNumberListTestMode");
10387
10388 final long identity = Binder.clearCallingIdentity();
10389 try {
10390 Set<String> emergencyNumbers = new HashSet<>();
10391 for (Phone phone: PhoneFactory.getPhones()) {
10392 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10393 if (tracker != null) {
10394 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10395 emergencyNumbers.add(num.getNumber());
10396 }
10397 }
10398 }
10399 return new ArrayList<>(emergencyNumbers);
10400 } finally {
10401 Binder.restoreCallingIdentity(identity);
10402 }
10403 }
10404
chen xud6b45bd2018-10-30 22:27:10 -070010405 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010406 public int getEmergencyNumberDbVersion(int subId) {
10407 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10408
joonhunshin4ac60942023-11-15 15:23:39 +000010409 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10410 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10411
Shuo Qian3b6ee772019-11-13 17:43:31 -080010412 final long identity = Binder.clearCallingIdentity();
10413 try {
10414 final Phone phone = getPhone(subId);
10415 if (phone == null) {
10416 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10417 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10418 }
10419 return phone.getEmergencyNumberDbVersion();
10420 } finally {
10421 Binder.restoreCallingIdentity(identity);
10422 }
10423 }
10424
10425 @Override
10426 public void notifyOtaEmergencyNumberDbInstalled() {
10427 enforceModifyPermission();
10428
joonhunshin4ac60942023-11-15 15:23:39 +000010429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10430 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10431
Shuo Qian3b6ee772019-11-13 17:43:31 -080010432 final long identity = Binder.clearCallingIdentity();
10433 try {
10434 for (Phone phone: PhoneFactory.getPhones()) {
10435 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10436 if (tracker != null) {
10437 tracker.updateOtaEmergencyNumberDatabase();
10438 }
10439 }
10440 } finally {
10441 Binder.restoreCallingIdentity(identity);
10442 }
10443 }
10444
10445 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010446 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010447 enforceActiveEmergencySessionPermission();
10448
joonhunshin4ac60942023-11-15 15:23:39 +000010449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10450 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10451
Shuo Qian3b6ee772019-11-13 17:43:31 -080010452 final long identity = Binder.clearCallingIdentity();
10453 try {
10454 for (Phone phone: PhoneFactory.getPhones()) {
10455 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10456 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010457 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10458 }
10459 }
10460 } finally {
10461 Binder.restoreCallingIdentity(identity);
10462 }
10463 }
10464
10465 @Override
10466 public void resetOtaEmergencyNumberDbFilePath() {
10467 enforceActiveEmergencySessionPermission();
10468
joonhunshin4ac60942023-11-15 15:23:39 +000010469 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10470 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10471
Shuo Qianc373f112020-03-05 17:55:34 -080010472 final long identity = Binder.clearCallingIdentity();
10473 try {
10474 for (Phone phone: PhoneFactory.getPhones()) {
10475 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10476 if (tracker != null) {
10477 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010478 }
10479 }
10480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
10485 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010486 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10487 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10488 Phone phone = getPhone(subId);
10489 if (phone == null) {
10490 return null;
10491 }
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 UiccProfile profile = UiccController.getInstance()
10495 .getUiccProfileForPhone(phone.getPhoneId());
10496 if (profile != null) {
10497 return profile.getCertsFromCarrierPrivilegeAccessRules();
10498 }
10499 } finally {
10500 Binder.restoreCallingIdentity(identity);
10501 }
10502 return null;
10503 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010504
10505 /**
10506 * Enable or disable a modem stack.
10507 */
10508 @Override
10509 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10510 enforceModifyPermission();
10511
joonhunshin4ac60942023-11-15 15:23:39 +000010512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10513 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10514
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010515 final long identity = Binder.clearCallingIdentity();
10516 try {
10517 Phone phone = PhoneFactory.getPhone(slotIndex);
10518 if (phone == null) {
10519 return false;
10520 } else {
10521 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10522 }
10523 } finally {
10524 Binder.restoreCallingIdentity(identity);
10525 }
10526 }
Michelecea4cf22018-12-21 15:00:11 -080010527
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010528 /**
10529 * Whether a modem stack is enabled or not.
10530 */
10531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010532 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10533 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010534 Phone phone = PhoneFactory.getPhone(slotIndex);
10535 if (phone == null) return false;
10536
10537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010538 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10539 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010540 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10541 }
10542
joonhunshin4ac60942023-11-15 15:23:39 +000010543 enforceTelephonyFeatureWithException(callingPackage,
10544 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10545
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010546 final long identity = Binder.clearCallingIdentity();
10547 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010548 try {
10549 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10550 } catch (NoSuchElementException ex) {
10551 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10552 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010553 } finally {
10554 Binder.restoreCallingIdentity(identity);
10555 }
10556 }
10557
Michelecea4cf22018-12-21 15:00:11 -080010558 @Override
Michele0ea7d782019-03-19 14:58:42 -070010559 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010560 enforceModifyPermission();
10561
joonhunshin4ac60942023-11-15 15:23:39 +000010562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10563 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10564
Michelecea4cf22018-12-21 15:00:11 -080010565 final long identity = Binder.clearCallingIdentity();
10566 try {
10567 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010568 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010569 .commit();
10570 } finally {
10571 Binder.restoreCallingIdentity(identity);
10572 }
10573 }
10574
10575 @Override
Michele0ea7d782019-03-19 14:58:42 -070010576 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010577 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010579 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10580 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010581 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010582 }
Michelecea4cf22018-12-21 15:00:11 -080010583
joonhunshin4ac60942023-11-15 15:23:39 +000010584 enforceTelephonyFeatureWithException(callingPackage,
10585 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10586
Michelecea4cf22018-12-21 15:00:11 -080010587 final long identity = Binder.clearCallingIdentity();
10588 try {
Michele0ea7d782019-03-19 14:58:42 -070010589 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010590 } finally {
10591 Binder.restoreCallingIdentity(identity);
10592 }
10593 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010594
Michele0ea7d782019-03-19 14:58:42 -070010595 @TelephonyManager.IsMultiSimSupportedResult
10596 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010597 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10598 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10599 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010600 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10601 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010602 }
10603 // Check if the hardware supports multisim functionality. If usage of multisim is not
10604 // supported by the modem, indicate that it is restricted.
10605 PhoneCapability staticCapability =
10606 mPhoneConfigurationManager.getStaticPhoneCapability();
10607 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010608 loge("isMultiSimSupportedInternal: no static configuration available");
10609 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010610 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010611 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010612 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10613 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010614 }
10615 // Check if support of multiple SIMs is restricted by carrier
10616 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010617 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010618 }
10619
Michele0ea7d782019-03-19 14:58:42 -070010620 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010621 }
10622
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010623 /**
10624 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010625 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10626 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10627 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010628 * @param numOfSims number of active sims we want to switch to
10629 */
10630 @Override
10631 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010632 if (numOfSims == 1) {
10633 enforceModifyPermission();
10634 } else {
10635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10636 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10637 }
joonhunshin4ac60942023-11-15 15:23:39 +000010638
10639 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10640 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10641
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010642 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010643
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010644 try {
Michele30b57b22019-03-01 12:01:14 -080010645 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010646 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010647 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10648 return;
10649 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010650 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10651 } finally {
10652 Binder.restoreCallingIdentity(identity);
10653 }
10654 }
10655
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010656 @Override
10657 public boolean isApplicationOnUicc(int subId, int appType) {
10658 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010659
10660 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10661 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10662
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010663 Phone phone = getPhone(subId);
10664 if (phone == null) {
10665 return false;
10666 }
10667 final long identity = Binder.clearCallingIdentity();
10668 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010669 UiccPort uiccPort = phone.getUiccPort();
10670 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010671 return false;
10672 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010673 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010674 if (uiccProfile == null) {
10675 return false;
10676 }
10677 if (TelephonyManager.APPTYPE_SIM <= appType
10678 && appType <= TelephonyManager.APPTYPE_ISIM) {
10679 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10680 }
10681 return false;
10682 } finally {
10683 Binder.restoreCallingIdentity(identity);
10684 }
10685 }
10686
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010687 /**
chen xub4baa772019-04-03 10:23:41 -070010688 * Get whether making changes to modem configurations will trigger reboot.
10689 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010690 */
10691 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010692 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10693 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010695 mApp, subId, callingPackage, callingFeatureId,
10696 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010697 return false;
10698 }
joonhunshin4ac60942023-11-15 15:23:39 +000010699
10700 enforceTelephonyFeatureWithException(callingPackage,
10701 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10702 "doesSwitchMultiSimConfigTriggerReboot");
10703
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010704 final long identity = Binder.clearCallingIdentity();
10705 try {
10706 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10707 } finally {
10708 Binder.restoreCallingIdentity(identity);
10709 }
10710 }
10711
Nathan Harold29f5f052019-02-15 13:41:57 -080010712 private void updateModemStateMetrics() {
10713 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10714 // TODO: check the state for each modem if the api is ready.
10715 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10716 }
10717
Pengquan Meng3889a572019-01-23 11:16:29 -080010718 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010719 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010720 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010721 // Verify that the callingPackage belongs to the calling UID
10722 mApp.getSystemService(AppOpsManager.class)
10723 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010724
10725 enforceTelephonyFeatureWithException(callingPackage,
10726 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10727
Pengquan Meng3889a572019-01-23 11:16:29 -080010728 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010729 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010730 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010731 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10732 if (slotInfos != null) {
10733 for (int i = 0; i < slotInfos.length; i++) {
10734 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10735 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10736 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10737 portInfo.getLogicalSlotIndex()));
10738 }
10739 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010740 }
10741 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010742 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010743 } finally {
10744 Binder.restoreCallingIdentity(identity);
10745 }
10746 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010747
10748 /**
10749 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010750 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010751 */
jimsunf9ec1622022-09-13 21:18:43 +080010752 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010753 @Override
10754 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010755 return getHalVersion(HAL_SERVICE_RADIO);
10756 }
10757
10758 /**
10759 * Get the HAL Version of a specific service
10760 */
10761 @Override
10762 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010763 Phone phone = getDefaultPhone();
10764 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010765 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010766 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10767 return hv.major * 100 + hv.minor;
10768 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010769
10770 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010771 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010772 *
10773 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010774 */
10775 @Override
sangyun097dcf72024-01-04 10:35:49 +090010776 public @Nullable String getCurrentPackageName() {
10777 PackageManager pm = mApp.getPackageManager();
10778 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10779 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010780 }
10781
10782 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010783 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10784 * corresponding network requests on a subId.
10785 *
10786 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010787 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010788 * 2) APN is un-metered for this subscription, or
10789 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010790 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010791 *
10792 * @return whether data is allowed for a apn type.
10793 *
10794 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010795 */
10796 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010797 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010798 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10799 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010800
joonhunshin4ac60942023-11-15 15:23:39 +000010801 enforceTelephonyFeatureWithException(callingPackage,
10802 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10803
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010804 // Now that all security checks passes, perform the operation as ourselves.
10805 final long identity = Binder.clearCallingIdentity();
10806 try {
10807 Phone phone = getPhone(subId);
10808 if (phone == null) return false;
10809
Jack Yu27422a52022-03-21 10:38:05 -070010810 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010811 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010812 isMetered = phone.getDataNetworkController().getDataConfigManager()
10813 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10814 phone.getServiceState().getDataRoaming());
10815 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010816 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010817 } finally {
10818 Binder.restoreCallingIdentity(identity);
10819 }
10820 }
10821
10822 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010823 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010824 enforceReadPrivilegedPermission("isApnMetered");
10825
joonhunshin4ac60942023-11-15 15:23:39 +000010826 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10827 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10828
Malcolm Chene5ad5792019-04-18 13:51:02 -070010829 // Now that all security checks passes, perform the operation as ourselves.
10830 final long identity = Binder.clearCallingIdentity();
10831 try {
10832 Phone phone = getPhone(subId);
10833 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010834 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10835 DataUtils.apnTypeToNetworkCapability(apnType),
10836 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010837 } finally {
10838 Binder.restoreCallingIdentity(identity);
10839 }
10840 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010841
10842 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010843 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10844 int subscriptionId, IBooleanConsumer resultCallback) {
10845 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010846
10847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10848 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10849
Hall Liu73f5d362020-01-20 13:42:00 -080010850 long token = Binder.clearCallingIdentity();
10851 try {
10852 Phone phone = getPhone(subscriptionId);
10853 if (phone == null) {
10854 try {
10855 if (resultCallback != null) {
10856 resultCallback.accept(false);
10857 }
10858 } catch (RemoteException e) {
10859 // ignore
10860 }
10861 return;
10862 }
10863 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10864 Pair.create(specifiers, (x) -> {
10865 try {
10866 if (resultCallback != null) {
10867 resultCallback.accept(x);
10868 }
10869 } catch (RemoteException e) {
10870 // ignore
10871 }
10872 });
10873 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10874 } finally {
10875 Binder.restoreCallingIdentity(token);
10876 }
10877 }
10878
10879 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010880 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10881 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010882 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010883 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010884
10885 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10886 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10887
Sarah Chin679c08a2020-11-18 13:39:35 -080010888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010891 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10892 if (result instanceof IllegalStateException) {
10893 throw (IllegalStateException) result;
10894 }
10895 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010896 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10897 return specifiers;
10898 } finally {
10899 Binder.restoreCallingIdentity(identity);
10900 }
10901 }
10902
10903 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010904 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010905 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010906
10907 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10908 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10909
Jack Yu8b766fc2022-03-21 09:42:33 -070010910 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010911 }
10912
10913 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010914 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10915 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010916 if (callingPackage == null) {
10917 callingPackage = getCurrentPackageName();
10918 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010919 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10920 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010921 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10922 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010923 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10924 }
10925 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10926 Intent intent = new Intent();
10927 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10928 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10929 // Bring up choose default SMS subscription dialog right now
10930 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10931 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10932 mApp.startActivity(intent);
10933 }
chen xud5ca2d52019-05-28 15:20:57 -070010934
10935 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010936 public void showSwitchToManagedProfileDialog() {
10937 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010938 try {
10939 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10940 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10941 // for work telephony.
10942 Intent intent = new Intent(Intent.ACTION_SENDTO);
10943 intent.setData(Uri.parse("smsto:"));
10944 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10945 mApp.startActivity(intent);
10946 } catch (ActivityNotFoundException e) {
10947 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10948 Intent intent = new Intent();
10949 intent.setClass(mApp, ErrorDialogActivity.class);
10950 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10951 mApp.startActivity(intent);
10952 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010953 }
10954
10955 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010956 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010957 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10958 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10959
chen xud5ca2d52019-05-28 15:20:57 -070010960 //TODO investigate if this API should require proper permission check in R b/133791609
10961 final long identity = Binder.clearCallingIdentity();
10962 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010963 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10964 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10965 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10966 return carrierUAProfUrl;
10967 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010968 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10969 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010970 } finally {
10971 Binder.restoreCallingIdentity(identity);
10972 }
10973 }
10974
10975 @Override
10976 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010977 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10978 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10979
chen xud5ca2d52019-05-28 15:20:57 -070010980 //TODO investigate if this API should require proper permission check in R b/133791609
10981 final long identity = Binder.clearCallingIdentity();
10982 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010983 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10984 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10985 if (!TextUtils.isEmpty(carrierUserAgent)) {
10986 return carrierUserAgent;
10987 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010988 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10989 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010990 } finally {
10991 Binder.restoreCallingIdentity(identity);
10992 }
10993 }
Jack Yub07d4972019-05-28 16:12:25 -070010994
10995 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010996 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10997 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010998
joonhunshin4ac60942023-11-15 15:23:39 +000010999 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11000 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11001
Jack Yub07d4972019-05-28 16:12:25 -070011002 final long identity = Binder.clearCallingIdentity();
11003 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011004 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011005 if (phone == null) return false;
11006
Ling Maf188d502022-09-16 15:22:36 -070011007 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011008 } finally {
11009 Binder.restoreCallingIdentity(identity);
11010 }
11011 }
11012
11013 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011014 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011015 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011016 enforceModifyPermission();
11017
joonhunshin4ac60942023-11-15 15:23:39 +000011018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11019 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11020
changbettyd5c246e2019-12-24 15:40:37 +080011021 final long identity = Binder.clearCallingIdentity();
11022 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011023 Phone phone = getPhone(subscriptionId);
11024 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011025
Ling Maf188d502022-09-16 15:22:36 -070011026 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011027 } finally {
11028 Binder.restoreCallingIdentity(identity);
11029 }
11030 }
11031
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011032 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011033 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011034 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11035 * otherwise.
11036 */
11037 @Override
11038 public void setCepEnabled(boolean isCepEnabled) {
11039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11040
11041 final long identity = Binder.clearCallingIdentity();
11042 try {
11043 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11044 for (Phone phone : PhoneFactory.getPhones()) {
11045 Phone defaultPhone = phone.getImsPhone();
11046 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11047 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11048 ImsPhoneCallTracker imsPhoneCallTracker =
11049 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11050 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11051 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11052 + imsPhone.getMsisdn());
11053 }
11054 }
11055 } finally {
11056 Binder.restoreCallingIdentity(identity);
11057 }
11058 }
allenwtsu46dcc572020-01-08 18:24:03 +080011059
11060 /**
11061 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11062 *
11063 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11064 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11065 * before being read.
11066 */
11067 @Override
11068 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11069 isCompressed) {
11070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11071 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011072 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11073 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11074 }
joonhunshin4ac60942023-11-15 15:23:39 +000011075
11076 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11077 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11078 Binder.getCallingUserHandle())) {
11079 if (!isImsAvailableOnDevice()) {
11080 // ProvisioningManager can not handle ServiceSpecificException.
11081 // Throw the IllegalStateException and annotate ProvisioningManager.
11082 throw new IllegalStateException("IMS not available on device.");
11083 }
11084 } else {
11085 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11086 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11087 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011088 }
11089
11090 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011091 try {
Hui Wang761a6682020-10-31 05:12:53 +000011092 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11093 } finally {
11094 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011095 }
11096 }
zoey chene02881a2019-12-30 16:11:23 +080011097
11098 @Override
11099 public boolean isIccLockEnabled(int subId) {
11100 enforceReadPrivilegedPermission("isIccLockEnabled");
11101
joonhunshin4ac60942023-11-15 15:23:39 +000011102 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11103 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11104
zoey chene02881a2019-12-30 16:11:23 +080011105 // Now that all security checks passes, perform the operation as ourselves.
11106 final long identity = Binder.clearCallingIdentity();
11107 try {
11108 Phone phone = getPhone(subId);
11109 if (phone != null && phone.getIccCard() != null) {
11110 return phone.getIccCard().getIccLockEnabled();
11111 } else {
11112 return false;
11113 }
11114 } finally {
11115 Binder.restoreCallingIdentity(identity);
11116 }
11117 }
11118
11119 /**
11120 * Set the ICC pin lock enabled or disabled.
11121 *
11122 * @return an integer representing the status of IccLock enabled or disabled in the following
11123 * three cases:
11124 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11125 * successfully.
11126 * - Positive number and zero for remaining password attempts.
11127 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11128 *
11129 */
11130 @Override
11131 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11132 enforceModifyPermission();
11133
joonhunshin4ac60942023-11-15 15:23:39 +000011134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11135 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11136
zoey chene02881a2019-12-30 16:11:23 +080011137 Phone phone = getPhone(subId);
11138 if (phone == null) {
11139 return 0;
11140 }
11141 // Now that all security checks passes, perform the operation as ourselves.
11142 final long identity = Binder.clearCallingIdentity();
11143 try {
11144 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11145 new Pair<Boolean, String>(enabled, password), phone, null);
11146 return attemptsRemaining;
11147
11148 } catch (Exception e) {
11149 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11150 } finally {
11151 Binder.restoreCallingIdentity(identity);
11152 }
11153 return 0;
11154 }
11155
11156 /**
11157 * Change the ICC password used in ICC pin lock.
11158 *
11159 * @return an integer representing the status of IccLock changed in the following three cases:
11160 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11161 * - Positive number and zero for remaining password attempts.
11162 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11163 *
11164 */
11165 @Override
11166 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11167 enforceModifyPermission();
11168
joonhunshin4ac60942023-11-15 15:23:39 +000011169 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11170 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11171
zoey chene02881a2019-12-30 16:11:23 +080011172 Phone phone = getPhone(subId);
11173 if (phone == null) {
11174 return 0;
11175 }
11176 // Now that all security checks passes, perform the operation as ourselves.
11177 final long identity = Binder.clearCallingIdentity();
11178 try {
11179 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11180 new Pair<String, String>(oldPassword, newPassword), phone, null);
11181 return attemptsRemaining;
11182
11183 } catch (Exception e) {
11184 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11185 } finally {
11186 Binder.restoreCallingIdentity(identity);
11187 }
11188 return 0;
11189 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011190
11191 /**
11192 * Request for receiving user activity notification
11193 */
11194 @Override
11195 public void requestUserActivityNotification() {
11196 if (!mNotifyUserActivity.get()
11197 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11198 mNotifyUserActivity.set(true);
11199 }
11200 }
11201
11202 /**
11203 * Called when userActivity is signalled in the power manager.
11204 * This is safe to call from any thread, with any window manager locks held or not.
11205 */
11206 @Override
11207 public void userActivity() {
11208 // ***************************************
11209 // * Inherited from PhoneWindowManager *
11210 // ***************************************
11211 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11212 // WITH ITS LOCKS HELD.
11213 //
11214 // This code must be VERY careful about the locks
11215 // it acquires.
11216 // In fact, the current code acquires way too many,
11217 // and probably has lurking deadlocks.
11218
11219 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11220 throw new SecurityException("Only the OS may call notifyUserActivity()");
11221 }
11222
11223 if (mNotifyUserActivity.getAndSet(false)) {
11224 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11225 USER_ACTIVITY_NOTIFICATION_DELAY);
11226 }
11227 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011228
11229 @Override
11230 public boolean canConnectTo5GInDsdsMode() {
11231 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11232 }
Jack Yud10cdd42020-09-28 20:28:01 -070011233
11234 @Override
11235 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11236 String callingFeatureId) {
11237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11238 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11239 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11240 }
11241
joonhunshin4ac60942023-11-15 15:23:39 +000011242 enforceTelephonyFeatureWithException(callingPackage,
11243 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11244
Jack Yud10cdd42020-09-28 20:28:01 -070011245 Phone phone = getPhone(subId);
11246 if (phone == null) {
11247 throw new RuntimeException("phone is not available");
11248 }
11249 // Now that all security checks passes, perform the operation as ourselves.
11250 final long identity = Binder.clearCallingIdentity();
11251 try {
11252 return phone.getEquivalentHomePlmns();
11253 } finally {
11254 Binder.restoreCallingIdentity(identity);
11255 }
11256 }
Daniel Bright59e67312020-11-13 11:49:37 -080011257
11258 @Override
11259 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011260 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011261 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11262 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11263 "isRadioInterfaceCapabilitySupported");
11264
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011265 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011266 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011267 if (radioInterfaceCapabilities == null) {
11268 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011269 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011270 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011271 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011272
Hui Wang641e81c2020-10-12 12:14:23 -070011273 @Override
11274 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11275 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011276 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11277 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11278 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11279 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11280 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011281
11282 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11283 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11284
Hui Wang641e81c2020-10-12 12:14:23 -070011285 if (DBG) {
11286 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11287 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11288 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11289 }
11290
11291 if (!SubscriptionManager.isValidSubscriptionId(subId)
11292 || appType < TelephonyManager.APPTYPE_UNKNOWN
11293 || appType > TelephonyManager.APPTYPE_ISIM
11294 || nafUrl == null || securityProtocol == null || callback == null) {
11295 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11296 if (callback != null) {
11297 try {
11298 callback.onAuthenticationFailure(
11299 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11300 } catch (RemoteException exception) {
11301 log("Fail to notify onAuthenticationFailure due to " + exception);
11302 }
11303 return;
11304 }
11305 }
11306
11307 final long token = Binder.clearCallingIdentity();
11308 try {
11309 getGbaManager(subId).bootstrapAuthenticationRequest(
11310 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011311 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011312 } finally {
11313 Binder.restoreCallingIdentity(token);
11314 }
11315 }
11316
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011317 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011318 * Attempts to set the radio power state for all phones for thermal reason.
11319 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011320 * requested radio power state will actually be set. See {@link
11321 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11322 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011323 * @param enable {@code true} if trying to turn radio on.
11324 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11325 * false}.
11326 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011327 private boolean setRadioPowerForThermal(boolean enable) {
11328 boolean isPhoneAvailable = false;
11329 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11330 Phone phone = PhoneFactory.getPhone(i);
11331 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011332 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011333 isPhoneAvailable = true;
11334 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011335 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011336
11337 // return true if successfully informed the phone object about the thermal radio power
11338 // request.
11339 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011340 }
11341
11342 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011343 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011344 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11345 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11346 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11347 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11348 throw new IllegalArgumentException("modem does not support data throttling");
11349 }
11350
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011351 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11352 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011353 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011354 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11355 }
11356
Sarah Chinecc78c42022-03-31 21:16:48 -070011357 setDataEnabledForReason(
11358 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011359
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011360 if (isDataThrottlingSupported) {
11361 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011362 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011363 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11364 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11365 } else if (thermalMitigationResult
11366 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011367 log("Modem likely does not support data throttling on secondary carrier. Data " +
11368 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11369 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011370 }
11371 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011372 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011373
11374 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011375 }
11376
Jack Nudelman644b91a2021-03-12 14:09:48 -080011377 private static List<String> getThermalMitigationAllowlist(Context context) {
11378 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11379 for (String pckg : context.getResources()
11380 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11381 sThermalMitigationAllowlistedPackages.add(pckg);
11382 }
11383 }
11384
11385 return sThermalMitigationAllowlistedPackages;
11386 }
11387
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011388 private boolean isAnyPhoneInEmergencyState() {
11389 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11390 if (tm.isInEmergencyCall()) {
11391 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11392 return true;
11393 }
11394 for (Phone phone : PhoneFactory.getPhones()) {
11395 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11396 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011397 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11398 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011399 return true;
11400 }
11401 }
11402
11403 return false;
11404 }
11405
Jack Nudelman644b91a2021-03-12 14:09:48 -080011406 /**
11407 * Used by shell commands to add an authorized package name for thermal mitigation.
11408 * @param packageName name of package to be allowlisted
11409 * @param context
11410 */
11411 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11412 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11413 sThermalMitigationAllowlistedPackages.add(packageName);
11414 }
11415
11416 /**
11417 * Used by shell commands to remove an authorized package name for thermal mitigation.
11418 * @param packageName name of package to remove from allowlist
11419 * @param context
11420 */
11421 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11422 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11423 sThermalMitigationAllowlistedPackages.remove(packageName);
11424 }
11425
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011426 /**
11427 * Thermal mitigation request to control functionalities at modem.
11428 *
11429 * @param subId the id of the subscription.
11430 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011431 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011432 *
11433 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11434 */
11435 @Override
11436 @ThermalMitigationResult
11437 public int sendThermalMitigationRequest(
11438 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011439 ThermalMitigationRequest thermalMitigationRequest,
11440 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011441 enforceModifyPermission();
11442
Jack Nudelman644b91a2021-03-12 14:09:48 -080011443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011444
11445 enforceTelephonyFeatureWithException(callingPackage,
11446 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11447
Jack Nudelman644b91a2021-03-12 14:09:48 -080011448 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11449 .contains(callingPackage)) {
11450 throw new SecurityException("Calling package must be configured in the device config. "
11451 + "calling package: " + callingPackage);
11452 }
11453
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011454 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11455 final long identity = Binder.clearCallingIdentity();
11456
11457 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11458 try {
11459 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11460 switch (thermalMitigationAction) {
11461 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11462 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011463 handleDataThrottlingRequest(subId,
11464 thermalMitigationRequest.getDataThrottlingRequest(),
11465 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011466 break;
11467 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11468 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11469 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11470 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11471 }
11472
11473 // Ensure that radio is on. If not able to power on due to phone being
11474 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011475 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011476 thermalMitigationResult =
11477 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11478 break;
11479 }
11480
11481 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011482 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011483 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11484 break;
11485 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11486 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11487 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11488 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11489 }
11490
11491 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11492 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011493 Phone phone = getPhone(subId);
11494 if (phone == null) {
11495 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011496 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011497 break;
11498 }
11499
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011500 TelephonyConnectionService service =
11501 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011502 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011503 Log.e(LOG_TAG, "An emergency call is pending");
11504 thermalMitigationResult =
11505 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11506 break;
11507 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011508 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011509 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011510 break;
11511 }
11512 } else {
11513 thermalMitigationResult =
11514 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11515 break;
11516 }
11517
11518 // Turn radio off. If not able to power off due to phone being unavailable,
11519 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011520 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011521 thermalMitigationResult =
11522 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11523 break;
11524 }
11525 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011526 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011527 break;
11528 default:
11529 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11530 + "not exist. Requested action: " + thermalMitigationAction);
11531 }
11532 } catch (IllegalArgumentException e) {
11533 throw e;
11534 } catch (Exception e) {
11535 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11536 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11537 } finally {
11538 Binder.restoreCallingIdentity(identity);
11539 }
11540
11541 if (DBG) {
11542 log("thermalMitigationRequest returning with thermalMitigationResult: "
11543 + thermalMitigationResult);
11544 }
11545
11546 return thermalMitigationResult;
11547 }
Hui Wang641e81c2020-10-12 12:14:23 -070011548
11549 /**
11550 * Set the GbaService Package Name that Telephony will bind to.
11551 *
11552 * @param subId The sim that the GbaService is associated with.
11553 * @param packageName The name of the package to be replaced with.
11554 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11555 */
11556 @Override
11557 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11558 enforceModifyPermission();
11559
11560 final long identity = Binder.clearCallingIdentity();
11561 try {
11562 return getGbaManager(subId).overrideServicePackage(packageName);
11563 } finally {
11564 Binder.restoreCallingIdentity(identity);
11565 }
11566 }
11567
11568 /**
11569 * Return the package name of the currently bound GbaService.
11570 *
11571 * @param subId The sim that the GbaService is associated with.
11572 * @return the package name of the GbaService configuration, null if GBA is not supported.
11573 */
11574 @Override
11575 public String getBoundGbaService(int subId) {
11576 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11577
11578 final long identity = Binder.clearCallingIdentity();
11579 try {
11580 return getGbaManager(subId).getServicePackage();
11581 } finally {
11582 Binder.restoreCallingIdentity(identity);
11583 }
11584 }
11585
11586 /**
11587 * Set the release time for telephony to unbind GbaService.
11588 *
11589 * @param subId The sim that the GbaService is associated with.
11590 * @param interval The release time to unbind GbaService by millisecond.
11591 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11592 */
11593 @Override
11594 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11595 enforceModifyPermission();
11596
11597 final long identity = Binder.clearCallingIdentity();
11598 try {
11599 return getGbaManager(subId).overrideReleaseTime(interval);
11600 } finally {
11601 Binder.restoreCallingIdentity(identity);
11602 }
11603 }
11604
11605 /**
11606 * Return the release time for telephony to unbind GbaService.
11607 *
11608 * @param subId The sim that the GbaService is associated with.
11609 * @return The release time to unbind GbaService by millisecond.
11610 */
11611 @Override
11612 public int getGbaReleaseTime(int subId) {
11613 enforceReadPrivilegedPermission("getGbaReleaseTime");
11614
11615 final long identity = Binder.clearCallingIdentity();
11616 try {
11617 return getGbaManager(subId).getReleaseTime();
11618 } finally {
11619 Binder.restoreCallingIdentity(identity);
11620 }
11621 }
11622
11623 private GbaManager getGbaManager(int subId) {
11624 GbaManager instance = GbaManager.getInstance(subId);
11625 if (instance == null) {
11626 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11627 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11628 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11629 }
11630 return instance;
11631 }
Hui Wang761a6682020-10-31 05:12:53 +000011632
11633 /**
11634 * indicate whether the device and the carrier can support
11635 * RCS VoLTE single registration.
11636 */
11637 @Override
11638 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011639 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11640 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11641 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11642 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011643
11644 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11645 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11646 }
11647
11648 final long identity = Binder.clearCallingIdentity();
11649 try {
11650 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11651 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011652 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11653 if (isCapable != null) {
11654 return isCapable;
11655 }
Hui Wang761a6682020-10-31 05:12:53 +000011656 }
Hui Wang67af90e2021-06-04 16:57:15 -070011657 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11658 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011659 } finally {
11660 Binder.restoreCallingIdentity(identity);
11661 }
11662 }
11663
11664 /**
11665 * Register RCS provisioning callback.
11666 */
11667 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011668 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011669 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011670 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011671 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011672 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11673 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011674
11675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11676 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11677 }
joonhunshin4ac60942023-11-15 15:23:39 +000011678 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11679 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11680 Binder.getCallingUserHandle())) {
11681 if (!isImsAvailableOnDevice()) {
11682 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11683 "IMS not available on device.");
11684 }
11685 } else {
11686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11687 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011688 }
11689
11690 final long identity = Binder.clearCallingIdentity();
11691 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011692 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011693 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011694 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11695 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011696 }
Hui Wang761a6682020-10-31 05:12:53 +000011697 } finally {
11698 Binder.restoreCallingIdentity(identity);
11699 }
11700 }
11701
11702 /**
11703 * Unregister RCS provisioning callback.
11704 */
11705 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011706 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011707 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011708 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011709 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011710 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11711 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011712
11713 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11714 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11715 }
joonhunshin4ac60942023-11-15 15:23:39 +000011716
11717 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11718 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11719 Binder.getCallingUserHandle())) {
11720 if (!isImsAvailableOnDevice()) {
11721 // operation failed silently
11722 Rlog.w(LOG_TAG, "IMS not available on device.");
11723 return;
11724 }
11725 } else {
11726 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11727 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11728 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011729 }
11730
11731 final long identity = Binder.clearCallingIdentity();
11732 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011733 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011734 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011735 } finally {
11736 Binder.restoreCallingIdentity(identity);
11737 }
11738 }
11739
11740 /**
11741 * trigger RCS reconfiguration.
11742 */
11743 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011744 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11745 "triggerRcsReconfiguration",
11746 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011747
11748 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11749 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11750 }
joonhunshin4ac60942023-11-15 15:23:39 +000011751 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11752 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11753 Binder.getCallingUserHandle())) {
11754 if (!isImsAvailableOnDevice()) {
11755 // ProvisioningManager can not handle ServiceSpecificException.
11756 // Throw the IllegalStateException and annotate ProvisioningManager.
11757 throw new IllegalStateException("IMS not available on device.");
11758 }
11759 } else {
11760 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11761 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011762 }
11763
11764 final long identity = Binder.clearCallingIdentity();
11765 try {
11766 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11767 } finally {
11768 Binder.restoreCallingIdentity(identity);
11769 }
11770 }
11771
11772 /**
11773 * Provide the client configuration parameters of the RCS application.
11774 */
11775 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011776 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11777 "setRcsClientConfiguration",
11778 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011779
11780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11781 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11782 }
joonhunshin4ac60942023-11-15 15:23:39 +000011783 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11784 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11785 Binder.getCallingUserHandle())) {
11786 if (!isImsAvailableOnDevice()) {
11787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11788 "IMS not available on device.");
11789 }
11790 } else {
11791 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11792 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011793 }
11794
11795 final long identity = Binder.clearCallingIdentity();
11796
11797 try {
11798 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11799 if (configBinder == null) {
11800 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011801 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11802 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011803 } else {
11804 configBinder.setRcsClientConfiguration(rcc);
11805 }
joonhunshin3e154242021-09-17 06:33:39 +000011806
11807 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11808 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011809 } catch (RemoteException e) {
11810 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011811 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11812 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011813 } finally {
11814 Binder.restoreCallingIdentity(identity);
11815 }
11816 }
11817
11818 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011819 * Enables or disables the test mode for RCS VoLTE single registration.
11820 */
11821 @Override
11822 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11823 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11824 "setRcsSingleRegistrationTestModeEnabled");
11825
11826 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11827 }
11828
11829 /**
11830 * Gets the test mode for RCS VoLTE single registration.
11831 */
11832 @Override
11833 public boolean getRcsSingleRegistrationTestModeEnabled() {
11834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11835 "getRcsSingleRegistrationTestModeEnabled");
11836
11837 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11838 }
11839
11840 /**
Hui Wang761a6682020-10-31 05:12:53 +000011841 * Overrides the config of RCS VoLTE single registration enabled for the device.
11842 */
11843 @Override
11844 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11846 "setDeviceSingleRegistrationEnabledOverride");
11847 enforceModifyPermission();
11848
11849 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11850 : Boolean.parseBoolean(enabledStr);
11851 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011852 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011853 }
11854
11855 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011856 * Sends a device to device communication message. Only usable via shell.
11857 * @param message message to send.
11858 * @param value message value.
11859 */
11860 @Override
11861 public void sendDeviceToDeviceMessage(int message, int value) {
11862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011863 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011864 enforceModifyPermission();
11865
11866 final long identity = Binder.clearCallingIdentity();
11867 try {
11868 TelephonyConnectionService service =
11869 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11870 if (service == null) {
11871 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11872 return;
11873 }
11874 service.sendTestDeviceToDeviceMessage(message, value);
11875 } finally {
11876 Binder.restoreCallingIdentity(identity);
11877 }
11878 }
11879
Tyler Gunnbabbda02021-02-10 11:05:02 -080011880 /**
11881 * Sets the specified device to device transport active.
11882 * @param transport The transport to set active.
11883 */
11884 @Override
11885 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11887 "setActiveDeviceToDeviceTransport");
11888 enforceModifyPermission();
11889
11890 final long identity = Binder.clearCallingIdentity();
11891 try {
11892 TelephonyConnectionService service =
11893 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11894 if (service == null) {
11895 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11896 return;
11897 }
11898 service.setActiveDeviceToDeviceTransport(transport);
11899 } finally {
11900 Binder.restoreCallingIdentity(identity);
11901 }
11902 }
Tyler Gunn92479152021-01-20 16:30:10 -080011903
Tyler Gunnd4339262021-05-03 14:46:49 -070011904 @Override
11905 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11907 "setDeviceToDeviceForceEnabled");
11908
11909 final long identity = Binder.clearCallingIdentity();
11910 try {
11911 Arrays.stream(PhoneFactory.getPhones()).forEach(
11912 p -> {
11913 Phone thePhone = p.getImsPhone();
11914 if (thePhone != null && thePhone instanceof ImsPhone) {
11915 ImsPhone imsPhone = (ImsPhone) thePhone;
11916 CallTracker tracker = imsPhone.getCallTracker();
11917 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11918 ImsPhoneCallTracker imsPhoneCallTracker =
11919 (ImsPhoneCallTracker) tracker;
11920 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11921 }
11922 }
11923 }
11924 );
11925 } finally {
11926 Binder.restoreCallingIdentity(identity);
11927 }
11928 }
11929
Tyler Gunn92479152021-01-20 16:30:10 -080011930 /**
Hui Wang761a6682020-10-31 05:12:53 +000011931 * Gets the config of RCS VoLTE single registration enabled for the device.
11932 */
11933 @Override
11934 public boolean getDeviceSingleRegistrationEnabled() {
11935 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11936 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11937 }
11938
11939 /**
11940 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11941 */
11942 @Override
11943 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11945 "setCarrierSingleRegistrationEnabledOverride");
11946 enforceModifyPermission();
11947
11948 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11949 : Boolean.parseBoolean(enabledStr);
11950 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11951 subId, enabled);
11952 }
11953
11954 /**
11955 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11956 */
11957 @Override
11958 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11959 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11960 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11961 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011962
11963 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011964 * Overrides the ims feature validation result
11965 */
11966 @Override
11967 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11969 "setImsFeatureValidationOverride");
11970
11971 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11972 : Boolean.parseBoolean(enabledStr);
11973 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11974 subId, enabled);
11975 }
11976
11977 /**
11978 * Gets the ims feature validation override value
11979 */
11980 @Override
11981 public boolean getImsFeatureValidationOverride(int subId) {
11982 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11983 "getImsFeatureValidationOverride");
11984 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11985 }
11986
11987 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011988 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11989 * their mobile plan.
11990 */
11991 @Override
11992 public String getMobileProvisioningUrl() {
11993 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11994 final long identity = Binder.clearCallingIdentity();
11995 try {
11996 return getDefaultPhone().getMobileProvisioningUrl();
11997 } finally {
11998 Binder.restoreCallingIdentity(identity);
11999 }
12000 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012001
James.cf Linbcdf8b32021-01-14 16:44:13 +080012002 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012003 * Get the EAB contact from the EAB database.
12004 */
12005 @Override
12006 public String getContactFromEab(String contact) {
12007 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12008 enforceModifyPermission();
12009 final long identity = Binder.clearCallingIdentity();
12010 try {
12011 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12012 } finally {
12013 Binder.restoreCallingIdentity(identity);
12014 }
12015 }
12016
12017 /**
Calvin Pana1434322021-07-01 19:27:01 +080012018 * Get the EAB capability from the EAB database.
12019 */
12020 @Override
12021 public String getCapabilityFromEab(String contact) {
12022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12023 enforceModifyPermission();
12024 final long identity = Binder.clearCallingIdentity();
12025 try {
12026 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12027 } finally {
12028 Binder.restoreCallingIdentity(identity);
12029 }
12030 }
12031
12032 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012033 * Remove the EAB contacts from the EAB database.
12034 */
12035 @Override
12036 public int removeContactFromEab(int subId, String contacts) {
12037 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12038 enforceModifyPermission();
12039 final long identity = Binder.clearCallingIdentity();
12040 try {
12041 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12042 } finally {
12043 Binder.restoreCallingIdentity(identity);
12044 }
12045 }
12046
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012047 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012048 public boolean getDeviceUceEnabled() {
12049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12050 final long identity = Binder.clearCallingIdentity();
12051 try {
12052 return mApp.getDeviceUceEnabled();
12053 } finally {
12054 Binder.restoreCallingIdentity(identity);
12055 }
12056 }
12057
12058 @Override
12059 public void setDeviceUceEnabled(boolean isEnabled) {
12060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12061 final long identity = Binder.clearCallingIdentity();
12062 try {
12063 mApp.setDeviceUceEnabled(isEnabled);
12064 } finally {
12065 Binder.restoreCallingIdentity(identity);
12066 }
12067 }
12068
Brad Ebinger14d467f2021-02-12 06:18:28 +000012069 /**
12070 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12071 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12072 */
12073 // Used for SHELL command only right now.
12074 @Override
12075 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12076 List<String> featureTags) {
12077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12078 "addUceRegistrationOverrideShell");
12079 final long identity = Binder.clearCallingIdentity();
12080 try {
12081 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12082 new ArraySet<>(featureTags));
12083 } catch (ImsException e) {
12084 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12085 } finally {
12086 Binder.restoreCallingIdentity(identity);
12087 }
12088 }
12089
12090 /**
12091 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12092 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12093 */
12094 // Used for SHELL command only right now.
12095 @Override
12096 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12097 List<String> featureTags) {
12098 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12099 "removeUceRegistrationOverrideShell");
12100 final long identity = Binder.clearCallingIdentity();
12101 try {
12102 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12103 new ArraySet<>(featureTags));
12104 } catch (ImsException e) {
12105 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12106 } finally {
12107 Binder.restoreCallingIdentity(identity);
12108 }
12109 }
12110
12111 /**
12112 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12113 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12114 */
12115 // Used for SHELL command only right now.
12116 @Override
12117 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12119 "clearUceRegistrationOverrideShell");
12120 final long identity = Binder.clearCallingIdentity();
12121 try {
12122 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12123 } catch (ImsException e) {
12124 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12125 } finally {
12126 Binder.restoreCallingIdentity(identity);
12127 }
12128 }
12129
12130 /**
12131 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12132 */
12133 // Used for SHELL command only right now.
12134 @Override
12135 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12136 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12137 "getLatestRcsContactUceCapabilityShell");
12138 final long identity = Binder.clearCallingIdentity();
12139 try {
12140 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12141 } catch (ImsException e) {
12142 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12143 } finally {
12144 Binder.restoreCallingIdentity(identity);
12145 }
12146 }
12147
12148 /**
12149 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12150 * device does not have an active PUBLISH.
12151 */
12152 // Used for SHELL command only right now.
12153 @Override
12154 public String getLastUcePidfXmlShell(int subId) {
12155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12156 final long identity = Binder.clearCallingIdentity();
12157 try {
12158 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12159 } catch (ImsException e) {
12160 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12161 } finally {
12162 Binder.restoreCallingIdentity(identity);
12163 }
12164 }
12165
James.cf Line8713a42021-04-29 16:04:26 +080012166 /**
12167 * Remove UCE requests cannot be sent to the network status.
12168 */
12169 // Used for SHELL command only right now.
12170 @Override
12171 public boolean removeUceRequestDisallowedStatus(int subId) {
12172 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12173 final long identity = Binder.clearCallingIdentity();
12174 try {
12175 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12176 } catch (ImsException e) {
12177 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12178 } finally {
12179 Binder.restoreCallingIdentity(identity);
12180 }
12181 }
12182
James.cf Lin18bb9002021-05-25 01:37:38 +080012183 /**
12184 * Remove UCE requests cannot be sent to the network status.
12185 */
12186 // Used for SHELL command only.
12187 @Override
12188 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12189 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12190 final long identity = Binder.clearCallingIdentity();
12191 try {
12192 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12193 } catch (ImsException e) {
12194 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12195 } finally {
12196 Binder.restoreCallingIdentity(identity);
12197 }
12198 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012199
James.cf Lin4b784aa2021-01-31 03:25:15 +080012200 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012201 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12202 String callingPackage) {
12203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12204 mApp, subId, "setSignalStrengthUpdateRequest");
12205
joonhunshin4ac60942023-11-15 15:23:39 +000012206 enforceTelephonyFeatureWithException(callingPackage,
12207 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12208
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012209 final int callingUid = Binder.getCallingUid();
12210 // Verify that tha callingPackage belongs to the calling UID
12211 mApp.getSystemService(AppOpsManager.class)
12212 .checkPackage(callingUid, callingPackage);
12213
Rambo Wang3607f502021-02-01 21:51:40 -080012214 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012215
12216 final long identity = Binder.clearCallingIdentity();
12217 try {
12218 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12219 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12220
12221 if (result instanceof IllegalStateException) {
12222 throw (IllegalStateException) result;
12223 }
12224 } finally {
12225 Binder.restoreCallingIdentity(identity);
12226 }
12227 }
12228
12229 @Override
12230 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12231 String callingPackage) {
12232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12233 mApp, subId, "clearSignalStrengthUpdateRequest");
12234
joonhunshin4ac60942023-11-15 15:23:39 +000012235 enforceTelephonyFeatureWithException(callingPackage,
12236 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12237
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012238 final int callingUid = Binder.getCallingUid();
12239 // Verify that tha callingPackage belongs to the calling UID
12240 mApp.getSystemService(AppOpsManager.class)
12241 .checkPackage(callingUid, callingPackage);
12242
12243 final long identity = Binder.clearCallingIdentity();
12244 try {
12245 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12246 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12247
12248 if (result instanceof IllegalStateException) {
12249 throw (IllegalStateException) result;
12250 }
12251 } finally {
12252 Binder.restoreCallingIdentity(identity);
12253 }
12254 }
12255
Rambo Wang3607f502021-02-01 21:51:40 -080012256 private static void validateSignalStrengthUpdateRequest(Context context,
12257 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012258 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12259 // phone/system process do not have further restriction on request
12260 return;
12261 }
12262
12263 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012264 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012265 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012266 context.enforceCallingOrSelfPermission(
12267 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12268 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012269 }
12270
12271 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012272 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012273 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012274 || info.isEnabled()) {
12275 throw new IllegalArgumentException(
12276 "Only system can set hide fields in SignalThresholdInfo");
12277 }
12278
12279 // Thresholds length for each RAN need in range. This has been validated in
12280 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12281 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12282 final int[] thresholds = info.getThresholds();
12283 Objects.requireNonNull(thresholds);
12284 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12285 || thresholds.length
12286 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12287 throw new IllegalArgumentException(
12288 "thresholds length is out of range: " + thresholds.length);
12289 }
12290 }
12291 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012292
12293 /**
12294 * Gets the current phone capability.
12295 *
12296 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12297 * @return the PhoneCapability which describes the data connection capability of modem.
12298 * It's used to evaluate possible phone config change, for example from single
12299 * SIM device to multi-SIM device.
12300 */
12301 @Override
12302 public PhoneCapability getPhoneCapability() {
12303 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012304
12305 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12306 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12307
SongFerngWang8236caa2021-01-17 21:51:44 +080012308 final long identity = Binder.clearCallingIdentity();
12309 try {
12310 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12311 } finally {
12312 Binder.restoreCallingIdentity(identity);
12313 }
12314 }
Michele Berionne5e411512020-11-13 02:36:59 +000012315
12316 /**
12317 * Prepare TelephonyManager for an unattended reboot. The reboot is
12318 * required to be done shortly after the API is invoked.
12319 */
12320 @Override
12321 @TelephonyManager.PrepareUnattendedRebootResult
12322 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012323 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012324 enforceRebootPermission();
12325
joonhunshin4ac60942023-11-15 15:23:39 +000012326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12327 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12328
Michele Berionne5e411512020-11-13 02:36:59 +000012329 final long identity = Binder.clearCallingIdentity();
12330 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012331 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012332 } finally {
12333 Binder.restoreCallingIdentity(identity);
12334 }
12335 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012336
12337 /**
12338 * Request to get the current slicing configuration including URSP rules and
12339 * NSSAIs (configured, allowed and rejected).
12340 *
12341 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12342 */
12343 @Override
12344 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012345 TelephonyPermissions
12346 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12347 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012348
joonhunshin4ac60942023-11-15 15:23:39 +000012349 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12350 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12351 "getSlicingConfig");
12352
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012353 final long identity = Binder.clearCallingIdentity();
12354 try {
12355 Phone phone = getDefaultPhone();
12356 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12357 } finally {
12358 Binder.restoreCallingIdentity(identity);
12359 }
12360 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012361
12362 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012363 * Check whether the given premium capability is available for purchase from the carrier.
12364 *
12365 * @param capability The premium capability to check.
12366 * @param subId The subId to check the premium capability for.
12367 *
12368 * @return Whether the given premium capability is available to purchase.
12369 */
12370 @Override
12371 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12372 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12373 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12374 log("Premium capability "
12375 + TelephonyManager.convertPremiumCapabilityToString(capability)
12376 + " is not available for purchase due to missing permissions.");
12377 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12378 + "permission READ_BASIC_PHONE_STATE.");
12379 }
12380
joonhunshin4ac60942023-11-15 15:23:39 +000012381 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12382 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12383
Sarah Chin2ec39f62022-08-31 17:03:26 -070012384 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012385 if (phone == null) {
12386 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12387 return false;
12388 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012389 final long identity = Binder.clearCallingIdentity();
12390 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012391 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012392 .isPremiumCapabilityAvailableForPurchase(capability);
12393 } finally {
12394 Binder.restoreCallingIdentity(identity);
12395 }
12396 }
12397
12398 /**
12399 * Purchase the given premium capability from the carrier.
12400 *
12401 * @param capability The premium capability to purchase.
12402 * @param callback The result of the purchase request.
12403 * @param subId The subId to purchase the premium capability for.
12404 */
12405 @Override
12406 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12407 log("purchasePremiumCapability: capability="
12408 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12409 + getCurrentPackageName());
12410
12411 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12412 mApp, "purchasePremiumCapability")) {
12413 log("purchasePremiumCapability "
12414 + TelephonyManager.convertPremiumCapabilityToString(capability)
12415 + " failed due to missing permissions.");
12416 throw new SecurityException("purchasePremiumCapability requires permission "
12417 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012418 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12419 mApp, "purchasePremiumCapability")) {
12420 log("purchasePremiumCapability "
12421 + TelephonyManager.convertPremiumCapabilityToString(capability)
12422 + " failed due to missing permissions.");
12423 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012424 }
12425
joonhunshin4ac60942023-11-15 15:23:39 +000012426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12427 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12428
Sarah Chin2ec39f62022-08-31 17:03:26 -070012429 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012430 if (phone == null) {
12431 try {
12432 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12433 callback.accept(result);
12434 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12435 } catch (RemoteException e) {
12436 String logStr = "Purchase premium capability "
12437 + TelephonyManager.convertPremiumCapabilityToString(capability)
12438 + " failed due to RemoteException handling null phone: " + e;
12439 if (DBG) log(logStr);
12440 AnomalyReporter.reportAnomaly(
12441 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12442 }
12443 return;
12444 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012445
12446 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012447 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012448 callingProcess = mApp.getPackageManager().getApplicationInfo(
12449 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012450 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012451 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012452 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012453
12454 boolean isVisible = false;
12455 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12456 if (am != null) {
12457 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12458 if (processes != null) {
12459 for (ActivityManager.RunningAppProcessInfo process : processes) {
12460 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012461 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012462 if (process.processName.equals(callingProcess) && process.importance
12463 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12464 isVisible = true;
12465 break;
12466 }
12467 }
12468 }
12469 }
12470
12471 if (!isVisible) {
12472 try {
12473 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12474 callback.accept(result);
12475 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12476 } catch (RemoteException e) {
12477 String logStr = "Purchase premium capability "
12478 + TelephonyManager.convertPremiumCapabilityToString(capability)
12479 + " failed due to RemoteException handling background application: " + e;
12480 if (DBG) log(logStr);
12481 AnomalyReporter.reportAnomaly(
12482 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12483 }
12484 return;
12485 }
12486
Sarah Chin71b3a852022-09-28 15:54:19 -070012487 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012488 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012489 }
12490
12491 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012492 * Register an IMS connection state callback
12493 */
12494 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012495 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12496 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012497 if (feature == ImsFeature.FEATURE_MMTEL) {
12498 // ImsMmTelManager
12499 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12500 TelephonyPermissions
12501 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12502 mApp, subId, "registerImsStateCallback");
12503 } else if (feature == ImsFeature.FEATURE_RCS) {
12504 // ImsRcsManager or SipDelegateManager
12505 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12506 Binder.getCallingUid(), "registerImsStateCallback",
12507 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12508 Manifest.permission.READ_PRECISE_PHONE_STATE,
12509 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12510 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12511 }
12512
12513 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12514 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12515 "IMS not available on device.");
12516 }
12517
12518 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12519 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12520 }
12521
12522 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12523 if (controller == null) {
12524 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12525 "IMS not available on device.");
12526 }
12527
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012528 if (callingPackage == null) {
12529 callingPackage = getCurrentPackageName();
12530 }
12531
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012532 final long token = Binder.clearCallingIdentity();
12533 try {
12534 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012535 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012536 } catch (ImsException e) {
12537 throw new ServiceSpecificException(e.getCode());
12538 } finally {
12539 Binder.restoreCallingIdentity(token);
12540 }
12541 }
12542
12543 /**
12544 * Unregister an IMS connection state callback
12545 */
12546 @Override
12547 public void unregisterImsStateCallback(IImsStateCallback cb) {
12548 final long token = Binder.clearCallingIdentity();
12549 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12550 if (controller == null) {
12551 return;
12552 }
12553 try {
12554 controller.unregisterImsStateCallback(cb);
12555 } finally {
12556 Binder.restoreCallingIdentity(token);
12557 }
12558 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012559
12560 /**
12561 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12562 *
12563 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012564 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012565 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012566 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012567 * If there is current registered network this value will be same as the registered cell
12568 * identity. If the device goes out of service the previous cell identity is cached and
12569 * will be returned. If the cache age of the Cell identity is more than 24 hours
12570 * it will be cleared and null will be returned.
12571 *
12572 */
12573 @Override
12574 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12575 String callingFeatureId) {
12576 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12577 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12578 LocationAccessPolicy.checkLocationPermission(mApp,
12579 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12580 .setCallingPackage(callingPackage)
12581 .setCallingFeatureId(callingFeatureId)
12582 .setCallingPid(Binder.getCallingPid())
12583 .setCallingUid(Binder.getCallingUid())
12584 .setMethod("getLastKnownCellIdentity")
12585 .setLogAsInfo(true)
12586 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12587 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12588 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12589 .build());
12590
12591 boolean hasFinePermission =
12592 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12593 if (!hasFinePermission
12594 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12595 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012596 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012597 }
12598
12599 final long identity = Binder.clearCallingIdentity();
12600 try {
Ling Mac28f0212023-03-24 16:07:15 -070012601 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012602 if (sst == null) return null;
12603 return sst.getLastKnownCellIdentity();
12604 } finally {
12605 Binder.restoreCallingIdentity(identity);
12606 }
12607 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012608
jimsun3b9ccac2021-10-26 15:01:23 +080012609 /**
12610 * Sets the modem service class Name that Telephony will bind to.
12611 *
12612 * @param serviceName The class name of the modem service.
12613 * @return true if the operation is succeed, otherwise false.
12614 */
12615 public boolean setModemService(String serviceName) {
12616 Log.d(LOG_TAG, "setModemService - " + serviceName);
12617 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012619 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12620 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012621 return mPhoneConfigurationManager.setModemService(serviceName);
12622 }
12623
12624 /**
12625 * Return the class name of the currently bounded modem service.
12626 *
12627 * @return the class name of the modem service.
12628 */
12629 public String getModemService() {
12630 String result;
12631 Log.d(LOG_TAG, "getModemService");
12632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12633 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012634 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012635 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12636 "getModemService");
12637 result = mPhoneConfigurationManager.getModemService();
12638 Log.d(LOG_TAG, "result = " + result);
12639 return result;
12640 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012641
Hakjun Choi3ee81112023-12-19 15:40:58 +000012642 /**
12643 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12644 * including carrier config, entitlement server, and config update.
12645 *
12646 * @param subId subId The subscription ID of the carrier.
12647 *
12648 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12649 * be returned.
12650 *
12651 * @throws SecurityException if the caller doesn't have the required permission.
12652 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012653 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12654 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012655 final long identity = Binder.clearCallingIdentity();
12656 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012657 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012658 } finally {
12659 Binder.restoreCallingIdentity(identity);
12660 }
12661 }
12662
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012663 @Override
12664 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12665 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12666 mApp.enforceCallingOrSelfPermission(
12667 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12668 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12669
12670 final long identity = Binder.clearCallingIdentity();
12671 try {
12672 Phone phone = getPhone(subId);
12673 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012674 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12675 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012676 phone.setVoiceServiceStateOverride(hasService);
12677 } finally {
12678 Binder.restoreCallingIdentity(identity);
12679 }
12680 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012681
12682 /**
12683 * set removable eSIM as default eUICC.
12684 *
12685 * @hide
12686 */
12687 @Override
12688 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12689 enforceModifyPermission();
12690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12691
12692 final long identity = Binder.clearCallingIdentity();
12693 try {
12694 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12695 } finally {
12696 Binder.restoreCallingIdentity(identity);
12697 }
12698 }
12699
12700 /**
12701 * Returns whether the removable eSIM is default eUICC or not.
12702 *
12703 * @hide
12704 */
12705 @Override
12706 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12707 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12708 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12709
12710 final long identity = Binder.clearCallingIdentity();
12711 try {
12712 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12713 } finally {
12714 Binder.restoreCallingIdentity(identity);
12715 }
12716 }
12717
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012718 /**
12719 * Get the component name of the default app to direct respond-via-message intent for the
12720 * user associated with this subscription, update the cache if there is no respond-via-message
12721 * application currently configured for this user.
12722 * @return component name of the app and class to direct Respond Via Message intent to, or
12723 * {@code null} if the functionality is not supported.
12724 * @hide
12725 */
12726 @Override
12727 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12728 boolean updateIfNeeded) {
12729 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012730
joonhunshin4ac60942023-11-15 15:23:39 +000012731 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12732 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12733 "getDefaultRespondViaMessageApplication");
12734
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012735 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12736
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012737 UserHandle userHandle = null;
12738 final long identity = Binder.clearCallingIdentity();
12739 try {
12740 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12741 } finally {
12742 Binder.restoreCallingIdentity(identity);
12743 }
12744 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12745 updateIfNeeded, userHandle);
12746 }
Jack Yuf5badd92022-12-08 00:50:53 -080012747
12748 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012749 * Set whether the device is able to connect with null ciphering or integrity
12750 * algorithms. This is a global setting and will apply to all active subscriptions
12751 * and all new subscriptions after this.
12752 *
12753 * @param enabled when true, null cipher and integrity algorithms are allowed.
12754 * @hide
12755 */
12756 @Override
12757 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12758 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12759 enforceModifyPermission();
12760 checkForNullCipherAndIntegritySupport();
12761
12762 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12763 // for listening to these preference changes and applying them immediately.
12764 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12765 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12766 editor.apply();
12767
12768 for (Phone phone: PhoneFactory.getPhones()) {
12769 phone.handleNullCipherEnabledChange();
12770 }
12771 }
12772
12773
12774 /**
12775 * Get whether the device is able to connect with null ciphering or integrity
12776 * algorithms. Note that this retrieves the phone-global preference and not
12777 * the state of the radio.
12778 *
12779 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12780 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12781 * version for this feature.
12782 * @hide
12783 */
12784 @Override
12785 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12786 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12787 enforceReadPermission();
12788 checkForNullCipherAndIntegritySupport();
12789 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12790 }
12791
12792 private void checkForNullCipherAndIntegritySupport() {
12793 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12794 throw new UnsupportedOperationException(
12795 "Null cipher and integrity operations require HAL 2.1 or above");
12796 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012797 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12798 throw new UnsupportedOperationException(
12799 "Null cipher and integrity operations unsupported by modem");
12800 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012801 }
12802
Gil Cukierman06403e12023-11-29 16:33:03 +000012803 private void checkForIdentifierDisclosureNotificationSupport() {
12804 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12805 throw new UnsupportedOperationException(
12806 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12807 + "above");
12808 }
12809 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12810 throw new UnsupportedOperationException(
12811 "Cellular identifier disclosure transparency operations unsupported by modem");
12812 }
12813 }
12814
Michael Groover826b71d2023-12-21 22:08:06 -060012815 private void checkForNullCipherNotificationSupport() {
12816 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12817 throw new UnsupportedOperationException(
12818 "Null cipher notification operations require HAL 2.2 or above");
12819 }
12820 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12821 throw new UnsupportedOperationException(
12822 "Null cipher notification operations unsupported by modem");
12823 }
12824 }
12825
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012826 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012827 * Get the SIM state for the slot index.
12828 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12829 *
12830 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12831 */
12832 @Override
12833 @SimState
12834 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12836 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12837
Jack Yuf5badd92022-12-08 00:50:53 -080012838 IccCardConstants.State simState;
12839 if (slotIndex < 0) {
12840 simState = IccCardConstants.State.UNKNOWN;
12841 } else {
12842 Phone phone = null;
12843 try {
12844 phone = PhoneFactory.getPhone(slotIndex);
12845 } catch (IllegalStateException e) {
12846 // ignore
12847 }
12848 if (phone == null) {
12849 simState = IccCardConstants.State.UNKNOWN;
12850 } else {
12851 IccCard icc = phone.getIccCard();
12852 if (icc == null) {
12853 simState = IccCardConstants.State.UNKNOWN;
12854 } else {
12855 simState = icc.getState();
12856 }
12857 }
12858 }
12859 return simState.ordinal();
12860 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012861
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012862 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12863 boolean enableLogcat,
12864 long logcatStartTimestampMillis, boolean enableTelecomDump,
12865 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012866 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012867 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12868 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12869 ecdDataBuilder
12870 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12871 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012872 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012873 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012874 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012875 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12876 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012877 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12878 Executors.newCachedThreadPool(), db,
12879 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012880 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012881 }
12882
12883 /**
12884 * Request telephony to persist state for debugging emergency call failures.
12885 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012886 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012887 * @param enableLogcat whether to collect logcat output
12888 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12889 * @param enableTelecomDump whether to collect telecom dumpsys
12890 * @param enableTelephonyDump whether to collect telephony dumpsys
12891 */
12892 @Override
12893 @RequiresPermission(android.Manifest.permission.DUMP)
12894 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12895 long logcatStartTimestampMillis, boolean enableTelecomDump,
12896 boolean enableTelephonyDump) {
12897 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12898 "persistEmergencyCallDiagnosticData");
12899 final long identity = Binder.clearCallingIdentity();
12900 try {
12901 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12902 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12903
12904 } finally {
12905 Binder.restoreCallingIdentity(identity);
12906 }
12907 }
12908
Hui Wang9b5793a2022-12-05 14:38:06 -060012909 /**
12910 * Get current cell broadcast ranges.
12911 */
12912 @Override
12913 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12914 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12915 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12916 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012917
12918 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12919 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12920
Hui Wang9b5793a2022-12-05 14:38:06 -060012921 final long identity = Binder.clearCallingIdentity();
12922 try {
12923 return getPhone(subId).getCellBroadcastIdRanges();
12924 } finally {
12925 Binder.restoreCallingIdentity(identity);
12926 }
12927 }
12928
12929 /**
12930 * Set reception of cell broadcast messages with the list of the given ranges
12931 *
12932 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12933 */
12934 @Override
12935 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12936 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12937 @Nullable IIntegerConsumer callback) {
12938 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12939 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012940
12941 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12942 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12943
Hui Wang9b5793a2022-12-05 14:38:06 -060012944 final long identity = Binder.clearCallingIdentity();
12945 try {
12946 Phone phone = getPhoneFromSubId(subId);
12947 if (DBG) {
12948 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12949 }
12950 phone.setCellBroadcastIdRanges(ranges, result -> {
12951 if (callback != null) {
12952 try {
12953 callback.accept(result);
12954 } catch (RemoteException e) {
12955 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12956 }
12957 }
12958 });
12959 } finally {
12960 Binder.restoreCallingIdentity(identity);
12961 }
12962 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012963
12964 /**
12965 * Returns whether the device supports the domain selection service.
12966 *
12967 * @return {@code true} if the device supports the domain selection service.
12968 */
12969 @Override
12970 public boolean isDomainSelectionSupported() {
12971 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12972 "isDomainSelectionSupported");
12973
12974 final long identity = Binder.clearCallingIdentity();
12975 try {
12976 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12977 } finally {
12978 Binder.restoreCallingIdentity(identity);
12979 }
12980 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012981
12982 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012983 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12984 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12985 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012986 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012987 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012988 * @param enableSatellite {@code true} to enable the satellite modem and
12989 * {@code false} to disable.
12990 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080012991 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080012992 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012993 *
12994 * @throws SecurityException if the caller doesn't have the required permission.
12995 */
12996 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012997 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080012998 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012999 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013000 if (enableSatellite) {
13001 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13002 @Override
13003 protected void onReceiveResult(int resultCode, Bundle resultData) {
13004 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13005 + ", resultData=" + resultData);
13006 boolean isAllowed = false;
13007 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13008 callback::accept);
13009 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13010 if (resultData != null
13011 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13012 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13013 } else {
13014 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13015 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013016 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013017 result.accept(resultCode);
13018 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013019 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013020 if (isAllowed) {
13021 mSatelliteController.requestSatelliteEnabled(
13022 subId, enableSatellite, enableDemoMode, callback);
13023 } else {
13024 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13025 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013026 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013027 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013028 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013029 subId, resultReceiver);
13030 } else {
13031 // No need to check if satellite is allowed at current location when disabling satellite
13032 mSatelliteController.requestSatelliteEnabled(
13033 subId, enableSatellite, enableDemoMode, callback);
13034 }
Sarah Chin503828c2023-02-01 23:54:20 -080013035 }
13036
13037 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013038 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013039 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013040 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013041 * @param result The result receiver that returns whether the satellite modem is enabled
13042 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013043 *
13044 * @throws SecurityException if the caller doesn't have the required permission.
13045 */
13046 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013047 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13048 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013049 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013050 }
13051
13052 /**
Sarah Chin43457982023-02-15 17:50:38 -080013053 * Request to get whether the satellite service demo mode is enabled.
13054 *
13055 * @param subId The subId of the subscription to check whether the satellite demo mode
13056 * is enabled for.
13057 * @param result The result receiver that returns whether the satellite demo mode is enabled
13058 * if the request is successful or an error code if the request failed.
13059 *
13060 * @throws SecurityException if the caller doesn't have the required permission.
13061 */
13062 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013063 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13064 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13065 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013066 }
13067
13068 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013069 * Request to get whether the satellite service is enabled with emergency mode.
13070 *
13071 * @param subId The subId of the subscription to check whether the satellite demo mode
13072 * is enabled for.
13073 * @param result The result receiver that returns whether the satellite emergency mode is
13074 * enabled if the request is successful or an error code if the request failed.
13075 *
13076 * @throws SecurityException if the caller doesn't have the required permission.
13077 */
13078 @Override
13079 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13080 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13081 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13082 }
13083
13084 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013085 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013086 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013087 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013088 * @param result The result receiver that returns whether the satellite service is supported on
13089 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013090 */
13091 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013092 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013093 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013094 }
13095
13096 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013097 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013098 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013099 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013100 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13101 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013102 *
13103 * @throws SecurityException if the caller doesn't have required permission.
13104 */
13105 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013106 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13107 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013108 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013109 }
13110
13111 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013112 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013113 * This can be called by the pointing UI when the user starts pointing to the satellite.
13114 * Modem should continue to report the pointing input as the device or satellite moves.
13115 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013116 * @param subId The subId of the subscription to start satellite transmission updates for.
13117 * @param resultCallback The callback to get the result of the request.
13118 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013119 *
13120 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013121 */
13122 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013123 public void startSatelliteTransmissionUpdates(int subId,
13124 @NonNull IIntegerConsumer resultCallback,
13125 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13126 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13127 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013128 }
13129
13130 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013131 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013132 * This can be called by the pointing UI when the user stops pointing to the satellite.
13133 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013134 * @param subId The subId of the subscription to stop satellite transmission updates for.
13135 * @param resultCallback The callback to get the result of the request.
13136 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13137 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013138 *
13139 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013140 */
13141 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013142 public void stopSatelliteTransmissionUpdates(int subId,
13143 @NonNull IIntegerConsumer resultCallback,
13144 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13145 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13146 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013147 }
13148
13149 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013150 * Register the subscription with a satellite provider.
13151 * This is needed to register the subscription if the provider allows dynamic registration.
13152 *
13153 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013154 * @param token The token to be used as a unique identifier for provisioning with satellite
13155 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013156 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013157 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013158 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013159 * @return The signal transport used by the caller to cancel the provision request,
13160 * or {@code null} if the request failed.
13161 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013162 * @throws SecurityException if the caller doesn't have the required permission.
13163 */
13164 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013165 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013166 @NonNull String token, @NonNull byte[] provisionData,
13167 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013168 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013169 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13170 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013171 }
13172
13173 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013174 * Unregister the device/subscription with the satellite provider.
13175 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013176 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013177 * should report as deprovisioned.
13178 *
13179 * @param subId The subId of the subscription to be deprovisioned.
13180 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013181 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013182 *
13183 * @throws SecurityException if the caller doesn't have the required permission.
13184 */
13185 @Override
13186 public void deprovisionSatelliteService(int subId,
13187 @NonNull String token, @NonNull IIntegerConsumer callback) {
13188 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013189 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013190 }
13191
13192 /**
Sarah Chin43457982023-02-15 17:50:38 -080013193 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013194 *
Sarah Chin43457982023-02-15 17:50:38 -080013195 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013196 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013197 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013198 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013199 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013200 * @throws SecurityException if the caller doesn't have the required permission.
13201 */
13202 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013203 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13204 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013205 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013206 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013207 }
13208
13209 /**
Sarah Chin43457982023-02-15 17:50:38 -080013210 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013211 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013212 *
Sarah Chin43457982023-02-15 17:50:38 -080013213 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013214 * @param callback The callback that was passed to
13215 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013216 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013217 * @throws SecurityException if the caller doesn't have the required permission.
13218 */
13219 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013220 public void unregisterForSatelliteProvisionStateChanged(
13221 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013222 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013223 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013224 }
13225
13226 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013227 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013228 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013229 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013230 * @param result The result receiver that returns whether the device is provisioned with a
13231 * satellite provider if the request is successful or an error code if the
13232 * request failed.
13233 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013234 * @throws SecurityException if the caller doesn't have the required permission.
13235 */
13236 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013237 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13238 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013239 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013240 }
13241
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013242 /**
Sarah Chin43457982023-02-15 17:50:38 -080013243 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013244 *
Sarah Chin43457982023-02-15 17:50:38 -080013245 * @param subId The subId of the subscription to register for satellite modem state changed.
13246 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013247 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013248 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013249 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013250 * @throws SecurityException if the caller doesn't have the required permission.
13251 */
13252 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013253 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013254 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013255 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013256 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013257 }
13258
13259 /**
Sarah Chin43457982023-02-15 17:50:38 -080013260 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013261 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013262 *
Sarah Chin43457982023-02-15 17:50:38 -080013263 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013264 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013265 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013266 *
13267 * @throws SecurityException if the caller doesn't have the required permission.
13268 */
13269 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013270 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013271 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013272 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13273 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013274 }
13275
13276 /**
13277 * Register to receive incoming datagrams over satellite.
13278 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013279 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013280 * @param callback The callback to handle incoming datagrams over satellite.
13281 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013282 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013283 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013284 * @throws SecurityException if the caller doesn't have the required permission.
13285 */
13286 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013287 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013288 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013289 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13290 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013291 }
13292
13293 /**
13294 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013295 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013296 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013297 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13298 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013299 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013300 *
13301 * @throws SecurityException if the caller doesn't have the required permission.
13302 */
13303 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013304 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013305 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013306 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13307 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013308 }
13309
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013310 /**
13311 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013312 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013313 * This method requests modem to check if there are any pending datagrams to be received over
13314 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013315 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013316 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013317 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013318 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013319 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013320 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013321 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013322 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13323 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13324 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013325 }
13326
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013327 /**
13328 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013329 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013330 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13331 * input to this method. Datagram received here will be passed down to modem without any
13332 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013333 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013334 * @param subId The subId of the subscription to send satellite datagrams for.
13335 * @param datagramType datagram type indicating whether the datagram is of type
13336 * SOS_SMS or LOCATION_SHARING.
13337 * @param datagram encoded gateway datagram which is encrypted by the caller.
13338 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013339 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13340 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013341 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013342 *
13343 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013344 */
13345 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013346 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013347 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13348 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013349 enforceSatelliteCommunicationPermission("sendDatagram");
13350 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13351 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013352 }
13353
Sarah Chindf715ec2023-02-13 13:46:24 -080013354 /**
13355 * Request to get whether satellite communication is allowed for the current location.
13356 *
13357 * @param subId The subId of the subscription to check whether satellite communication is
13358 * allowed for the current location for.
13359 * @param result The result receiver that returns whether satellite communication is allowed
13360 * for the current location if the request is successful or an error code
13361 * if the request failed.
13362 *
13363 * @throws SecurityException if the caller doesn't have the required permission.
13364 */
13365 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013366 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013367 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013368 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13369 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13370 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013371 }
13372
13373 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013374 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013375 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013376 * @param subId The subId to get the time after which the satellite will be visible for.
13377 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013378 * be visible if the request is successful or an error code if the request failed.
13379 *
13380 * @throws SecurityException if the caller doesn't have the required permission.
13381 */
13382 @Override
13383 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13384 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013385 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013386 }
13387
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013388 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013389 * Inform that Device is aligned to satellite for demo mode.
13390 *
13391 * @param subId The subId to get the time after which the satellite will be visible for.
13392 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13393 * {@code false} Device fails to align with the satellite for demo mode.
13394 *
13395 * @throws SecurityException if the caller doesn't have required permission.
13396 */
13397 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13398
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013399 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013400 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013401 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013402 }
13403
13404 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013405 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13406 * by modem.
13407 *
13408 * @param subId The subId of the subscription to request for.
13409 * @param reason Reason for disallowing satellite communication for carrier.
13410 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13411 * operation.
13412 *
13413 * @throws SecurityException if the caller doesn't have required permission.
13414 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013415 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013416 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13417 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013418 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013419 final long identity = Binder.clearCallingIdentity();
13420 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013421 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013422 } finally {
13423 Binder.restoreCallingIdentity(identity);
13424 }
13425 }
13426
13427 /**
13428 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13429 * by modem.
13430 *
13431 * @param subId The subId of the subscription to request for.
13432 * @param reason Reason for disallowing satellite communication.
13433 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13434 * operation.
13435 *
13436 * @throws SecurityException if the caller doesn't have required permission.
13437 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013438 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013439 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13440 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013441 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013442 final long identity = Binder.clearCallingIdentity();
13443 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013444 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013445 } finally {
13446 Binder.restoreCallingIdentity(identity);
13447 }
13448 }
13449
13450 /**
13451 * Get reasons for disallowing satellite communication, as requested by
13452 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13453 *
13454 * @param subId The subId of the subscription to request for.
13455 *
13456 * @return Integer array of reasons for disallowing satellite communication.
13457 *
13458 * @throws SecurityException if the caller doesn't have the required permission.
13459 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013460 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013461 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013462 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013463 final long identity = Binder.clearCallingIdentity();
13464 try {
13465 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013466 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013467 return reasonSet.stream().mapToInt(i->i).toArray();
13468 } finally {
13469 Binder.restoreCallingIdentity(identity);
13470 }
13471 }
13472
13473 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013474 * Request to get the signal strength of the satellite connection.
13475 *
13476 * @param subId The subId of the subscription to request for.
13477 * @param result Result receiver to get the error code of the request and the current signal
13478 * strength of the satellite connection.
13479 *
13480 * @throws SecurityException if the caller doesn't have required permission.
13481 */
13482 @Override
13483 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13484 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13485 final long identity = Binder.clearCallingIdentity();
13486 try {
13487 mSatelliteController.requestNtnSignalStrength(subId, result);
13488 } finally {
13489 Binder.restoreCallingIdentity(identity);
13490 }
13491 }
13492
13493 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013494 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13495 * is not successful, a {@link ServiceSpecificException} that contains
13496 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013497 *
13498 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013499 * @param callback The callback to handle the NTN signal strength changed event. If the
13500 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13501 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13502 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13503 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013504 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013505 * @throws SecurityException If the caller doesn't have the required permission.
13506 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013507 */
13508 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013509 public void registerForNtnSignalStrengthChanged(int subId,
13510 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013511 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13512 final long identity = Binder.clearCallingIdentity();
13513 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013514 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013515 } finally {
13516 Binder.restoreCallingIdentity(identity);
13517 }
13518 }
13519
13520 /**
13521 * Unregisters for NTN signal strength changed from satellite modem.
13522 * If callback was not registered before, the request will be ignored.
13523 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013524 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13525 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013526 * @param callback The callback that was passed to
13527 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13528 *
13529 * @throws SecurityException if the caller doesn't have the required permission.
13530 */
13531 @Override
13532 public void unregisterForNtnSignalStrengthChanged(
13533 int subId, @NonNull INtnSignalStrengthCallback callback) {
13534 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13535 final long identity = Binder.clearCallingIdentity();
13536 try {
13537 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13538 } finally {
13539 Binder.restoreCallingIdentity(identity);
13540 }
13541 }
13542
13543 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013544 * Registers for satellite capabilities change event from the satellite service.
13545 *
13546 * @param subId The subId of the subscription to request for.
13547 * @param callback The callback to handle the satellite capabilities changed event.
13548 *
13549 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13550 *
13551 * @throws SecurityException if the caller doesn't have required permission.
13552 */
13553 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013554 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013555 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013556 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013557 final long identity = Binder.clearCallingIdentity();
13558 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013559 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013560 } finally {
13561 Binder.restoreCallingIdentity(identity);
13562 }
13563 }
13564
13565 /**
13566 * Unregisters for satellite capabilities change event from the satellite service.
13567 * If callback was not registered before, the request will be ignored.
13568 *
13569 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13570 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013571 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013572 *
13573 * @throws SecurityException if the caller doesn't have required permission.
13574 */
13575 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013576 public void unregisterForCapabilitiesChanged(int subId,
13577 @NonNull ISatelliteCapabilitiesCallback callback) {
13578 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013579 final long identity = Binder.clearCallingIdentity();
13580 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013581 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013582 } finally {
13583 Binder.restoreCallingIdentity(identity);
13584 }
13585 }
13586
13587 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013588 * This API can be used by only CTS to update satellite vendor service package name.
13589 *
13590 * @param servicePackageName The package name of the satellite vendor service.
13591 * @return {@code true} if the satellite vendor service is set successfully,
13592 * {@code false} otherwise.
13593 */
13594 public boolean setSatelliteServicePackageName(String servicePackageName) {
13595 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13596 TelephonyPermissions.enforceShellOnly(
13597 Binder.getCallingUid(), "setSatelliteServicePackageName");
13598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13599 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13600 "setSatelliteServicePackageName");
13601 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13602 }
13603
13604 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013605 * This API can be used by only CTS to update satellite gateway service package name.
13606 *
13607 * @param servicePackageName The package name of the satellite gateway service.
13608 * @return {@code true} if the satellite gateway service is set successfully,
13609 * {@code false} otherwise.
13610 */
13611 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13612 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13613 TelephonyPermissions.enforceShellOnly(
13614 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13616 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13617 "setSatelliteGatewayServicePackageName");
13618 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13619 }
13620
13621 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013622 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13623 *
13624 * @param packageName The package name of the satellite pointing UI app.
13625 * @param className The class name of the satellite pointing UI app.
13626 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13627 * {@code false} otherwise.
13628 */
13629 public boolean setSatellitePointingUiClassName(
13630 @Nullable String packageName, @Nullable String className) {
13631 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13632 + ", className=" + className);
13633 TelephonyPermissions.enforceShellOnly(
13634 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13636 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13637 "setSatelliteGatewayServicePackageName");
13638 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13639 }
13640
13641 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013642 * This API can be used by only CTS to update the timeout duration in milliseconds that
13643 * satellite should stay at listening mode to wait for the next incoming page before disabling
13644 * listening mode.
13645 *
13646 * @param timeoutMillis The timeout duration in millisecond.
13647 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13648 */
13649 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13650 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13651 TelephonyPermissions.enforceShellOnly(
13652 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13654 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13655 "setSatelliteListeningTimeoutDuration");
13656 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13657 }
13658
13659 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013660 * This API can be used by only CTS to override the timeout durations used by the
13661 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013662 *
13663 * @param timeoutMillis The timeout duration in millisecond.
13664 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13665 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013666 public boolean setDatagramControllerTimeoutDuration(
13667 boolean reset, int timeoutType, long timeoutMillis) {
13668 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13669 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013670 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013671 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13673 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013674 "setDatagramControllerTimeoutDuration");
13675 return mSatelliteController.setDatagramControllerTimeoutDuration(
13676 reset, timeoutType, timeoutMillis);
13677 }
13678
13679 /**
13680 * This API can be used by only CTS to override the timeout durations used by the
13681 * SatelliteController module.
13682 *
13683 * @param timeoutMillis The timeout duration in millisecond.
13684 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13685 */
13686 public boolean setSatelliteControllerTimeoutDuration(
13687 boolean reset, int timeoutType, long timeoutMillis) {
13688 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13689 + reset + ", timeoutMillis=" + timeoutMillis);
13690 TelephonyPermissions.enforceShellOnly(
13691 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13693 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13694 "setSatelliteControllerTimeoutDuration");
13695 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13696 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013697 }
13698
13699 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013700 * This API can be used in only testing to override connectivity status in monitoring emergency
13701 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13702 *
13703 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13704 * of the following values to enable the override:
13705 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13706 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13707 * To disable the override, use -1 for handoverType.
13708 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13709 * delaySeconds after the emergency call starts.
13710 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13711 */
13712 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13713 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13714 TelephonyPermissions.enforceShellOnly(
13715 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13717 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13718 "setEmergencyCallToSatelliteHandoverType");
13719 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13720 handoverType, delaySeconds);
13721 }
13722
13723 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013724 * This API can be used in only testing to override oem-enabled satellite provision status.
13725 *
13726 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13727 * otherwise.
13728 * @param isProvisioned The overriding provision status.
13729 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13730 */
13731 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13732 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13733 + ", isProvisioned=" + isProvisioned);
13734 TelephonyPermissions.enforceShellOnly(
13735 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13737 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13738 "setOemEnabledSatelliteProvisionStatus");
13739 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13740 }
13741
13742 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013743 * This API should be used by only CTS tests to forcefully set telephony country codes.
13744 *
13745 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13746 */
13747 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13748 Map cachedNetworkCountryCodes, String locationCountryCode,
13749 long locationCountryCodeTimestampNanos) {
13750 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13751 + String.join(", ", currentNetworkCountryCodes)
13752 + ", locationCountryCode=" + locationCountryCode
13753 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13754 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13755 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13756 TelephonyPermissions.enforceShellOnly(
13757 Binder.getCallingUid(), "setCachedLocationCountryCode");
13758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13759 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13760 "setCachedLocationCountryCode");
13761 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13762 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13763 locationCountryCodeTimestampNanos);
13764 }
13765
13766 /**
13767 * This API should be used by only CTS tests to override the overlay configs of satellite
13768 * access controller.
13769 *
13770 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13771 * otherwise.
13772 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13773 */
13774 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13775 String s2CellFile, long locationFreshDurationNanos,
13776 List<String> satelliteCountryCodes) {
13777 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13778 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13779 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13780 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13781 ? String.join(", ", satelliteCountryCodes) : null));
13782 TelephonyPermissions.enforceShellOnly(
13783 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13785 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13786 "setSatelliteAccessControlOverlayConfigs");
13787 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13788 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13789 }
13790
13791 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013792 * This API can be used by only CTS to override the cached value for the device overlay config
13793 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13794 * outgoing satellite datagrams should be sent to modem in demo mode.
13795 *
13796 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13797 * satellite modem or not.
13798 *
13799 * @return {@code true} if the operation is successful, {@code false} otherwise.
13800 */
13801 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13802 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13803 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13804 + "disabled");
13805 return false;
13806 }
13807 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13808 TelephonyPermissions.enforceShellOnly(
13809 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13811 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13812 "setShouldSendDatagramToModemInDemoMode");
13813 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13814 shouldSendToModemInDemoMode);
13815 }
13816
13817 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013818 * Sets the service defined in ComponentName to be bound.
13819 *
13820 * This should only be used for testing.
13821 * @return {@code true} if the DomainSelectionService to bind to was set,
13822 * {@code false} otherwise.
13823 */
13824 @Override
13825 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13826 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13827
13828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13829 "setDomainSelectionServiceOverride");
13830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13831 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13832
13833 final long identity = Binder.clearCallingIdentity();
13834 try {
13835 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13836 return DomainSelectionResolver.getInstance()
13837 .setDomainSelectionServiceOverride(componentName);
13838 }
13839 } finally {
13840 Binder.restoreCallingIdentity(identity);
13841 }
13842 return false;
13843 }
13844
13845 /**
13846 * Clears the DomainSelectionService override.
13847 *
13848 * This should only be used for testing.
13849 * @return {@code true} if the DomainSelectionService override was cleared,
13850 * {@code false} otherwise.
13851 */
13852 @Override
13853 public boolean clearDomainSelectionServiceOverride() {
13854 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13855
13856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13857 "clearDomainSelectionServiceOverride");
13858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13859 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13860
13861 final long identity = Binder.clearCallingIdentity();
13862 try {
13863 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13864 return DomainSelectionResolver.getInstance()
13865 .clearDomainSelectionServiceOverride();
13866 }
13867 } finally {
13868 Binder.restoreCallingIdentity(identity);
13869 }
13870 return false;
13871 }
13872
13873 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013874 * Enable or disable notifications sent for cellular identifier disclosure events.
13875 *
13876 * Disclosure events are defined as instances where a device has sent a cellular identifier
13877 * on the Non-access stratum (NAS) before a security context is established. As a result the
13878 * identifier is sent in the clear, which has privacy implications for the user.
13879 *
13880 * @param enable if notifications about disclosure events should be enabled
13881 * @throws SecurityException if the caller does not have the required privileges
13882 * @throws UnsupportedOperationException if the modem does not support this feature.
13883 */
13884 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013885 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013886 enforceModifyPermission();
13887 checkForIdentifierDisclosureNotificationSupport();
13888
13889 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13890 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13891 editor.apply();
13892
13893 // Each phone instance is responsible for updating its respective modem immediately
13894 // after we've made a preference change.
13895 for (Phone phone : PhoneFactory.getPhones()) {
13896 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13897 }
13898 }
13899
13900 /**
13901 * Get whether or not cellular identifier disclosure notifications are enabled.
13902 *
13903 * @throws SecurityException if the caller does not have the required privileges
13904 * @throws UnsupportedOperationException if the modem does not support this feature.
13905 */
13906 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013907 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013908 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13909 checkForIdentifierDisclosureNotificationSupport();
13910 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13911 }
13912
13913 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013914 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13915 * are in use by the cellular modem.
13916 *
13917 * @throws IllegalStateException if the Telephony process is not currently available
13918 * @throws SecurityException if the caller does not have the required privileges
13919 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13920 * and integrity algorithms in use
13921 * @hide
13922 */
13923 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013924 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013925 enforceModifyPermission();
13926 checkForNullCipherNotificationSupport();
13927
13928 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13929 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13930 editor.apply();
13931
13932 // Each phone instance is responsible for updating its respective modem immediately
13933 // after a preference change.
13934 for (Phone phone : PhoneFactory.getPhones()) {
13935 phone.handleNullCipherNotificationPreferenceChanged();
13936 }
13937 }
13938
13939 /**
13940 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13941 * cellular modem.
13942 *
13943 * @throws IllegalStateException if the Telephony process is not currently available
13944 * @throws SecurityException if the caller does not have the required privileges
13945 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13946 * and integrity algorithms in use
13947 * @hide
13948 */
13949 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
13950 public boolean isNullCipherNotificationsEnabled() {
13951 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
13952 checkForNullCipherNotificationSupport();
13953 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
13954 }
13955
13956 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013957 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13958 *
13959 * <p>This method behaves in one of the following ways:
13960 * <ul>
13961 * <li>return true : if the calling package has the appop permission {@link
13962 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13963 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13964 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13965 * Owner device identifier access check, or the calling package has carrier privileges</>
13966 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13967 * </ul>
13968 */
13969 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13970 String callingPackage, @Nullable String callingFeatureId, String message) {
13971 for (Phone phone : PhoneFactory.getPhones()) {
13972 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13973 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13974 return true;
13975 }
13976 }
13977 return false;
13978 }
arunvoddud7401012022-12-15 16:08:12 +000013979
13980 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013981 * @return The subscription manager service instance.
13982 */
13983 public SubscriptionManagerService getSubscriptionManagerService() {
13984 return SubscriptionManagerService.getInstance();
13985 }
13986
13987 /**
arunvoddud7401012022-12-15 16:08:12 +000013988 * Class binds the consumer[callback] and carrierId.
13989 */
13990 private static class CallerCallbackInfo {
13991 private final Consumer<Integer> mConsumer;
13992 private final int mCarrierId;
13993
13994 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13995 mConsumer = consumer;
13996 mCarrierId = carrierId;
13997 }
13998
13999 public Consumer<Integer> getConsumer() {
14000 return mConsumer;
14001 }
14002
14003 public int getCarrierId() {
14004 return mCarrierId;
14005 }
14006 }
joonhunshin4ac60942023-11-15 15:23:39 +000014007
14008 /*
14009 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14010 * But the context that is passed in is unused if the phone app is already alive.
14011 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14012 */
14013 @VisibleForTesting
14014 public void setPackageManager(PackageManager packageManager) {
14015 mPackageManager = packageManager;
14016 }
14017
14018 /*
14019 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14020 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14021 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14022 */
14023 @VisibleForTesting
14024 public void setFeatureFlags(FeatureFlags featureFlags) {
14025 mFeatureFlags = featureFlags;
14026 }
14027
14028 /**
14029 * Make sure the device has required telephony feature
14030 *
14031 * @throws UnsupportedOperationException if the device does not have required telephony feature
14032 */
14033 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14034 @NonNull String telephonyFeature, @NonNull String methodName) {
14035 if (callingPackage == null || mPackageManager == null) {
14036 return;
14037 }
14038
14039 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14040 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14041 Binder.getCallingUserHandle())) {
14042 return;
14043 }
14044
14045 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14046 throw new UnsupportedOperationException(
14047 methodName + " is unsupported without " + telephonyFeature);
14048 }
14049 }
Jack Yufa8ed012023-02-11 15:42:28 -080014050}