blob: eacdf78890bfa5dc9f38851b763df25cac146fe5 [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);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008507 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008508 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008509 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008510 // There has been issues when Sms raw table somehow stores orphan
8511 // fragments. They lead to garbled message when new fragments come
8512 // in and combined with those stale ones. In case this happens again,
8513 // user can reset all network settings which will clean up this table.
8514 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008515 // Clean up IMS settings as well here.
8516 int slotId = getSlotIndex(subId);
8517 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8518 ImsManager.getInstance(mApp, slotId).factoryReset();
8519 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008520
Kai Shif70f46f2021-03-03 13:59:46 -08008521 if (defaultPhone == null) {
8522 return;
8523 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008524 // Erase modem config if erase modem on network setting is enabled.
8525 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8526 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8527 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008528 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008529 }
Kai Shif70f46f2021-03-03 13:59:46 -08008530
8531 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008532 } finally {
8533 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008534 }
8535 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008536
SongFerngWangfd89b102021-05-27 22:44:54 +08008537 @VisibleForTesting
8538 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8539 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8540 return;
8541 }
8542 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8543 RILConstants.PREFERRED_NETWORK_MODE);
8544 SubscriptionManager.setSubscriptionProperty(subId,
8545 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8546 "user=" + defaultNetworkType);
8547 phone.loadAllowedNetworksFromSubscriptionDatabase();
8548 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8549 defaultNetworkType, null);
8550 }
8551
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008552 private void cleanUpSmsRawTable(Context context) {
8553 ContentResolver resolver = context.getContentResolver();
8554 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8555 resolver.delete(uri, null, null);
8556 }
8557
Narayan Kamath1c496c22015-04-16 14:40:19 +01008558 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008559 public String getSimLocaleForSubscriber(int subId) {
8560 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008561
8562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8563 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8564
chen xu5d3637b2019-01-21 23:31:38 -08008565 final Phone phone = getPhone(subId);
8566 if (phone == null) {
8567 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008568 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570 final long identity = Binder.clearCallingIdentity();
8571 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008572 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8573 phone.getContext().getOpPackageName(),
8574 phone.getContext().getAttributionTag());
8575 if (info == null) {
8576 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8577 return null;
chen xu6291c472019-02-04 12:55:53 -08008578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 // Try and fetch the locale from the carrier properties or from the SIM language
8580 // preferences (EF-PL and EF-LI)...
8581 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008583 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8584 if (localeFromDefaultSim != null) {
8585 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8586 if (DBG) log("Using locale from subId: " + subId + " locale: "
8587 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008588 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008589 } else {
8590 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008591 }
8592 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 // The SIM language preferences only store a language (e.g. fr = French), not an
8595 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8596 // the SIM and carrier preferences does not include a country we add the country
8597 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008598 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008600 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008601 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008602 }
8603
8604 if (DBG) log("No locale found - returning null");
8605 return null;
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
8608 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008609 }
8610
tom hsu0b59d292022-09-29 23:49:21 +08008611 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008612 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008613 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008614 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008615 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008616 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8617 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008618 Locale.forLanguageTag(localeTag).getCountry())) {
8619 return localeTag;
8620 }
8621 }
8622 return inputLocale.toLanguageTag();
8623 }
8624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625 /**
8626 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8627 */
8628 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008629 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008630 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008631 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008632
Gary Jian3aa9a762022-01-24 16:41:19 +08008633 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8634 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008635
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008636 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008637 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8638 * representing the state of the modem.
8639 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008640 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8641 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008642 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008643 */
8644 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008645 public void requestModemActivityInfo(ResultReceiver result) {
8646 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008647
8648 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8649 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8650
vagdeviaf9a5b92018-08-15 16:01:53 -07008651 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008652
8653 final long identity = Binder.clearCallingIdentity();
8654 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008655 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656 } finally {
8657 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008658 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008659 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008660
Gary Jian76280a42022-12-07 16:18:33 +08008661 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008662 // less than total activity duration.
8663 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8664 if (info == null) {
8665 return false;
8666 }
8667 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008668 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008669 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8670
Hall Liu49656c02020-10-09 19:00:11 -07008671 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8672
Siddharth Rayb8114062018-06-17 15:02:38 -07008673 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008674 && (info.getSleepTimeMillis() <= activityDurationMs)
8675 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008676 }
8677
Gary Jian3aa9a762022-01-24 16:41:19 +08008678 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8679 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8680 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8681 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8682
8683 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8684 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8685 }
8686
8687 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8688 mLastModemActivityInfo.setReceiveTimeMillis(
8689 rat,
8690 freq,
8691 info.getReceiveTimeMillis(rat, freq)
8692 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8693 }
8694
8695 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8696 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8697 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8698 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8699
8700 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8701 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8702 }
8703 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8704 mLastModemActivityInfo.setReceiveTimeMillis(
8705 rat,
8706 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8707 }
8708
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008709 /**
8710 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8711 * @param info recent ModemActivityInfo
8712 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008713 private void mergeModemActivityInfo(ModemActivityInfo info) {
8714 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008715 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008716 boolean matched;
8717 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8718 matched = false;
8719 int rat = info.getSpecificInfoRat(i);
8720 int freq = info.getSpecificInfoFrequencyRange(i);
8721 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8722 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8723 //if it already exists
8724 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8725 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8726 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8727 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8728 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8729 updateLastModemActivityInfo(info, rat, freq);
8730 matched = true;
8731 }
8732 } else {
8733 updateLastModemActivityInfo(info, rat);
8734 matched = true;
8735 }
8736 }
8737 }
8738
8739 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008740 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008741 new ActivityStatsTechSpecificInfo(
8742 rat,
8743 freq,
8744 info.getTransmitTimeMillis(rat, freq),
8745 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008746 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008747 }
8748 }
8749 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8750 mLastModemActivitySpecificInfo =
8751 new ActivityStatsTechSpecificInfo[merged.size()];
8752 merged.toArray(mLastModemActivitySpecificInfo);
8753
8754 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8755 mLastModemActivityInfo.setSleepTimeMillis(
8756 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008757 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008758 mLastModemActivityInfo.setIdleTimeMillis(
8759 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008760 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008761
8762 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008763 new ModemActivityInfo(
8764 mLastModemActivityInfo.getTimestampMillis(),
8765 mLastModemActivityInfo.getSleepTimeMillis(),
8766 mLastModemActivityInfo.getIdleTimeMillis(),
8767 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008768 }
8769
8770 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8771 ActivityStatsTechSpecificInfo[] info) {
8772 int infoSize = info.length;
8773 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8774 for (int i = 0; i < infoSize; i++) {
8775 ret[i] = new ActivityStatsTechSpecificInfo(
8776 info[i].getRat(), info[i].getFrequencyRange(),
8777 info[i].getTransmitTimeMillis(),
8778 (int) info[i].getReceiveTimeMillis());
8779 }
8780 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008781 }
8782
Jack Yu85bd38a2015-11-09 11:34:32 -08008783 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008784 * Returns the service state information on specified subscription.
8785 */
8786 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008787 public ServiceState getServiceStateForSubscriber(int subId,
8788 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8789 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008791 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008792 return null;
8793 }
8794
joonhunshin4ac60942023-11-15 15:23:39 +00008795 enforceTelephonyFeatureWithException(callingPackage,
8796 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8797
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008798 boolean hasFinePermission = false;
8799 boolean hasCoarsePermission = false;
8800 if (!renounceFineLocationAccess) {
8801 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8802 LocationAccessPolicy.checkLocationPermission(mApp,
8803 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8804 .setCallingPackage(callingPackage)
8805 .setCallingFeatureId(callingFeatureId)
8806 .setCallingPid(Binder.getCallingPid())
8807 .setCallingUid(Binder.getCallingUid())
8808 .setMethod("getServiceStateForSubscriber")
8809 .setLogAsInfo(true)
8810 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8811 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8812 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8813 .build());
8814 hasFinePermission =
8815 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8816 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008817
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008818 if (!renounceCoarseLocationAccess) {
8819 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8820 LocationAccessPolicy.checkLocationPermission(mApp,
8821 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8822 .setCallingPackage(callingPackage)
8823 .setCallingFeatureId(callingFeatureId)
8824 .setCallingPid(Binder.getCallingPid())
8825 .setCallingUid(Binder.getCallingUid())
8826 .setMethod("getServiceStateForSubscriber")
8827 .setLogAsInfo(true)
8828 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8829 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8830 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8831 .build());
8832 hasCoarsePermission =
8833 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8834 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008835
Jack Yu479f40e2020-10-27 21:29:25 -07008836 final Phone phone = getPhone(subId);
8837 if (phone == null) {
8838 return null;
8839 }
8840
Jordan Liu0f2bc442020-11-18 16:47:37 -08008841 final long identity = Binder.clearCallingIdentity();
8842
Jack Yu479f40e2020-10-27 21:29:25 -07008843 boolean isCallingPackageDataService = phone.getDataServicePackages()
8844 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008845 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008846 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008847 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8848 .getSubscriptionInfoInternal(subId);
8849 if (subInfo == null || !subInfo.isActive()) {
8850 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8851 + "subId=" + subId);
8852 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008853 }
8854
Hall Liuf19c44f2018-11-27 14:38:17 -08008855 ServiceState ss = phone.getServiceState();
8856
8857 // Scrub out the location info in ServiceState depending on what level of access
8858 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008859 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008860 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8861 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008862 } finally {
8863 Binder.restoreCallingIdentity(identity);
8864 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008865 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008866
8867 /**
8868 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8869 *
8870 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8871 * voicemail ringtone.
8872 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8873 * PhoneAccount.
8874 */
8875 @Override
8876 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008877 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8878 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008880 final long identity = Binder.clearCallingIdentity();
8881 try {
8882 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8883 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008884 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008885 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008891 }
8892
8893 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008894 * Sets the per-account voicemail ringtone.
8895 *
8896 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8897 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8898 *
8899 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8900 * voicemail ringtone.
8901 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8902 * PhoneAccount.
8903 */
8904 @Override
8905 public void setVoicemailRingtoneUri(String callingPackage,
8906 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008907 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008909 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8910 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8912 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8913 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915
joonhunshin4ac60942023-11-15 15:23:39 +00008916 enforceTelephonyFeatureWithException(callingPackage,
8917 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919 final long identity = Binder.clearCallingIdentity();
8920 try {
8921 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8922 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008923 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008924 }
8925 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008928 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008929 }
8930
8931 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008932 * Returns whether vibration is set for voicemail notification in Phone settings.
8933 *
8934 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8935 * voicemail vibration setting.
8936 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8937 */
8938 @Override
8939 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008940 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8941 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 final long identity = Binder.clearCallingIdentity();
8944 try {
8945 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8946 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008947 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008948 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8951 } finally {
8952 Binder.restoreCallingIdentity(identity);
8953 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008954 }
8955
Youhan Wange64578a2016-05-02 15:32:42 -07008956 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008957 * Sets the per-account voicemail vibration.
8958 *
8959 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8960 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8961 *
8962 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8963 * voicemail vibration setting.
8964 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8965 * specific PhoneAccount.
8966 */
8967 @Override
8968 public void setVoicemailVibrationEnabled(String callingPackage,
8969 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008970 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008971 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008972 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8973 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8975 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8976 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008977 }
8978
joonhunshin4ac60942023-11-15 15:23:39 +00008979 enforceTelephonyFeatureWithException(callingPackage,
8980 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8985 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008986 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 }
8988 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8989 } finally {
8990 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008991 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008992 }
8993
8994 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008995 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8996 *
8997 * @throws SecurityException if the caller does not have the required permission
8998 */
arunvoddud7401012022-12-15 16:08:12 +00008999 @VisibleForTesting
9000 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009001 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009002 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009003 }
9004
9005 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009006 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9007 * permission.
9008 *
9009 * @throws SecurityException if the caller does not have the required permission
9010 */
9011 private void enforceSendSmsPermission() {
9012 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9013 }
9014
9015 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009016 * Make sure either called from same process as self (phone) or IPC caller has interact across
9017 * users permission.
9018 *
9019 * @throws SecurityException if the caller does not have the required permission
9020 */
9021 private void enforceInteractAcrossUsersPermission(String message) {
9022 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9023 }
9024
9025 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009026 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009027 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009028 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009029 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009030 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009031 final long identity = Binder.clearCallingIdentity();
9032 try {
9033 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009034 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009035 if (componentName == null) {
9036 throw new SecurityException(
9037 "Caller not current active visual voicemail package[null]");
9038 }
9039 String vvmPackage = componentName.getPackageName();
9040 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009041 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 }
9043 } finally {
9044 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009045 }
9046 }
9047
9048 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009049 * Return the application ID for the app type.
9050 *
9051 * @param subId the subscription ID that this request applies to.
9052 * @param appType the uicc app type.
9053 * @return Application ID for specificied app type, or null if no uicc.
9054 */
9055 @Override
9056 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009057 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009058
9059 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9060 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9061
Youhan Wange64578a2016-05-02 15:32:42 -07009062 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009063
9064 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009065 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066 if (phone == null) {
9067 return null;
9068 }
9069 String aid = null;
9070 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009071 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009072 .getApplicationByType(appType).getAid();
9073 } catch (Exception e) {
9074 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9075 }
9076 return aid;
9077 } finally {
9078 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009079 }
Youhan Wange64578a2016-05-02 15:32:42 -07009080 }
9081
Youhan Wang4001d252016-05-11 10:29:41 -07009082 /**
9083 * Return the Electronic Serial Number.
9084 *
9085 * @param subId the subscription ID that this request applies to.
9086 * @return ESN or null if error.
9087 */
9088 @Override
9089 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009090 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009091 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009092
9093 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009094 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009095 if (phone == null) {
9096 return null;
9097 }
9098 String esn = null;
9099 try {
9100 esn = phone.getEsn();
9101 } catch (Exception e) {
9102 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9103 }
9104 return esn;
9105 } finally {
9106 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009107 }
Youhan Wang4001d252016-05-11 10:29:41 -07009108 }
9109
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009110 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009111 * Return the Preferred Roaming List Version.
9112 *
9113 * @param subId the subscription ID that this request applies to.
9114 * @return PRLVersion or null if error.
9115 */
9116 @Override
9117 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009118 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009119
9120 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9121 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9122
Youhan Wang66ad5d72016-07-18 17:56:58 -07009123 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009124
9125 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009126 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009127 if (phone == null) {
9128 return null;
9129 }
9130 String cdmaPrlVersion = null;
9131 try {
9132 cdmaPrlVersion = phone.getCdmaPrlVersion();
9133 } catch (Exception e) {
9134 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9135 }
9136 return cdmaPrlVersion;
9137 } finally {
9138 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009139 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009140 }
9141
9142 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009143 * Get snapshot of Telephony histograms
9144 * @return List of Telephony histograms
9145 * @hide
9146 */
9147 @Override
9148 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9150 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009151
9152 final long identity = Binder.clearCallingIdentity();
9153 try {
9154 return RIL.getTelephonyRILTimingHistograms();
9155 } finally {
9156 Binder.restoreCallingIdentity(identity);
9157 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009158 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009159
9160 /**
9161 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009162 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9163 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009164 * Require system privileges. In the future we may add this to carrier APIs.
9165 *
Michele Berionne482f8202018-11-27 18:57:59 -08009166 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009167 */
9168 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009169 @TelephonyManager.SetCarrierRestrictionResult
9170 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009171 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009172
9173 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9174 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9175
vagdeviaf9a5b92018-08-15 16:01:53 -07009176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009177
Michele Berionne482f8202018-11-27 18:57:59 -08009178 if (carrierRestrictionRules == null) {
9179 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009180 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009182 final long identity = Binder.clearCallingIdentity();
9183 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009184 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009185 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009189 }
9190
9191 /**
9192 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009193 * Get the allowed carrier list and the excluded carrier list, including the priority between
9194 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009195 * Require system privileges. In the future we may add this to carrier APIs.
9196 *
Michele Berionne482f8202018-11-27 18:57:59 -08009197 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009198 */
9199 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009200 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009201 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009202
9203 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9204 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9205
vagdeviaf9a5b92018-08-15 16:01:53 -07009206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009207
9208 final long identity = Binder.clearCallingIdentity();
9209 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009210 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9211 if (response instanceof CarrierRestrictionRules) {
9212 return (CarrierRestrictionRules) response;
9213 }
9214 // Response is an Exception of some kind,
9215 // which is signalled to the user as a NULL retval
9216 return null;
9217 } catch (Exception e) {
9218 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9219 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009220 } finally {
9221 Binder.restoreCallingIdentity(identity);
9222 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009223 }
9224
fionaxu59545b42016-05-25 15:53:37 -07009225 /**
arunvoddud7401012022-12-15 16:08:12 +00009226 * Fetches the carrier restriction status of the device and sends the status to the caller
9227 * through the callback.
9228 *
9229 * @param callback The callback that will be used to send the result.
9230 * @throws SecurityException if the caller does not have the required permission/privileges or
9231 * the caller is not allowlisted.
9232 */
9233 @Override
9234 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9235 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009236
9237 enforceTelephonyFeatureWithException(packageName,
9238 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9239
arunvoddud7401012022-12-15 16:08:12 +00009240 int carrierId = validateCallerAndGetCarrierId(packageName);
9241 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9242 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9243 throw new SecurityException("Not an authorized caller");
9244 }
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9248 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9249 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9250 } finally {
9251 Binder.restoreCallingIdentity(identity);
9252 }
9253 }
9254
arunvoddu567f2b42023-04-25 17:22:00 +00009255 @Override
9256 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9257 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9258 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9259 return allowListInfo.getShaIdList(pkgName, carrierId);
9260 }
9261
arunvoddud7401012022-12-15 16:08:12 +00009262 @VisibleForTesting
9263 public int validateCallerAndGetCarrierId(String packageName) {
9264 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9265 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9266 }
9267
9268 /**
fionaxu59545b42016-05-25 15:53:37 -07009269 * Action set from carrier signalling broadcast receivers to enable/disable radio
9270 * @param subId the subscription ID that this action applies to.
9271 * @param enabled control enable or disable radio.
9272 * {@hide}
9273 */
9274 @Override
9275 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9276 enforceModifyPermission();
9277 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009278
9279 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009280 if (phone == null) {
9281 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9282 return;
9283 }
9284 try {
9285 phone.carrierActionSetRadioEnabled(enabled);
9286 } catch (Exception e) {
9287 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009288 } finally {
9289 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009290 }
9291 }
9292
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009293 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009294 * Enable or disable Voice over NR (VoNR)
9295 * @param subId the subscription ID that this action applies to.
9296 * @param enabled enable or disable VoNR.
9297 * @return operation result.
9298 */
9299 @Override
9300 public int setVoNrEnabled(int subId, boolean enabled) {
9301 enforceModifyPermission();
9302 final Phone phone = getPhone(subId);
9303
9304 final long identity = Binder.clearCallingIdentity();
9305 if (phone == null) {
9306 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9307 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9308 }
9309
9310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9311 try {
9312 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9313 workSource);
9314 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009315
9316 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9317 if (DBG) {
9318 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9319 }
9320 SubscriptionManager.setSubscriptionProperty(
9321 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9322 (enabled ? "1" : "0"));
9323 }
9324
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009325 return result;
9326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
9330
9331 /**
9332 * Is voice over NR enabled
9333 * @return true if VoNR is enabled else false
9334 */
9335 @Override
9336 public boolean isVoNrEnabled(int subId) {
9337 enforceReadPrivilegedPermission("isVoNrEnabled");
9338 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9339 final long identity = Binder.clearCallingIdentity();
9340 try {
9341 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9342 null, subId, workSource);
9343 if (DBG) log("isVoNrEnabled: " + isEnabled);
9344 return isEnabled;
9345 } finally {
9346 Binder.restoreCallingIdentity(identity);
9347 }
9348 }
9349
9350 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009351 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9352 * network status based on which carrier apps could apply actions accordingly,
9353 * enable/disable default url handler for example.
9354 *
9355 * @param subId the subscription ID that this action applies to.
9356 * @param report control start/stop reporting the default network status.
9357 * {@hide}
9358 */
9359 @Override
9360 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9361 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009362
9363 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9364 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9365 "carrierActionReportDefaultNetworkStatus");
9366
fionaxu8da9cb12017-05-23 15:02:46 -07009367 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009368
9369 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009370 if (phone == null) {
9371 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9372 return;
9373 }
9374 try {
9375 phone.carrierActionReportDefaultNetworkStatus(report);
9376 } catch (Exception e) {
9377 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009378 } finally {
9379 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009380 }
9381 }
9382
9383 /**
fionaxud9622282017-07-17 17:51:30 -07009384 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9385 * @param subId the subscription ID that this action applies to.
9386 * {@hide}
9387 */
9388 @Override
9389 public void carrierActionResetAll(int subId) {
9390 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009391
9392 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9393 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9394
fionaxud9622282017-07-17 17:51:30 -07009395 final Phone phone = getPhone(subId);
9396 if (phone == null) {
9397 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9398 return;
9399 }
9400 try {
9401 phone.carrierActionResetAll();
9402 } catch (Exception e) {
9403 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9404 }
9405 }
9406
9407 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009408 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9409 * bug report is being generated.
9410 */
9411 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009412 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009413 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9414 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009415 writer.println("Permission Denial: can't dump Phone from pid="
9416 + Binder.getCallingPid()
9417 + ", uid=" + Binder.getCallingUid()
9418 + "without permission "
9419 + android.Manifest.permission.DUMP);
9420 return;
9421 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009422 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009423 }
Jack Yueb89b242016-06-22 13:27:47 -07009424
Brad Ebingerdac2f002018-04-03 15:17:52 -07009425 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009426 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9427 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9428 @NonNull String[] args) {
9429 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9430 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009431 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009432 }
9433
Jack Yueb89b242016-06-22 13:27:47 -07009434 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009435 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009436 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009437 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009438 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009439 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009440 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009441 */
9442 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009443 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009444 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009445 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9446 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9447 try {
9448 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009449 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009450 } catch (SecurityException se) {
9451 enforceModifyPermission();
9452 }
9453 } else {
9454 enforceModifyPermission();
9455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009456
Nate Myrenae97d192023-06-09 15:22:31 -07009457 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9458 && null != callingPackage && opEnableMobileDataByUser()) {
9459 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
9460 callingPackage, null, null);
9461 }
9462
joonhunshin4ac60942023-11-15 15:23:39 +00009463 enforceTelephonyFeatureWithException(callingPackage,
9464 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009466 final long identity = Binder.clearCallingIdentity();
9467 try {
9468 Phone phone = getPhone(subId);
9469 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009470 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9471 phone.carrierActionSetMeteredApnsEnabled(enabled);
9472 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009473 phone.getDataSettingsManager().setDataEnabled(
9474 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009476 }
9477 } finally {
9478 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009479 }
9480 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009481
9482 /**
9483 * Get Client request stats
9484 * @return List of Client Request Stats
9485 * @hide
9486 */
9487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009488 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9489 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009491 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009492 return null;
9493 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009494 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009496 final long identity = Binder.clearCallingIdentity();
9497 try {
9498 if (phone != null) {
9499 return phone.getClientRequestStats();
9500 }
9501
9502 return null;
9503 } finally {
9504 Binder.restoreCallingIdentity(identity);
9505 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009506 }
9507
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009508 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009509 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009510 if (uid == Process.ROOT_UID && packageName == null) {
9511 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9512 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9513 // exception. ROOT_UID seems not to have a valid package name returned by
9514 // PackageManager, so just fake it here to avoid issues when running telephony shell
9515 // commands that plumb through the RIL as root, like so:
9516 // $ adb root
9517 // $ adb shell cmd phone ...
9518 packageName = "root";
9519 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009520 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009521 }
Jack Yueb4124c2017-02-16 15:32:43 -08009522
9523 /**
Grace Chen70990072017-03-24 17:21:30 -07009524 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009525 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009526 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009527 * @param state State of SIM (power down, power up, pass through)
9528 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9529 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009531 *
9532 **/
9533 @Override
Grace Chen70990072017-03-24 17:21:30 -07009534 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009535 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009536
9537 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9538 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9539
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009540 Phone phone = PhoneFactory.getPhone(slotIndex);
9541
vagdeviaf9a5b92018-08-15 16:01:53 -07009542 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009547 phone.setSimPowerState(state, null, workSource);
9548 }
9549 } finally {
9550 Binder.restoreCallingIdentity(identity);
9551 }
9552 }
9553
9554 /**
9555 * Set SIM card power state.
9556 *
9557 * @param slotIndex SIM slot id.
9558 * @param state State of SIM (power down, power up, pass through)
9559 * @param callback callback to trigger after success or failure
9560 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9561 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9562 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9563 *
9564 **/
9565 @Override
9566 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9567 IIntegerConsumer callback) {
9568 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009569
9570 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9571 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9572 "setSimPowerStateForSlotWithCallback");
9573
Jordan Liu109698e2020-11-24 14:50:34 -08009574 Phone phone = PhoneFactory.getPhone(slotIndex);
9575
9576 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9577
9578 final long identity = Binder.clearCallingIdentity();
9579 try {
9580 if (phone != null) {
9581 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9582 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009583 }
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009586 }
9587 }
Shuo Qiandd210312017-04-12 22:11:33 +00009588
Tyler Gunn65d45c22017-06-05 11:22:26 -07009589 private boolean isUssdApiAllowed(int subId) {
9590 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009591 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009592 if (configManager == null) {
9593 return false;
9594 }
9595 PersistableBundle pb = configManager.getConfigForSubId(subId);
9596 if (pb == null) {
9597 return false;
9598 }
9599 return pb.getBoolean(
9600 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9601 }
9602
Shuo Qiandd210312017-04-12 22:11:33 +00009603 /**
Ling Mac28f0212023-03-24 16:07:15 -07009604 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009605 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009606 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009607 */
goneil9c5f4872017-12-05 14:07:56 -08009608 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009609 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009610 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009611
9612 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9613 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009615 final long identity = Binder.clearCallingIdentity();
9616 try {
Ling Mac28f0212023-03-24 16:07:15 -07009617 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009618 } finally {
9619 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009620 }
9621 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009622
9623 /**
9624 * Get the current signal strength information for the given subscription.
9625 * Because this information is not updated when the device is in a low power state
9626 * it should not be relied-upon to be current.
9627 * @param subId Subscription index
9628 * @return the most recent cached signal strength info from the modem
9629 */
9630 @Override
9631 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009632 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9633 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009635 final long identity = Binder.clearCallingIdentity();
9636 try {
9637 Phone p = getPhone(subId);
9638 if (p == null) {
9639 return null;
9640 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009642 return p.getSignalStrength();
9643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009646 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009647
Pengquan Meng77b7f132018-08-22 14:49:57 -07009648 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009649 * Get the current modem radio state for the given slot.
9650 * @param slotIndex slot index.
9651 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009652 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009653 * @return the current radio power state from the modem
9654 */
9655 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009656 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009657 Phone phone = PhoneFactory.getPhone(slotIndex);
9658 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9660 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009661 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9662 }
9663
joonhunshin4ac60942023-11-15 15:23:39 +00009664 enforceTelephonyFeatureWithException(callingPackage,
9665 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9666
Chen Xuf792fd62018-10-17 17:54:36 +00009667 final long identity = Binder.clearCallingIdentity();
9668 try {
9669 return phone.getRadioPowerState();
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
9674 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9675 }
9676
9677 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009678 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9679 *
9680 * <p>Requires one of the following permissions:
9681 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009682 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009683 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9684 * privileges.
9685 *
9686 * @param subId subscription id
9687 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9688 * {@code false}.
9689 */
9690 @Override
9691 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009692 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009693 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009694 try {
9695 mApp.enforceCallingOrSelfPermission(
9696 android.Manifest.permission.ACCESS_NETWORK_STATE,
9697 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009698 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009699 mApp.enforceCallingOrSelfPermission(
9700 permission.READ_BASIC_PHONE_STATE, functionName);
9701 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009702 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009703 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009704 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009705 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009706
joonhunshin4ac60942023-11-15 15:23:39 +00009707 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9708 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9709
Pengquan Menga1bb6272018-09-06 09:59:22 -07009710 boolean isEnabled = false;
9711 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009712 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009713 Phone phone = getPhone(subId);
9714 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009715 } finally {
9716 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009717 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009718 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009719 }
9720
9721
9722 /**
9723 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9724 *
9725 * <p> Requires permission:
9726 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9727 * privileges.
9728 *
9729 * @param subId subscription id
9730 * @param isEnabled {@code true} means enable, {@code false} means disable.
9731 */
9732 @Override
9733 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9735 mApp, subId, "setDataRoamingEnabled");
9736
joonhunshin4ac60942023-11-15 15:23:39 +00009737 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9738 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9739
Pengquan Menga1bb6272018-09-06 09:59:22 -07009740 final long identity = Binder.clearCallingIdentity();
9741 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009742 Phone phone = getPhone(subId);
9743 if (phone != null) {
9744 phone.setDataRoamingEnabled(isEnabled);
9745 }
9746 } finally {
9747 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009748 }
9749 }
9750
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009751 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009752 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009753 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009754 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009755 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009756
joonhunshin4ac60942023-11-15 15:23:39 +00009757 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9758 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9759
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009760 boolean isAllowed = true;
9761 final long identity = Binder.clearCallingIdentity();
9762 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009763 Phone phone = getPhone(subId);
9764 if (phone != null) {
9765 isAllowed = phone.isCspPlmnEnabled();
9766 }
9767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 return isAllowed;
9771 }
9772
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009773 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9774 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009775 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009776 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009777 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009778 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9779 if (phone == null) {
9780 return false;
9781 }
9782 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9783 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9784 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009785 }
9786
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009787 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009788 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009789 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009790 mApp.getSystemService(AppOpsManager.class)
9791 .checkPackage(Binder.getCallingUid(), callingPackage);
9792
Jordan Liu1e142fc2019-04-22 15:10:43 -07009793 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009794 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009795 try {
9796 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009797 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009798 } catch (SecurityException e) {
9799 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9800 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009801 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009802 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009803 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009804 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009805 }
joonhunshin4ac60942023-11-15 15:23:39 +00009806
9807 enforceTelephonyFeatureWithException(callingPackage,
9808 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9809
sandeepjsb6c87872021-09-27 15:34:44 +00009810 // checking compatibility, if calling app's target SDK is T and beyond.
9811 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9812 Binder.getCallingUid())) {
9813 isIccIdAccessRestricted = true;
9814 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009815 final long identity = Binder.clearCallingIdentity();
9816 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009817 UiccController uiccController = UiccController.getInstance();
9818 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009819 if (hasReadPermission) {
9820 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009821 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009822
9823 // Remove private info if the caller doesn't have access
9824 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9825 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009826 //setting the value after compatibility check
9827 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009828 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9829 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009830 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009831 if (card == null) {
9832 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009833 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009834 continue;
9835 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009836 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9837 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009838 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009839 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009840 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009841 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9842 for (UiccPortInfo portInfo : portInfos) {
9843 UiccPort port = uiccController.getUiccPortForSlot(
9844 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9845 if (port == null) {
9846 // assume no access if port is null
9847 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9848 continue;
9849 }
9850 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9851 uiccPortInfos.add(portInfo);
9852 } else {
9853 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9854 }
9855 }
9856 filteredInfos.add(new UiccCardInfo(
9857 cardInfo.isEuicc(),
9858 cardInfo.getCardId(),
9859 null,
9860 cardInfo.getPhysicalSlotIndex(),
9861 cardInfo.isRemovable(),
9862 cardInfo.isMultipleEnabledProfilesSupported(),
9863 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009864 }
9865 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009866 } finally {
9867 Binder.restoreCallingIdentity(identity);
9868 }
9869 }
9870
sandeepjsb6c87872021-09-27 15:34:44 +00009871 /**
9872 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9873 * generally private and require carrier privileges to view.
9874 *
9875 * @hide
9876 */
9877 @NonNull
9878 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9879 List<UiccPortInfo> portinfo = new ArrayList<>();
9880 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9881 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9882 }
9883 return new UiccCardInfo(
9884 cardInfo.isEuicc(),
9885 cardInfo.getCardId(),
9886 null,
9887 cardInfo.getPhysicalSlotIndex(),
9888 cardInfo.isRemovable(),
9889 cardInfo.isMultipleEnabledProfilesSupported(),
9890 portinfo
9891 );
9892 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009893
sandeepjsb6c87872021-09-27 15:34:44 +00009894 /**
9895 * @hide
9896 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9897 * These values are generally private and require carrier privileges to view.
9898 */
9899 @NonNull
9900 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9901 return new UiccPortInfo(
9902 UiccPortInfo.ICCID_REDACTED,
9903 portInfo.getPortIndex(),
9904 portInfo.getLogicalSlotIndex(),
9905 portInfo.isActive()
9906 );
9907 }
9908 @Override
9909 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009910 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009911 mApp.getSystemService(AppOpsManager.class)
9912 .checkPackage(Binder.getCallingUid(), callingPackage);
9913
sandeepjsb6c87872021-09-27 15:34:44 +00009914 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009915
Aman Guptaf3c90b32022-03-17 04:54:16 +00009916 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9917 // we are reading iccId which is PII data.
9918 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009919
joonhunshin4ac60942023-11-15 15:23:39 +00009920 enforceTelephonyFeatureWithException(callingPackage,
9921 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9922
sandeepjsb6c87872021-09-27 15:34:44 +00009923 // checking compatibility, if calling app's target SDK is T and beyond.
9924 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9925 Binder.getCallingUid())) {
9926 isLogicalSlotAccessRestricted = true;
9927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009928 final long identity = Binder.clearCallingIdentity();
9929 try {
9930 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009931 if (slots == null || slots.length == 0) {
9932 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009933 return null;
9934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009935 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9936 for (int i = 0; i < slots.length; i++) {
9937 UiccSlot slot = slots[i];
9938 if (slot == null) {
9939 continue;
9940 }
9941
Jordan Liu7be7e652019-05-06 18:55:02 +00009942 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009943 UiccCard card = slot.getUiccCard();
9944 if (card != null) {
9945 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009946 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009947 cardId = slot.getEid();
9948 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009949 // If cardId is null, use iccId of default port as cardId.
9950 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009952 }
9953
Jordan Liu857451f2019-05-09 16:35:35 -07009954 if (cardId != null) {
9955 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9956 // if cardId is an EID, it's all digits so this is fine
9957 cardId = IccUtils.stripTrailingFs(cardId);
9958 }
9959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009960 int cardState = 0;
9961 switch (slot.getCardState()) {
9962 case CARDSTATE_ABSENT:
9963 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9964 break;
9965 case CARDSTATE_PRESENT:
9966 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9967 break;
9968 case CARDSTATE_ERROR:
9969 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9970 break;
9971 case CARDSTATE_RESTRICTED:
9972 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9973 break;
9974 default:
9975 break;
9976
9977 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009978 List<UiccPortInfo> portInfos = new ArrayList<>();
9979 int[] portIndexes = slot.getPortList();
9980 for (int portIdx : portIndexes) {
9981 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009982 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009983 portInfos.add(new UiccPortInfo(iccId, portIdx,
9984 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009986 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009987 slot.isEuicc(),
9988 cardId,
9989 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009990 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009991 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009992 //setting the value after compatibility check
9993 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009994 }
9995 return infos;
9996 } finally {
9997 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009998 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009999 }
10000
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010001 /* Returns null if doesn't have read permission or carrier privilege access. */
10002 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10003 boolean hasReadPermission) {
10004 String iccId = slot.getIccId(portIndex);
10005 if (hasReadPermission) { // if has read permission
10006 return iccId;
10007 } else {
10008 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10009 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10010 // if no read permission, checking carrier privilege access
10011 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10012 return iccId;
10013 }
10014 }
10015 }
10016 // No read permission or carrier privilege access.
10017 return UiccPortInfo.ICCID_REDACTED;
10018 }
10019
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010020 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010021 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010022 public boolean switchSlots(int[] physicalSlots) {
10023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010024
joonhunshin4ac60942023-11-15 15:23:39 +000010025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10026 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10027
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010028 final long identity = Binder.clearCallingIdentity();
10029 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010030 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10031 for (int i = 0; i < physicalSlots.length; i++) {
10032 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10033 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10034 physicalSlots[i], i));
10035 }
10036 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010037 } finally {
10038 Binder.restoreCallingIdentity(identity);
10039 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010040 }
Jack Yu4c988042018-02-27 15:30:01 -080010041
10042 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010043 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10044 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10045 enforceModifyPermission();
10046
joonhunshin4ac60942023-11-15 15:23:39 +000010047 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10048 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10049
sandeepjsb6c87872021-09-27 15:34:44 +000010050 final long identity = Binder.clearCallingIdentity();
10051 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010052 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010053 } finally {
10054 Binder.restoreCallingIdentity(identity);
10055 }
10056 }
10057
10058 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010059 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010060 enforceTelephonyFeatureWithException(callingPackage,
10061 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10062
Jordan Liu7de49fa2018-12-06 14:48:49 -080010063 final long identity = Binder.clearCallingIdentity();
10064 try {
10065 return UiccController.getInstance().getCardIdForDefaultEuicc();
10066 } finally {
10067 Binder.restoreCallingIdentity(identity);
10068 }
10069 }
10070
Pengquan Meng85728fb2018-03-12 16:31:21 -070010071 /**
goneil47ffb6e2018-04-06 15:40:58 -070010072 * A test API to reload the UICC profile.
10073 *
10074 * <p>Requires that the calling app has permission
10075 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10076 * @hide
10077 */
10078 @Override
10079 public void refreshUiccProfile(int subId) {
10080 enforceModifyPermission();
10081
10082 final long identity = Binder.clearCallingIdentity();
10083 try {
10084 Phone phone = getPhone(subId);
10085 if (phone == null) {
10086 return;
10087 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010088 UiccPort uiccPort = phone.getUiccPort();
10089 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010090 return;
10091 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010092 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010093 if (uiccProfile == null) {
10094 return;
10095 }
10096 uiccProfile.refresh();
10097 } finally {
10098 Binder.restoreCallingIdentity(identity);
10099 }
10100 }
10101
10102 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010103 * Returns false if the mobile data is disabled by default, otherwise return true.
10104 */
10105 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010106 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010107 }
10108
10109 /**
10110 * Returns true if the data roaming is enabled by default, i.e the system property
10111 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10112 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10113 */
10114 private boolean getDefaultDataRoamingEnabled(int subId) {
10115 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010116 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010117 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010118 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10119 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10120 return isDataRoamingEnabled;
10121 }
10122
10123 /**
10124 * Returns the default network type for the given {@code subId}, if the default network type is
10125 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10126 */
10127 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010128 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010129 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010130 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10131 return list.get(phoneId);
10132 }
10133 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010134 }
fionaxua13278b2018-03-21 00:08:13 -070010135
10136 @Override
10137 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010138 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010139 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010140
10141 final long identity = Binder.clearCallingIdentity();
10142 try {
10143 final Phone phone = getPhone(subId);
10144 if (phone == null) {
10145 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10146 return;
10147 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010148 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10149 if (cpt != null) {
10150 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10151 }
10152 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010153 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10154 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010155 if (carrierPrivilegeRules == null) {
10156 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10157 } else {
10158 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010160 } finally {
10161 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010162 }
fionaxua13278b2018-03-21 00:08:13 -070010163 }
10164
10165 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010166 public void setCarrierServicePackageOverride(
10167 int subId, String carrierServicePackage, String callingPackage) {
10168 TelephonyPermissions.enforceShellOnly(
10169 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10170
Benedict Wong66477622023-02-03 23:30:57 +000010171 final long identity = Binder.clearCallingIdentity();
10172 try {
10173 final Phone phone = getPhone(subId);
10174 if (phone == null || phone.getSubId() != subId) {
10175 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10176 throw new IllegalArgumentException("No phone for subid");
10177 }
10178 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10179 if (cpt == null) {
10180 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10181 throw new IllegalStateException("No CPT for phone");
10182 }
10183 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10184 } finally {
10185 Binder.restoreCallingIdentity(identity);
10186 }
10187 }
10188
10189 @Override
fionaxua13278b2018-03-21 00:08:13 -070010190 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010191 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010192
10193 final long identity = Binder.clearCallingIdentity();
10194 try {
10195 final Phone phone = getPhone(subId);
10196 if (phone == null) {
10197 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10198 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10199 }
10200 return phone.getCarrierIdListVersion();
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010203 }
fionaxua13278b2018-03-21 00:08:13 -070010204 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010205
10206 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010207 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10208 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010209 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010210 mApp, subId, callingPackage, callingFeatureId,
10211 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010212 return -1;
10213 }
10214
10215 final long identity = Binder.clearCallingIdentity();
10216 try {
10217 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10218 } finally {
10219 Binder.restoreCallingIdentity(identity);
10220 }
10221 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010222
10223 @Override
10224 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010225 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010226 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010227 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010228
joonhunshin4ac60942023-11-15 15:23:39 +000010229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10230 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10231
Pengquan Menga1bb6272018-09-06 09:59:22 -070010232 final long identity = Binder.clearCallingIdentity();
10233 try {
10234 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10235 } finally {
10236 Binder.restoreCallingIdentity(identity);
10237 }
10238 }
10239
10240 @Override
10241 public boolean setCdmaRoamingMode(int subId, int mode) {
10242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10243 mApp, subId, "setCdmaRoamingMode");
10244
joonhunshin4ac60942023-11-15 15:23:39 +000010245 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10246 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10247
Pengquan Menga1bb6272018-09-06 09:59:22 -070010248 final long identity = Binder.clearCallingIdentity();
10249 try {
10250 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10251 } finally {
10252 Binder.restoreCallingIdentity(identity);
10253 }
10254 }
10255
10256 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010257 public int getCdmaSubscriptionMode(int subId) {
10258 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010259 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010260 mApp, subId, "getCdmaSubscriptionMode");
10261
joonhunshin4ac60942023-11-15 15:23:39 +000010262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10263 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10264
Sarah Chinbaab1432020-10-28 13:46:24 -070010265 final long identity = Binder.clearCallingIdentity();
10266 try {
10267 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 }
10272
10273 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010274 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10276 mApp, subId, "setCdmaSubscriptionMode");
10277
joonhunshin4ac60942023-11-15 15:23:39 +000010278 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10279 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10280
Pengquan Menga1bb6272018-09-06 09:59:22 -070010281 final long identity = Binder.clearCallingIdentity();
10282 try {
10283 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10284 } finally {
10285 Binder.restoreCallingIdentity(identity);
10286 }
10287 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010288
sqianc5eccab2018-10-19 18:46:41 -070010289 @Override
sqian8c685422019-02-22 15:55:18 -080010290 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010291 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010293 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10294 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010295 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10296 }
joonhunshin4ac60942023-11-15 15:23:39 +000010297
10298 enforceTelephonyFeatureWithException(callingPackage,
10299 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10300
sqian11b7a0e2018-12-05 18:48:28 -080010301 final long identity = Binder.clearCallingIdentity();
10302 try {
sqian854d44b2018-12-12 16:48:18 -080010303 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10304 for (Phone phone: PhoneFactory.getPhones()) {
10305 if (phone.getEmergencyNumberTracker() != null
10306 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10307 emergencyNumberListInternal.put(
10308 phone.getSubId(),
10309 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10310 }
sqian11b7a0e2018-12-05 18:48:28 -080010311 }
sqian854d44b2018-12-12 16:48:18 -080010312 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010313 } finally {
10314 Binder.restoreCallingIdentity(identity);
10315 }
sqianc5eccab2018-10-19 18:46:41 -070010316 }
10317
10318 @Override
sqian8c685422019-02-22 15:55:18 -080010319 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010320 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010321 if (!exactMatch) {
10322 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010323 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010324 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010325 }
joonhunshin4ac60942023-11-15 15:23:39 +000010326
10327 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10328 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10329
sqian11b7a0e2018-12-05 18:48:28 -080010330 final long identity = Binder.clearCallingIdentity();
10331 try {
sqian854d44b2018-12-12 16:48:18 -080010332 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010333 //Note: we ignore passed in param exactMatch. We can remove it once
10334 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010335 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010336 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010337 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010338 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010339 }
sqian11b7a0e2018-12-05 18:48:28 -080010340 }
10341 return false;
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
10346
sqianf4ca7ed2019-01-15 18:32:07 -080010347 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010348 * Start emergency callback mode for GsmCdmaPhone for testing.
10349 */
10350 @Override
10351 public void startEmergencyCallbackMode() {
10352 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10353 "startEmergencyCallbackMode");
10354 enforceModifyPermission();
10355 final long identity = Binder.clearCallingIdentity();
10356 try {
10357 for (Phone phone : PhoneFactory.getPhones()) {
10358 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10359 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10360 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10361 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10362 gsmCdmaPhone.obtainMessage(
10363 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10364 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10365 }
10366 }
10367 } finally {
10368 Binder.restoreCallingIdentity(identity);
10369 }
10370 }
10371
10372 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010373 * Update emergency number list for test mode.
10374 */
10375 @Override
10376 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10378 "updateEmergencyNumberListTestMode");
10379
10380 final long identity = Binder.clearCallingIdentity();
10381 try {
10382 for (Phone phone: PhoneFactory.getPhones()) {
10383 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10384 if (tracker != null) {
10385 tracker.executeEmergencyNumberTestModeCommand(action, num);
10386 }
10387 }
10388 } finally {
10389 Binder.restoreCallingIdentity(identity);
10390 }
10391 }
10392
10393 /**
10394 * Get the full emergency number list for test mode.
10395 */
10396 @Override
10397 public List<String> getEmergencyNumberListTestMode() {
10398 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10399 "getEmergencyNumberListTestMode");
10400
10401 final long identity = Binder.clearCallingIdentity();
10402 try {
10403 Set<String> emergencyNumbers = new HashSet<>();
10404 for (Phone phone: PhoneFactory.getPhones()) {
10405 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10406 if (tracker != null) {
10407 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10408 emergencyNumbers.add(num.getNumber());
10409 }
10410 }
10411 }
10412 return new ArrayList<>(emergencyNumbers);
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
10417
chen xud6b45bd2018-10-30 22:27:10 -070010418 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010419 public int getEmergencyNumberDbVersion(int subId) {
10420 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10421
joonhunshin4ac60942023-11-15 15:23:39 +000010422 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10423 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10424
Shuo Qian3b6ee772019-11-13 17:43:31 -080010425 final long identity = Binder.clearCallingIdentity();
10426 try {
10427 final Phone phone = getPhone(subId);
10428 if (phone == null) {
10429 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10430 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10431 }
10432 return phone.getEmergencyNumberDbVersion();
10433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436 }
10437
10438 @Override
10439 public void notifyOtaEmergencyNumberDbInstalled() {
10440 enforceModifyPermission();
10441
joonhunshin4ac60942023-11-15 15:23:39 +000010442 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10443 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10444
Shuo Qian3b6ee772019-11-13 17:43:31 -080010445 final long identity = Binder.clearCallingIdentity();
10446 try {
10447 for (Phone phone: PhoneFactory.getPhones()) {
10448 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10449 if (tracker != null) {
10450 tracker.updateOtaEmergencyNumberDatabase();
10451 }
10452 }
10453 } finally {
10454 Binder.restoreCallingIdentity(identity);
10455 }
10456 }
10457
10458 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010459 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010460 enforceActiveEmergencySessionPermission();
10461
joonhunshin4ac60942023-11-15 15:23:39 +000010462 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10463 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10464
Shuo Qian3b6ee772019-11-13 17:43:31 -080010465 final long identity = Binder.clearCallingIdentity();
10466 try {
10467 for (Phone phone: PhoneFactory.getPhones()) {
10468 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10469 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010470 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10471 }
10472 }
10473 } finally {
10474 Binder.restoreCallingIdentity(identity);
10475 }
10476 }
10477
10478 @Override
10479 public void resetOtaEmergencyNumberDbFilePath() {
10480 enforceActiveEmergencySessionPermission();
10481
joonhunshin4ac60942023-11-15 15:23:39 +000010482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10483 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10484
Shuo Qianc373f112020-03-05 17:55:34 -080010485 final long identity = Binder.clearCallingIdentity();
10486 try {
10487 for (Phone phone: PhoneFactory.getPhones()) {
10488 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10489 if (tracker != null) {
10490 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010491 }
10492 }
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
10497
10498 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010499 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10500 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10501 Phone phone = getPhone(subId);
10502 if (phone == null) {
10503 return null;
10504 }
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 UiccProfile profile = UiccController.getInstance()
10508 .getUiccProfileForPhone(phone.getPhoneId());
10509 if (profile != null) {
10510 return profile.getCertsFromCarrierPrivilegeAccessRules();
10511 }
10512 } finally {
10513 Binder.restoreCallingIdentity(identity);
10514 }
10515 return null;
10516 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010517
10518 /**
10519 * Enable or disable a modem stack.
10520 */
10521 @Override
10522 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10523 enforceModifyPermission();
10524
joonhunshin4ac60942023-11-15 15:23:39 +000010525 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10526 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10527
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010528 final long identity = Binder.clearCallingIdentity();
10529 try {
10530 Phone phone = PhoneFactory.getPhone(slotIndex);
10531 if (phone == null) {
10532 return false;
10533 } else {
10534 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10535 }
10536 } finally {
10537 Binder.restoreCallingIdentity(identity);
10538 }
10539 }
Michelecea4cf22018-12-21 15:00:11 -080010540
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010541 /**
10542 * Whether a modem stack is enabled or not.
10543 */
10544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010545 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10546 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010547 Phone phone = PhoneFactory.getPhone(slotIndex);
10548 if (phone == null) return false;
10549
10550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010551 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10552 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010553 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10554 }
10555
joonhunshin4ac60942023-11-15 15:23:39 +000010556 enforceTelephonyFeatureWithException(callingPackage,
10557 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10558
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010559 final long identity = Binder.clearCallingIdentity();
10560 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010561 try {
10562 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10563 } catch (NoSuchElementException ex) {
10564 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10565 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010566 } finally {
10567 Binder.restoreCallingIdentity(identity);
10568 }
10569 }
10570
Michelecea4cf22018-12-21 15:00:11 -080010571 @Override
Michele0ea7d782019-03-19 14:58:42 -070010572 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010573 enforceModifyPermission();
10574
joonhunshin4ac60942023-11-15 15:23:39 +000010575 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10576 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10577
Michelecea4cf22018-12-21 15:00:11 -080010578 final long identity = Binder.clearCallingIdentity();
10579 try {
10580 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010581 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010582 .commit();
10583 } finally {
10584 Binder.restoreCallingIdentity(identity);
10585 }
10586 }
10587
10588 @Override
Michele0ea7d782019-03-19 14:58:42 -070010589 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010590 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010592 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10593 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010594 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010595 }
Michelecea4cf22018-12-21 15:00:11 -080010596
joonhunshin4ac60942023-11-15 15:23:39 +000010597 enforceTelephonyFeatureWithException(callingPackage,
10598 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10599
Michelecea4cf22018-12-21 15:00:11 -080010600 final long identity = Binder.clearCallingIdentity();
10601 try {
Michele0ea7d782019-03-19 14:58:42 -070010602 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010603 } finally {
10604 Binder.restoreCallingIdentity(identity);
10605 }
10606 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010607
Michele0ea7d782019-03-19 14:58:42 -070010608 @TelephonyManager.IsMultiSimSupportedResult
10609 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010610 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10611 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10612 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010613 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010615 }
10616 // Check if the hardware supports multisim functionality. If usage of multisim is not
10617 // supported by the modem, indicate that it is restricted.
10618 PhoneCapability staticCapability =
10619 mPhoneConfigurationManager.getStaticPhoneCapability();
10620 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010621 loge("isMultiSimSupportedInternal: no static configuration available");
10622 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010623 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010624 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010625 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10626 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010627 }
10628 // Check if support of multiple SIMs is restricted by carrier
10629 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010630 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010631 }
10632
Michele0ea7d782019-03-19 14:58:42 -070010633 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010634 }
10635
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010636 /**
10637 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010638 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10639 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10640 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010641 * @param numOfSims number of active sims we want to switch to
10642 */
10643 @Override
10644 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010645 if (numOfSims == 1) {
10646 enforceModifyPermission();
10647 } else {
10648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10649 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10650 }
joonhunshin4ac60942023-11-15 15:23:39 +000010651
10652 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10653 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10654
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010655 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010656
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010657 try {
Michele30b57b22019-03-01 12:01:14 -080010658 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010659 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010660 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10661 return;
10662 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010663 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10664 } finally {
10665 Binder.restoreCallingIdentity(identity);
10666 }
10667 }
10668
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010669 @Override
10670 public boolean isApplicationOnUicc(int subId, int appType) {
10671 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010672
10673 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10674 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10675
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010676 Phone phone = getPhone(subId);
10677 if (phone == null) {
10678 return false;
10679 }
10680 final long identity = Binder.clearCallingIdentity();
10681 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010682 UiccPort uiccPort = phone.getUiccPort();
10683 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010684 return false;
10685 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010686 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010687 if (uiccProfile == null) {
10688 return false;
10689 }
10690 if (TelephonyManager.APPTYPE_SIM <= appType
10691 && appType <= TelephonyManager.APPTYPE_ISIM) {
10692 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10693 }
10694 return false;
10695 } finally {
10696 Binder.restoreCallingIdentity(identity);
10697 }
10698 }
10699
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010700 /**
chen xub4baa772019-04-03 10:23:41 -070010701 * Get whether making changes to modem configurations will trigger reboot.
10702 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010703 */
10704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010705 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10706 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010708 mApp, subId, callingPackage, callingFeatureId,
10709 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010710 return false;
10711 }
joonhunshin4ac60942023-11-15 15:23:39 +000010712
10713 enforceTelephonyFeatureWithException(callingPackage,
10714 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10715 "doesSwitchMultiSimConfigTriggerReboot");
10716
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010717 final long identity = Binder.clearCallingIdentity();
10718 try {
10719 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10720 } finally {
10721 Binder.restoreCallingIdentity(identity);
10722 }
10723 }
10724
Nathan Harold29f5f052019-02-15 13:41:57 -080010725 private void updateModemStateMetrics() {
10726 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10727 // TODO: check the state for each modem if the api is ready.
10728 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10729 }
10730
Pengquan Meng3889a572019-01-23 11:16:29 -080010731 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010732 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010733 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010734 // Verify that the callingPackage belongs to the calling UID
10735 mApp.getSystemService(AppOpsManager.class)
10736 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010737
10738 enforceTelephonyFeatureWithException(callingPackage,
10739 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10740
Pengquan Meng3889a572019-01-23 11:16:29 -080010741 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010742 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010743 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010744 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10745 if (slotInfos != null) {
10746 for (int i = 0; i < slotInfos.length; i++) {
10747 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10748 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10749 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10750 portInfo.getLogicalSlotIndex()));
10751 }
10752 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010753 }
10754 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010755 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010760
10761 /**
10762 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010763 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010764 */
jimsunf9ec1622022-09-13 21:18:43 +080010765 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010766 @Override
10767 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010768 return getHalVersion(HAL_SERVICE_RADIO);
10769 }
10770
10771 /**
10772 * Get the HAL Version of a specific service
10773 */
10774 @Override
10775 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010776 Phone phone = getDefaultPhone();
10777 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010778 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010779 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10780 return hv.major * 100 + hv.minor;
10781 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010782
10783 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010784 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010785 *
10786 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010787 */
10788 @Override
sangyun097dcf72024-01-04 10:35:49 +090010789 public @Nullable String getCurrentPackageName() {
10790 PackageManager pm = mApp.getPackageManager();
10791 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10792 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010793 }
10794
10795 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010796 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10797 * corresponding network requests on a subId.
10798 *
10799 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010800 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010801 * 2) APN is un-metered for this subscription, or
10802 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010803 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010804 *
10805 * @return whether data is allowed for a apn type.
10806 *
10807 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010808 */
10809 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010810 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010811 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10812 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010813
joonhunshin4ac60942023-11-15 15:23:39 +000010814 enforceTelephonyFeatureWithException(callingPackage,
10815 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10816
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010817 // Now that all security checks passes, perform the operation as ourselves.
10818 final long identity = Binder.clearCallingIdentity();
10819 try {
10820 Phone phone = getPhone(subId);
10821 if (phone == null) return false;
10822
Jack Yu27422a52022-03-21 10:38:05 -070010823 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010824 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010825 isMetered = phone.getDataNetworkController().getDataConfigManager()
10826 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10827 phone.getServiceState().getDataRoaming());
10828 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010829 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010830 } finally {
10831 Binder.restoreCallingIdentity(identity);
10832 }
10833 }
10834
10835 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010836 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010837 enforceReadPrivilegedPermission("isApnMetered");
10838
joonhunshin4ac60942023-11-15 15:23:39 +000010839 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10840 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10841
Malcolm Chene5ad5792019-04-18 13:51:02 -070010842 // Now that all security checks passes, perform the operation as ourselves.
10843 final long identity = Binder.clearCallingIdentity();
10844 try {
10845 Phone phone = getPhone(subId);
10846 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010847 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10848 DataUtils.apnTypeToNetworkCapability(apnType),
10849 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010854
10855 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010856 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10857 int subscriptionId, IBooleanConsumer resultCallback) {
10858 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010859
10860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10861 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10862
Hall Liu73f5d362020-01-20 13:42:00 -080010863 long token = Binder.clearCallingIdentity();
10864 try {
10865 Phone phone = getPhone(subscriptionId);
10866 if (phone == null) {
10867 try {
10868 if (resultCallback != null) {
10869 resultCallback.accept(false);
10870 }
10871 } catch (RemoteException e) {
10872 // ignore
10873 }
10874 return;
10875 }
10876 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10877 Pair.create(specifiers, (x) -> {
10878 try {
10879 if (resultCallback != null) {
10880 resultCallback.accept(x);
10881 }
10882 } catch (RemoteException e) {
10883 // ignore
10884 }
10885 });
10886 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10887 } finally {
10888 Binder.restoreCallingIdentity(token);
10889 }
10890 }
10891
10892 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010893 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10894 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010895 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010896 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010897
10898 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10899 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10900
Sarah Chin679c08a2020-11-18 13:39:35 -080010901 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10902 final long identity = Binder.clearCallingIdentity();
10903 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010904 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10905 if (result instanceof IllegalStateException) {
10906 throw (IllegalStateException) result;
10907 }
10908 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010909 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10910 return specifiers;
10911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
10915
10916 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010917 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010918 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010919
10920 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10921 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10922
Jack Yu8b766fc2022-03-21 09:42:33 -070010923 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010924 }
10925
10926 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010927 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10928 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010929 if (callingPackage == null) {
10930 callingPackage = getCurrentPackageName();
10931 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010932 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10933 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010934 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10935 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010936 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10937 }
10938 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10939 Intent intent = new Intent();
10940 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10941 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10942 // Bring up choose default SMS subscription dialog right now
10943 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10944 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10945 mApp.startActivity(intent);
10946 }
chen xud5ca2d52019-05-28 15:20:57 -070010947
10948 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010949 public void showSwitchToManagedProfileDialog() {
10950 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010951 try {
10952 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10953 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10954 // for work telephony.
10955 Intent intent = new Intent(Intent.ACTION_SENDTO);
10956 intent.setData(Uri.parse("smsto:"));
10957 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10958 mApp.startActivity(intent);
10959 } catch (ActivityNotFoundException e) {
10960 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10961 Intent intent = new Intent();
10962 intent.setClass(mApp, ErrorDialogActivity.class);
10963 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10964 mApp.startActivity(intent);
10965 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010966 }
10967
10968 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010969 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10971 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10972
chen xud5ca2d52019-05-28 15:20:57 -070010973 //TODO investigate if this API should require proper permission check in R b/133791609
10974 final long identity = Binder.clearCallingIdentity();
10975 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010976 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10977 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10978 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10979 return carrierUAProfUrl;
10980 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010981 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10982 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010983 } finally {
10984 Binder.restoreCallingIdentity(identity);
10985 }
10986 }
10987
10988 @Override
10989 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010990 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10991 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10992
chen xud5ca2d52019-05-28 15:20:57 -070010993 //TODO investigate if this API should require proper permission check in R b/133791609
10994 final long identity = Binder.clearCallingIdentity();
10995 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010996 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10997 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10998 if (!TextUtils.isEmpty(carrierUserAgent)) {
10999 return carrierUserAgent;
11000 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011001 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11002 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011003 } finally {
11004 Binder.restoreCallingIdentity(identity);
11005 }
11006 }
Jack Yub07d4972019-05-28 16:12:25 -070011007
11008 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011009 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11010 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011011
joonhunshin4ac60942023-11-15 15:23:39 +000011012 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11013 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11014
Jack Yub07d4972019-05-28 16:12:25 -070011015 final long identity = Binder.clearCallingIdentity();
11016 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011017 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011018 if (phone == null) return false;
11019
Ling Maf188d502022-09-16 15:22:36 -070011020 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
11025
11026 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011027 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011028 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011029 enforceModifyPermission();
11030
joonhunshin4ac60942023-11-15 15:23:39 +000011031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11032 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11033
changbettyd5c246e2019-12-24 15:40:37 +080011034 final long identity = Binder.clearCallingIdentity();
11035 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011036 Phone phone = getPhone(subscriptionId);
11037 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011038
Ling Maf188d502022-09-16 15:22:36 -070011039 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011040 } finally {
11041 Binder.restoreCallingIdentity(identity);
11042 }
11043 }
11044
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011045 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011046 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011047 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11048 * otherwise.
11049 */
11050 @Override
11051 public void setCepEnabled(boolean isCepEnabled) {
11052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11053
11054 final long identity = Binder.clearCallingIdentity();
11055 try {
11056 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11057 for (Phone phone : PhoneFactory.getPhones()) {
11058 Phone defaultPhone = phone.getImsPhone();
11059 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11060 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11061 ImsPhoneCallTracker imsPhoneCallTracker =
11062 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11063 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11064 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11065 + imsPhone.getMsisdn());
11066 }
11067 }
11068 } finally {
11069 Binder.restoreCallingIdentity(identity);
11070 }
11071 }
allenwtsu46dcc572020-01-08 18:24:03 +080011072
11073 /**
11074 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11075 *
11076 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11077 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11078 * before being read.
11079 */
11080 @Override
11081 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11082 isCompressed) {
11083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11084 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11086 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11087 }
joonhunshin4ac60942023-11-15 15:23:39 +000011088
11089 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11090 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11091 Binder.getCallingUserHandle())) {
11092 if (!isImsAvailableOnDevice()) {
11093 // ProvisioningManager can not handle ServiceSpecificException.
11094 // Throw the IllegalStateException and annotate ProvisioningManager.
11095 throw new IllegalStateException("IMS not available on device.");
11096 }
11097 } else {
11098 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11099 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11100 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011101 }
11102
11103 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011104 try {
Hui Wang761a6682020-10-31 05:12:53 +000011105 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11106 } finally {
11107 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011108 }
11109 }
zoey chene02881a2019-12-30 16:11:23 +080011110
11111 @Override
11112 public boolean isIccLockEnabled(int subId) {
11113 enforceReadPrivilegedPermission("isIccLockEnabled");
11114
joonhunshin4ac60942023-11-15 15:23:39 +000011115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11117
zoey chene02881a2019-12-30 16:11:23 +080011118 // Now that all security checks passes, perform the operation as ourselves.
11119 final long identity = Binder.clearCallingIdentity();
11120 try {
11121 Phone phone = getPhone(subId);
11122 if (phone != null && phone.getIccCard() != null) {
11123 return phone.getIccCard().getIccLockEnabled();
11124 } else {
11125 return false;
11126 }
11127 } finally {
11128 Binder.restoreCallingIdentity(identity);
11129 }
11130 }
11131
11132 /**
11133 * Set the ICC pin lock enabled or disabled.
11134 *
11135 * @return an integer representing the status of IccLock enabled or disabled in the following
11136 * three cases:
11137 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11138 * successfully.
11139 * - Positive number and zero for remaining password attempts.
11140 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11141 *
11142 */
11143 @Override
11144 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11145 enforceModifyPermission();
11146
joonhunshin4ac60942023-11-15 15:23:39 +000011147 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11148 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11149
zoey chene02881a2019-12-30 16:11:23 +080011150 Phone phone = getPhone(subId);
11151 if (phone == null) {
11152 return 0;
11153 }
11154 // Now that all security checks passes, perform the operation as ourselves.
11155 final long identity = Binder.clearCallingIdentity();
11156 try {
11157 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11158 new Pair<Boolean, String>(enabled, password), phone, null);
11159 return attemptsRemaining;
11160
11161 } catch (Exception e) {
11162 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11163 } finally {
11164 Binder.restoreCallingIdentity(identity);
11165 }
11166 return 0;
11167 }
11168
11169 /**
11170 * Change the ICC password used in ICC pin lock.
11171 *
11172 * @return an integer representing the status of IccLock changed in the following three cases:
11173 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11174 * - Positive number and zero for remaining password attempts.
11175 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11176 *
11177 */
11178 @Override
11179 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11180 enforceModifyPermission();
11181
joonhunshin4ac60942023-11-15 15:23:39 +000011182 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11183 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11184
zoey chene02881a2019-12-30 16:11:23 +080011185 Phone phone = getPhone(subId);
11186 if (phone == null) {
11187 return 0;
11188 }
11189 // Now that all security checks passes, perform the operation as ourselves.
11190 final long identity = Binder.clearCallingIdentity();
11191 try {
11192 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11193 new Pair<String, String>(oldPassword, newPassword), phone, null);
11194 return attemptsRemaining;
11195
11196 } catch (Exception e) {
11197 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11198 } finally {
11199 Binder.restoreCallingIdentity(identity);
11200 }
11201 return 0;
11202 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011203
11204 /**
11205 * Request for receiving user activity notification
11206 */
11207 @Override
11208 public void requestUserActivityNotification() {
11209 if (!mNotifyUserActivity.get()
11210 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11211 mNotifyUserActivity.set(true);
11212 }
11213 }
11214
11215 /**
11216 * Called when userActivity is signalled in the power manager.
11217 * This is safe to call from any thread, with any window manager locks held or not.
11218 */
11219 @Override
11220 public void userActivity() {
11221 // ***************************************
11222 // * Inherited from PhoneWindowManager *
11223 // ***************************************
11224 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11225 // WITH ITS LOCKS HELD.
11226 //
11227 // This code must be VERY careful about the locks
11228 // it acquires.
11229 // In fact, the current code acquires way too many,
11230 // and probably has lurking deadlocks.
11231
11232 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11233 throw new SecurityException("Only the OS may call notifyUserActivity()");
11234 }
11235
11236 if (mNotifyUserActivity.getAndSet(false)) {
11237 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11238 USER_ACTIVITY_NOTIFICATION_DELAY);
11239 }
11240 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011241
11242 @Override
11243 public boolean canConnectTo5GInDsdsMode() {
11244 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11245 }
Jack Yud10cdd42020-09-28 20:28:01 -070011246
11247 @Override
11248 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11249 String callingFeatureId) {
11250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11251 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11252 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11253 }
11254
joonhunshin4ac60942023-11-15 15:23:39 +000011255 enforceTelephonyFeatureWithException(callingPackage,
11256 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11257
Jack Yud10cdd42020-09-28 20:28:01 -070011258 Phone phone = getPhone(subId);
11259 if (phone == null) {
11260 throw new RuntimeException("phone is not available");
11261 }
11262 // Now that all security checks passes, perform the operation as ourselves.
11263 final long identity = Binder.clearCallingIdentity();
11264 try {
11265 return phone.getEquivalentHomePlmns();
11266 } finally {
11267 Binder.restoreCallingIdentity(identity);
11268 }
11269 }
Daniel Bright59e67312020-11-13 11:49:37 -080011270
11271 @Override
11272 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011273 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11275 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11276 "isRadioInterfaceCapabilitySupported");
11277
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011278 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011279 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011280 if (radioInterfaceCapabilities == null) {
11281 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011282 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011283 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011284 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011285
Hui Wang641e81c2020-10-12 12:14:23 -070011286 @Override
11287 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11288 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011289 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11290 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11291 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11292 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11293 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011294
11295 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11296 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11297
Hui Wang641e81c2020-10-12 12:14:23 -070011298 if (DBG) {
11299 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11300 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11301 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11302 }
11303
11304 if (!SubscriptionManager.isValidSubscriptionId(subId)
11305 || appType < TelephonyManager.APPTYPE_UNKNOWN
11306 || appType > TelephonyManager.APPTYPE_ISIM
11307 || nafUrl == null || securityProtocol == null || callback == null) {
11308 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11309 if (callback != null) {
11310 try {
11311 callback.onAuthenticationFailure(
11312 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11313 } catch (RemoteException exception) {
11314 log("Fail to notify onAuthenticationFailure due to " + exception);
11315 }
11316 return;
11317 }
11318 }
11319
11320 final long token = Binder.clearCallingIdentity();
11321 try {
11322 getGbaManager(subId).bootstrapAuthenticationRequest(
11323 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011324 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011325 } finally {
11326 Binder.restoreCallingIdentity(token);
11327 }
11328 }
11329
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011330 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011331 * Attempts to set the radio power state for all phones for thermal reason.
11332 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011333 * requested radio power state will actually be set. See {@link
11334 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11335 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011336 * @param enable {@code true} if trying to turn radio on.
11337 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11338 * false}.
11339 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011340 private boolean setRadioPowerForThermal(boolean enable) {
11341 boolean isPhoneAvailable = false;
11342 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11343 Phone phone = PhoneFactory.getPhone(i);
11344 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011345 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011346 isPhoneAvailable = true;
11347 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011348 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011349
11350 // return true if successfully informed the phone object about the thermal radio power
11351 // request.
11352 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011353 }
11354
11355 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011356 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011357 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11358 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11359 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11360 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11361 throw new IllegalArgumentException("modem does not support data throttling");
11362 }
11363
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11365 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011366 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011367 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11368 }
11369
Sarah Chinecc78c42022-03-31 21:16:48 -070011370 setDataEnabledForReason(
11371 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011372
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011373 if (isDataThrottlingSupported) {
11374 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011375 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011376 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11377 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11378 } else if (thermalMitigationResult
11379 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011380 log("Modem likely does not support data throttling on secondary carrier. Data " +
11381 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11382 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011383 }
11384 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011385 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011386
11387 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011388 }
11389
Jack Nudelman644b91a2021-03-12 14:09:48 -080011390 private static List<String> getThermalMitigationAllowlist(Context context) {
11391 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11392 for (String pckg : context.getResources()
11393 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11394 sThermalMitigationAllowlistedPackages.add(pckg);
11395 }
11396 }
11397
11398 return sThermalMitigationAllowlistedPackages;
11399 }
11400
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011401 private boolean isAnyPhoneInEmergencyState() {
11402 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11403 if (tm.isInEmergencyCall()) {
11404 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11405 return true;
11406 }
11407 for (Phone phone : PhoneFactory.getPhones()) {
11408 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11409 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011410 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11411 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011412 return true;
11413 }
11414 }
11415
11416 return false;
11417 }
11418
Jack Nudelman644b91a2021-03-12 14:09:48 -080011419 /**
11420 * Used by shell commands to add an authorized package name for thermal mitigation.
11421 * @param packageName name of package to be allowlisted
11422 * @param context
11423 */
11424 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11425 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11426 sThermalMitigationAllowlistedPackages.add(packageName);
11427 }
11428
11429 /**
11430 * Used by shell commands to remove an authorized package name for thermal mitigation.
11431 * @param packageName name of package to remove from allowlist
11432 * @param context
11433 */
11434 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11435 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11436 sThermalMitigationAllowlistedPackages.remove(packageName);
11437 }
11438
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011439 /**
11440 * Thermal mitigation request to control functionalities at modem.
11441 *
11442 * @param subId the id of the subscription.
11443 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011444 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011445 *
11446 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11447 */
11448 @Override
11449 @ThermalMitigationResult
11450 public int sendThermalMitigationRequest(
11451 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011452 ThermalMitigationRequest thermalMitigationRequest,
11453 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011454 enforceModifyPermission();
11455
Jack Nudelman644b91a2021-03-12 14:09:48 -080011456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011457
11458 enforceTelephonyFeatureWithException(callingPackage,
11459 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11460
Jack Nudelman644b91a2021-03-12 14:09:48 -080011461 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11462 .contains(callingPackage)) {
11463 throw new SecurityException("Calling package must be configured in the device config. "
11464 + "calling package: " + callingPackage);
11465 }
11466
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11468 final long identity = Binder.clearCallingIdentity();
11469
11470 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11471 try {
11472 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11473 switch (thermalMitigationAction) {
11474 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11475 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011476 handleDataThrottlingRequest(subId,
11477 thermalMitigationRequest.getDataThrottlingRequest(),
11478 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011479 break;
11480 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11481 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11482 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11483 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11484 }
11485
11486 // Ensure that radio is on. If not able to power on due to phone being
11487 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011488 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011489 thermalMitigationResult =
11490 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11491 break;
11492 }
11493
11494 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011495 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011496 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11497 break;
11498 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11499 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11500 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11501 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11502 }
11503
11504 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11505 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011506 Phone phone = getPhone(subId);
11507 if (phone == null) {
11508 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011509 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011510 break;
11511 }
11512
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011513 TelephonyConnectionService service =
11514 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011515 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011516 Log.e(LOG_TAG, "An emergency call is pending");
11517 thermalMitigationResult =
11518 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11519 break;
11520 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011521 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011522 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011523 break;
11524 }
11525 } else {
11526 thermalMitigationResult =
11527 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11528 break;
11529 }
11530
11531 // Turn radio off. If not able to power off due to phone being unavailable,
11532 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011533 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011534 thermalMitigationResult =
11535 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11536 break;
11537 }
11538 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011539 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011540 break;
11541 default:
11542 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11543 + "not exist. Requested action: " + thermalMitigationAction);
11544 }
11545 } catch (IllegalArgumentException e) {
11546 throw e;
11547 } catch (Exception e) {
11548 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11549 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11550 } finally {
11551 Binder.restoreCallingIdentity(identity);
11552 }
11553
11554 if (DBG) {
11555 log("thermalMitigationRequest returning with thermalMitigationResult: "
11556 + thermalMitigationResult);
11557 }
11558
11559 return thermalMitigationResult;
11560 }
Hui Wang641e81c2020-10-12 12:14:23 -070011561
11562 /**
11563 * Set the GbaService Package Name that Telephony will bind to.
11564 *
11565 * @param subId The sim that the GbaService is associated with.
11566 * @param packageName The name of the package to be replaced with.
11567 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11568 */
11569 @Override
11570 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11571 enforceModifyPermission();
11572
11573 final long identity = Binder.clearCallingIdentity();
11574 try {
11575 return getGbaManager(subId).overrideServicePackage(packageName);
11576 } finally {
11577 Binder.restoreCallingIdentity(identity);
11578 }
11579 }
11580
11581 /**
11582 * Return the package name of the currently bound GbaService.
11583 *
11584 * @param subId The sim that the GbaService is associated with.
11585 * @return the package name of the GbaService configuration, null if GBA is not supported.
11586 */
11587 @Override
11588 public String getBoundGbaService(int subId) {
11589 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11590
11591 final long identity = Binder.clearCallingIdentity();
11592 try {
11593 return getGbaManager(subId).getServicePackage();
11594 } finally {
11595 Binder.restoreCallingIdentity(identity);
11596 }
11597 }
11598
11599 /**
11600 * Set the release time for telephony to unbind GbaService.
11601 *
11602 * @param subId The sim that the GbaService is associated with.
11603 * @param interval The release time to unbind GbaService by millisecond.
11604 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11605 */
11606 @Override
11607 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11608 enforceModifyPermission();
11609
11610 final long identity = Binder.clearCallingIdentity();
11611 try {
11612 return getGbaManager(subId).overrideReleaseTime(interval);
11613 } finally {
11614 Binder.restoreCallingIdentity(identity);
11615 }
11616 }
11617
11618 /**
11619 * Return the release time for telephony to unbind GbaService.
11620 *
11621 * @param subId The sim that the GbaService is associated with.
11622 * @return The release time to unbind GbaService by millisecond.
11623 */
11624 @Override
11625 public int getGbaReleaseTime(int subId) {
11626 enforceReadPrivilegedPermission("getGbaReleaseTime");
11627
11628 final long identity = Binder.clearCallingIdentity();
11629 try {
11630 return getGbaManager(subId).getReleaseTime();
11631 } finally {
11632 Binder.restoreCallingIdentity(identity);
11633 }
11634 }
11635
11636 private GbaManager getGbaManager(int subId) {
11637 GbaManager instance = GbaManager.getInstance(subId);
11638 if (instance == null) {
11639 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11640 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11641 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11642 }
11643 return instance;
11644 }
Hui Wang761a6682020-10-31 05:12:53 +000011645
11646 /**
11647 * indicate whether the device and the carrier can support
11648 * RCS VoLTE single registration.
11649 */
11650 @Override
11651 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011652 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11653 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11654 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11655 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011656
11657 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11658 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11659 }
11660
11661 final long identity = Binder.clearCallingIdentity();
11662 try {
11663 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11664 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011665 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11666 if (isCapable != null) {
11667 return isCapable;
11668 }
Hui Wang761a6682020-10-31 05:12:53 +000011669 }
Hui Wang67af90e2021-06-04 16:57:15 -070011670 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11671 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011672 } finally {
11673 Binder.restoreCallingIdentity(identity);
11674 }
11675 }
11676
11677 /**
11678 * Register RCS provisioning callback.
11679 */
11680 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011681 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011682 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011683 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011684 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011685 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11686 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011687
11688 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11689 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11690 }
joonhunshin4ac60942023-11-15 15:23:39 +000011691 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11692 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11693 Binder.getCallingUserHandle())) {
11694 if (!isImsAvailableOnDevice()) {
11695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11696 "IMS not available on device.");
11697 }
11698 } else {
11699 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11700 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011701 }
11702
11703 final long identity = Binder.clearCallingIdentity();
11704 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011705 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011706 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011707 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11708 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011709 }
Hui Wang761a6682020-10-31 05:12:53 +000011710 } finally {
11711 Binder.restoreCallingIdentity(identity);
11712 }
11713 }
11714
11715 /**
11716 * Unregister RCS provisioning callback.
11717 */
11718 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011719 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011720 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011721 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011722 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011723 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11724 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011725
11726 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11727 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11728 }
joonhunshin4ac60942023-11-15 15:23:39 +000011729
11730 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11731 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11732 Binder.getCallingUserHandle())) {
11733 if (!isImsAvailableOnDevice()) {
11734 // operation failed silently
11735 Rlog.w(LOG_TAG, "IMS not available on device.");
11736 return;
11737 }
11738 } else {
11739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11740 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11741 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011742 }
11743
11744 final long identity = Binder.clearCallingIdentity();
11745 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011746 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011747 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011748 } finally {
11749 Binder.restoreCallingIdentity(identity);
11750 }
11751 }
11752
11753 /**
11754 * trigger RCS reconfiguration.
11755 */
11756 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011757 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11758 "triggerRcsReconfiguration",
11759 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011760
11761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11762 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11763 }
joonhunshin4ac60942023-11-15 15:23:39 +000011764 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11765 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11766 Binder.getCallingUserHandle())) {
11767 if (!isImsAvailableOnDevice()) {
11768 // ProvisioningManager can not handle ServiceSpecificException.
11769 // Throw the IllegalStateException and annotate ProvisioningManager.
11770 throw new IllegalStateException("IMS not available on device.");
11771 }
11772 } else {
11773 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11774 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011775 }
11776
11777 final long identity = Binder.clearCallingIdentity();
11778 try {
11779 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11780 } finally {
11781 Binder.restoreCallingIdentity(identity);
11782 }
11783 }
11784
11785 /**
11786 * Provide the client configuration parameters of the RCS application.
11787 */
11788 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011789 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11790 "setRcsClientConfiguration",
11791 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011792
11793 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11794 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11795 }
joonhunshin4ac60942023-11-15 15:23:39 +000011796 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11797 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11798 Binder.getCallingUserHandle())) {
11799 if (!isImsAvailableOnDevice()) {
11800 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11801 "IMS not available on device.");
11802 }
11803 } else {
11804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11805 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011806 }
11807
11808 final long identity = Binder.clearCallingIdentity();
11809
11810 try {
11811 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11812 if (configBinder == null) {
11813 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011814 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11815 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011816 } else {
11817 configBinder.setRcsClientConfiguration(rcc);
11818 }
joonhunshin3e154242021-09-17 06:33:39 +000011819
11820 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11821 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011822 } catch (RemoteException e) {
11823 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011824 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11825 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011826 } finally {
11827 Binder.restoreCallingIdentity(identity);
11828 }
11829 }
11830
11831 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011832 * Enables or disables the test mode for RCS VoLTE single registration.
11833 */
11834 @Override
11835 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11836 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11837 "setRcsSingleRegistrationTestModeEnabled");
11838
11839 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11840 }
11841
11842 /**
11843 * Gets the test mode for RCS VoLTE single registration.
11844 */
11845 @Override
11846 public boolean getRcsSingleRegistrationTestModeEnabled() {
11847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11848 "getRcsSingleRegistrationTestModeEnabled");
11849
11850 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11851 }
11852
11853 /**
Hui Wang761a6682020-10-31 05:12:53 +000011854 * Overrides the config of RCS VoLTE single registration enabled for the device.
11855 */
11856 @Override
11857 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11859 "setDeviceSingleRegistrationEnabledOverride");
11860 enforceModifyPermission();
11861
11862 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11863 : Boolean.parseBoolean(enabledStr);
11864 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011865 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011866 }
11867
11868 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011869 * Sends a device to device communication message. Only usable via shell.
11870 * @param message message to send.
11871 * @param value message value.
11872 */
11873 @Override
11874 public void sendDeviceToDeviceMessage(int message, int value) {
11875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011876 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011877 enforceModifyPermission();
11878
11879 final long identity = Binder.clearCallingIdentity();
11880 try {
11881 TelephonyConnectionService service =
11882 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11883 if (service == null) {
11884 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11885 return;
11886 }
11887 service.sendTestDeviceToDeviceMessage(message, value);
11888 } finally {
11889 Binder.restoreCallingIdentity(identity);
11890 }
11891 }
11892
Tyler Gunnbabbda02021-02-10 11:05:02 -080011893 /**
11894 * Sets the specified device to device transport active.
11895 * @param transport The transport to set active.
11896 */
11897 @Override
11898 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11900 "setActiveDeviceToDeviceTransport");
11901 enforceModifyPermission();
11902
11903 final long identity = Binder.clearCallingIdentity();
11904 try {
11905 TelephonyConnectionService service =
11906 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11907 if (service == null) {
11908 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11909 return;
11910 }
11911 service.setActiveDeviceToDeviceTransport(transport);
11912 } finally {
11913 Binder.restoreCallingIdentity(identity);
11914 }
11915 }
Tyler Gunn92479152021-01-20 16:30:10 -080011916
Tyler Gunnd4339262021-05-03 14:46:49 -070011917 @Override
11918 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11920 "setDeviceToDeviceForceEnabled");
11921
11922 final long identity = Binder.clearCallingIdentity();
11923 try {
11924 Arrays.stream(PhoneFactory.getPhones()).forEach(
11925 p -> {
11926 Phone thePhone = p.getImsPhone();
11927 if (thePhone != null && thePhone instanceof ImsPhone) {
11928 ImsPhone imsPhone = (ImsPhone) thePhone;
11929 CallTracker tracker = imsPhone.getCallTracker();
11930 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11931 ImsPhoneCallTracker imsPhoneCallTracker =
11932 (ImsPhoneCallTracker) tracker;
11933 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11934 }
11935 }
11936 }
11937 );
11938 } finally {
11939 Binder.restoreCallingIdentity(identity);
11940 }
11941 }
11942
Tyler Gunn92479152021-01-20 16:30:10 -080011943 /**
Hui Wang761a6682020-10-31 05:12:53 +000011944 * Gets the config of RCS VoLTE single registration enabled for the device.
11945 */
11946 @Override
11947 public boolean getDeviceSingleRegistrationEnabled() {
11948 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11949 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11950 }
11951
11952 /**
11953 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11954 */
11955 @Override
11956 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11957 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11958 "setCarrierSingleRegistrationEnabledOverride");
11959 enforceModifyPermission();
11960
11961 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11962 : Boolean.parseBoolean(enabledStr);
11963 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11964 subId, enabled);
11965 }
11966
11967 /**
11968 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11969 */
11970 @Override
11971 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11972 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11973 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11974 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011975
11976 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011977 * Overrides the ims feature validation result
11978 */
11979 @Override
11980 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11982 "setImsFeatureValidationOverride");
11983
11984 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11985 : Boolean.parseBoolean(enabledStr);
11986 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11987 subId, enabled);
11988 }
11989
11990 /**
11991 * Gets the ims feature validation override value
11992 */
11993 @Override
11994 public boolean getImsFeatureValidationOverride(int subId) {
11995 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11996 "getImsFeatureValidationOverride");
11997 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11998 }
11999
12000 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012001 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12002 * their mobile plan.
12003 */
12004 @Override
12005 public String getMobileProvisioningUrl() {
12006 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12007 final long identity = Binder.clearCallingIdentity();
12008 try {
12009 return getDefaultPhone().getMobileProvisioningUrl();
12010 } finally {
12011 Binder.restoreCallingIdentity(identity);
12012 }
12013 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012014
James.cf Linbcdf8b32021-01-14 16:44:13 +080012015 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012016 * Get the EAB contact from the EAB database.
12017 */
12018 @Override
12019 public String getContactFromEab(String contact) {
12020 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12021 enforceModifyPermission();
12022 final long identity = Binder.clearCallingIdentity();
12023 try {
12024 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12025 } finally {
12026 Binder.restoreCallingIdentity(identity);
12027 }
12028 }
12029
12030 /**
Calvin Pana1434322021-07-01 19:27:01 +080012031 * Get the EAB capability from the EAB database.
12032 */
12033 @Override
12034 public String getCapabilityFromEab(String contact) {
12035 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12036 enforceModifyPermission();
12037 final long identity = Binder.clearCallingIdentity();
12038 try {
12039 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12040 } finally {
12041 Binder.restoreCallingIdentity(identity);
12042 }
12043 }
12044
12045 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012046 * Remove the EAB contacts from the EAB database.
12047 */
12048 @Override
12049 public int removeContactFromEab(int subId, String contacts) {
12050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12051 enforceModifyPermission();
12052 final long identity = Binder.clearCallingIdentity();
12053 try {
12054 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12055 } finally {
12056 Binder.restoreCallingIdentity(identity);
12057 }
12058 }
12059
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012060 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012061 public boolean getDeviceUceEnabled() {
12062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12063 final long identity = Binder.clearCallingIdentity();
12064 try {
12065 return mApp.getDeviceUceEnabled();
12066 } finally {
12067 Binder.restoreCallingIdentity(identity);
12068 }
12069 }
12070
12071 @Override
12072 public void setDeviceUceEnabled(boolean isEnabled) {
12073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12074 final long identity = Binder.clearCallingIdentity();
12075 try {
12076 mApp.setDeviceUceEnabled(isEnabled);
12077 } finally {
12078 Binder.restoreCallingIdentity(identity);
12079 }
12080 }
12081
Brad Ebinger14d467f2021-02-12 06:18:28 +000012082 /**
12083 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12084 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12085 */
12086 // Used for SHELL command only right now.
12087 @Override
12088 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12089 List<String> featureTags) {
12090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12091 "addUceRegistrationOverrideShell");
12092 final long identity = Binder.clearCallingIdentity();
12093 try {
12094 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12095 new ArraySet<>(featureTags));
12096 } catch (ImsException e) {
12097 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12098 } finally {
12099 Binder.restoreCallingIdentity(identity);
12100 }
12101 }
12102
12103 /**
12104 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12105 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12106 */
12107 // Used for SHELL command only right now.
12108 @Override
12109 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12110 List<String> featureTags) {
12111 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12112 "removeUceRegistrationOverrideShell");
12113 final long identity = Binder.clearCallingIdentity();
12114 try {
12115 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12116 new ArraySet<>(featureTags));
12117 } catch (ImsException e) {
12118 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12119 } finally {
12120 Binder.restoreCallingIdentity(identity);
12121 }
12122 }
12123
12124 /**
12125 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12126 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12127 */
12128 // Used for SHELL command only right now.
12129 @Override
12130 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12132 "clearUceRegistrationOverrideShell");
12133 final long identity = Binder.clearCallingIdentity();
12134 try {
12135 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12136 } catch (ImsException e) {
12137 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12138 } finally {
12139 Binder.restoreCallingIdentity(identity);
12140 }
12141 }
12142
12143 /**
12144 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12145 */
12146 // Used for SHELL command only right now.
12147 @Override
12148 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12149 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12150 "getLatestRcsContactUceCapabilityShell");
12151 final long identity = Binder.clearCallingIdentity();
12152 try {
12153 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12154 } catch (ImsException e) {
12155 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12156 } finally {
12157 Binder.restoreCallingIdentity(identity);
12158 }
12159 }
12160
12161 /**
12162 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12163 * device does not have an active PUBLISH.
12164 */
12165 // Used for SHELL command only right now.
12166 @Override
12167 public String getLastUcePidfXmlShell(int subId) {
12168 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12169 final long identity = Binder.clearCallingIdentity();
12170 try {
12171 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12172 } catch (ImsException e) {
12173 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12174 } finally {
12175 Binder.restoreCallingIdentity(identity);
12176 }
12177 }
12178
James.cf Line8713a42021-04-29 16:04:26 +080012179 /**
12180 * Remove UCE requests cannot be sent to the network status.
12181 */
12182 // Used for SHELL command only right now.
12183 @Override
12184 public boolean removeUceRequestDisallowedStatus(int subId) {
12185 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12186 final long identity = Binder.clearCallingIdentity();
12187 try {
12188 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12189 } catch (ImsException e) {
12190 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12191 } finally {
12192 Binder.restoreCallingIdentity(identity);
12193 }
12194 }
12195
James.cf Lin18bb9002021-05-25 01:37:38 +080012196 /**
12197 * Remove UCE requests cannot be sent to the network status.
12198 */
12199 // Used for SHELL command only.
12200 @Override
12201 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12203 final long identity = Binder.clearCallingIdentity();
12204 try {
12205 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12206 } catch (ImsException e) {
12207 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12208 } finally {
12209 Binder.restoreCallingIdentity(identity);
12210 }
12211 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012212
James.cf Lin4b784aa2021-01-31 03:25:15 +080012213 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012214 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12215 String callingPackage) {
12216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12217 mApp, subId, "setSignalStrengthUpdateRequest");
12218
joonhunshin4ac60942023-11-15 15:23:39 +000012219 enforceTelephonyFeatureWithException(callingPackage,
12220 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12221
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012222 final int callingUid = Binder.getCallingUid();
12223 // Verify that tha callingPackage belongs to the calling UID
12224 mApp.getSystemService(AppOpsManager.class)
12225 .checkPackage(callingUid, callingPackage);
12226
Rambo Wang3607f502021-02-01 21:51:40 -080012227 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012228
12229 final long identity = Binder.clearCallingIdentity();
12230 try {
12231 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12232 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12233
12234 if (result instanceof IllegalStateException) {
12235 throw (IllegalStateException) result;
12236 }
12237 } finally {
12238 Binder.restoreCallingIdentity(identity);
12239 }
12240 }
12241
12242 @Override
12243 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12244 String callingPackage) {
12245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12246 mApp, subId, "clearSignalStrengthUpdateRequest");
12247
joonhunshin4ac60942023-11-15 15:23:39 +000012248 enforceTelephonyFeatureWithException(callingPackage,
12249 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12250
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012251 final int callingUid = Binder.getCallingUid();
12252 // Verify that tha callingPackage belongs to the calling UID
12253 mApp.getSystemService(AppOpsManager.class)
12254 .checkPackage(callingUid, callingPackage);
12255
12256 final long identity = Binder.clearCallingIdentity();
12257 try {
12258 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12259 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12260
12261 if (result instanceof IllegalStateException) {
12262 throw (IllegalStateException) result;
12263 }
12264 } finally {
12265 Binder.restoreCallingIdentity(identity);
12266 }
12267 }
12268
Rambo Wang3607f502021-02-01 21:51:40 -080012269 private static void validateSignalStrengthUpdateRequest(Context context,
12270 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012271 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12272 // phone/system process do not have further restriction on request
12273 return;
12274 }
12275
12276 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012277 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012278 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012279 context.enforceCallingOrSelfPermission(
12280 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12281 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012282 }
12283
12284 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012285 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012286 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012287 || info.isEnabled()) {
12288 throw new IllegalArgumentException(
12289 "Only system can set hide fields in SignalThresholdInfo");
12290 }
12291
12292 // Thresholds length for each RAN need in range. This has been validated in
12293 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12294 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12295 final int[] thresholds = info.getThresholds();
12296 Objects.requireNonNull(thresholds);
12297 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12298 || thresholds.length
12299 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12300 throw new IllegalArgumentException(
12301 "thresholds length is out of range: " + thresholds.length);
12302 }
12303 }
12304 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012305
12306 /**
12307 * Gets the current phone capability.
12308 *
12309 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12310 * @return the PhoneCapability which describes the data connection capability of modem.
12311 * It's used to evaluate possible phone config change, for example from single
12312 * SIM device to multi-SIM device.
12313 */
12314 @Override
12315 public PhoneCapability getPhoneCapability() {
12316 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012317
12318 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12319 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12320
SongFerngWang8236caa2021-01-17 21:51:44 +080012321 final long identity = Binder.clearCallingIdentity();
12322 try {
12323 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12324 } finally {
12325 Binder.restoreCallingIdentity(identity);
12326 }
12327 }
Michele Berionne5e411512020-11-13 02:36:59 +000012328
12329 /**
12330 * Prepare TelephonyManager for an unattended reboot. The reboot is
12331 * required to be done shortly after the API is invoked.
12332 */
12333 @Override
12334 @TelephonyManager.PrepareUnattendedRebootResult
12335 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012337 enforceRebootPermission();
12338
joonhunshin4ac60942023-11-15 15:23:39 +000012339 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12340 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12341
Michele Berionne5e411512020-11-13 02:36:59 +000012342 final long identity = Binder.clearCallingIdentity();
12343 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012344 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012345 } finally {
12346 Binder.restoreCallingIdentity(identity);
12347 }
12348 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012349
12350 /**
12351 * Request to get the current slicing configuration including URSP rules and
12352 * NSSAIs (configured, allowed and rejected).
12353 *
12354 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12355 */
12356 @Override
12357 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012358 TelephonyPermissions
12359 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12360 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012361
joonhunshin4ac60942023-11-15 15:23:39 +000012362 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12363 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12364 "getSlicingConfig");
12365
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012366 final long identity = Binder.clearCallingIdentity();
12367 try {
12368 Phone phone = getDefaultPhone();
12369 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12370 } finally {
12371 Binder.restoreCallingIdentity(identity);
12372 }
12373 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012374
12375 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012376 * Check whether the given premium capability is available for purchase from the carrier.
12377 *
12378 * @param capability The premium capability to check.
12379 * @param subId The subId to check the premium capability for.
12380 *
12381 * @return Whether the given premium capability is available to purchase.
12382 */
12383 @Override
12384 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12385 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12386 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12387 log("Premium capability "
12388 + TelephonyManager.convertPremiumCapabilityToString(capability)
12389 + " is not available for purchase due to missing permissions.");
12390 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12391 + "permission READ_BASIC_PHONE_STATE.");
12392 }
12393
joonhunshin4ac60942023-11-15 15:23:39 +000012394 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12395 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12396
Sarah Chin2ec39f62022-08-31 17:03:26 -070012397 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012398 if (phone == null) {
12399 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12400 return false;
12401 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012402 final long identity = Binder.clearCallingIdentity();
12403 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012404 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012405 .isPremiumCapabilityAvailableForPurchase(capability);
12406 } finally {
12407 Binder.restoreCallingIdentity(identity);
12408 }
12409 }
12410
12411 /**
12412 * Purchase the given premium capability from the carrier.
12413 *
12414 * @param capability The premium capability to purchase.
12415 * @param callback The result of the purchase request.
12416 * @param subId The subId to purchase the premium capability for.
12417 */
12418 @Override
12419 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12420 log("purchasePremiumCapability: capability="
12421 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12422 + getCurrentPackageName());
12423
12424 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12425 mApp, "purchasePremiumCapability")) {
12426 log("purchasePremiumCapability "
12427 + TelephonyManager.convertPremiumCapabilityToString(capability)
12428 + " failed due to missing permissions.");
12429 throw new SecurityException("purchasePremiumCapability requires permission "
12430 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012431 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12432 mApp, "purchasePremiumCapability")) {
12433 log("purchasePremiumCapability "
12434 + TelephonyManager.convertPremiumCapabilityToString(capability)
12435 + " failed due to missing permissions.");
12436 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012437 }
12438
joonhunshin4ac60942023-11-15 15:23:39 +000012439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12440 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12441
Sarah Chin2ec39f62022-08-31 17:03:26 -070012442 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012443 if (phone == null) {
12444 try {
12445 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12446 callback.accept(result);
12447 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12448 } catch (RemoteException e) {
12449 String logStr = "Purchase premium capability "
12450 + TelephonyManager.convertPremiumCapabilityToString(capability)
12451 + " failed due to RemoteException handling null phone: " + e;
12452 if (DBG) log(logStr);
12453 AnomalyReporter.reportAnomaly(
12454 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12455 }
12456 return;
12457 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012458
12459 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012460 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012461 callingProcess = mApp.getPackageManager().getApplicationInfo(
12462 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012463 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012464 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012465 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012466
12467 boolean isVisible = false;
12468 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12469 if (am != null) {
12470 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12471 if (processes != null) {
12472 for (ActivityManager.RunningAppProcessInfo process : processes) {
12473 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012474 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012475 if (process.processName.equals(callingProcess) && process.importance
12476 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12477 isVisible = true;
12478 break;
12479 }
12480 }
12481 }
12482 }
12483
12484 if (!isVisible) {
12485 try {
12486 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12487 callback.accept(result);
12488 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12489 } catch (RemoteException e) {
12490 String logStr = "Purchase premium capability "
12491 + TelephonyManager.convertPremiumCapabilityToString(capability)
12492 + " failed due to RemoteException handling background application: " + e;
12493 if (DBG) log(logStr);
12494 AnomalyReporter.reportAnomaly(
12495 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12496 }
12497 return;
12498 }
12499
Sarah Chin71b3a852022-09-28 15:54:19 -070012500 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012501 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012502 }
12503
12504 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012505 * Register an IMS connection state callback
12506 */
12507 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012508 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12509 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012510 if (feature == ImsFeature.FEATURE_MMTEL) {
12511 // ImsMmTelManager
12512 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12513 TelephonyPermissions
12514 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12515 mApp, subId, "registerImsStateCallback");
12516 } else if (feature == ImsFeature.FEATURE_RCS) {
12517 // ImsRcsManager or SipDelegateManager
12518 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12519 Binder.getCallingUid(), "registerImsStateCallback",
12520 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12521 Manifest.permission.READ_PRECISE_PHONE_STATE,
12522 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12523 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12524 }
12525
12526 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12527 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12528 "IMS not available on device.");
12529 }
12530
12531 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12532 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12533 }
12534
12535 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12536 if (controller == null) {
12537 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12538 "IMS not available on device.");
12539 }
12540
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012541 if (callingPackage == null) {
12542 callingPackage = getCurrentPackageName();
12543 }
12544
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012545 final long token = Binder.clearCallingIdentity();
12546 try {
12547 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012548 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012549 } catch (ImsException e) {
12550 throw new ServiceSpecificException(e.getCode());
12551 } finally {
12552 Binder.restoreCallingIdentity(token);
12553 }
12554 }
12555
12556 /**
12557 * Unregister an IMS connection state callback
12558 */
12559 @Override
12560 public void unregisterImsStateCallback(IImsStateCallback cb) {
12561 final long token = Binder.clearCallingIdentity();
12562 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12563 if (controller == null) {
12564 return;
12565 }
12566 try {
12567 controller.unregisterImsStateCallback(cb);
12568 } finally {
12569 Binder.restoreCallingIdentity(token);
12570 }
12571 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012572
12573 /**
12574 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12575 *
12576 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012577 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012578 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012579 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012580 * If there is current registered network this value will be same as the registered cell
12581 * identity. If the device goes out of service the previous cell identity is cached and
12582 * will be returned. If the cache age of the Cell identity is more than 24 hours
12583 * it will be cleared and null will be returned.
12584 *
12585 */
12586 @Override
12587 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12588 String callingFeatureId) {
12589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12590 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12591 LocationAccessPolicy.checkLocationPermission(mApp,
12592 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12593 .setCallingPackage(callingPackage)
12594 .setCallingFeatureId(callingFeatureId)
12595 .setCallingPid(Binder.getCallingPid())
12596 .setCallingUid(Binder.getCallingUid())
12597 .setMethod("getLastKnownCellIdentity")
12598 .setLogAsInfo(true)
12599 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12600 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12601 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12602 .build());
12603
12604 boolean hasFinePermission =
12605 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12606 if (!hasFinePermission
12607 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12608 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012609 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012610 }
12611
12612 final long identity = Binder.clearCallingIdentity();
12613 try {
Ling Mac28f0212023-03-24 16:07:15 -070012614 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012615 if (sst == null) return null;
12616 return sst.getLastKnownCellIdentity();
12617 } finally {
12618 Binder.restoreCallingIdentity(identity);
12619 }
12620 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012621
jimsun3b9ccac2021-10-26 15:01:23 +080012622 /**
12623 * Sets the modem service class Name that Telephony will bind to.
12624 *
12625 * @param serviceName The class name of the modem service.
12626 * @return true if the operation is succeed, otherwise false.
12627 */
12628 public boolean setModemService(String serviceName) {
12629 Log.d(LOG_TAG, "setModemService - " + serviceName);
12630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012632 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12633 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012634 return mPhoneConfigurationManager.setModemService(serviceName);
12635 }
12636
12637 /**
12638 * Return the class name of the currently bounded modem service.
12639 *
12640 * @return the class name of the modem service.
12641 */
12642 public String getModemService() {
12643 String result;
12644 Log.d(LOG_TAG, "getModemService");
12645 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12646 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012648 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12649 "getModemService");
12650 result = mPhoneConfigurationManager.getModemService();
12651 Log.d(LOG_TAG, "result = " + result);
12652 return result;
12653 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012654
Hakjun Choi3ee81112023-12-19 15:40:58 +000012655 /**
12656 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12657 * including carrier config, entitlement server, and config update.
12658 *
12659 * @param subId subId The subscription ID of the carrier.
12660 *
12661 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12662 * be returned.
12663 *
12664 * @throws SecurityException if the caller doesn't have the required permission.
12665 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012666 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12667 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012668 final long identity = Binder.clearCallingIdentity();
12669 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012670 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012671 } finally {
12672 Binder.restoreCallingIdentity(identity);
12673 }
12674 }
12675
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012676 @Override
12677 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12678 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12679 mApp.enforceCallingOrSelfPermission(
12680 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12682
12683 final long identity = Binder.clearCallingIdentity();
12684 try {
12685 Phone phone = getPhone(subId);
12686 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012687 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12688 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012689 phone.setVoiceServiceStateOverride(hasService);
12690 } finally {
12691 Binder.restoreCallingIdentity(identity);
12692 }
12693 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012694
12695 /**
12696 * set removable eSIM as default eUICC.
12697 *
12698 * @hide
12699 */
12700 @Override
12701 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12702 enforceModifyPermission();
12703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12704
12705 final long identity = Binder.clearCallingIdentity();
12706 try {
12707 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12708 } finally {
12709 Binder.restoreCallingIdentity(identity);
12710 }
12711 }
12712
12713 /**
12714 * Returns whether the removable eSIM is default eUICC or not.
12715 *
12716 * @hide
12717 */
12718 @Override
12719 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12720 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12722
12723 final long identity = Binder.clearCallingIdentity();
12724 try {
12725 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12726 } finally {
12727 Binder.restoreCallingIdentity(identity);
12728 }
12729 }
12730
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012731 /**
12732 * Get the component name of the default app to direct respond-via-message intent for the
12733 * user associated with this subscription, update the cache if there is no respond-via-message
12734 * application currently configured for this user.
12735 * @return component name of the app and class to direct Respond Via Message intent to, or
12736 * {@code null} if the functionality is not supported.
12737 * @hide
12738 */
12739 @Override
12740 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12741 boolean updateIfNeeded) {
12742 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012743
joonhunshin4ac60942023-11-15 15:23:39 +000012744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12745 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12746 "getDefaultRespondViaMessageApplication");
12747
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012748 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12749
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012750 UserHandle userHandle = null;
12751 final long identity = Binder.clearCallingIdentity();
12752 try {
12753 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12754 } finally {
12755 Binder.restoreCallingIdentity(identity);
12756 }
12757 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12758 updateIfNeeded, userHandle);
12759 }
Jack Yuf5badd92022-12-08 00:50:53 -080012760
12761 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012762 * Set whether the device is able to connect with null ciphering or integrity
12763 * algorithms. This is a global setting and will apply to all active subscriptions
12764 * and all new subscriptions after this.
12765 *
12766 * @param enabled when true, null cipher and integrity algorithms are allowed.
12767 * @hide
12768 */
12769 @Override
12770 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12771 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12772 enforceModifyPermission();
12773 checkForNullCipherAndIntegritySupport();
12774
12775 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12776 // for listening to these preference changes and applying them immediately.
12777 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12778 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12779 editor.apply();
12780
12781 for (Phone phone: PhoneFactory.getPhones()) {
12782 phone.handleNullCipherEnabledChange();
12783 }
12784 }
12785
12786
12787 /**
12788 * Get whether the device is able to connect with null ciphering or integrity
12789 * algorithms. Note that this retrieves the phone-global preference and not
12790 * the state of the radio.
12791 *
12792 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12793 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12794 * version for this feature.
12795 * @hide
12796 */
12797 @Override
12798 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12799 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12800 enforceReadPermission();
12801 checkForNullCipherAndIntegritySupport();
12802 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12803 }
12804
12805 private void checkForNullCipherAndIntegritySupport() {
12806 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12807 throw new UnsupportedOperationException(
12808 "Null cipher and integrity operations require HAL 2.1 or above");
12809 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012810 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12811 throw new UnsupportedOperationException(
12812 "Null cipher and integrity operations unsupported by modem");
12813 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012814 }
12815
Gil Cukierman06403e12023-11-29 16:33:03 +000012816 private void checkForIdentifierDisclosureNotificationSupport() {
12817 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12818 throw new UnsupportedOperationException(
12819 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12820 + "above");
12821 }
12822 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12823 throw new UnsupportedOperationException(
12824 "Cellular identifier disclosure transparency operations unsupported by modem");
12825 }
12826 }
12827
Michael Groover826b71d2023-12-21 22:08:06 -060012828 private void checkForNullCipherNotificationSupport() {
12829 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12830 throw new UnsupportedOperationException(
12831 "Null cipher notification operations require HAL 2.2 or above");
12832 }
12833 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12834 throw new UnsupportedOperationException(
12835 "Null cipher notification operations unsupported by modem");
12836 }
12837 }
12838
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012839 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012840 * Get the SIM state for the slot index.
12841 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12842 *
12843 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12844 */
12845 @Override
12846 @SimState
12847 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012848 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12849 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12850
Jack Yuf5badd92022-12-08 00:50:53 -080012851 IccCardConstants.State simState;
12852 if (slotIndex < 0) {
12853 simState = IccCardConstants.State.UNKNOWN;
12854 } else {
12855 Phone phone = null;
12856 try {
12857 phone = PhoneFactory.getPhone(slotIndex);
12858 } catch (IllegalStateException e) {
12859 // ignore
12860 }
12861 if (phone == null) {
12862 simState = IccCardConstants.State.UNKNOWN;
12863 } else {
12864 IccCard icc = phone.getIccCard();
12865 if (icc == null) {
12866 simState = IccCardConstants.State.UNKNOWN;
12867 } else {
12868 simState = icc.getState();
12869 }
12870 }
12871 }
12872 return simState.ordinal();
12873 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012874
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012875 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12876 boolean enableLogcat,
12877 long logcatStartTimestampMillis, boolean enableTelecomDump,
12878 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012879 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012880 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12881 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12882 ecdDataBuilder
12883 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12884 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012885 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012886 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012887 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012888 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12889 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012890 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12891 Executors.newCachedThreadPool(), db,
12892 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012893 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012894 }
12895
12896 /**
12897 * Request telephony to persist state for debugging emergency call failures.
12898 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012899 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012900 * @param enableLogcat whether to collect logcat output
12901 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12902 * @param enableTelecomDump whether to collect telecom dumpsys
12903 * @param enableTelephonyDump whether to collect telephony dumpsys
12904 */
12905 @Override
12906 @RequiresPermission(android.Manifest.permission.DUMP)
12907 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12908 long logcatStartTimestampMillis, boolean enableTelecomDump,
12909 boolean enableTelephonyDump) {
12910 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12911 "persistEmergencyCallDiagnosticData");
12912 final long identity = Binder.clearCallingIdentity();
12913 try {
12914 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12915 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12916
12917 } finally {
12918 Binder.restoreCallingIdentity(identity);
12919 }
12920 }
12921
Hui Wang9b5793a2022-12-05 14:38:06 -060012922 /**
12923 * Get current cell broadcast ranges.
12924 */
12925 @Override
12926 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12927 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12928 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12929 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012930
12931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12932 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12933
Hui Wang9b5793a2022-12-05 14:38:06 -060012934 final long identity = Binder.clearCallingIdentity();
12935 try {
12936 return getPhone(subId).getCellBroadcastIdRanges();
12937 } finally {
12938 Binder.restoreCallingIdentity(identity);
12939 }
12940 }
12941
12942 /**
12943 * Set reception of cell broadcast messages with the list of the given ranges
12944 *
12945 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12946 */
12947 @Override
12948 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12949 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12950 @Nullable IIntegerConsumer callback) {
12951 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12952 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012953
12954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12955 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12956
Hui Wang9b5793a2022-12-05 14:38:06 -060012957 final long identity = Binder.clearCallingIdentity();
12958 try {
12959 Phone phone = getPhoneFromSubId(subId);
12960 if (DBG) {
12961 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12962 }
12963 phone.setCellBroadcastIdRanges(ranges, result -> {
12964 if (callback != null) {
12965 try {
12966 callback.accept(result);
12967 } catch (RemoteException e) {
12968 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12969 }
12970 }
12971 });
12972 } finally {
12973 Binder.restoreCallingIdentity(identity);
12974 }
12975 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012976
12977 /**
12978 * Returns whether the device supports the domain selection service.
12979 *
12980 * @return {@code true} if the device supports the domain selection service.
12981 */
12982 @Override
12983 public boolean isDomainSelectionSupported() {
12984 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12985 "isDomainSelectionSupported");
12986
12987 final long identity = Binder.clearCallingIdentity();
12988 try {
12989 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12990 } finally {
12991 Binder.restoreCallingIdentity(identity);
12992 }
12993 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012994
12995 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012996 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12997 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12998 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012999 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013000 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013001 * @param enableSatellite {@code true} to enable the satellite modem and
13002 * {@code false} to disable.
13003 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013004 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013005 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013006 *
13007 * @throws SecurityException if the caller doesn't have the required permission.
13008 */
13009 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013010 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013011 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013012 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013013 if (enableSatellite) {
13014 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13015 @Override
13016 protected void onReceiveResult(int resultCode, Bundle resultData) {
13017 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13018 + ", resultData=" + resultData);
13019 boolean isAllowed = false;
13020 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13021 callback::accept);
13022 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13023 if (resultData != null
13024 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13025 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13026 } else {
13027 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13028 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013029 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013030 result.accept(resultCode);
13031 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013032 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013033 if (isAllowed) {
13034 mSatelliteController.requestSatelliteEnabled(
13035 subId, enableSatellite, enableDemoMode, callback);
13036 } else {
13037 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13038 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013039 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013040 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013041 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013042 subId, resultReceiver);
13043 } else {
13044 // No need to check if satellite is allowed at current location when disabling satellite
13045 mSatelliteController.requestSatelliteEnabled(
13046 subId, enableSatellite, enableDemoMode, callback);
13047 }
Sarah Chin503828c2023-02-01 23:54:20 -080013048 }
13049
13050 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013051 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013052 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013053 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013054 * @param result The result receiver that returns whether the satellite modem is enabled
13055 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013056 *
13057 * @throws SecurityException if the caller doesn't have the required permission.
13058 */
13059 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013060 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13061 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013062 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013063 }
13064
13065 /**
Sarah Chin43457982023-02-15 17:50:38 -080013066 * Request to get whether the satellite service demo mode is enabled.
13067 *
13068 * @param subId The subId of the subscription to check whether the satellite demo mode
13069 * is enabled for.
13070 * @param result The result receiver that returns whether the satellite demo mode is enabled
13071 * if the request is successful or an error code if the request failed.
13072 *
13073 * @throws SecurityException if the caller doesn't have the required permission.
13074 */
13075 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013076 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13077 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13078 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013079 }
13080
13081 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013082 * Request to get whether the satellite service is enabled with emergency mode.
13083 *
13084 * @param subId The subId of the subscription to check whether the satellite demo mode
13085 * is enabled for.
13086 * @param result The result receiver that returns whether the satellite emergency mode is
13087 * enabled if the request is successful or an error code if the request failed.
13088 *
13089 * @throws SecurityException if the caller doesn't have the required permission.
13090 */
13091 @Override
13092 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13093 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13094 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13095 }
13096
13097 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013098 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013099 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013100 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013101 * @param result The result receiver that returns whether the satellite service is supported on
13102 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013103 */
13104 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013105 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013106 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013107 }
13108
13109 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013110 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013111 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013112 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013113 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13114 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013115 *
13116 * @throws SecurityException if the caller doesn't have required permission.
13117 */
13118 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013119 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13120 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013121 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013122 }
13123
13124 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013125 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013126 * This can be called by the pointing UI when the user starts pointing to the satellite.
13127 * Modem should continue to report the pointing input as the device or satellite moves.
13128 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013129 * @param subId The subId of the subscription to start satellite transmission updates for.
13130 * @param resultCallback The callback to get the result of the request.
13131 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013132 *
13133 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013134 */
13135 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013136 public void startSatelliteTransmissionUpdates(int subId,
13137 @NonNull IIntegerConsumer resultCallback,
13138 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13139 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13140 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013141 }
13142
13143 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013144 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013145 * This can be called by the pointing UI when the user stops pointing to the satellite.
13146 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013147 * @param subId The subId of the subscription to stop satellite transmission updates for.
13148 * @param resultCallback The callback to get the result of the request.
13149 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13150 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013151 *
13152 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013153 */
13154 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013155 public void stopSatelliteTransmissionUpdates(int subId,
13156 @NonNull IIntegerConsumer resultCallback,
13157 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13158 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13159 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013160 }
13161
13162 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013163 * Register the subscription with a satellite provider.
13164 * This is needed to register the subscription if the provider allows dynamic registration.
13165 *
13166 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013167 * @param token The token to be used as a unique identifier for provisioning with satellite
13168 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013169 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013170 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013171 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013172 * @return The signal transport used by the caller to cancel the provision request,
13173 * or {@code null} if the request failed.
13174 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013175 * @throws SecurityException if the caller doesn't have the required permission.
13176 */
13177 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013178 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013179 @NonNull String token, @NonNull byte[] provisionData,
13180 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013181 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013182 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13183 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013184 }
13185
13186 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013187 * Unregister the device/subscription with the satellite provider.
13188 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013189 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013190 * should report as deprovisioned.
13191 *
13192 * @param subId The subId of the subscription to be deprovisioned.
13193 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013194 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013195 *
13196 * @throws SecurityException if the caller doesn't have the required permission.
13197 */
13198 @Override
13199 public void deprovisionSatelliteService(int subId,
13200 @NonNull String token, @NonNull IIntegerConsumer callback) {
13201 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013202 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013203 }
13204
13205 /**
Sarah Chin43457982023-02-15 17:50:38 -080013206 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013207 *
Sarah Chin43457982023-02-15 17:50:38 -080013208 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013209 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013210 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013211 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013212 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013213 * @throws SecurityException if the caller doesn't have the required permission.
13214 */
13215 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013216 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13217 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013218 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013219 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013220 }
13221
13222 /**
Sarah Chin43457982023-02-15 17:50:38 -080013223 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013224 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013225 *
Sarah Chin43457982023-02-15 17:50:38 -080013226 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013227 * @param callback The callback that was passed to
13228 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013229 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013230 * @throws SecurityException if the caller doesn't have the required permission.
13231 */
13232 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013233 public void unregisterForSatelliteProvisionStateChanged(
13234 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013235 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013236 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013237 }
13238
13239 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013240 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013241 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013242 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013243 * @param result The result receiver that returns whether the device is provisioned with a
13244 * satellite provider if the request is successful or an error code if the
13245 * request failed.
13246 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013247 * @throws SecurityException if the caller doesn't have the required permission.
13248 */
13249 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013250 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13251 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013252 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013253 }
13254
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013255 /**
Sarah Chin43457982023-02-15 17:50:38 -080013256 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013257 *
Sarah Chin43457982023-02-15 17:50:38 -080013258 * @param subId The subId of the subscription to register for satellite modem state changed.
13259 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013260 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013261 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013262 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013263 * @throws SecurityException if the caller doesn't have the required permission.
13264 */
13265 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013266 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013267 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013268 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013269 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013270 }
13271
13272 /**
Sarah Chin43457982023-02-15 17:50:38 -080013273 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013274 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013275 *
Sarah Chin43457982023-02-15 17:50:38 -080013276 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013277 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013278 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013279 *
13280 * @throws SecurityException if the caller doesn't have the required permission.
13281 */
13282 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013283 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013284 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013285 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13286 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013287 }
13288
13289 /**
13290 * Register to receive incoming datagrams over satellite.
13291 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013292 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013293 * @param callback The callback to handle incoming datagrams over satellite.
13294 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013295 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013296 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013297 * @throws SecurityException if the caller doesn't have the required permission.
13298 */
13299 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013300 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013301 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013302 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13303 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013304 }
13305
13306 /**
13307 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013308 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013309 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013310 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13311 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013312 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013313 *
13314 * @throws SecurityException if the caller doesn't have the required permission.
13315 */
13316 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013317 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013318 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013319 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13320 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013321 }
13322
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013323 /**
13324 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013325 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013326 * This method requests modem to check if there are any pending datagrams to be received over
13327 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013328 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013329 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013330 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013331 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013332 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013333 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013334 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013335 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13336 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13337 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013338 }
13339
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013340 /**
13341 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013342 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013343 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13344 * input to this method. Datagram received here will be passed down to modem without any
13345 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013346 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013347 * @param subId The subId of the subscription to send satellite datagrams for.
13348 * @param datagramType datagram type indicating whether the datagram is of type
13349 * SOS_SMS or LOCATION_SHARING.
13350 * @param datagram encoded gateway datagram which is encrypted by the caller.
13351 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013352 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13353 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013354 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013355 *
13356 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013357 */
13358 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013359 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013360 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13361 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013362 enforceSatelliteCommunicationPermission("sendDatagram");
13363 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13364 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013365 }
13366
Sarah Chindf715ec2023-02-13 13:46:24 -080013367 /**
13368 * Request to get whether satellite communication is allowed for the current location.
13369 *
13370 * @param subId The subId of the subscription to check whether satellite communication is
13371 * allowed for the current location for.
13372 * @param result The result receiver that returns whether satellite communication is allowed
13373 * for the current location if the request is successful or an error code
13374 * if the request failed.
13375 *
13376 * @throws SecurityException if the caller doesn't have the required permission.
13377 */
13378 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013379 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013380 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013381 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13382 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13383 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013384 }
13385
13386 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013387 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013388 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013389 * @param subId The subId to get the time after which the satellite will be visible for.
13390 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013391 * be visible if the request is successful or an error code if the request failed.
13392 *
13393 * @throws SecurityException if the caller doesn't have the required permission.
13394 */
13395 @Override
13396 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13397 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013398 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013399 }
13400
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013401 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013402 * Inform that Device is aligned to satellite for demo mode.
13403 *
13404 * @param subId The subId to get the time after which the satellite will be visible for.
13405 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13406 * {@code false} Device fails to align with the satellite for demo mode.
13407 *
13408 * @throws SecurityException if the caller doesn't have required permission.
13409 */
13410 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13411
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013412 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013413 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013414 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013415 }
13416
13417 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013418 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13419 * by modem.
13420 *
13421 * @param subId The subId of the subscription to request for.
13422 * @param reason Reason for disallowing satellite communication for carrier.
13423 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13424 * operation.
13425 *
13426 * @throws SecurityException if the caller doesn't have required permission.
13427 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013428 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013429 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13430 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013431 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013432 final long identity = Binder.clearCallingIdentity();
13433 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013434 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013435 } finally {
13436 Binder.restoreCallingIdentity(identity);
13437 }
13438 }
13439
13440 /**
13441 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13442 * by modem.
13443 *
13444 * @param subId The subId of the subscription to request for.
13445 * @param reason Reason for disallowing satellite communication.
13446 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13447 * operation.
13448 *
13449 * @throws SecurityException if the caller doesn't have required permission.
13450 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013451 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013452 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13453 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013454 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013455 final long identity = Binder.clearCallingIdentity();
13456 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013457 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013458 } finally {
13459 Binder.restoreCallingIdentity(identity);
13460 }
13461 }
13462
13463 /**
13464 * Get reasons for disallowing satellite communication, as requested by
13465 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13466 *
13467 * @param subId The subId of the subscription to request for.
13468 *
13469 * @return Integer array of reasons for disallowing satellite communication.
13470 *
13471 * @throws SecurityException if the caller doesn't have the required permission.
13472 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013473 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013474 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013475 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013476 final long identity = Binder.clearCallingIdentity();
13477 try {
13478 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013479 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013480 return reasonSet.stream().mapToInt(i->i).toArray();
13481 } finally {
13482 Binder.restoreCallingIdentity(identity);
13483 }
13484 }
13485
13486 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013487 * Request to get the signal strength of the satellite connection.
13488 *
13489 * @param subId The subId of the subscription to request for.
13490 * @param result Result receiver to get the error code of the request and the current signal
13491 * strength of the satellite connection.
13492 *
13493 * @throws SecurityException if the caller doesn't have required permission.
13494 */
13495 @Override
13496 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13497 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13498 final long identity = Binder.clearCallingIdentity();
13499 try {
13500 mSatelliteController.requestNtnSignalStrength(subId, result);
13501 } finally {
13502 Binder.restoreCallingIdentity(identity);
13503 }
13504 }
13505
13506 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013507 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13508 * is not successful, a {@link ServiceSpecificException} that contains
13509 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013510 *
13511 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013512 * @param callback The callback to handle the NTN signal strength changed event. If the
13513 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13514 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13515 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13516 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013517 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013518 * @throws SecurityException If the caller doesn't have the required permission.
13519 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013520 */
13521 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013522 public void registerForNtnSignalStrengthChanged(int subId,
13523 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013524 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13525 final long identity = Binder.clearCallingIdentity();
13526 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013527 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013528 } finally {
13529 Binder.restoreCallingIdentity(identity);
13530 }
13531 }
13532
13533 /**
13534 * Unregisters for NTN signal strength changed from satellite modem.
13535 * If callback was not registered before, the request will be ignored.
13536 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013537 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13538 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013539 * @param callback The callback that was passed to
13540 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13541 *
13542 * @throws SecurityException if the caller doesn't have the required permission.
13543 */
13544 @Override
13545 public void unregisterForNtnSignalStrengthChanged(
13546 int subId, @NonNull INtnSignalStrengthCallback callback) {
13547 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13548 final long identity = Binder.clearCallingIdentity();
13549 try {
13550 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13551 } finally {
13552 Binder.restoreCallingIdentity(identity);
13553 }
13554 }
13555
13556 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013557 * Registers for satellite capabilities change event from the satellite service.
13558 *
13559 * @param subId The subId of the subscription to request for.
13560 * @param callback The callback to handle the satellite capabilities changed event.
13561 *
13562 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13563 *
13564 * @throws SecurityException if the caller doesn't have required permission.
13565 */
13566 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013567 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013568 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013569 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013570 final long identity = Binder.clearCallingIdentity();
13571 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013572 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013573 } finally {
13574 Binder.restoreCallingIdentity(identity);
13575 }
13576 }
13577
13578 /**
13579 * Unregisters for satellite capabilities change event from the satellite service.
13580 * If callback was not registered before, the request will be ignored.
13581 *
13582 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13583 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013584 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013585 *
13586 * @throws SecurityException if the caller doesn't have required permission.
13587 */
13588 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013589 public void unregisterForCapabilitiesChanged(int subId,
13590 @NonNull ISatelliteCapabilitiesCallback callback) {
13591 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013592 final long identity = Binder.clearCallingIdentity();
13593 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013594 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013595 } finally {
13596 Binder.restoreCallingIdentity(identity);
13597 }
13598 }
13599
13600 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013601 * This API can be used by only CTS to update satellite vendor service package name.
13602 *
13603 * @param servicePackageName The package name of the satellite vendor service.
13604 * @return {@code true} if the satellite vendor service is set successfully,
13605 * {@code false} otherwise.
13606 */
13607 public boolean setSatelliteServicePackageName(String servicePackageName) {
13608 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13609 TelephonyPermissions.enforceShellOnly(
13610 Binder.getCallingUid(), "setSatelliteServicePackageName");
13611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13612 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13613 "setSatelliteServicePackageName");
13614 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13615 }
13616
13617 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013618 * This API can be used by only CTS to update satellite gateway service package name.
13619 *
13620 * @param servicePackageName The package name of the satellite gateway service.
13621 * @return {@code true} if the satellite gateway service is set successfully,
13622 * {@code false} otherwise.
13623 */
13624 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13625 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13626 TelephonyPermissions.enforceShellOnly(
13627 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13629 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13630 "setSatelliteGatewayServicePackageName");
13631 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13632 }
13633
13634 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013635 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13636 *
13637 * @param packageName The package name of the satellite pointing UI app.
13638 * @param className The class name of the satellite pointing UI app.
13639 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13640 * {@code false} otherwise.
13641 */
13642 public boolean setSatellitePointingUiClassName(
13643 @Nullable String packageName, @Nullable String className) {
13644 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13645 + ", className=" + className);
13646 TelephonyPermissions.enforceShellOnly(
13647 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13649 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13650 "setSatelliteGatewayServicePackageName");
13651 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13652 }
13653
13654 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013655 * This API can be used by only CTS to update the timeout duration in milliseconds that
13656 * satellite should stay at listening mode to wait for the next incoming page before disabling
13657 * listening mode.
13658 *
13659 * @param timeoutMillis The timeout duration in millisecond.
13660 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13661 */
13662 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13663 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13664 TelephonyPermissions.enforceShellOnly(
13665 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13667 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13668 "setSatelliteListeningTimeoutDuration");
13669 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13670 }
13671
13672 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013673 * This API can be used by only CTS to override the timeout durations used by the
13674 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013675 *
13676 * @param timeoutMillis The timeout duration in millisecond.
13677 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13678 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013679 public boolean setDatagramControllerTimeoutDuration(
13680 boolean reset, int timeoutType, long timeoutMillis) {
13681 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13682 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013683 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013684 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13686 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013687 "setDatagramControllerTimeoutDuration");
13688 return mSatelliteController.setDatagramControllerTimeoutDuration(
13689 reset, timeoutType, timeoutMillis);
13690 }
13691
13692 /**
13693 * This API can be used by only CTS to override the timeout durations used by the
13694 * SatelliteController module.
13695 *
13696 * @param timeoutMillis The timeout duration in millisecond.
13697 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13698 */
13699 public boolean setSatelliteControllerTimeoutDuration(
13700 boolean reset, int timeoutType, long timeoutMillis) {
13701 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13702 + reset + ", timeoutMillis=" + timeoutMillis);
13703 TelephonyPermissions.enforceShellOnly(
13704 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13706 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13707 "setSatelliteControllerTimeoutDuration");
13708 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13709 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013710 }
13711
13712 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013713 * This API can be used in only testing to override connectivity status in monitoring emergency
13714 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13715 *
13716 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13717 * of the following values to enable the override:
13718 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13719 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13720 * To disable the override, use -1 for handoverType.
13721 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13722 * delaySeconds after the emergency call starts.
13723 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13724 */
13725 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13726 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13727 TelephonyPermissions.enforceShellOnly(
13728 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13730 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13731 "setEmergencyCallToSatelliteHandoverType");
13732 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13733 handoverType, delaySeconds);
13734 }
13735
13736 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013737 * This API can be used in only testing to override oem-enabled satellite provision status.
13738 *
13739 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13740 * otherwise.
13741 * @param isProvisioned The overriding provision status.
13742 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13743 */
13744 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13745 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13746 + ", isProvisioned=" + isProvisioned);
13747 TelephonyPermissions.enforceShellOnly(
13748 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13750 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13751 "setOemEnabledSatelliteProvisionStatus");
13752 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13753 }
13754
13755 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013756 * This API should be used by only CTS tests to forcefully set telephony country codes.
13757 *
13758 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13759 */
13760 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13761 Map cachedNetworkCountryCodes, String locationCountryCode,
13762 long locationCountryCodeTimestampNanos) {
13763 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13764 + String.join(", ", currentNetworkCountryCodes)
13765 + ", locationCountryCode=" + locationCountryCode
13766 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13767 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13768 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13769 TelephonyPermissions.enforceShellOnly(
13770 Binder.getCallingUid(), "setCachedLocationCountryCode");
13771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13772 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13773 "setCachedLocationCountryCode");
13774 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13775 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13776 locationCountryCodeTimestampNanos);
13777 }
13778
13779 /**
13780 * This API should be used by only CTS tests to override the overlay configs of satellite
13781 * access controller.
13782 *
13783 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13784 * otherwise.
13785 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13786 */
13787 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13788 String s2CellFile, long locationFreshDurationNanos,
13789 List<String> satelliteCountryCodes) {
13790 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13791 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13792 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13793 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13794 ? String.join(", ", satelliteCountryCodes) : null));
13795 TelephonyPermissions.enforceShellOnly(
13796 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13798 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13799 "setSatelliteAccessControlOverlayConfigs");
13800 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13801 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13802 }
13803
13804 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013805 * This API can be used by only CTS to override the cached value for the device overlay config
13806 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13807 * outgoing satellite datagrams should be sent to modem in demo mode.
13808 *
13809 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13810 * satellite modem or not.
13811 *
13812 * @return {@code true} if the operation is successful, {@code false} otherwise.
13813 */
13814 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13815 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13816 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13817 + "disabled");
13818 return false;
13819 }
13820 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13821 TelephonyPermissions.enforceShellOnly(
13822 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13824 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13825 "setShouldSendDatagramToModemInDemoMode");
13826 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13827 shouldSendToModemInDemoMode);
13828 }
13829
13830 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013831 * Sets the service defined in ComponentName to be bound.
13832 *
13833 * This should only be used for testing.
13834 * @return {@code true} if the DomainSelectionService to bind to was set,
13835 * {@code false} otherwise.
13836 */
13837 @Override
13838 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13839 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13840
13841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13842 "setDomainSelectionServiceOverride");
13843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13844 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13845
13846 final long identity = Binder.clearCallingIdentity();
13847 try {
13848 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13849 return DomainSelectionResolver.getInstance()
13850 .setDomainSelectionServiceOverride(componentName);
13851 }
13852 } finally {
13853 Binder.restoreCallingIdentity(identity);
13854 }
13855 return false;
13856 }
13857
13858 /**
13859 * Clears the DomainSelectionService override.
13860 *
13861 * This should only be used for testing.
13862 * @return {@code true} if the DomainSelectionService override was cleared,
13863 * {@code false} otherwise.
13864 */
13865 @Override
13866 public boolean clearDomainSelectionServiceOverride() {
13867 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13868
13869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13870 "clearDomainSelectionServiceOverride");
13871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13872 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13873
13874 final long identity = Binder.clearCallingIdentity();
13875 try {
13876 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13877 return DomainSelectionResolver.getInstance()
13878 .clearDomainSelectionServiceOverride();
13879 }
13880 } finally {
13881 Binder.restoreCallingIdentity(identity);
13882 }
13883 return false;
13884 }
13885
13886 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013887 * Enable or disable notifications sent for cellular identifier disclosure events.
13888 *
13889 * Disclosure events are defined as instances where a device has sent a cellular identifier
13890 * on the Non-access stratum (NAS) before a security context is established. As a result the
13891 * identifier is sent in the clear, which has privacy implications for the user.
13892 *
13893 * @param enable if notifications about disclosure events should be enabled
13894 * @throws SecurityException if the caller does not have the required privileges
13895 * @throws UnsupportedOperationException if the modem does not support this feature.
13896 */
13897 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013898 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013899 enforceModifyPermission();
13900 checkForIdentifierDisclosureNotificationSupport();
13901
13902 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13903 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13904 editor.apply();
13905
13906 // Each phone instance is responsible for updating its respective modem immediately
13907 // after we've made a preference change.
13908 for (Phone phone : PhoneFactory.getPhones()) {
13909 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13910 }
13911 }
13912
13913 /**
13914 * Get whether or not cellular identifier disclosure notifications are enabled.
13915 *
13916 * @throws SecurityException if the caller does not have the required privileges
13917 * @throws UnsupportedOperationException if the modem does not support this feature.
13918 */
13919 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013920 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013921 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13922 checkForIdentifierDisclosureNotificationSupport();
13923 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13924 }
13925
13926 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013927 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13928 * are in use by the cellular modem.
13929 *
13930 * @throws IllegalStateException if the Telephony process is not currently available
13931 * @throws SecurityException if the caller does not have the required privileges
13932 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13933 * and integrity algorithms in use
13934 * @hide
13935 */
13936 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013937 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013938 enforceModifyPermission();
13939 checkForNullCipherNotificationSupport();
13940
13941 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13942 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13943 editor.apply();
13944
13945 // Each phone instance is responsible for updating its respective modem immediately
13946 // after a preference change.
13947 for (Phone phone : PhoneFactory.getPhones()) {
13948 phone.handleNullCipherNotificationPreferenceChanged();
13949 }
13950 }
13951
13952 /**
13953 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13954 * cellular modem.
13955 *
13956 * @throws IllegalStateException if the Telephony process is not currently available
13957 * @throws SecurityException if the caller does not have the required privileges
13958 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13959 * and integrity algorithms in use
13960 * @hide
13961 */
13962 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
13963 public boolean isNullCipherNotificationsEnabled() {
13964 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
13965 checkForNullCipherNotificationSupport();
13966 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
13967 }
13968
13969 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013970 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13971 *
13972 * <p>This method behaves in one of the following ways:
13973 * <ul>
13974 * <li>return true : if the calling package has the appop permission {@link
13975 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13976 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13977 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13978 * Owner device identifier access check, or the calling package has carrier privileges</>
13979 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13980 * </ul>
13981 */
13982 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13983 String callingPackage, @Nullable String callingFeatureId, String message) {
13984 for (Phone phone : PhoneFactory.getPhones()) {
13985 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13986 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13987 return true;
13988 }
13989 }
13990 return false;
13991 }
arunvoddud7401012022-12-15 16:08:12 +000013992
13993 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013994 * @return The subscription manager service instance.
13995 */
13996 public SubscriptionManagerService getSubscriptionManagerService() {
13997 return SubscriptionManagerService.getInstance();
13998 }
13999
14000 /**
arunvoddud7401012022-12-15 16:08:12 +000014001 * Class binds the consumer[callback] and carrierId.
14002 */
14003 private static class CallerCallbackInfo {
14004 private final Consumer<Integer> mConsumer;
14005 private final int mCarrierId;
14006
14007 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
14008 mConsumer = consumer;
14009 mCarrierId = carrierId;
14010 }
14011
14012 public Consumer<Integer> getConsumer() {
14013 return mConsumer;
14014 }
14015
14016 public int getCarrierId() {
14017 return mCarrierId;
14018 }
14019 }
joonhunshin4ac60942023-11-15 15:23:39 +000014020
14021 /*
14022 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14023 * But the context that is passed in is unused if the phone app is already alive.
14024 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14025 */
14026 @VisibleForTesting
14027 public void setPackageManager(PackageManager packageManager) {
14028 mPackageManager = packageManager;
14029 }
14030
14031 /*
14032 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14033 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14034 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14035 */
14036 @VisibleForTesting
14037 public void setFeatureFlags(FeatureFlags featureFlags) {
14038 mFeatureFlags = featureFlags;
14039 }
14040
14041 /**
14042 * Make sure the device has required telephony feature
14043 *
14044 * @throws UnsupportedOperationException if the device does not have required telephony feature
14045 */
14046 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14047 @NonNull String telephonyFeature, @NonNull String methodName) {
14048 if (callingPackage == null || mPackageManager == null) {
14049 return;
14050 }
14051
14052 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14053 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14054 Binder.getCallingUserHandle())) {
14055 return;
14056 }
14057
14058 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14059 throw new UnsupportedOperationException(
14060 methodName + " is unsupported without " + telephonyFeature);
14061 }
14062 }
Jack Yufa8ed012023-02-11 15:42:28 -080014063}