blob: 3274b071c66b6f6275b632b4acf13887cb9aeaf8 [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;
Hall Liud892bec2018-11-30 14:51:45 -080026
Shuo Qianccbaf742021-02-22 18:32:21 -080027import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
28import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070029import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070030import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000031import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070032
Brad Ebinger34c09a52021-02-17 23:23:21 +000033import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080034import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080035import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070036import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080038import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080040import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070041import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000042import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080043import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000044import android.compat.annotation.ChangeId;
45import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000046import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070047import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070048import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.content.Context;
50import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070052import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070053import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.net.Uri;
55import android.os.AsyncResult;
56import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080057import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080059import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080062import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080063import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Looper;
65import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070066import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080067import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070068import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070069import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080070import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080071import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070072import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070073import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080074import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070076import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070078import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070079import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080080import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070081import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000082import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090083import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080084import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080085import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070086import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080087import android.telephony.AccessNetworkConstants;
88import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070089import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070090import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080091import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070092import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080093import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070094import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080095import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060096import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070097import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080098import android.telephony.CellIdentityCdma;
99import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700101import android.telephony.CellInfoGsm;
102import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700103import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800104import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700105import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700106import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700107import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800108import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700109import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700111import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800112import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800113import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700114import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800115import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800117import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800118import android.telephony.SignalStrengthUpdateRequest;
119import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800120import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800121import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800122import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700123import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700124import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800125import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800126import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800127import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800128import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000129import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000130import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000131import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700132import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700133import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800134import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800135import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700136import android.telephony.gba.GbaAuthRequest;
137import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700138import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800139import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000140import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000141import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700142import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000143import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700144import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800145import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700146import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800147import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000149import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700150import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800151import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800152import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000153import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000154import android.telephony.satellite.ISatelliteCapabilitiesCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800155import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.ISatelliteProvisionStateCallback;
157import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800158import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000159import android.telephony.satellite.NtnSignalStrength;
160import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800161import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000162import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800163import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800164import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800165import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700168import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800170import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800171
Andrew Lee312e8172014-10-23 17:01:36 -0700172import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800173import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800174import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800175import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800176import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700178import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700179import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800180import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800181import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700182import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800184import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700185import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800186import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800187import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800188import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700189import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000190import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700191import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800192import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800194import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800195import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800196import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700197import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700198import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700199import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700201import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800202import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700203import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700204import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700205import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700206import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800207import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800208import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700209import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000210import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700211import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700212import com.android.internal.telephony.SmsPermissions;
Peter Wang59571be2020-01-27 12:35:15 +0800213import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800214import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700215import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000216import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800217import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700218import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700219import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800220import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700221import com.android.internal.telephony.imsphone.ImsPhone;
222import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000223import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800224import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000225import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800226import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
227import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700228import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700229import com.android.internal.telephony.uicc.IccIoResult;
230import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800231import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700232import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800233import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700234import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000235import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800236import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000237import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800238import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000239import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700240import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700241import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800242import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800243import com.android.phone.callcomposer.CallComposerPictureManager;
244import com.android.phone.callcomposer.CallComposerPictureTransfer;
245import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700246import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700247import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000248import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700249import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800250import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700251import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700252import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800253import com.android.services.telephony.TelecomAccountRegistry;
254import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800255import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800256
Hall Liu82694d52020-12-11 18:22:04 -0800257import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700258import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800259import java.io.IOException;
260import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700261import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800263import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000264import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800265import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800266import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800267import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800268import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100269import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800270import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800272import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800273import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700274import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800275import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800276import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800277import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278
279/**
280 * Implementation of the ITelephony interface.
281 */
Santos Cordon117fee72014-05-16 17:56:12 -0700282public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 private static final String LOG_TAG = "PhoneInterfaceManager";
284 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
285 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800286 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
288 // Message codes used with mMainThreadHandler
289 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700290 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
291 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700292 private static final int CMD_OPEN_CHANNEL = 9;
293 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
294 private static final int CMD_CLOSE_CHANNEL = 11;
295 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800296 private static final int CMD_NV_READ_ITEM = 13;
297 private static final int EVENT_NV_READ_ITEM_DONE = 14;
298 private static final int CMD_NV_WRITE_ITEM = 15;
299 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
300 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
301 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700302 private static final int CMD_RESET_MODEM_CONFIG = 19;
303 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800304 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
305 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800306 private static final int CMD_SEND_ENVELOPE = 25;
307 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700308 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
309 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
310 private static final int CMD_EXCHANGE_SIM_IO = 31;
311 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800312 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
313 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700314 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
315 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700316 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
317 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700318 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
319 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
320 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
321 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700322 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
323 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
324 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
325 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700326 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800327 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
328 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000329 private static final int CMD_SWITCH_SLOTS = 50;
330 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700331 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
332 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
333 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
334 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
335 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
336 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
337 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
338 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700339 private static final int CMD_GET_ALL_CELL_INFO = 60;
340 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
341 private static final int CMD_GET_CELL_LOCATION = 62;
342 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700343 private static final int CMD_MODEM_REBOOT = 64;
344 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700345 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
346 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800347 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
348 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700349 private static final int CMD_GET_MODEM_STATUS = 70;
350 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700351 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
352 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700353 private static final int CMD_ERASE_MODEM_CONFIG = 74;
354 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800355 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
356 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
357 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
358 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800359 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
360 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800361 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800362 private static final int CMD_GET_CALL_FORWARDING = 83;
363 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
364 private static final int CMD_SET_CALL_FORWARDING = 85;
365 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
366 private static final int CMD_GET_CALL_WAITING = 87;
367 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
368 private static final int CMD_SET_CALL_WAITING = 89;
369 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700370 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
371 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
372 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
373 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700374 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
375 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800376 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
377 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800378 private static final int CMD_SET_DATA_THROTTLING = 99;
379 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800380 private static final int CMD_SET_SIM_POWER = 101;
381 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800382 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
383 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
384 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
385 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800386 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
387 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000388 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800389 private static final int CMD_GET_SLICING_CONFIG = 110;
390 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800391 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700392 private static final int CMD_ENABLE_VONR = 113;
393 private static final int EVENT_ENABLE_VONR_DONE = 114;
394 private static final int CMD_IS_VONR_ENABLED = 115;
395 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700396 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
397 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000398
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800399 // Parameters of select command.
400 private static final int SELECT_COMMAND = 0xA4;
401 private static final int SELECT_P1 = 0x04;
402 private static final int SELECT_P2 = 0;
403 private static final int SELECT_P3 = 0x10;
404
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000405 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
406 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000407 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
408 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000409
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 /** The singleton instance. */
411 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800412 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413
Sarah Chin4beb2b72023-02-14 14:47:54 -0800414 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000415 private FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800416 private final CallManager mCM;
417 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000418
419 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800420 private final UserManager mUserManager;
421 private final AppOpsManager mAppOps;
422 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800423 private final SharedPreferences mTelephonySharedPreferences;
424 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800425 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
joonhunshin4ac60942023-11-15 15:23:39 +0000426 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Peter Wangdafb9ac2020-01-15 14:13:38 -0800428 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800430 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800431 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800432
Derek Tan97ebb422014-09-05 16:55:38 -0700433 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
434 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800435 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800436 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700437
Michelecea4cf22018-12-21 15:00:11 -0800438 // String to store multi SIM allowed
439 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
440
Derek Tan740e1672017-06-27 14:56:27 -0700441 // The AID of ISD-R.
442 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
443
yinxub1bed742017-04-17 11:45:04 -0700444 private NetworkScanRequestTracker mNetworkScanRequestTracker;
445
David Kelly5e06a7f2018-03-12 14:10:59 +0000446 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
447 private static final int MANUFACTURER_CODE_LENGTH = 8;
448
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800449 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800450 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800451
Sarah Chin2ec39f62022-08-31 17:03:26 -0700452 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
453 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
454
Derek Tan89e89d42014-07-08 17:00:10 -0700455 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700456 * Experiment flag to enable erase modem config on reset network, default value is false
457 */
458 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
459 "reset_network_erase_modem_config_enabled";
460
Rambo Wang0f050d82021-02-12 11:43:36 -0800461 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800462
Gary Jian76280a42022-12-07 16:18:33 +0800463 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
464
sandeepjsb6c87872021-09-27 15:34:44 +0000465 /**
466 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
467 * one ICCID active at the same time.
468 * Apps should use below API signatures if targeting SDK is T and beyond.
469 *
470 * @hide
471 */
472 @ChangeId
473 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
474 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800475
Naina Nallurid63128d2019-09-17 14:10:30 -0700476 /**
Chen Xu540470b2021-12-14 17:15:47 -0800477 * Apps targeting on Android T and beyond will get exception whenever icc close channel
478 * operation fails.
479 */
480 @ChangeId
481 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
482 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
483
484 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700485 * A request object to use for transmitting data to an ICC.
486 */
487 private static final class IccAPDUArgument {
488 public int channel, cla, command, p1, p2, p3;
489 public String data;
490
491 public IccAPDUArgument(int channel, int cla, int command,
492 int p1, int p2, int p3, String data) {
493 this.channel = channel;
494 this.cla = cla;
495 this.command = command;
496 this.p1 = p1;
497 this.p2 = p2;
498 this.p3 = p3;
499 this.data = data;
500 }
501 }
502
503 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700504 * A request object to use for transmitting data to an ICC.
505 */
506 private static final class ManualNetworkSelectionArgument {
507 public OperatorInfo operatorInfo;
508 public boolean persistSelection;
509
510 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
511 this.operatorInfo = operatorInfo;
512 this.persistSelection = persistSelection;
513 }
514 }
515
Sarah Chin71b3a852022-09-28 15:54:19 -0700516 private static final class PurchasePremiumCapabilityArgument {
517 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700518 public @NonNull IIntegerConsumer callback;
519
520 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800521 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700522 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700523 this.callback = callback;
524 }
525 }
526
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700527 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
529 * request after sending. The main thread will notify the request when it is complete.
530 */
531 private static final class MainThreadRequest {
532 /** The argument to use for the request */
533 public Object argument;
534 /** The result of the request that is run on the main thread */
535 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800536 // The subscriber id that this request applies to. Defaults to
537 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
538 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539
Nathan Harold92bed182018-10-12 18:16:49 -0700540 // In cases where subId is unavailable, the caller needs to specify the phone.
541 public Phone phone;
542
vagdeviaf9a5b92018-08-15 16:01:53 -0700543 public WorkSource workSource;
544
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 public MainThreadRequest(Object argument) {
546 this.argument = argument;
547 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800548
Nathan Harold92bed182018-10-12 18:16:49 -0700549 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
550 this.argument = argument;
551 if (phone != null) {
552 this.phone = phone;
553 }
554 this.workSource = workSource;
555 }
556
vagdeviaf9a5b92018-08-15 16:01:53 -0700557 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800558 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800559 if (subId != null) {
560 this.subId = subId;
561 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700562 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 }
565
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800566 private static final class IncomingThirdPartyCallArgs {
567 public final ComponentName component;
568 public final String callId;
569 public final String callerDisplayName;
570
571 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
572 String callerDisplayName) {
573 this.component = component;
574 this.callId = callId;
575 this.callerDisplayName = callerDisplayName;
576 }
577 }
578
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 /**
580 * A handler that processes messages on the main thread in the phone process. Since many
581 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
582 * inbound binder threads to the main thread in the phone process. The Binder thread
583 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
584 * on, which will be notified when the operation completes and will contain the result of the
585 * request.
586 *
587 * <p>If a MainThreadRequest object is provided in the msg.obj field,
588 * note that request.result must be set to something non-null for the calling thread to
589 * unblock.
590 */
591 private final class MainThreadHandler extends Handler {
592 @Override
593 public void handleMessage(Message msg) {
594 MainThreadRequest request;
595 Message onCompleted;
596 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000597 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800599 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700600
601 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 case CMD_HANDLE_USSD_REQUEST: {
603 request = (MainThreadRequest) msg.obj;
604 final Phone phone = getPhoneFromRequest(request);
605 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800606 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700608
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 if (!isUssdApiAllowed(request.subId)) {
610 // Carrier does not support use of this API, return failure.
611 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
612 UssdResponse response = new UssdResponse(ussdRequest, null);
613 Bundle returnData = new Bundle();
614 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
615 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700616
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 request.result = true;
618 notifyRequester(request);
619 return;
620 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700621
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 try {
623 request.result = phone != null
624 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
625 } catch (CallStateException cse) {
626 request.result = false;
627 }
628 // Wake up the requesting thread
629 notifyRequester(request);
630 break;
pkanwar32d516d2016-10-14 19:37:38 -0700631 }
632
Yorke Lee716f67e2015-06-17 15:39:16 -0700633 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700635 final Phone phone = getPhoneFromRequest(request);
636 request.result = phone != null ?
637 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
638 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700639 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700641 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700643
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000647 uiccPort = getUiccPortFromRequest(request);
648 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800650 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800654 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000655 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800656 iccArgument.channel, iccArgument.cla, iccArgument.command,
657 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
658 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 break;
661
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
667 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 if (ar.result == null) {
670 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800671 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800673 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 } else {
675 loge("iccTransmitApduLogicalChannel: Unknown exception");
676 }
677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
682 request = (MainThreadRequest) msg.obj;
683 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort = getUiccPortFromRequest(request);
685 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800687 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 } else {
690 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800691 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800693 iccArgument.cla, iccArgument.command, iccArgument.p1,
694 iccArgument.p2,
695 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 }
697 break;
698
699 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
702 if (ar.exception == null && ar.result != null) {
703 request.result = ar.result;
704 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800705 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 if (ar.result == null) {
707 loge("iccTransmitApduBasicChannel: Empty response");
708 } else if (ar.exception instanceof CommandException) {
709 loge("iccTransmitApduBasicChannel: CommandException: " +
710 ar.exception);
711 } else {
712 loge("iccTransmitApduBasicChannel: Unknown exception");
713 }
714 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 break;
717
718 case CMD_EXCHANGE_SIM_IO:
719 request = (MainThreadRequest) msg.obj;
720 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
722 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800724 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700725 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 } else {
727 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
728 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000729 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
731 iccArgument.data, onCompleted);
732 }
733 break;
734
735 case EVENT_EXCHANGE_SIM_IO_DONE:
736 ar = (AsyncResult) msg.obj;
737 request = (MainThreadRequest) ar.userObj;
738 if (ar.exception == null && ar.result != null) {
739 request.result = ar.result;
740 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800741 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 break;
745
Derek Tan4d5e5c12014-02-04 11:54:58 -0800746 case CMD_SEND_ENVELOPE:
747 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000748 uiccPort = getUiccPortFromRequest(request);
749 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800751 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700753 } else {
754 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800755 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700756 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800757 break;
758
759 case EVENT_SEND_ENVELOPE_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700762 if (ar.exception == null && ar.result != null) {
763 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800764 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800765 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700766 if (ar.result == null) {
767 loge("sendEnvelopeWithStatus: Empty response");
768 } else if (ar.exception instanceof CommandException) {
769 loge("sendEnvelopeWithStatus: CommandException: " +
770 ar.exception);
771 } else {
772 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
773 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800774 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800776 break;
777
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 case CMD_OPEN_CHANNEL:
779 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000780 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800781 IccLogicalChannelRequest openChannelRequest =
782 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000783 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700784 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800785 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800786 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700788 } else {
789 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800790 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
791 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 break;
794
795 case EVENT_OPEN_CHANNEL_DONE:
796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700798 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700800 int[] result = (int[]) ar.result;
801 int channelId = result[0];
802 byte[] selectResponse = null;
803 if (result.length > 1) {
804 selectResponse = new byte[result.length - 1];
805 for (int i = 1; i < result.length; ++i) {
806 selectResponse[i - 1] = (byte) result[i];
807 }
808 }
809 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800810 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800811
812 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700813 if (uiccPort == null) {
814 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
815 } else {
816 IccLogicalChannelRequest channelRequest =
817 (IccLogicalChannelRequest) request.argument;
818 channelRequest.channel = channelId;
819 uiccPort.onLogicalChannelOpened(channelRequest);
820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700822 if (ar.result == null) {
823 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700824 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700825 if (ar.exception != null) {
826 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
827 }
828
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700829 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700830 if (ar.exception instanceof CommandException) {
831 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800832 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700833 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700834 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700835 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700836 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700837 }
838 }
839 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800840 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700842 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700843 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 break;
845
846 case CMD_CLOSE_CHANNEL:
847 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000848 uiccPort = getUiccPortFromRequest(request);
849 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700850 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800851 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800852 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800853 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700854 } else {
855 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000856 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700857 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 break;
859
860 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800861 ar = (AsyncResult) msg.obj;
862 request = (MainThreadRequest) ar.userObj;
863 if (ar.exception == null) {
864 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800865 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700866 if (uiccPort == null) {
867 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
868 } else {
869 final int channelId = (Integer) request.argument;
870 uiccPort.onLogicalChannelClosed(channelId);
871 }
Chen Xu540470b2021-12-14 17:15:47 -0800872 } else {
873 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800874 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800875 if (ar.exception instanceof CommandException) {
876 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
877 CommandException.Error error =
878 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800879 if (error == CommandException.Error.INVALID_ARGUMENTS) {
880 // should only throw exceptions from the binder threads.
881 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800882 "iccCloseLogicalChannel: invalid argument ");
883 }
884 } else {
885 loge("iccCloseLogicalChannel: Unknown exception");
886 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800887 request.result = (exception != null) ? exception :
888 new IllegalStateException(
889 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800890 }
891 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
894 case CMD_NV_READ_ITEM:
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800897 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
898 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800899 break;
900
901 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700902 ar = (AsyncResult) msg.obj;
903 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800904 if (ar.exception == null && ar.result != null) {
905 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700906 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800907 request.result = "";
908 if (ar.result == null) {
909 loge("nvReadItem: Empty response");
910 } else if (ar.exception instanceof CommandException) {
911 loge("nvReadItem: CommandException: " +
912 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700913 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800914 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700915 }
916 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700917 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700918 break;
919
Jake Hambye994d462014-02-03 13:10:13 -0800920 case CMD_NV_WRITE_ITEM:
921 request = (MainThreadRequest) msg.obj;
922 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
923 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800924 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700925 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800926 break;
927
928 case EVENT_NV_WRITE_ITEM_DONE:
929 handleNullReturnEvent(msg, "nvWriteItem");
930 break;
931
932 case CMD_NV_WRITE_CDMA_PRL:
933 request = (MainThreadRequest) msg.obj;
934 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800935 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800936 break;
937
938 case EVENT_NV_WRITE_CDMA_PRL_DONE:
939 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
940 break;
941
chen xu6dac5ab2018-10-26 17:39:23 -0700942 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800943 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700944 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800945 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800946 break;
947
chen xu6dac5ab2018-10-26 17:39:23 -0700948 case EVENT_RESET_MODEM_CONFIG_DONE:
949 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800950 break;
951
Sooraj Sasindran37444802020-08-11 10:40:43 -0700952 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
955 request);
956 Phone phone = getPhoneFromRequest(request);
957 if (phone != null) {
958 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
959 } else {
960 loge("isNRDualConnectivityEnabled: No phone object");
961 request.result = false;
962 notifyRequester(request);
963 }
964 break;
965 }
966
967 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 if (ar.exception == null && ar.result != null) {
971 request.result = ar.result;
972 } else {
973 // request.result must be set to something non-null
974 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700975 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700976 request.result = ar.result;
977 } else {
978 request.result = false;
979 }
980 if (ar.result == null) {
981 loge("isNRDualConnectivityEnabled: Empty response");
982 } else if (ar.exception instanceof CommandException) {
983 loge("isNRDualConnectivityEnabled: CommandException: "
984 + ar.exception);
985 } else {
986 loge("isNRDualConnectivityEnabled: Unknown exception");
987 }
988 }
989 notifyRequester(request);
990 break;
991
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700992 case CMD_IS_VONR_ENABLED: {
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
995 request);
996 Phone phone = getPhoneFromRequest(request);
997 if (phone != null) {
998 phone.isVoNrEnabled(onCompleted, request.workSource);
999 } else {
1000 loge("isVoNrEnabled: No phone object");
1001 request.result = false;
1002 notifyRequester(request);
1003 }
1004 break;
1005 }
1006
1007 case EVENT_IS_VONR_ENABLED_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception == null && ar.result != null) {
1011 request.result = ar.result;
1012 } else {
1013 // request.result must be set to something non-null
1014 // for the calling thread to unblock
1015 if (ar.result != null) {
1016 request.result = ar.result;
1017 } else {
1018 request.result = false;
1019 }
1020 if (ar.result == null) {
1021 loge("isVoNrEnabled: Empty response");
1022 } else if (ar.exception instanceof CommandException) {
1023 loge("isVoNrEnabled: CommandException: "
1024 + ar.exception);
1025 } else {
1026 loge("isVoNrEnabled: Unknown exception");
1027 }
1028 }
1029 notifyRequester(request);
1030 break;
1031
Sooraj Sasindran37444802020-08-11 10:40:43 -07001032 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1033 request = (MainThreadRequest) msg.obj;
1034 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1035 Phone phone = getPhoneFromRequest(request);
1036 if (phone != null) {
1037 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1038 request.workSource);
1039 } else {
1040 loge("enableNrDualConnectivity: No phone object");
1041 request.result =
1042 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1043 notifyRequester(request);
1044 }
1045 break;
1046 }
1047
1048 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1049 ar = (AsyncResult) msg.obj;
1050 request = (MainThreadRequest) ar.userObj;
1051 if (ar.exception == null) {
1052 request.result =
1053 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1054 } else {
1055 request.result =
1056 TelephonyManager
1057 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1058 if (ar.exception instanceof CommandException) {
1059 CommandException.Error error =
1060 ((CommandException) (ar.exception)).getCommandError();
1061 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1062 request.result =
1063 TelephonyManager
1064 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001065 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1066 request.result =
1067 TelephonyManager
1068 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001069 }
1070 loge("enableNrDualConnectivity" + ": CommandException: "
1071 + ar.exception);
1072 } else {
1073 loge("enableNrDualConnectivity" + ": Unknown exception");
1074 }
1075 }
1076 notifyRequester(request);
1077 break;
1078 }
1079
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001080 case CMD_ENABLE_VONR: {
1081 request = (MainThreadRequest) msg.obj;
1082 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1083 Phone phone = getPhoneFromRequest(request);
1084 if (phone != null) {
1085 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1086 request.workSource);
1087 } else {
1088 loge("setVoNrEnabled: No phone object");
1089 request.result =
1090 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1091 notifyRequester(request);
1092 }
1093 break;
1094 }
1095
1096 case EVENT_ENABLE_VONR_DONE: {
1097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null) {
1100 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1101 } else {
1102 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1103 if (ar.exception instanceof CommandException) {
1104 CommandException.Error error =
1105 ((CommandException) (ar.exception)).getCommandError();
1106 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1107 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1108 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1109 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1110 } else {
1111 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1112 }
1113 loge("setVoNrEnabled" + ": CommandException: "
1114 + ar.exception);
1115 } else {
1116 loge("setVoNrEnabled" + ": Unknown exception");
1117 }
1118 }
1119 notifyRequester(request);
1120 break;
1121 }
1122
SongFerngWang3ef3e072020-12-21 16:41:52 +08001123 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001124 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001125 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1126 request);
1127 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001128 break;
1129
SongFerngWang3ef3e072020-12-21 16:41:52 +08001130 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 ar = (AsyncResult) msg.obj;
1132 request = (MainThreadRequest) ar.userObj;
1133 if (ar.exception == null && ar.result != null) {
1134 request.result = ar.result; // Integer
1135 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301136 // request.result must be set to something non-null
1137 // for the calling thread to unblock
1138 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 loge("getAllowedNetworkTypesBitmask: CommandException: "
1143 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001145 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 }
1147 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001148 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001149 break;
1150
SongFerngWang3ef3e072020-12-21 16:41:52 +08001151 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001153 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1154 request);
1155 Pair<Integer, Long> reasonWithNetworkTypes =
1156 (Pair<Integer, Long>) request.argument;
1157 getPhoneFromRequest(request).setAllowedNetworkTypes(
1158 reasonWithNetworkTypes.first,
1159 reasonWithNetworkTypes.second,
1160 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 break;
1162
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1164 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001165 break;
1166
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001167 case CMD_SET_VOICEMAIL_NUMBER:
1168 request = (MainThreadRequest) msg.obj;
1169 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1170 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001171 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1172 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001173 break;
1174
1175 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1176 handleNullReturnEvent(msg, "setVoicemailNumber");
1177 break;
1178
Stuart Scott54788802015-03-30 13:18:01 -07001179 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1182 request);
1183 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1184 break;
1185
1186 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1187 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1188 break;
1189
Shishir Agrawal302c8692015-06-19 13:49:39 -07001190 case CMD_PERFORM_NETWORK_SCAN:
1191 request = (MainThreadRequest) msg.obj;
1192 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1193 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1194 break;
1195
Hall Liu27d24262020-09-18 19:04:59 -07001196 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001197 request = (MainThreadRequest) msg.obj;
1198 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001199 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1200 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1201 request.argument;
1202 int callForwardingReason = args.first;
1203 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001204 break;
Hall Liu27d24262020-09-18 19:04:59 -07001205 }
1206 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001207 ar = (AsyncResult) msg.obj;
1208 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001209 TelephonyManager.CallForwardingInfoCallback callback =
1210 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1211 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001212 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001213 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001214 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1215 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1216 // Service Class is a bit mask per 3gpp 27.007. Search for
1217 // any service for voice call.
1218 if ((callForwardInfo.serviceClass
1219 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001220 callForwardingInfo = new CallForwardingInfo(
1221 callForwardInfo.status
1222 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001223 callForwardInfo.reason,
1224 callForwardInfo.number,
1225 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 break;
1227 }
1228 }
1229 // Didn't find a call forward info for voice call.
1230 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001231 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1232 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001233 }
Hall Liu27d24262020-09-18 19:04:59 -07001234 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001235 } else {
1236 if (ar.result == null) {
1237 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1238 }
1239 if (ar.exception != null) {
1240 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1241 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001242 int errorCode = TelephonyManager
1243 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001244 if (ar.exception instanceof CommandException) {
1245 CommandException.Error error =
1246 ((CommandException) (ar.exception)).getCommandError();
1247 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 errorCode = TelephonyManager
1249 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001250 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001251 errorCode = TelephonyManager
1252 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001253 }
1254 }
Hall Liu27d24262020-09-18 19:04:59 -07001255 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257 break;
Hall Liu27d24262020-09-18 19:04:59 -07001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259
Hall Liu27d24262020-09-18 19:04:59 -07001260 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 request = (MainThreadRequest) msg.obj;
1262 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001263 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001264 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001265 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1266 request.argument).first;
1267 request.phone.setCallForwardingOption(
1268 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001269 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001270 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001271 callForwardingInfoToSet.getReason(),
1272 callForwardingInfoToSet.getNumber(),
1273 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1274 break;
Hall Liu27d24262020-09-18 19:04:59 -07001275 }
Shuo Qian4a594052020-01-23 11:59:30 -08001276
Hall Liu27d24262020-09-18 19:04:59 -07001277 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001278 ar = (AsyncResult) msg.obj;
1279 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001280 Consumer<Integer> callback =
1281 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1282 request.argument).second;
1283 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001284 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001285 int errorCode = TelephonyManager.CallForwardingInfoCallback
1286 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001287 if (ar.exception instanceof CommandException) {
1288 CommandException.Error error =
1289 ((CommandException) (ar.exception)).getCommandError();
1290 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001291 errorCode = TelephonyManager.CallForwardingInfoCallback
1292 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001293 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001294 errorCode = TelephonyManager.CallForwardingInfoCallback
1295 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001296 }
1297 }
1298 callback.accept(errorCode);
1299 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001300 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001301 }
Shuo Qian4a594052020-01-23 11:59:30 -08001302 break;
Hall Liu27d24262020-09-18 19:04:59 -07001303 }
Shuo Qian4a594052020-01-23 11:59:30 -08001304
Hall Liu27d24262020-09-18 19:04:59 -07001305 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001306 request = (MainThreadRequest) msg.obj;
1307 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1308 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1309 break;
Hall Liu27d24262020-09-18 19:04:59 -07001310 }
Shuo Qian4a594052020-01-23 11:59:30 -08001311
Hall Liu27d24262020-09-18 19:04:59 -07001312 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001313 ar = (AsyncResult) msg.obj;
1314 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001315 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001316 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001317 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001318 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001319 // Service Class is a bit mask per 3gpp 27.007.
1320 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001321 if (callForwardResults.length > 1
1322 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001323 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001324 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001325 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1326 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001327 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001329 }
1330 } else {
1331 if (ar.result == null) {
1332 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1333 }
1334 if (ar.exception != null) {
1335 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1336 }
1337 if (ar.exception instanceof CommandException) {
1338 CommandException.Error error =
1339 ((CommandException) (ar.exception)).getCommandError();
1340 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001342 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001343 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1344 callWaitingStatus =
1345 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 }
1347 }
1348 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001349 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001350 break;
Hall Liu27d24262020-09-18 19:04:59 -07001351 }
Shuo Qian4a594052020-01-23 11:59:30 -08001352
Hall Liu27d24262020-09-18 19:04:59 -07001353 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001354 request = (MainThreadRequest) msg.obj;
1355 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001356 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1357 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001358 break;
Hall Liu27d24262020-09-18 19:04:59 -07001359 }
Shuo Qian4a594052020-01-23 11:59:30 -08001360
Hall Liu27d24262020-09-18 19:04:59 -07001361 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001364 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1365 Consumer<Integer> callback =
1366 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1367 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001368 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001369 if (ar.exception instanceof CommandException) {
1370 CommandException.Error error =
1371 ((CommandException) (ar.exception)).getCommandError();
1372 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1373 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001374 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1375 callback.accept(
1376 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001377 } else {
1378 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1379 }
1380 } else {
1381 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1382 }
1383 } else {
1384 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1385 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001386 }
Shuo Qian4a594052020-01-23 11:59:30 -08001387 break;
Hall Liu27d24262020-09-18 19:04:59 -07001388 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001389 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
1392 CellNetworkScanResult cellScanResult;
1393 if (ar.exception == null && ar.result != null) {
1394 cellScanResult = new CellNetworkScanResult(
1395 CellNetworkScanResult.STATUS_SUCCESS,
1396 (List<OperatorInfo>) ar.result);
1397 } else {
1398 if (ar.result == null) {
1399 loge("getCellNetworkScanResults: Empty response");
1400 }
1401 if (ar.exception != null) {
1402 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1403 }
1404 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1405 if (ar.exception instanceof CommandException) {
1406 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001407 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001408 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1409 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1410 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1411 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1412 }
1413 }
1414 cellScanResult = new CellNetworkScanResult(errorCode, null);
1415 }
1416 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001417 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001418 break;
1419
1420 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1421 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001422 ManualNetworkSelectionArgument selArg =
1423 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001424 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1425 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001426 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1427 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001428 break;
1429
1430 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001431 ar = (AsyncResult) msg.obj;
1432 request = (MainThreadRequest) ar.userObj;
1433 if (ar.exception == null) {
1434 request.result = true;
1435 } else {
1436 request.result = false;
1437 loge("setNetworkSelectionModeManual " + ar.exception);
1438 }
1439 notifyRequester(request);
1440 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001441 break;
1442
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 case CMD_GET_MODEM_ACTIVITY_INFO:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001446 if (defaultPhone != null) {
1447 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001448 } else {
1449 ResultReceiver result = (ResultReceiver) request.argument;
1450 Bundle bundle = new Bundle();
1451 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001452 new ModemActivityInfo(0, 0, 0,
1453 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001454 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001455 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 break;
1457
Hall Liud0f208c2020-10-14 16:54:44 -07001458 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 ar = (AsyncResult) msg.obj;
1460 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001461 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001462 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001463 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001464 if (mLastModemActivityInfo == null) {
1465 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1466 mLastModemActivitySpecificInfo[0] =
1467 new ActivityStatsTechSpecificInfo(
1468 0,
1469 0,
1470 new int[ModemActivityInfo.getNumTxPowerLevels()],
1471 0);
1472 mLastModemActivityInfo =
1473 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1474 }
1475
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001477 // Update the last modem activity info and the result of the request.
1478 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1479 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001480 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001481 } else {
1482 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001483 }
Kai Shi917fdc62022-11-28 14:01:02 -08001484 // This is needed to decouple ret from mLastModemActivityInfo
1485 // We don't want to return mLastModemActivityInfo which is updated
1486 // inside mergeModemActivityInfo()
1487 ret = new ModemActivityInfo(
1488 mLastModemActivityInfo.getTimestampMillis(),
1489 mLastModemActivityInfo.getSleepTimeMillis(),
1490 mLastModemActivityInfo.getIdleTimeMillis(),
1491 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001492
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 } else {
1494 if (ar.result == null) {
1495 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001496 error = TelephonyManager.ModemActivityInfoException
1497 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001498 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001499 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001500 error = TelephonyManager.ModemActivityInfoException
1501 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001502 } else {
1503 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001504 error = TelephonyManager.ModemActivityInfoException
1505 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 }
1507 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001508 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001509 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001510 bundle.putParcelable(
1511 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001512 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001513 } else {
1514 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1515 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001516 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001517 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001518 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001519 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001521 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001522 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001523 CarrierRestrictionRules argument =
1524 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001526 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001527 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001528 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529
1530 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception == null && ar.result != null) {
1534 request.result = ar.result;
1535 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001536 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1537 if (ar.exception instanceof CommandException) {
1538 loge("setAllowedCarriers: CommandException: " + ar.exception);
1539 CommandException.Error error =
1540 ((CommandException) (ar.exception)).getCommandError();
1541 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1542 request.result =
1543 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1544 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 } else {
1546 loge("setAllowedCarriers: Unknown exception");
1547 }
1548 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001549 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001550 break;
1551
1552 case CMD_GET_ALLOWED_CARRIERS:
1553 request = (MainThreadRequest) msg.obj;
1554 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001555 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001556 break;
1557
1558 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1559 ar = (AsyncResult) msg.obj;
1560 request = (MainThreadRequest) ar.userObj;
1561 if (ar.exception == null && ar.result != null) {
1562 request.result = ar.result;
1563 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001564 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001565 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001566 if (ar.result == null) {
1567 loge("getAllowedCarriers: Empty response");
1568 } else if (ar.exception instanceof CommandException) {
1569 loge("getAllowedCarriers: CommandException: " +
1570 ar.exception);
1571 } else {
1572 loge("getAllowedCarriers: Unknown exception");
1573 }
1574 }
arunvoddud7401012022-12-15 16:08:12 +00001575 if (request.argument != null) {
1576 // This is for the implementation of carrierRestrictionStatus.
1577 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1578 Consumer<Integer> callback = callbackInfo.getConsumer();
1579 int callerCarrierId = callbackInfo.getCarrierId();
1580 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1581 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1582 CarrierRestrictionRules carrierRestrictionRules =
1583 (CarrierRestrictionRules) ar.result;
1584 int carrierId = -1;
1585 try {
1586 CarrierIdentifier carrierIdentifier =
1587 carrierRestrictionRules.getAllowedCarriers().get(0);
1588 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1589 carrierIdentifier);
1590 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1591 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1592 }
1593 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1594 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1595 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001596 lockStatus = TelephonyManager
1597 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001598 }
1599 } else {
1600 Rlog.e(LOG_TAG,
1601 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1602 }
1603 callback.accept(lockStatus);
1604 } else {
1605 // This is for the implementation of getAllowedCarriers.
1606 notifyRequester(request);
1607 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001608 break;
1609
Nathan Haroldb3014052017-01-25 15:57:32 -08001610 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception == null && ar.result != null) {
1614 request.result = ar.result;
1615 } else {
1616 request.result = new IllegalArgumentException(
1617 "Failed to retrieve Forbidden Plmns");
1618 if (ar.result == null) {
1619 loge("getForbiddenPlmns: Empty response");
1620 } else {
1621 loge("getForbiddenPlmns: Unknown exception");
1622 }
1623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001624 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001625 break;
1626
1627 case CMD_GET_FORBIDDEN_PLMNS:
1628 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001629 uiccPort = getUiccPortFromRequest(request);
1630 if (uiccPort == null) {
1631 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001632 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001633 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001634 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001635 break;
1636 }
1637 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001638 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 if (uiccApp == null) {
1640 loge("getForbiddenPlmns() no app with specified type -- "
1641 + appType);
1642 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001643 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 break;
1645 } else {
1646 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1647 + " specified type -- " + appType);
1648 }
1649 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1650 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001651 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001652 break;
1653
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001654 case CMD_SWITCH_SLOTS:
1655 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001656 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001657 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001658 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001659 break;
1660
1661 case EVENT_SWITCH_SLOTS_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001665 notifyRequester(request);
1666 break;
1667 case CMD_GET_NETWORK_SELECTION_MODE:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1670 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1671 break;
1672
1673 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1674 ar = (AsyncResult) msg.obj;
1675 request = (MainThreadRequest) ar.userObj;
1676 if (ar.exception != null) {
1677 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1678 } else {
1679 int mode = ((int[]) ar.result)[0];
1680 if (mode == 0) {
1681 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1682 } else {
1683 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1684 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001685 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001686 notifyRequester(request);
1687 break;
1688 case CMD_GET_CDMA_ROAMING_MODE:
1689 request = (MainThreadRequest) msg.obj;
1690 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1691 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1692 break;
1693 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1694 ar = (AsyncResult) msg.obj;
1695 request = (MainThreadRequest) ar.userObj;
1696 if (ar.exception != null) {
1697 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1698 } else {
1699 request.result = ((int[]) ar.result)[0];
1700 }
1701 notifyRequester(request);
1702 break;
1703 case CMD_SET_CDMA_ROAMING_MODE:
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1706 int mode = (int) request.argument;
1707 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1708 break;
1709 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1710 ar = (AsyncResult) msg.obj;
1711 request = (MainThreadRequest) ar.userObj;
1712 request.result = ar.exception == null;
1713 notifyRequester(request);
1714 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001715 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1716 request = (MainThreadRequest) msg.obj;
1717 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1718 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1719 break;
1720 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1721 ar = (AsyncResult) msg.obj;
1722 request = (MainThreadRequest) ar.userObj;
1723 if (ar.exception != null) {
1724 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1725 } else {
1726 request.result = ((int[]) ar.result)[0];
1727 }
1728 notifyRequester(request);
1729 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001730 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1731 request = (MainThreadRequest) msg.obj;
1732 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1733 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001734 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1735 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001736 break;
1737 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1738 ar = (AsyncResult) msg.obj;
1739 request = (MainThreadRequest) ar.userObj;
1740 request.result = ar.exception == null;
1741 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001742 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001743 case CMD_GET_ALL_CELL_INFO:
1744 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001746 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001748 case EVENT_GET_ALL_CELL_INFO_DONE:
1749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001751 // If a timeout occurs, the response will be null
1752 request.result = (ar.exception == null && ar.result != null)
1753 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001754 synchronized (request) {
1755 request.notifyAll();
1756 }
1757 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001758 case CMD_REQUEST_CELL_INFO_UPDATE:
1759 request = (MainThreadRequest) msg.obj;
1760 request.phone.requestCellInfoUpdate(request.workSource,
1761 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1762 break;
1763 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
1766 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1767 try {
1768 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001769 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001770 cb.onError(
1771 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1772 ar.exception.getClass().getName(),
1773 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001774 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001775 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001776 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001777 } else {
1778 // use the result as returned
1779 cb.onCellInfo((List<CellInfo>) ar.result);
1780 }
1781 } catch (RemoteException re) {
1782 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1783 }
1784 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001785 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001786 request = (MainThreadRequest) msg.obj;
1787 WorkSource ws = (WorkSource) request.argument;
1788 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001789 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001791 }
1792 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 if (ar.exception == null) {
1796 request.result = ar.result;
1797 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001798 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001799 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001800 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001801 }
1802
1803 synchronized (request) {
1804 request.notifyAll();
1805 }
1806 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001807 }
chen xu6dac5ab2018-10-26 17:39:23 -07001808 case CMD_MODEM_REBOOT:
1809 request = (MainThreadRequest) msg.obj;
1810 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001811 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001812 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001813 case EVENT_CMD_MODEM_REBOOT_DONE:
1814 handleNullReturnEvent(msg, "rebootModem");
1815 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001816 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001817 request = (MainThreadRequest) msg.obj;
1818 boolean enable = (boolean) request.argument;
1819 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001820 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001821 PhoneConfigurationManager.getInstance()
1822 .enablePhone(request.phone, enable, onCompleted);
1823 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001824 }
Michele Berionne5e411512020-11-13 02:36:59 +00001825 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001826 ar = (AsyncResult) msg.obj;
1827 request = (MainThreadRequest) ar.userObj;
1828 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001829 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001830 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001831 if ((boolean) request.result) {
1832 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1833 updateModemStateMetrics();
1834 } else {
1835 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1836 + ar.exception);
1837 }
1838 notifyRequester(request);
1839 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001840 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001841 case CMD_GET_MODEM_STATUS:
1842 request = (MainThreadRequest) msg.obj;
1843 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1844 PhoneConfigurationManager.getInstance()
1845 .getPhoneStatusFromModem(request.phone, onCompleted);
1846 break;
1847 case EVENT_GET_MODEM_STATUS_DONE:
1848 ar = (AsyncResult) msg.obj;
1849 request = (MainThreadRequest) ar.userObj;
1850 int id = request.phone.getPhoneId();
1851 if (ar.exception == null && ar.result != null) {
1852 request.result = ar.result;
1853 //update the cache as modem status has changed
1854 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1855 (boolean) request.result);
1856 } else {
1857 // Return true if modem status cannot be retrieved. For most cases,
1858 // modem status is on. And for older version modems, GET_MODEM_STATUS
1859 // and disable modem are not supported. Modem is always on.
1860 // TODO: this should be fixed in R to support a third
1861 // status UNKNOWN b/131631629
1862 request.result = true;
1863 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1864 + ar.exception);
1865 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001866 notifyRequester(request);
1867 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001868 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1869 request = (MainThreadRequest) msg.obj;
1870 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1871 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1872 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1873 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1874 break;
1875 }
1876 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1877 ar = (AsyncResult) msg.obj;
1878 request = (MainThreadRequest) ar.userObj;
1879 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1880 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1881 args.second.accept(ar.exception == null);
1882 notifyRequester(request);
1883 break;
1884 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001885 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1886 request = (MainThreadRequest) msg.obj;
1887 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1888 Phone phone = getPhoneFromRequest(request);
1889 if (phone != null) {
1890 phone.getSystemSelectionChannels(onCompleted);
1891 } else {
1892 loge("getSystemSelectionChannels: No phone object");
1893 request.result = new ArrayList<RadioAccessSpecifier>();
1894 notifyRequester(request);
1895 }
1896 break;
1897 }
1898 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 if (ar.exception == null && ar.result != null) {
1902 request.result = ar.result;
1903 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001904 request.result = new IllegalStateException(
1905 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001906 if (ar.result == null) {
1907 loge("getSystemSelectionChannels: Empty response");
1908 } else {
1909 loge("getSystemSelectionChannels: Unknown exception");
1910 }
1911 }
1912 notifyRequester(request);
1913 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001914 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1915 ar = (AsyncResult) msg.obj;
1916 request = (MainThreadRequest) ar.userObj;
1917 if (ar.exception == null && ar.result != null) {
1918 request.result = ar.result;
1919 } else {
1920 request.result = -1;
1921 loge("Failed to set Forbidden Plmns");
1922 if (ar.result == null) {
1923 loge("setForbidenPlmns: Empty response");
1924 } else if (ar.exception != null) {
1925 loge("setForbiddenPlmns: Exception: " + ar.exception);
1926 request.result = -1;
1927 } else {
1928 loge("setForbiddenPlmns: Unknown exception");
1929 }
1930 }
1931 notifyRequester(request);
1932 break;
1933 case CMD_SET_FORBIDDEN_PLMNS:
1934 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001935 uiccPort = getUiccPortFromRequest(request);
1936 if (uiccPort == null) {
1937 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001938 request.result = -1;
1939 notifyRequester(request);
1940 break;
1941 }
1942 Pair<Integer, List<String>> setFplmnsArgs =
1943 (Pair<Integer, List<String>>) request.argument;
1944 appType = setFplmnsArgs.first;
1945 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001946 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001947 if (uiccApp == null) {
1948 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1949 request.result = -1;
1950 loge("Failed to get UICC App");
1951 notifyRequester(request);
1952 } else {
1953 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1954 ((SIMRecords) uiccApp.getIccRecords())
1955 .setForbiddenPlmns(onCompleted, fplmns);
1956 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001957 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001958 case CMD_ERASE_MODEM_CONFIG:
1959 request = (MainThreadRequest) msg.obj;
1960 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1961 defaultPhone.eraseModemConfig(onCompleted);
1962 break;
1963 case EVENT_ERASE_MODEM_CONFIG_DONE:
1964 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001965 break;
zoey chene02881a2019-12-30 16:11:23 +08001966
Kai Shif70f46f2021-03-03 13:59:46 -08001967 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1968 request = (MainThreadRequest) msg.obj;
1969 request.result = defaultPhone.eraseDataInSharedPreferences();
1970 notifyRequester(request);
1971 break;
1972
zoey chene02881a2019-12-30 16:11:23 +08001973 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1974 request = (MainThreadRequest) msg.obj;
1975 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1976 Pair<String, String> changed = (Pair<String, String>) request.argument;
1977 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1978 changed.first, changed.second, onCompleted);
1979 break;
1980 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1981 ar = (AsyncResult) msg.obj;
1982 request = (MainThreadRequest) ar.userObj;
1983 if (ar.exception == null) {
1984 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001985 // If the operation is successful, update the PIN storage
1986 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1987 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001988 UiccController.getInstance().getPinStorage()
1989 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001990 } else {
1991 request.result = msg.arg1;
1992 }
1993 notifyRequester(request);
1994 break;
1995
Michele Berionne5e411512020-11-13 02:36:59 +00001996 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001997 request = (MainThreadRequest) msg.obj;
1998 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1999 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2000 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2001 enabled.first, enabled.second, onCompleted);
2002 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002003 }
zoey chene02881a2019-12-30 16:11:23 +08002004 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007 if (ar.exception == null) {
2008 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002009 // If the operation is successful, update the PIN storage
2010 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2011 int phoneId = getPhoneFromRequest(request).getPhoneId();
2012 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002013 UiccController.getInstance().getPinStorage()
2014 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002015 } else {
2016 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2017 }
zoey chene02881a2019-12-30 16:11:23 +08002018 } else {
2019 request.result = msg.arg1;
2020 }
Michele Berionne5e411512020-11-13 02:36:59 +00002021
2022
zoey chene02881a2019-12-30 16:11:23 +08002023 notifyRequester(request);
2024 break;
2025
Peter Wangdafb9ac2020-01-15 14:13:38 -08002026 case MSG_NOTIFY_USER_ACTIVITY:
2027 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002028 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002029 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2030 getDefaultPhone().getContext().sendBroadcastAsUser(
2031 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2032 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002033
2034 case CMD_SET_DATA_THROTTLING: {
2035 request = (MainThreadRequest) msg.obj;
2036 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2037 DataThrottlingRequest dataThrottlingRequest =
2038 (DataThrottlingRequest) request.argument;
2039 Phone phone = getPhoneFromRequest(request);
2040 if (phone != null) {
2041 phone.setDataThrottling(onCompleted,
2042 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2043 dataThrottlingRequest.getCompletionDurationMillis());
2044 } else {
2045 loge("setDataThrottling: No phone object");
2046 request.result =
2047 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2048 notifyRequester(request);
2049 }
2050
2051 break;
2052 }
2053 case EVENT_SET_DATA_THROTTLING_DONE:
2054 ar = (AsyncResult) msg.obj;
2055 request = (MainThreadRequest) ar.userObj;
2056
2057 if (ar.exception == null) {
2058 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2059 } else if (ar.exception instanceof CommandException) {
2060 loge("setDataThrottling: CommandException: " + ar.exception);
2061 CommandException.Error error =
2062 ((CommandException) (ar.exception)).getCommandError();
2063
2064 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2065 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002066 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002067 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2068 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002069 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2070 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002071 } else {
2072 request.result =
2073 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2074 }
2075 } else {
2076 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2077 }
2078 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2079 notifyRequester(request);
2080 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002081
2082 case CMD_SET_SIM_POWER: {
2083 request = (MainThreadRequest) msg.obj;
2084 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2085 request = (MainThreadRequest) msg.obj;
2086 int stateToSet =
2087 ((Pair<Integer, IIntegerConsumer>)
2088 request.argument).first;
2089 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2090 break;
2091 }
2092 case EVENT_SET_SIM_POWER_DONE: {
2093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095 IIntegerConsumer callback =
2096 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2097 if (ar.exception != null) {
2098 loge("setSimPower exception: " + ar.exception);
2099 int errorCode = TelephonyManager.CallForwardingInfoCallback
2100 .RESULT_ERROR_UNKNOWN;
2101 if (ar.exception instanceof CommandException) {
2102 CommandException.Error error =
2103 ((CommandException) (ar.exception)).getCommandError();
2104 if (error == CommandException.Error.SIM_ERR) {
2105 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2106 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2107 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2108 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2109 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2110 } else {
2111 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2112 }
2113 }
2114 try {
2115 callback.accept(errorCode);
2116 } catch (RemoteException e) {
2117 // Ignore if the remote process is no longer available to call back.
2118 Log.w(LOG_TAG, "setSimPower: callback not available.");
2119 }
2120 } else {
2121 try {
2122 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2123 } catch (RemoteException e) {
2124 // Ignore if the remote process is no longer available to call back.
2125 Log.w(LOG_TAG, "setSimPower: callback not available.");
2126 }
2127 }
2128 break;
2129 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002130 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2131 request = (MainThreadRequest) msg.obj;
2132
2133 final Phone phone = getPhoneFromRequest(request);
2134 if (phone == null || phone.getServiceStateTracker() == null) {
2135 request.result = new IllegalStateException("Phone or SST is null");
2136 notifyRequester(request);
2137 break;
2138 }
2139
2140 Pair<Integer, SignalStrengthUpdateRequest> pair =
2141 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2142 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2143 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002144 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002145 request.subId, pair.first /*callingUid*/,
2146 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002147 break;
2148 }
2149 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2150 ar = (AsyncResult) msg.obj;
2151 request = (MainThreadRequest) ar.userObj;
2152 // request.result will be the exception of ar if present, true otherwise.
2153 // Be cautious not to leave result null which will wait() forever
2154 request.result = ar.exception != null ? ar.exception : true;
2155 notifyRequester(request);
2156 break;
2157 }
2158 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2159 request = (MainThreadRequest) msg.obj;
2160
2161 Phone phone = getPhoneFromRequest(request);
2162 if (phone == null || phone.getServiceStateTracker() == null) {
2163 request.result = new IllegalStateException("Phone or SST is null");
2164 notifyRequester(request);
2165 break;
2166 }
2167
2168 Pair<Integer, SignalStrengthUpdateRequest> pair =
2169 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2170 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2171 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002172 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002173 request.subId, pair.first /*callingUid*/,
2174 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002175 break;
2176 }
2177 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2178 ar = (AsyncResult) msg.obj;
2179 request = (MainThreadRequest) ar.userObj;
2180 request.result = ar.exception != null ? ar.exception : true;
2181 notifyRequester(request);
2182 break;
2183 }
Jordan Liu109698e2020-11-24 14:50:34 -08002184
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002185 case CMD_GET_SLICING_CONFIG: {
2186 request = (MainThreadRequest) msg.obj;
2187 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2188 request.phone.getSlicingConfig(onCompleted);
2189 break;
2190 }
2191 case EVENT_GET_SLICING_CONFIG_DONE: {
2192 ar = (AsyncResult) msg.obj;
2193 request = (MainThreadRequest) ar.userObj;
2194 ResultReceiver result = (ResultReceiver) request.argument;
2195
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002196 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002197 Bundle bundle = new Bundle();
2198 int resultCode = 0;
2199 if (ar.exception != null) {
2200 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2201 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002202 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002203 } else if (ar.result == null) {
2204 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002205 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002206 } else {
2207 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002208 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2209 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002210 }
2211
2212 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002213 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002214 }
2215 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2216 result.send(resultCode, bundle);
2217 notifyRequester(request);
2218 break;
2219 }
2220
Sarah Chin71b3a852022-09-28 15:54:19 -07002221 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002222 request = (MainThreadRequest) msg.obj;
2223 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002224 PurchasePremiumCapabilityArgument arg =
2225 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002226 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2227 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002228 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002229 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002230
Sarah Chin71b3a852022-09-28 15:54:19 -07002231 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002232 ar = (AsyncResult) msg.obj;
2233 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002234 PurchasePremiumCapabilityArgument arg =
2235 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236 try {
2237 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002239 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002241 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242 + TelephonyManager.convertPurchaseResultToString(result));
2243 } catch (RemoteException e) {
2244 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246 + " failed: " + e;
2247 if (DBG) log(logStr);
2248 AnomalyReporter.reportAnomaly(
2249 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2250 }
2251 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002252 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002253
Michele Berionne5e411512020-11-13 02:36:59 +00002254 case CMD_PREPARE_UNATTENDED_REBOOT:
2255 request = (MainThreadRequest) msg.obj;
2256 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002257 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002258 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002259 notifyRequester(request);
2260 break;
2261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 default:
2263 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2264 break;
2265 }
2266 }
Jake Hambye994d462014-02-03 13:10:13 -08002267
Pengquan Menga1bb6272018-09-06 09:59:22 -07002268 private void notifyRequester(MainThreadRequest request) {
2269 synchronized (request) {
2270 request.notifyAll();
2271 }
2272 }
2273
Jake Hambye994d462014-02-03 13:10:13 -08002274 private void handleNullReturnEvent(Message msg, String command) {
2275 AsyncResult ar = (AsyncResult) msg.obj;
2276 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2277 if (ar.exception == null) {
2278 request.result = true;
2279 } else {
2280 request.result = false;
2281 if (ar.exception instanceof CommandException) {
2282 loge(command + ": CommandException: " + ar.exception);
2283 } else {
2284 loge(command + ": Unknown exception");
2285 }
2286 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002287 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
2291 /**
2292 * Posts the specified command to be executed on the main thread,
2293 * waits for the request to complete, and returns the result.
2294 * @see #sendRequestAsync
2295 */
2296 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002297 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2298 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -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, WorkSource workSource) {
2307 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002308 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -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 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002316 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002317 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2318 }
2319
2320 /**
2321 * Posts the specified command to be executed on the main thread,
2322 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2323 * if not timeout or null otherwise.
2324 * @see #sendRequestAsync
2325 */
2326 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2327 long timeoutInMs) {
2328 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002329 }
2330
2331 /**
2332 * Posts the specified command to be executed on the main thread,
2333 * waits for the request to complete, and returns the result.
2334 * @see #sendRequestAsync
2335 */
Nathan Harold92bed182018-10-12 18:16:49 -07002336 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002337 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002338 }
2339
2340 /**
2341 * Posts the specified command to be executed on the main thread,
2342 * waits for the request to complete, and returns the result.
2343 * @see #sendRequestAsync
2344 */
2345 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002346 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2347 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002348 }
2349
2350 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002351 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2352 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2353 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002354 * @see #sendRequestAsync
2355 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002356 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2357 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2359 throw new RuntimeException("This method will deadlock if called from the main thread.");
2360 }
2361
Nathan Harold92bed182018-10-12 18:16:49 -07002362 MainThreadRequest request = null;
2363 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2364 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2365 } else if (phone != null) {
2366 request = new MainThreadRequest(argument, phone, workSource);
2367 } else {
2368 request = new MainThreadRequest(argument, subId, workSource);
2369 }
2370
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 Message msg = mMainThreadHandler.obtainMessage(command, request);
2372 msg.sendToTarget();
2373
Rambo Wang0f050d82021-02-12 11:43:36 -08002374
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002376 if (timeoutInMs >= 0) {
2377 // Wait for at least timeoutInMs before returning null request result
2378 long now = SystemClock.elapsedRealtime();
2379 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002380 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002381 try {
2382 request.wait(deadline - now);
2383 } catch (InterruptedException e) {
2384 // Do nothing, go back and check if request is completed or timeout
2385 } finally {
2386 now = SystemClock.elapsedRealtime();
2387 }
2388 }
2389 } else {
2390 // Wait for the request to complete
2391 while (request.result == null) {
2392 try {
2393 request.wait();
2394 } catch (InterruptedException e) {
2395 // Do nothing, go back and wait until the request is complete
2396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 }
2398 }
2399 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002400 if (request.result == null) {
2401 Log.wtf(LOG_TAG,
2402 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 return request.result;
2405 }
2406
2407 /**
2408 * Asynchronous ("fire and forget") version of sendRequest():
2409 * Posts the specified command to be executed on the main thread, and
2410 * returns immediately.
2411 * @see #sendRequest
2412 */
2413 private void sendRequestAsync(int command) {
2414 mMainThreadHandler.sendEmptyMessage(command);
2415 }
2416
2417 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002418 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002419 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002420 */
2421 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002422 sendRequestAsync(command, argument, null, null);
2423 }
2424
2425 /**
2426 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2427 * @see {@link #sendRequest(int,Object)}
2428 */
2429 private void sendRequestAsync(
2430 int command, Object argument, Phone phone, WorkSource workSource) {
2431 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002432 Message msg = mMainThreadHandler.obtainMessage(command, request);
2433 msg.sendToTarget();
2434 }
2435
2436 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 * Initialize the singleton PhoneInterfaceManager instance.
2438 * This is only done once, at startup, from PhoneApp.onCreate().
2439 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002440 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 synchronized (PhoneInterfaceManager.class) {
2442 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002443 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 } else {
2445 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2446 }
2447 return sInstance;
2448 }
2449 }
2450
2451 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002452 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002454 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002456 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002457 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002458 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2460 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002461 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002462 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002463 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002464 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002465 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002466 mPackageManager = app.getPackageManager();
Tyler Gunn64144d92022-03-17 14:16:41 -07002467 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 publish();
arunvoddud7401012022-12-15 16:08:12 +00002469 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 }
2471
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002472 @VisibleForTesting
2473 public SharedPreferences getSharedPreferences() {
2474 return mTelephonySharedPreferences;
2475 }
2476
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002477 /**
2478 * Get the default phone for this device.
2479 */
2480 @VisibleForTesting
2481 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002482 Phone thePhone = getPhone(getDefaultSubscription());
2483 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2484 }
2485
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 private void publish() {
2487 if (DBG) log("publish: " + this);
2488
Peter Wangc035ce42020-01-08 21:00:22 -08002489 TelephonyFrameworkInitializer
2490 .getTelephonyServiceManager()
2491 .getTelephonyServiceRegisterer()
2492 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
2494
Stuart Scott584921c2015-01-15 17:10:34 -08002495 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002496 if (request.phone != null) {
2497 return request.phone;
2498 } else {
2499 return getPhoneFromSubId(request.subId);
2500 }
2501 }
2502
2503 private Phone getPhoneFromSubId(int subId) {
2504 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2505 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002506 }
2507
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002508 /**
2509 * Get phone object associated with a subscription.
2510 * Return default phone if phone object associated with subscription is null
2511 * @param subId - subscriptionId
2512 * @return phone object associated with a subscription or default phone if null.
2513 */
Ling Mac28f0212023-03-24 16:07:15 -07002514 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002515 Phone phone = getPhoneFromSubId(subId);
2516 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002517 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002518 phone = getDefaultPhone();
2519 }
2520 return phone;
2521 }
2522
Rambo Wange53e07d2022-05-10 13:01:13 -07002523 @Nullable
2524 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002525 Phone phone = getPhoneFromRequest(request);
2526 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002527 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002528 }
2529
Ling Mac28f0212023-03-24 16:07:15 -07002530 /**
2531 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2532 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2533 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2534 * @return The Phone associated the sub Id
2535 */
2536 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002537 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
Kai Shif70f46f2021-03-03 13:59:46 -08002540 private void sendEraseModemConfig(@NonNull Phone phone) {
2541 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2542 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2543 }
2544
2545 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2546 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2547 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002548 }
2549
Peter Wang44b186e2020-01-13 23:33:09 -08002550 private boolean isImsAvailableOnDevice() {
2551 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2552 if (pm == null) {
2553 // For some reason package manger is not available.. This will fail internally anyway,
2554 // so do not throw error and allow.
2555 return true;
2556 }
2557 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2558 }
2559
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2562 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2563
Wink Savilleadd7cc52014-09-08 14:23:09 -07002564 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002565 }
2566
Wink Savilleb564aae2014-10-23 10:18:09 -07002567 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 if (DBG) log("dial: " + number);
2569 // No permission check needed here: This is just a wrapper around the
2570 // ACTION_DIAL intent, which is available to any app since it puts up
2571 // the UI before it does anything.
2572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 String url = createTelUrl(number);
2576 if (url == null) {
2577 return;
2578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580 // PENDING: should we just silently fail if phone is offhook or ringing?
2581 PhoneConstants.State state = mCM.getState(subId);
2582 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2583 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2584 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2585 mApp.startActivity(intent);
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 }
2590 }
2591
2592 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002593 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002594 }
2595
Wink Savilleb564aae2014-10-23 10:18:09 -07002596 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 if (DBG) log("call: " + number);
2598
2599 // This is just a wrapper around the ACTION_CALL intent, but we still
2600 // need to do a permission check since we're calling startActivity()
2601 // from the context of the phone app.
2602 enforceCallPermission();
2603
Jordan Liu1617b712019-07-10 15:06:26 -07002604 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 != AppOpsManager.MODE_ALLOWED) {
2606 return;
2607 }
2608
joonhunshin4ac60942023-11-15 15:23:39 +00002609 enforceTelephonyFeatureWithException(callingPackage,
2610 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 String url = createTelUrl(number);
2615 if (url == null) {
2616 return;
2617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 boolean isValid = false;
2620 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2621 if (slist != null) {
2622 for (SubscriptionInfo subInfoRecord : slist) {
2623 if (subInfoRecord.getSubscriptionId() == subId) {
2624 isValid = true;
2625 break;
2626 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002627 }
Wink Saville08874612014-08-31 19:19:58 -07002628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 if (!isValid) {
2630 return;
2631 }
Wink Saville08874612014-08-31 19:19:58 -07002632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2634 intent.putExtra(SUBSCRIPTION_KEY, subId);
2635 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2636 mApp.startActivity(intent);
2637 } finally {
2638 Binder.restoreCallingIdentity(identity);
2639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 }
2641
Wink Savilleb564aae2014-10-23 10:18:09 -07002642 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002643 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002644 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2645 }
2646
Wink Savilleb564aae2014-10-23 10:18:09 -07002647 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002648 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002649 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2650 }
2651
Wink Savilleb564aae2014-10-23 10:18:09 -07002652 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654
joonhunshin4ac60942023-11-15 15:23:39 +00002655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2656 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2657 "supplyPinReportResultForSubscriber");
2658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002661 Phone phone = getPhone(subId);
2662 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 checkSimPin.start();
2664 return checkSimPin.unlockSim(null, pin);
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 }
2669
Wink Savilleb564aae2014-10-23 10:18:09 -07002670 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672
joonhunshin4ac60942023-11-15 15:23:39 +00002673 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2674 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 final long identity = Binder.clearCallingIdentity();
2677 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002678 Phone phone = getPhone(subId);
2679 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 checkSimPuk.start();
2681 return checkSimPuk.unlockSim(puk, pin);
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 }
2686
2687 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002688 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 * a synchronous one.
2690 */
2691 private static class UnlockSim extends Thread {
2692
2693 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002694 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695
2696 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002697 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2698 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699
2700 // For replies from SimCard interface
2701 private Handler mHandler;
2702
2703 // For async handler to identify request type
2704 private static final int SUPPLY_PIN_COMPLETE = 100;
2705
Michele Berionne5e411512020-11-13 02:36:59 +00002706 UnlockSim(int phoneId, IccCard simCard) {
2707 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 mSimCard = simCard;
2709 }
2710
2711 @Override
2712 public void run() {
2713 Looper.prepare();
2714 synchronized (UnlockSim.this) {
2715 mHandler = new Handler() {
2716 @Override
2717 public void handleMessage(Message msg) {
2718 AsyncResult ar = (AsyncResult) msg.obj;
2719 switch (msg.what) {
2720 case SUPPLY_PIN_COMPLETE:
2721 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2722 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002723 mRetryCount = msg.arg1;
2724 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002725 CommandException.Error error = null;
2726 if (ar.exception instanceof CommandException) {
2727 error = ((CommandException) (ar.exception))
2728 .getCommandError();
2729 }
2730 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002731 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002732 } else if (error == CommandException.Error.ABORTED) {
2733 /* When UiccCardApp dispose, handle message and return
2734 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002735 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002736 } else {
2737 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2738 }
2739 } else {
2740 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 mDone = true;
2743 UnlockSim.this.notifyAll();
2744 }
2745 break;
2746 }
2747 }
2748 };
2749 UnlockSim.this.notifyAll();
2750 }
2751 Looper.loop();
2752 }
2753
2754 /*
2755 * Use PIN or PUK to unlock SIM card
2756 *
2757 * If PUK is null, unlock SIM card with PIN
2758 *
2759 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302760 *
2761 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2762 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 */
Wink Saville9de0f752013-10-22 19:04:03 -07002764 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765
2766 while (mHandler == null) {
2767 try {
2768 wait();
2769 } catch (InterruptedException e) {
2770 Thread.currentThread().interrupt();
2771 }
2772 }
2773 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2774
2775 if (puk == null) {
2776 mSimCard.supplyPin(pin, callback);
2777 } else {
2778 mSimCard.supplyPuk(puk, pin, callback);
2779 }
2780
2781 while (!mDone) {
2782 try {
2783 Log.d(LOG_TAG, "wait for done");
2784 wait();
2785 } catch (InterruptedException e) {
2786 // Restore the interrupted status
2787 Thread.currentThread().interrupt();
2788 }
2789 }
2790 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002791 int[] resultArray = new int[2];
2792 resultArray[0] = mResult;
2793 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002794
2795 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002796 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002797 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302798 // This instance is no longer reused, so quit its thread's looper.
2799 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002800
Wink Saville9de0f752013-10-22 19:04:03 -07002801 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 }
2803 }
2804
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002805 /**
2806 * This method has been removed due to privacy and stability concerns.
2807 */
2808 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002810 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2811 return;
Wink Saville36469e72014-06-11 15:17:00 -07002812 }
2813
Nathan Harold1f889d82020-06-04 17:05:26 -07002814 @Override
2815 public void updateServiceLocationWithPackageName(String callingPackage) {
2816 mApp.getSystemService(AppOpsManager.class)
2817 .checkPackage(Binder.getCallingUid(), callingPackage);
2818
Nathan Haroldf096d982020-11-18 17:18:06 -08002819 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002820 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2821 // Callers targeting S have no business invoking this method.
2822 return;
2823 }
2824
2825 LocationAccessPolicy.LocationPermissionResult locationResult =
2826 LocationAccessPolicy.checkLocationPermission(mApp,
2827 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2828 .setCallingPackage(callingPackage)
2829 .setCallingFeatureId(null)
2830 .setCallingPid(Binder.getCallingPid())
2831 .setCallingUid(Binder.getCallingUid())
2832 .setMethod("updateServiceLocation")
2833 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2834 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2835 .build());
2836 // Apps that lack location permission have no business calling this method;
2837 // however, because no permission was declared in the public API, denials must
2838 // all be "soft".
2839 switch (locationResult) {
2840 case DENIED_HARD: /* fall through */
2841 case DENIED_SOFT:
2842 return;
2843 }
2844
2845 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
Ling Mac28f0212023-03-24 16:07:15 -07002848 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849 } finally {
2850 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 }
2853
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002854 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002855 @Override
2856 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002857 return isRadioOnWithFeature(callingPackage, null);
2858 }
2859
2860
2861 @Override
2862 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2863 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2864 callingFeatureId);
2865 }
2866
2867 @Deprecated
2868 @Override
2869 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2870 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002871 }
2872
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002873 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002874 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2875 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002877 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002878 return false;
2879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
joonhunshin4ac60942023-11-15 15:23:39 +00002881 enforceTelephonyFeatureWithException(callingPackage,
2882 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 return isRadioOnForSubscriber(subId);
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
2889 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002890 }
2891
2892 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 final Phone phone = getPhone(subId);
2896 if (phone != null) {
2897 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2898 } else {
2899 return false;
2900 }
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002904 }
2905
2906 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002907 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 }
Wink Saville36469e72014-06-11 15:17:00 -07002909
Wink Savilleb564aae2014-10-23 10:18:09 -07002910 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912
joonhunshin4ac60942023-11-15 15:23:39 +00002913 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2914 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2915
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 final Phone phone = getPhone(subId);
2919 if (phone != null) {
2920 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2921 }
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002924 }
Wink Saville36469e72014-06-11 15:17:00 -07002925 }
2926
2927 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002928 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002929 }
2930
Wink Savilleb564aae2014-10-23 10:18:09 -07002931 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 final Phone phone = getPhone(subId);
2937 if (phone == null) {
2938 return false;
2939 }
2940 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2941 toggleRadioOnOffForSubscriber(subId);
2942 }
2943 return true;
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
Wink Saville36469e72014-06-11 15:17:00 -07002948
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002949 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002950 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002951
2952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2953 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2954
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002955 /*
2956 * If any of the Radios are available, it will need to be
2957 * shutdown. So return true if any Radio is available.
2958 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2962 Phone phone = PhoneFactory.getPhone(i);
2963 if (phone != null && phone.isRadioAvailable()) return true;
2964 }
2965 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2966 return false;
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002969 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002970 }
2971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002973 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 enforceModifyPermission();
2975
joonhunshin4ac60942023-11-15 15:23:39 +00002976 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2977 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
2978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2982 logv("Shutting down Phone " + i);
2983 shutdownRadioUsingPhoneId(i);
2984 }
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002987 }
2988 }
2989
2990 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002991 Phone phone = PhoneFactory.getPhone(phoneId);
2992 if (phone != null && phone.isRadioAvailable()) {
2993 phone.shutdownRadio();
2994 }
2995 }
2996
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002998 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999
Ling Ma83dc5ea2023-01-12 15:06:04 -08003000 if (!turnOn) {
3001 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3002 }
3003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3007 if (defaultPhone != null) {
3008 defaultPhone.setRadioPower(turnOn);
3009 return true;
3010 } else {
3011 loge("There's no default phone.");
3012 return false;
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003016 }
Wink Saville36469e72014-06-11 15:17:00 -07003017 }
3018
Wink Savilleb564aae2014-10-23 10:18:09 -07003019 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
Ling Ma83dc5ea2023-01-12 15:06:04 -08003022 if (!turnOn) {
3023 log("setRadioPowerForSubscriber off: subId=" + subId
3024 + ",callingPackage=" + getCurrentPackageName());
3025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 final Phone phone = getPhone(subId);
3029 if (phone != null) {
3030 phone.setRadioPower(turnOn);
3031 return true;
3032 } else {
3033 return false;
3034 }
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 }
3039
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003040 /**
3041 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3042 * no reason to power it off. When any of the voters want to power it off, it will be turned
3043 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3044 * powering it off, and these radio off votes will be cleared.
3045 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3046 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3047 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3048 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3049 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3050 * check its vote.
3051 *
3052 * @param subId The subscription ID.
3053 * @param reason The reason for powering off radio.
3054 * @return true on success and false on failure.
3055 */
3056 public boolean requestRadioPowerOffForReason(int subId,
3057 @TelephonyManager.RadioPowerReason int reason) {
3058 enforceModifyPermission();
3059
joonhunshin4ac60942023-11-15 15:23:39 +00003060 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3061 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3062
Ling Ma83dc5ea2023-01-12 15:06:04 -08003063 log("requestRadioPowerOffForReason: subId=" + subId
3064 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003065 final long identity = Binder.clearCallingIdentity();
3066 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003067 boolean result = false;
3068 for (Phone phone : PhoneFactory.getPhones()) {
3069 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003070 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003071 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003072 if (!result) {
3073 loge("requestRadioPowerOffForReason: no phone exists");
3074 }
3075 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
3081 /**
3082 * Remove the vote on powering off the radio for a reason, as requested by
3083 * {@link requestRadioPowerOffForReason}.
3084 *
3085 * @param subId The subscription ID.
3086 * @param reason The reason for powering off radio.
3087 * @return true on success and false on failure.
3088 */
3089 public boolean clearRadioPowerOffForReason(int subId,
3090 @TelephonyManager.RadioPowerReason int reason) {
3091 enforceModifyPermission();
3092
joonhunshin4ac60942023-11-15 15:23:39 +00003093 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3094 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3095
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003096 final long identity = Binder.clearCallingIdentity();
3097 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003098 boolean result = false;
3099 for (Phone phone : PhoneFactory.getPhones()) {
3100 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003101 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003102 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003103 if (!result) {
3104 loge("clearRadioPowerOffForReason: no phone exists");
3105 }
3106 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
3110 }
3111
3112 /**
3113 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3114 *
3115 * @param subId The subscription ID.
3116 * @param callingPackage The package making the call.
3117 * @param callingFeatureId The feature in the package.
3118 * @return List of reasons for powering off radio.
3119 */
3120 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3121 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3122
joonhunshin4ac60942023-11-15 15:23:39 +00003123 enforceTelephonyFeatureWithException(callingPackage,
3124 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3125
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003126 final long identity = Binder.clearCallingIdentity();
3127 List result = new ArrayList();
3128 try {
3129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3130 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3131 return result;
3132 }
3133
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003134 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003135 if (phone != null) {
3136 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003137 } else {
3138 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003139 }
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
3143 return result;
3144 }
3145
Wink Saville36469e72014-06-11 15:17:00 -07003146 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003148 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150
joonhunshin4ac60942023-11-15 15:23:39 +00003151 enforceTelephonyFeatureWithException(callingPackage,
3152 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003154 final long identity = Binder.clearCallingIdentity();
3155 try {
Jack Yu285100e2022-12-02 22:48:35 -08003156 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 final Phone phone = getPhone(subId);
3158 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003159 phone.getDataSettingsManager().setDataEnabled(
3160 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161 return true;
3162 } else {
3163 return false;
3164 }
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 }
3169
Wink Saville36469e72014-06-11 15:17:00 -07003170 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003172 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174
joonhunshin4ac60942023-11-15 15:23:39 +00003175 enforceTelephonyFeatureWithException(callingPackage,
3176 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003178 final long identity = Binder.clearCallingIdentity();
3179 try {
Jack Yu285100e2022-12-02 22:48:35 -08003180 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181 final Phone phone = getPhone(subId);
3182 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003183 phone.getDataSettingsManager().setDataEnabled(
3184 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 return true;
3186 } else {
3187 return false;
3188 }
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 }
3193
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003195 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003196 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3197 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 final Phone phone = getPhone(subId);
3202 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003203 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 } else {
3205 return false;
3206 }
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 }
3211
3212 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003213 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003214 }
3215
pkanwarae03a6b2016-11-06 20:37:09 -08003216 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 enforceCallPermission();
3218
joonhunshin4ac60942023-11-15 15:23:39 +00003219 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3220 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3225 return;
3226 }
3227 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3228 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
pkanwar32d516d2016-10-14 19:37:38 -07003232 };
3233
Wink Savilleb564aae2014-10-23 10:18:09 -07003234 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236
joonhunshin4ac60942023-11-15 15:23:39 +00003237 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3238 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3243 return false;
3244 }
3245 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 }
3250
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003251 /**
3252 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3253 * tag on getCallState Binder call.
3254 */
3255 @Deprecated
3256 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003258 if (CompatChanges.isChangeEnabled(
3259 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3260 Binder.getCallingUid())) {
3261 // Do not allow this API to be called on API version 31+, it should only be
3262 // called on old apps using this Binder call directly.
3263 throw new SecurityException("This method can only be used for applications "
3264 + "targeting API version 30 or less.");
3265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266 final long identity = Binder.clearCallingIdentity();
3267 try {
Ling Mac28f0212023-03-24 16:07:15 -07003268 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3269 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
3276 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3277 if (CompatChanges.isChangeEnabled(
3278 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3279 Binder.getCallingUid())) {
3280 // Check READ_PHONE_STATE for API version 31+
3281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3282 featureId, "getCallStateForSubscription")) {
3283 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3284 + "targeting API level 31+.");
3285 }
3286 }
joonhunshin4ac60942023-11-15 15:23:39 +00003287
3288 enforceTelephonyFeatureWithException(callingPackage,
3289 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3290
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3295 PhoneConstantConversions.convertCallState(phone.getState());
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003299 }
3300
Sanket Padawe356d7632015-06-22 14:03:32 -07003301 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003302 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003303 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003304 }
3305
3306 @Override
3307 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003308 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3309 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 final long identity = Binder.clearCallingIdentity();
3312 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003313 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003315 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 } else {
3317 return PhoneConstantConversions.convertDataState(
3318 PhoneConstants.DataState.DISCONNECTED);
3319 }
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003323 }
3324
Sanket Padawe356d7632015-06-22 14:03:32 -07003325 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003326 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003327 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003328 }
3329
3330 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003331 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003332 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3333 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 final long identity = Binder.clearCallingIdentity();
3336 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003337 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003339 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 } else {
3341 return TelephonyManager.DATA_ACTIVITY_NONE;
3342 }
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003346 }
3347
3348 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003349 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003350 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003351 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003352
3353 LocationAccessPolicy.LocationPermissionResult locationResult =
3354 LocationAccessPolicy.checkLocationPermission(mApp,
3355 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3356 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003357 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003358 .setCallingPid(Binder.getCallingPid())
3359 .setCallingUid(Binder.getCallingUid())
3360 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003361 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003362 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3363 .build());
3364 switch (locationResult) {
3365 case DENIED_HARD:
3366 throw new SecurityException("Not allowed to access cell location");
3367 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003368 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3369 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003370 }
3371
joonhunshin4ac60942023-11-15 15:23:39 +00003372 enforceTelephonyFeatureWithException(callingPackage,
3373 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3374
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003379 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003380 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
Svetoslav64fad262015-04-14 14:35:21 -07003384 }
3385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003387 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003388 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3389 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3390
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003391 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3392 // registered cell info, so return a NULL country instead.
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003395 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3396 // Get default phone in this case.
3397 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3398 }
Jack Yu285100e2022-12-02 22:48:35 -08003399 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003401 if (phone == null) return "";
3402 ServiceStateTracker sst = phone.getServiceStateTracker();
3403 if (sst == null) return "";
3404 LocaleTracker lt = sst.getLocaleTracker();
3405 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003406 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003410 }
3411
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003412 /**
3413 * This method was removed due to potential issues caused by performing partial
3414 * updates of service state, and lack of a credible use case.
3415 *
3416 * This has the ability to break the telephony implementation by disabling notification of
3417 * changes in device connectivity. DO NOT USE THIS!
3418 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003419 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003420 public void enableLocationUpdates() {
3421 mApp.enforceCallingOrSelfPermission(
3422 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423 }
3424
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003425 /**
3426 * This method was removed due to potential issues caused by performing partial
3427 * updates of service state, and lack of a credible use case.
3428 *
3429 * This has the ability to break the telephony implementation by disabling notification of
3430 * changes in device connectivity. DO NOT USE THIS!
3431 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003432 @Override
3433 public void disableLocationUpdates() {
3434 mApp.enforceCallingOrSelfPermission(
3435 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003436 }
3437
3438 @Override
3439 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003440 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3441 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003442 try {
3443 mApp.getSystemService(AppOpsManager.class)
3444 .checkPackage(Binder.getCallingUid(), callingPackage);
3445 } catch (SecurityException e) {
3446 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3447 throw e;
3448 }
3449
Nathan Haroldf096d982020-11-18 17:18:06 -08003450 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003451 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3452 throw new SecurityException(
3453 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3454 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003455
Jordan Liu1617b712019-07-10 15:06:26 -07003456 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003457 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3458 return null;
3459 }
Svetoslav64fad262015-04-14 14:35:21 -07003460
joonhunshin4ac60942023-11-15 15:23:39 +00003461 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3462 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3463
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003464 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003466 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003467 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468
Nathan Haroldf180aac2018-06-01 18:43:55 -07003469 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3470 for (CellInfo ci : info) {
3471 if (ci instanceof CellInfoGsm) {
3472 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3473 } else if (ci instanceof CellInfoWcdma) {
3474 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003477 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 }
3479
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003480 private List<CellInfo> getCachedCellInfo() {
3481 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3482 for (Phone phone : PhoneFactory.getPhones()) {
3483 List<CellInfo> info = phone.getAllCellInfo();
3484 if (info != null) cellInfos.addAll(info);
3485 }
3486 return cellInfos;
3487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488
3489 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003490 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003491 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003492 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003493
3494 LocationAccessPolicy.LocationPermissionResult locationResult =
3495 LocationAccessPolicy.checkLocationPermission(mApp,
3496 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3497 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003498 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003499 .setCallingPid(Binder.getCallingPid())
3500 .setCallingUid(Binder.getCallingUid())
3501 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003502 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003503 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3504 .build());
3505 switch (locationResult) {
3506 case DENIED_HARD:
3507 throw new SecurityException("Not allowed to access cell info");
3508 case DENIED_SOFT:
3509 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510 }
3511
Nathan Haroldf096d982020-11-18 17:18:06 -08003512 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003513 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3514 return getCachedCellInfo();
3515 }
3516
joonhunshin4ac60942023-11-15 15:23:39 +00003517 enforceTelephonyFeatureWithException(callingPackage,
3518 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3519
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003520 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3525 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003526 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003527 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528 if (info != null) cellInfos.addAll(info);
3529 }
3530 return cellInfos;
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534 }
3535
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003536 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003537 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3538 String callingFeatureId) {
3539 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3540 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003541 }
3542
3543 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003544 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3545 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003546 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003547 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003548 }
3549
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003550 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3551 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003552 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003553 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003554
3555 LocationAccessPolicy.LocationPermissionResult locationResult =
3556 LocationAccessPolicy.checkLocationPermission(mApp,
3557 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3558 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003559 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003560 .setCallingPid(Binder.getCallingPid())
3561 .setCallingUid(Binder.getCallingUid())
3562 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003563 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3564 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003565 .build());
3566 switch (locationResult) {
3567 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003568 if (TelephonyPermissions
3569 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003570 // Safetynet logging for b/154934934
3571 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3572 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003573 throw new SecurityException("Not allowed to access cell info");
3574 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003575 if (TelephonyPermissions
3576 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003577 // Safetynet logging for b/154934934
3578 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3579 }
Nathan Harold5320c422019-05-09 10:26:08 -07003580 try {
3581 cb.onCellInfo(new ArrayList<CellInfo>());
3582 } catch (RemoteException re) {
3583 // Drop without consequences
3584 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003585 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003586 }
3587
joonhunshin4ac60942023-11-15 15:23:39 +00003588 enforceTelephonyFeatureWithException(callingPackage,
3589 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003590
3591 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003592 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3593
3594 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3595 }
3596
3597 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003598 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003599 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601
3602 final long identity = Binder.clearCallingIdentity();
3603 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003604 Phone phone = getPhone(subId);
3605 if (phone == null) {
3606 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3607 } else {
3608 phone.setCellInfoListRate(rateInMillis, workSource);
3609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003613 }
3614
Shishir Agrawala9f32182016-04-12 12:00:16 -07003615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003616 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003617 Phone phone = PhoneFactory.getPhone(slotIndex);
3618 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003619 return null;
3620 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003621 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003622 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003623 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003624 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003625 return null;
3626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003627
joonhunshin4ac60942023-11-15 15:23:39 +00003628 enforceTelephonyFeatureWithException(callingPackage,
3629 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 return phone.getImei();
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003637 }
3638
3639 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003640 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3641 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3642 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3643 callingFeatureId, "getPrimaryImei")) {
3644 throw new SecurityException("Caller does not have permission");
3645 }
joonhunshin4ac60942023-11-15 15:23:39 +00003646
3647 enforceTelephonyFeatureWithException(callingPackage,
3648 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3649
arunvoddud5c6ce02022-12-11 06:03:12 +00003650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 for (Phone phone : PhoneFactory.getPhones()) {
3653 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3654 return phone.getImei();
3655 }
3656 }
3657 throw new UnsupportedOperationException("Operation not supported");
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
3661 }
3662
3663 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003664 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003665 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3666 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3667
David Kelly5e06a7f2018-03-12 14:10:59 +00003668 Phone phone = PhoneFactory.getPhone(slotIndex);
3669 String tac = null;
3670 if (phone != null) {
3671 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003672 try {
3673 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3674 } catch (IndexOutOfBoundsException e) {
3675 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3676 return null;
3677 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003678 }
3679 return tac;
3680 }
3681
3682 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003683 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003684 try {
3685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3686 } catch (SecurityException se) {
3687 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3688 throw new SecurityException("Package " + callingPackage + " does not belong to "
3689 + Binder.getCallingUid());
3690 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003691 Phone phone = PhoneFactory.getPhone(slotIndex);
3692 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003693 return null;
3694 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003695
Jeff Davidson913390f2018-02-23 17:11:49 -08003696 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003697 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003698 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003699 return null;
3700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701
joonhunshin4ac60942023-11-15 15:23:39 +00003702 enforceTelephonyFeatureWithException(callingPackage,
3703 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 return phone.getMeid();
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
Jack Yu2af8d712017-03-15 17:14:14 -07003711 }
3712
3713 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003714 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003715 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3716 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3717
David Kelly5e06a7f2018-03-12 14:10:59 +00003718 Phone phone = PhoneFactory.getPhone(slotIndex);
3719 String manufacturerCode = null;
3720 if (phone != null) {
3721 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003722 try {
3723 manufacturerCode =
3724 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3725 } catch (IndexOutOfBoundsException e) {
3726 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3727 return null;
3728 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003729 }
3730 return manufacturerCode;
3731 }
3732
3733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003734 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3735 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003736 Phone phone = PhoneFactory.getPhone(slotIndex);
3737 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003738 return null;
3739 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003740 int subId = phone.getSubId();
3741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 mApp, subId, callingPackage, callingFeatureId,
3743 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003744 return null;
3745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
joonhunshin4ac60942023-11-15 15:23:39 +00003747 enforceTelephonyFeatureWithException(callingPackage,
3748 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 return phone.getDeviceSvn();
3753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003756 }
3757
fionaxu43304da2017-11-27 22:51:16 -08003758 @Override
3759 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003760 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3761 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 final Phone phone = getPhone(subId);
3766 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
fionaxu43304da2017-11-27 22:51:16 -08003770 }
3771
3772 @Override
3773 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003774 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3775 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 final Phone phone = getPhone(subId);
3780 return phone == null ? null : phone.getCarrierName();
3781 } finally {
3782 Binder.restoreCallingIdentity(identity);
3783 }
fionaxu43304da2017-11-27 22:51:16 -08003784 }
3785
calvinpanffe225e2018-11-01 19:43:06 +08003786 @Override
chen xu0026ca62019-03-06 15:28:50 -08003787 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003788 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3789 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3790
chen xu25637222018-11-04 17:17:00 -08003791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 final Phone phone = getPhone(subId);
3794 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003795 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
3799 }
3800
3801 @Override
chen xu0026ca62019-03-06 15:28:50 -08003802 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3804 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3805 "getSubscriptionSpecificCarrierName");
3806
chen xu25637222018-11-04 17:17:00 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003810 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003811 } finally {
3812 Binder.restoreCallingIdentity(identity);
3813 }
3814 }
3815
chen xu651eec72018-11-11 19:03:44 -08003816 @Override
chen xu864e11c2018-12-06 22:10:03 -08003817 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3818 if (!isSubscriptionMccMnc) {
3819 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3820 }
chen xu651eec72018-11-11 19:03:44 -08003821 final Phone phone = PhoneFactory.getPhone(slotIndex);
3822 if (phone == null) {
3823 return TelephonyManager.UNKNOWN_CARRIER_ID;
3824 }
joonhunshin4ac60942023-11-15 15:23:39 +00003825
3826 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3827 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3828
chen xu651eec72018-11-11 19:03:44 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
3835 }
3836
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003837 //
3838 // Internal helper methods.
3839 //
3840
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003841 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003842 * Make sure the caller is the calling package itself
3843 *
3844 * @throws SecurityException if the caller is not the calling package
3845 */
3846 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3847 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003848 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3849 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003850 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003851 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003852 } catch (PackageManager.NameNotFoundException e) {
3853 // packageUid is -1
3854 }
3855 if (packageUid != callingUid) {
3856 throw new SecurityException(message + ": Package " + callingPackage
3857 + " does not belong to " + callingUid);
3858 }
3859 }
3860
3861 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003862 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3863 *
3864 * @throws SecurityException if the caller does not have the required permission
3865 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003866 @VisibleForTesting
3867 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3869 }
3870
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003871 /**
arunvoddud7401012022-12-15 16:08:12 +00003872 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003873 *
3874 * @throws SecurityException if the caller does not have the required permission
3875 */
3876 @VisibleForTesting
3877 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003878 enforceReadPermission(null);
3879 }
3880
3881 /**
3882 * Make sure the caller has the READ_PHONE_STATE permissions.
3883 *
3884 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3885 */
3886 @VisibleForTesting
3887 public void enforceReadPermission(String msg) {
3888 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003889 }
3890
Shuo Qian3b6ee772019-11-13 17:43:31 -08003891 private void enforceActiveEmergencySessionPermission() {
3892 mApp.enforceCallingOrSelfPermission(
3893 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3894 }
3895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003896 /**
3897 * Make sure the caller has the CALL_PHONE permission.
3898 *
3899 * @throws SecurityException if the caller does not have the required permission
3900 */
3901 private void enforceCallPermission() {
3902 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3903 }
3904
paulhu5a773602019-08-23 19:17:33 +08003905 private void enforceSettingsPermission() {
3906 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003907 }
3908
Michele Berionne5e411512020-11-13 02:36:59 +00003909 private void enforceRebootPermission() {
3910 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3911 }
3912
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003913 /**
3914 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3915 * @param message - log message to print.
3916 * @throws SecurityException if the caller does not have the required permission
3917 */
3918 private void enforceSatelliteCommunicationPermission(String message) {
3919 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3920 }
3921
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003922 private String createTelUrl(String number) {
3923 if (TextUtils.isEmpty(number)) {
3924 return null;
3925 }
3926
Jake Hambye994d462014-02-03 13:10:13 -08003927 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003928 }
3929
Ihab Awadf9e92732013-12-05 18:02:52 -08003930 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003931 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003932 }
3933
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003934 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003935 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003936 }
3937
Ihab Awadf9e92732013-12-05 18:02:52 -08003938 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003939 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003940 }
3941
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003942 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003943 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003944 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003945 }
3946
Sanket Padawe356d7632015-06-22 14:03:32 -07003947 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003948 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003949 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3950 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 final Phone phone = PhoneFactory.getPhone(slotIndex);
3955 if (phone == null) {
3956 return PhoneConstants.PHONE_TYPE_NONE;
3957 } else {
3958 return phone.getPhoneType();
3959 }
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003963 }
3964
3965 /**
3966 * Returns the CDMA ERI icon index to display
3967 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003969 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3970 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3971 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003972 }
3973
Sanket Padawe356d7632015-06-22 14:03:32 -07003974 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003975 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3976 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003978 mApp, subId, callingPackage, callingFeatureId,
3979 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003980 return -1;
3981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982
joonhunshin4ac60942023-11-15 15:23:39 +00003983 enforceTelephonyFeatureWithException(callingPackage,
3984 PackageManager.FEATURE_TELEPHONY_CDMA,
3985 "getCdmaEriIconIndexForSubscriber");
3986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 final Phone phone = getPhone(subId);
3990 if (phone != null) {
3991 return phone.getCdmaEriIconIndex();
3992 } else {
3993 return -1;
3994 }
3995 } finally {
3996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003998 }
3999
4000 /**
4001 * Returns the CDMA ERI icon mode,
4002 * 0 - ON
4003 * 1 - FLASHING
4004 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004006 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4007 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4008 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004009 }
4010
Sanket Padawe356d7632015-06-22 14:03:32 -07004011 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004012 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4013 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004015 mApp, subId, callingPackage, callingFeatureId,
4016 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004017 return -1;
4018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019
4020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 final Phone phone = getPhone(subId);
4023 if (phone != null) {
4024 return phone.getCdmaEriIconMode();
4025 } else {
4026 return -1;
4027 }
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004031 }
4032
4033 /**
4034 * Returns the CDMA ERI text,
4035 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004037 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4038 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4039 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004040 }
4041
Sanket Padawe356d7632015-06-22 14:03:32 -07004042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004043 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4044 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004046 mApp, subId, callingPackage, callingFeatureId,
4047 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004048 return null;
4049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 final Phone phone = getPhone(subId);
4054 if (phone != null) {
4055 return phone.getCdmaEriText();
4056 } else {
4057 return null;
4058 }
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004062 }
4063
4064 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004065 * Returns the CDMA MDN.
4066 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004067 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004068 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4070 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071
joonhunshin4ac60942023-11-15 15:23:39 +00004072 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4073 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004078 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 return phone.getLine1Number();
4080 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004081 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 return null;
4083 }
4084 } finally {
4085 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004086 }
4087 }
4088
4089 /**
4090 * Returns the CDMA MIN.
4091 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004092 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004093 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4095 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096
joonhunshin4ac60942023-11-15 15:23:39 +00004097 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4098 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 final Phone phone = getPhone(subId);
4103 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4104 return phone.getCdmaMin();
4105 } else {
4106 return null;
4107 }
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004110 }
4111 }
4112
Hall Liud892bec2018-11-30 14:51:45 -08004113 @Override
4114 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4115 INumberVerificationCallback callback, String callingPackage) {
4116 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4117 != PERMISSION_GRANTED) {
4118 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4119 }
4120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4121
4122 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4123 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004124 throw new SecurityException("Calling package must be configured in the device config: "
4125 + "calling package: " + callingPackage
4126 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004127 }
4128
joonhunshin4ac60942023-11-15 15:23:39 +00004129 enforceTelephonyFeatureWithException(callingPackage,
4130 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4131
Hall Liud892bec2018-11-30 14:51:45 -08004132 if (range == null) {
4133 throw new NullPointerException("Range must be non-null");
4134 }
4135
4136 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004137 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004138
4139 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4140 }
4141
Junda Liuca05d5d2014-08-14 22:36:34 -07004142 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004143 * Returns true if CDMA provisioning needs to run.
4144 */
4145 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004146 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4147 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004151 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004155 }
4156
4157 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004158 * Sets the voice mail number of a given subId.
4159 */
4160 @Override
4161 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004162 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4163 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164
joonhunshin4ac60942023-11-15 15:23:39 +00004165 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4166 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168 final long identity = Binder.clearCallingIdentity();
4169 try {
4170 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4171 new Pair<String, String>(alphaTag, number), new Integer(subId));
4172 return success;
4173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004176 }
4177
Ta-wei Yen87c49842016-05-13 21:19:52 -07004178 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004179 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4180 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004181 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4182 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004183 if (!TextUtils.equals(callingPackage, systemDialer)) {
4184 throw new SecurityException("caller must be system dialer");
4185 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186
joonhunshin4ac60942023-11-15 15:23:39 +00004187 enforceTelephonyFeatureWithException(callingPackage,
4188 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4193 if (phoneAccountHandle == null) {
4194 return null;
4195 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004196 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 } finally {
4198 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004199 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004200 }
4201
4202 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004203 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4204 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004205 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004207 mApp, subId, callingPackage, callingFeatureId,
4208 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004209 return null;
4210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211
joonhunshin4ac60942023-11-15 15:23:39 +00004212 enforceTelephonyFeatureWithException(callingPackage,
4213 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4214
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004215 final long identity = Binder.clearCallingIdentity();
4216 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004217 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004221 }
4222
4223 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004224 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4225 VisualVoicemailSmsFilterSettings settings) {
4226 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227
joonhunshin4ac60942023-11-15 15:23:39 +00004228 enforceTelephonyFeatureWithException(callingPackage,
4229 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004234 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004238 }
4239
4240 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004241 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
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, "disableVisualVoicemailSmsFilter");
4246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 final long identity = Binder.clearCallingIdentity();
4248 try {
4249 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004250 mApp, callingPackage, subId);
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 VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4258 String callingPackage, int subId) {
4259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260
4261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004264 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004268 }
4269
4270 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004271 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004277 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004281 }
4282
4283 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004284 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4285 String callingAttributionTag, int subId, String number, int port, String text,
4286 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004287 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004288 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004289 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004290
4291 enforceTelephonyFeatureWithException(callingPackage,
4292 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4293
Amit Mahajandccb3f12019-05-13 13:48:32 -07004294 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004295 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4296 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004297 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004298
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004299 /**
fionaxu0152e512016-11-14 13:36:14 -08004300 * Sets the voice activation state of a given subId.
4301 */
4302 @Override
4303 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4305 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306
joonhunshin4ac60942023-11-15 15:23:39 +00004307 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4308 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 final Phone phone = getPhone(subId);
4313 if (phone != null) {
4314 phone.setVoiceActivationState(activationState);
4315 } else {
4316 loge("setVoiceActivationState fails with invalid subId: " + subId);
4317 }
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004320 }
4321 }
4322
4323 /**
4324 * Sets the data activation state of a given subId.
4325 */
4326 @Override
4327 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4329 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330
joonhunshin4ac60942023-11-15 15:23:39 +00004331 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4332 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 final long identity = Binder.clearCallingIdentity();
4335 try {
4336 final Phone phone = getPhone(subId);
4337 if (phone != null) {
4338 phone.setDataActivationState(activationState);
4339 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004340 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 }
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004344 }
4345 }
4346
4347 /**
4348 * Returns the voice activation state of a given subId.
4349 */
4350 @Override
4351 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353
joonhunshin4ac60942023-11-15 15:23:39 +00004354 enforceTelephonyFeatureWithException(callingPackage,
4355 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4356
fionaxu0152e512016-11-14 13:36:14 -08004357 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358 final long identity = Binder.clearCallingIdentity();
4359 try {
4360 if (phone != null) {
4361 return phone.getVoiceActivationState();
4362 } else {
4363 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4364 }
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004367 }
4368 }
4369
4370 /**
4371 * Returns the data activation state of a given subId.
4372 */
4373 @Override
4374 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376
joonhunshin4ac60942023-11-15 15:23:39 +00004377 enforceTelephonyFeatureWithException(callingPackage,
4378 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4379
fionaxu0152e512016-11-14 13:36:14 -08004380 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 final long identity = Binder.clearCallingIdentity();
4382 try {
4383 if (phone != null) {
4384 return phone.getDataActivationState();
4385 } else {
4386 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4387 }
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004390 }
4391 }
4392
4393 /**
Wink Saville36469e72014-06-11 15:17:00 -07004394 * Returns the unread count of voicemails for a subId
4395 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004396 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004397 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4398 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004400 mApp, subId, callingPackage, callingFeatureId,
4401 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004402 return 0;
4403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 final long identity = Binder.clearCallingIdentity();
4405 try {
4406 final Phone phone = getPhone(subId);
4407 if (phone != null) {
4408 return phone.getVoiceMessageCount();
4409 } else {
4410 return 0;
4411 }
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004415 }
4416
4417 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004418 * returns true, if the device is in a state where both voice and data
4419 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004420 */
4421 @Override
4422 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004423 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4424 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 final long identity = Binder.clearCallingIdentity();
4427 try {
Ling Mac28f0212023-03-24 16:07:15 -07004428 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004432 }
4433
4434 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004435 * Send the dialer code if called from the current default dialer or the caller has
4436 * carrier privilege.
4437 * @param inputCode The dialer code to send
4438 */
4439 @Override
4440 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004441 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004443 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4444 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004445 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004446 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004447 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449
joonhunshin4ac60942023-11-15 15:23:39 +00004450 enforceTelephonyFeatureWithException(callingPackage,
4451 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 final long identity = Binder.clearCallingIdentity();
4454 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004455 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
fionaxu235cc5e2017-03-06 22:25:57 -08004459 }
4460
Pengquan Menga1bb6272018-09-06 09:59:22 -07004461 @Override
4462 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004463 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004464 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4465 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004466
4467 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4468 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4469
shilufc958392020-01-20 11:36:01 -08004470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 if (!isActiveSubscription(subId)) {
4473 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4474 }
4475 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4476 } finally {
4477 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004478 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004479 }
4480
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004482 public boolean isInEmergencySmsMode() {
4483 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004484
4485 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4486 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4487
Brad Ebingerb2b65522019-03-15 13:48:47 -07004488 final long identity = Binder.clearCallingIdentity();
4489 try {
4490 for (Phone phone : PhoneFactory.getPhones()) {
4491 if (phone.isInEmergencySmsMode()) {
4492 return true;
4493 }
4494 }
4495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
4498 return false;
4499 }
4500
shilu366312e2019-12-17 09:28:10 -08004501 /**
4502 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4503 * @param subId The subscription to use to check the configuration.
4504 * @param c The callback that will be used to send the result.
4505 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004506 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004507 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4508 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004509 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004510 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004511
4512 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4513 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4514 "IMS not available on device.");
4515 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 final long token = Binder.clearCallingIdentity();
4517 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004518 int slotId = getSlotIndexOrException(subId);
4519 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004520
4521 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4522 if (controller != null) {
4523 ImsManager imsManager = controller.getImsManager(subId);
4524 if (imsManager != null) {
4525 imsManager.addRegistrationCallbackForSubscription(c, subId);
4526 } else {
4527 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4528 }
4529 } else {
4530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4531 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004532 } catch (ImsException e) {
4533 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004534 } finally {
4535 Binder.restoreCallingIdentity(token);
4536 }
4537 }
4538
shilu366312e2019-12-17 09:28:10 -08004539 /**
4540 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4541 * @param subId The subscription to use to check the configuration.
4542 * @param c The callback that will be used to send the result.
4543 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004545 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004546 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004547 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004548 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4549 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4550 }
Meng Wangafbc5852019-09-19 17:37:13 -07004551 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004552
Meng Wangafbc5852019-09-19 17:37:13 -07004553 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004554 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4555 if (controller != null) {
4556 ImsManager imsManager = controller.getImsManager(subId);
4557 if (imsManager != null) {
4558 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4559 } else {
4560 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4561 + "is inactive, ignoring unregister.");
4562 // If the ImsManager is not valid, just return, since the callback
4563 // will already have been removed internally.
4564 }
4565 }
Meng Wangafbc5852019-09-19 17:37:13 -07004566 } finally {
4567 Binder.restoreCallingIdentity(token);
4568 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004569 }
4570
Brad Ebingera34a6c22019-10-22 17:36:18 -07004571 /**
4572 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4573 */
4574 @Override
4575 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4576 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4577 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4578 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4579 "IMS not available on device.");
4580 }
4581 final long token = Binder.clearCallingIdentity();
4582 try {
4583 Phone phone = getPhone(subId);
4584 if (phone == null) {
4585 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4586 + subId + "'");
4587 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4588 }
4589 phone.getImsRegistrationState(regState -> {
4590 try {
4591 consumer.accept((regState == null)
4592 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4593 } catch (RemoteException e) {
4594 // Ignore if the remote process is no longer available to call back.
4595 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4596 }
4597 });
4598 } finally {
4599 Binder.restoreCallingIdentity(token);
4600 }
4601 }
4602
4603 /**
4604 * Get the transport type for the IMS service registration state.
4605 */
4606 @Override
4607 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004609 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004610 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4611 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4612 "IMS not available on device.");
4613 }
4614 final long token = Binder.clearCallingIdentity();
4615 try {
4616 Phone phone = getPhone(subId);
4617 if (phone == null) {
4618 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4619 + subId + "'");
4620 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4621 }
4622 phone.getImsRegistrationTech(regTech -> {
4623 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4624 int regTechConverted = (regTech == null)
4625 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4626 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4627 regTechConverted);
4628 try {
4629 consumer.accept(regTechConverted);
4630 } catch (RemoteException e) {
4631 // Ignore if the remote process is no longer available to call back.
4632 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4633 }
4634 });
4635 } finally {
4636 Binder.restoreCallingIdentity(token);
4637 }
4638 }
4639
shilu366312e2019-12-17 09:28:10 -08004640 /**
4641 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4642 * @param subId The subscription to use to check the configuration.
4643 * @param c The callback that will be used to send the result.
4644 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004645 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004646 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4647 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004648 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004649 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004650 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4651 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4652 "IMS not available on device.");
4653 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004654 final long token = Binder.clearCallingIdentity();
4655 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004656 int slotId = getSlotIndexOrException(subId);
4657 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004658
4659 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4660 if (controller != null) {
4661 ImsManager imsManager = controller.getImsManager(subId);
4662 if (imsManager != null) {
4663 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4664 } else {
4665 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4666 }
4667 } else {
4668 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4669 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004670 } catch (ImsException e) {
4671 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004672 } finally {
4673 Binder.restoreCallingIdentity(token);
4674 }
4675 }
4676
shilu366312e2019-12-17 09:28:10 -08004677 /**
4678 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4679 * @param subId The subscription to use to check the configuration.
4680 * @param c The callback that will be used to send the result.
4681 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004682 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004683 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004684 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004685 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4687 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4688 }
Meng Wangafbc5852019-09-19 17:37:13 -07004689
4690 final long token = Binder.clearCallingIdentity();
4691 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004692 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4693 if (controller != null) {
4694 ImsManager imsManager = controller.getImsManager(subId);
4695 if (imsManager != null) {
4696 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4697 } else {
4698 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4699 + " is inactive, ignoring unregister.");
4700 // If the ImsManager is not valid, just return, since the callback
4701 // will already have been removed internally.
4702 }
4703 }
Meng Wangafbc5852019-09-19 17:37:13 -07004704 } finally {
4705 Binder.restoreCallingIdentity(token);
4706 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004707 }
4708
4709 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004710 public boolean isCapable(int subId, int capability, int regTech) {
4711 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004712
4713 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4714 FEATURE_TELEPHONY_IMS, "isCapable");
4715
Brad Ebinger35c841c2018-10-01 10:40:55 -07004716 final long token = Binder.clearCallingIdentity();
4717 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004718 int slotId = getSlotIndexOrException(subId);
4719 verifyImsMmTelConfiguredOrThrow(slotId);
4720 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4721 } catch (com.android.ims.ImsException e) {
4722 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4723 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004724 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004725 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4726 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004727 } finally {
4728 Binder.restoreCallingIdentity(token);
4729 }
4730 }
4731
4732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004733 public boolean isAvailable(int subId, int capability, int regTech) {
4734 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004735
4736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4737 FEATURE_TELEPHONY_IMS, "isAvailable");
4738
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 final long token = Binder.clearCallingIdentity();
4740 try {
4741 Phone phone = getPhone(subId);
4742 if (phone == null) return false;
4743 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004744 } catch (com.android.ims.ImsException e) {
4745 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4746 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004747 } finally {
4748 Binder.restoreCallingIdentity(token);
4749 }
4750 }
4751
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004752 /**
4753 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4754 * subscription.
4755 * @param subId The subscription to use to check the configuration.
4756 * @param callback The callback that will be used to send the result.
4757 * @param capability The MmTelFeature capability that will be used to send the result.
4758 * @param transportType The transport type of the MmTelFeature capability.
4759 */
4760 @Override
4761 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4762 int transportType) {
4763 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004764 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4766 "IMS not available on device.");
4767 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004768 final long token = Binder.clearCallingIdentity();
4769 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004770 int slotId = getSlotIndex(subId);
4771 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4772 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4773 + subId + "'");
4774 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4775 }
4776 verifyImsMmTelConfiguredOrThrow(slotId);
4777 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4778 transportType, aBoolean -> {
4779 try {
4780 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4781 } catch (RemoteException e) {
4782 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4783 + "running. Ignore");
4784 }
4785 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004786 } catch (ImsException e) {
4787 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004788 } finally {
4789 Binder.restoreCallingIdentity(token);
4790 }
4791 }
4792
shilu366312e2019-12-17 09:28:10 -08004793 /**
4794 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4795 * @param subId The subscription to use to check the configuration.
4796 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004797 @Override
4798 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004799 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004800 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004801
joonhunshin4ac60942023-11-15 15:23:39 +00004802 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4803 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4804
Brad Ebinger35c841c2018-10-01 10:40:55 -07004805 final long token = Binder.clearCallingIdentity();
4806 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004807 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004808 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004809 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004810 } catch (ImsException e) {
4811 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004812 } finally {
4813 Binder.restoreCallingIdentity(token);
4814 }
4815 }
4816
4817 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004818 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004820 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004821
4822 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4823 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4824
Brad Ebinger35c841c2018-10-01 10:40:55 -07004825 final long identity = Binder.clearCallingIdentity();
4826 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004827 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004828 // This setting doesn't require an active ImsService connection, so do not verify. The
4829 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004830 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004831 } catch (ImsException e) {
4832 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
4836 }
4837
shilu366312e2019-12-17 09:28:10 -08004838 /**
4839 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4840 * @param subId The subscription to use to check the configuration.
4841 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004842 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004843 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004844 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004845 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004846
4847 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4848 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4849
Brad Ebinger35c841c2018-10-01 10:40:55 -07004850 final long identity = Binder.clearCallingIdentity();
4851 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004852 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004853 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004854 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004855 } catch (ImsException e) {
4856 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
4860 }
4861
4862 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004863 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004865 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004866
4867 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4868 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4869
Brad Ebinger35c841c2018-10-01 10:40:55 -07004870 final long identity = Binder.clearCallingIdentity();
4871 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004872 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004873 // This setting doesn't require an active ImsService connection, so do not verify. The
4874 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004875 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004876 } catch (ImsException e) {
4877 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
4881 }
4882
shilu366312e2019-12-17 09:28:10 -08004883 /**
4884 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4885 * @param subId The subscription to use to check the configuration.
4886 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004887 @Override
4888 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004889 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004890 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004891
4892 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4893 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4894
Brad Ebinger35c841c2018-10-01 10:40:55 -07004895 final long identity = Binder.clearCallingIdentity();
4896 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004897 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004898 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004899 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004900 } catch (ImsException e) {
4901 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
4905 }
4906
4907 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004908 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004910 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004911
4912 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4913 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
4914
Brad Ebinger35c841c2018-10-01 10:40:55 -07004915 final long identity = Binder.clearCallingIdentity();
4916 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004917 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004918 // This setting doesn't require an active ImsService connection, so do not verify. The
4919 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004920 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004921 } catch (ImsException e) {
4922 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004923 } finally {
4924 Binder.restoreCallingIdentity(identity);
4925 }
4926 }
4927
shilu366312e2019-12-17 09:28:10 -08004928 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004929 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4930 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4931 * @param subId The subscription to use to check the configuration.
4932 */
4933 @Override
4934 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004935 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004936 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00004937
4938 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4939 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
4940
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004941 final long identity = Binder.clearCallingIdentity();
4942 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004943 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004944 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004945 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004946 } catch (ImsException e) {
4947 throw new ServiceSpecificException(e.getCode());
4948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
4951 }
4952
4953 /**
4954 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4955 * Requires MODIFY_PHONE_STATE permission.
4956 * @param subId The subscription to use to check the configuration.
4957 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4958 * false otherwise
4959 */
4960 @Override
4961 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4963 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004964
4965 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4966 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
4967
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004968 final long identity = Binder.clearCallingIdentity();
4969 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004970 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004971 // This setting doesn't require an active ImsService connection, so do not verify. The
4972 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004973 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004974 } catch (ImsException e) {
4975 throw new ServiceSpecificException(e.getCode());
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
4979 }
4980
4981 /**
shilu366312e2019-12-17 09:28:10 -08004982 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4983 * @param subId The subscription to use to check the configuration.
4984 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004985 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004986
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004988 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004989 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004990
4991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4992 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
4993
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 final long identity = Binder.clearCallingIdentity();
4995 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004996 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004997 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004998 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004999 } catch (ImsException e) {
5000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
5004 }
5005
5006 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005007 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005009 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005010
5011 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5012 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5013
Brad Ebinger35c841c2018-10-01 10:40:55 -07005014 final long identity = Binder.clearCallingIdentity();
5015 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005016 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005017 // This setting doesn't require an active ImsService connection, so do not verify. The
5018 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005019 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 } catch (ImsException e) {
5021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
5025 }
5026
5027 @Override
5028 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5030 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005031
5032 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5033 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5034
Brad Ebinger35c841c2018-10-01 10:40:55 -07005035 final long identity = Binder.clearCallingIdentity();
5036 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005037 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005038 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005039 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005040 } catch (ImsException e) {
5041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005042 } finally {
5043 Binder.restoreCallingIdentity(identity);
5044 }
5045 }
5046
shilu366312e2019-12-17 09:28:10 -08005047 /**
5048 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5049 * @param subId The subscription to use to check the configuration.
5050 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005051 @Override
5052 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005053 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005054 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005055
5056 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5057 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5058
Brad Ebinger35c841c2018-10-01 10:40:55 -07005059 final long identity = Binder.clearCallingIdentity();
5060 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005061 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005062 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005063 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005064 } catch (ImsException e) {
5065 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
5069 }
5070
5071 @Override
5072 public void setVoWiFiModeSetting(int subId, int mode) {
5073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5074 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005075
5076 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5077 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5078
Brad Ebinger35c841c2018-10-01 10:40:55 -07005079 final long identity = Binder.clearCallingIdentity();
5080 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005081 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005082 // This setting doesn't require an active ImsService connection, so do not verify. The
5083 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005084 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
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
5093 public int getVoWiFiRoamingModeSetting(int subId) {
5094 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005095
5096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5097 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5098
Brad Ebinger35c841c2018-10-01 10:40:55 -07005099 final long identity = Binder.clearCallingIdentity();
5100 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005101 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005102 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005103 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005104 } catch (ImsException e) {
5105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005106 } finally {
5107 Binder.restoreCallingIdentity(identity);
5108 }
5109 }
5110
5111 @Override
5112 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5114 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005115
5116 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5117 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5118
Brad Ebinger35c841c2018-10-01 10:40:55 -07005119 final long identity = Binder.clearCallingIdentity();
5120 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005121 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005122 // This setting doesn't require an active ImsService connection, so do not verify. The
5123 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005124 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005125 } catch (ImsException e) {
5126 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005127 } finally {
5128 Binder.restoreCallingIdentity(identity);
5129 }
5130 }
5131
5132 @Override
5133 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5135 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005136
5137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5138 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5139
Brad Ebinger35c841c2018-10-01 10:40:55 -07005140 final long identity = Binder.clearCallingIdentity();
5141 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005142 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005143 // This setting doesn't require an active ImsService connection, so do not verify. The
5144 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005145 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005146 } catch (ImsException e) {
5147 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005148 } finally {
5149 Binder.restoreCallingIdentity(identity);
5150 }
5151 }
5152
shilu366312e2019-12-17 09:28:10 -08005153 /**
5154 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5155 * @param subId The subscription to use to check the configuration.
5156 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 @Override
5158 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005159 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005160 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005161
5162 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5163 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07005169 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005170 } catch (ImsException e) {
5171 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
5175 }
5176
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005177 @Override
5178 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5179 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005180
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005181 final long identity = Binder.clearCallingIdentity();
5182 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005183 if (!isImsAvailableOnDevice()) {
5184 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5185 "IMS not available on device.");
5186 }
5187 int slotId = getSlotIndexOrException(subId);
5188 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005189
5190 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5191 if (controller != null) {
5192 ImsManager imsManager = controller.getImsManager(subId);
5193 if (imsManager != null) {
5194 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5195 } else {
5196 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5197 }
5198 } else {
5199 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5200 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005201 } catch (ImsException e) {
5202 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
5206 }
5207
5208 @Override
5209 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5210 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005211
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005212 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005213 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5214 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5215 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005216 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005217 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5218 if (controller != null) {
5219 ImsManager imsManager = controller.getImsManager(subId);
5220 if (imsManager != null) {
5221 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5222 } else {
5223 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5224 + " is inactive, ignoring unregister.");
5225 // If the ImsManager is not valid, just return, since the callback will already
5226 // have been removed internally.
5227 }
5228 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005229 } finally {
5230 Binder.restoreCallingIdentity(identity);
5231 }
5232 }
5233
joonhunshincffb7fc2021-11-28 07:32:01 +00005234 @Override
5235 public void registerFeatureProvisioningChangedCallback(int subId,
5236 IFeatureProvisioningCallback callback) {
5237 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5238 mApp, subId, "registerFeatureProvisioningChangedCallback");
5239
5240 final long identity = Binder.clearCallingIdentity();
5241 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5242 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5243 }
5244
joonhunshin91bc1952022-04-29 08:47:15 +00005245 try {
5246 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5247 if (controller == null) {
5248 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5249 "Device does not support IMS");
5250 }
5251 controller.addFeatureProvisioningChangedCallback(subId, callback);
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005255 }
5256
5257 @Override
5258 public void unregisterFeatureProvisioningChangedCallback(int subId,
5259 IFeatureProvisioningCallback callback) {
5260 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5261 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5262
5263 final long identity = Binder.clearCallingIdentity();
5264 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5265 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5266 }
5267
joonhunshin91bc1952022-04-29 08:47:15 +00005268 try {
5269 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5270 if (controller == null) {
5271 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5272 return;
5273 }
5274 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005278 }
allenwtsu99c623b2020-01-03 18:24:23 +08005279
5280 private void checkModifyPhoneStatePermission(int subId, String message) {
5281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5282 message);
5283 }
5284
allenwtsu99c623b2020-01-03 18:24:23 +08005285 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005286 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005287 boolean isProvisioned) {
5288 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5289
joonhunshin4ac60942023-11-15 15:23:39 +00005290 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5291 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5292
allenwtsu99c623b2020-01-03 18:24:23 +08005293 final long identity = Binder.clearCallingIdentity();
5294 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005295 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5296 if (controller == null) {
5297 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5298 return;
5299 }
5300 controller.setRcsProvisioningStatusForCapability(
5301 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
allenwtsu99c623b2020-01-03 18:24:23 +08005305 }
5306
5307
5308 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005309 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5310 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5311 mApp, subId, "getRcsProvisioningStatusForCapability");
5312
joonhunshin4ac60942023-11-15 15:23:39 +00005313 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5314 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5315
allenwtsu99c623b2020-01-03 18:24:23 +08005316 final long identity = Binder.clearCallingIdentity();
5317 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005318 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5319 if (controller == null) {
5320 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5321
5322 // device does not support IMS, this method will return true always.
5323 return true;
5324 }
5325 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
5329 }
5330
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005331 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005332 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5333 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005334 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005335
joonhunshin4ac60942023-11-15 15:23:39 +00005336 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5337 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5338
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005339 final long identity = Binder.clearCallingIdentity();
5340 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005341 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5342 if (controller == null) {
5343 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5344 return;
5345 }
5346 controller.setImsProvisioningStatusForCapability(
5347 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
5351 }
5352
5353 @Override
5354 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005355 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5356 mApp, subId, "getProvisioningStatusForCapability");
5357
joonhunshin4ac60942023-11-15 15:23:39 +00005358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5359 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5360
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005361 final long identity = Binder.clearCallingIdentity();
5362 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005363 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5364 if (controller == null) {
5365 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005366
joonhunshin91bc1952022-04-29 08:47:15 +00005367 // device does not support IMS, this method will return true always.
5368 return true;
5369 }
5370 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
5374 }
5375
5376 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005377 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5378 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5379 mApp, subId, "isProvisioningRequiredForCapability");
5380
joonhunshin4ac60942023-11-15 15:23:39 +00005381 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5382 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5383
joonhunshincffb7fc2021-11-28 07:32:01 +00005384 final long identity = Binder.clearCallingIdentity();
5385 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005386 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5387 if (controller == null) {
5388 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5389
5390 // device does not support IMS, this method will return false
5391 return false;
5392 }
5393 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005394 } finally {
5395 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005396 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005397 }
5398
5399 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005400 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5401 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5402 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005403
joonhunshin4ac60942023-11-15 15:23:39 +00005404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5405 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5406
joonhunshincffb7fc2021-11-28 07:32:01 +00005407 final long identity = Binder.clearCallingIdentity();
5408 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005409 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5410 if (controller == null) {
5411 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5412
5413 // device does not support IMS, this method will return false
5414 return false;
5415 }
5416 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005420 }
5421
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005422 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005423 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005424 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5425 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5426 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005427 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5428 mApp, subId, "getImsProvisioningInt");
5429
joonhunshin4ac60942023-11-15 15:23:39 +00005430 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5431 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5432
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005436 int slotId = getSlotIndex(subId);
5437 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5438 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5439 + subId + "' for key:" + key);
5440 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5441 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005442
joonhunshin91bc1952022-04-29 08:47:15 +00005443 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5444 if (controller == null) {
5445 loge("getImsProvisioningInt: Device does not support IMS");
5446
5447 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5448 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5449 }
5450 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005451 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5452 return retVal;
5453 }
5454
calvinpanb5a34062021-02-08 19:59:36 +08005455 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005456 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005457 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5458 + subId + "' for key:" + key);
5459 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
5463 }
5464
5465 @Override
5466 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005467 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5468 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5469 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005470 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5471 mApp, subId, "getImsProvisioningString");
5472
joonhunshin4ac60942023-11-15 15:23:39 +00005473 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5474 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5475
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005476 final long identity = Binder.clearCallingIdentity();
5477 try {
5478 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005479 int slotId = getSlotIndex(subId);
5480 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5481 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5482 + subId + "' for key:" + key);
5483 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5484 }
calvinpanb5a34062021-02-08 19:59:36 +08005485 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005486 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005487 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5488 + subId + "' for key:" + key);
5489 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005490 } finally {
5491 Binder.restoreCallingIdentity(identity);
5492 }
5493 }
5494
5495 @Override
5496 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5498 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5499 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5501 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005502
joonhunshin4ac60942023-11-15 15:23:39 +00005503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5504 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5505
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005506 final long identity = Binder.clearCallingIdentity();
5507 try {
5508 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005509 int slotId = getSlotIndex(subId);
5510 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5511 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5512 + subId + "' for key:" + key);
5513 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5514 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005515
joonhunshin91bc1952022-04-29 08:47:15 +00005516 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5517 if (controller == null) {
5518 loge("setImsProvisioningInt: Device does not support IMS");
5519
5520 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5521 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5522 }
5523 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005524 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5525 return retVal;
5526 }
5527
calvinpanb5a34062021-02-08 19:59:36 +08005528 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5529 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005530 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005531 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005532 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
5536 }
5537
5538 @Override
5539 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005540 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5541 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5542 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5544 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005545
5546 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5547 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5548
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005552 int slotId = getSlotIndex(subId);
5553 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5554 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5555 + subId + "' for key:" + key);
5556 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5557 }
calvinpanb5a34062021-02-08 19:59:36 +08005558 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5559 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005560 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005561 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005562 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
5566 }
5567
Brad Ebinger919631e2021-06-02 17:46:35 -07005568 /**
5569 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5570 * for the given slot ID or no ImsResolver instance has been created.
5571 * @param slotId The slot ID that the IMS service is created for.
5572 * @throws ImsException If there is no ImsService configured for this slot.
5573 */
5574 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5575 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5576 ImsFeature.FEATURE_MMTEL)) {
5577 throw new ImsException("This subscription does not support MMTEL over IMS",
5578 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5579 }
5580 }
5581
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005582 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005583 int slotId = SubscriptionManager.getSlotIndex(subId);
5584 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005585 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5586 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005587 }
5588 return slotId;
5589 }
5590
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005591 private int getSlotIndex(int subId) {
5592 int slotId = SubscriptionManager.getSlotIndex(subId);
5593 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5594 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5595 }
5596 return slotId;
5597 }
5598
Wink Saville36469e72014-06-11 15:17:00 -07005599 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005600 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005601 */
5602 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005603 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5604 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005605 try {
5606 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5607 } catch (SecurityException se) {
5608 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5609 throw new SecurityException("Package " + callingPackage + " does not belong to "
5610 + Binder.getCallingUid());
5611 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005612 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005613 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005614 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005615 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005616 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005617 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005618 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005619 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5620 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005621
joonhunshin4ac60942023-11-15 15:23:39 +00005622 enforceTelephonyFeatureWithException(callingPackage,
5623 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 final long identity = Binder.clearCallingIdentity();
5626 try {
5627 final Phone phone = getPhone(subId);
5628 if (phone != null) {
5629 return phone.getServiceState().getDataNetworkType();
5630 } else {
5631 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5632 }
5633 } finally {
5634 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005636 }
5637
5638 /**
5639 * Returns the data network type
5640 */
5641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005642 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005643 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005644 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005645 }
5646
5647 /**
5648 * Returns the data network type for a subId
5649 */
5650 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005651 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5652 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005653 String functionName = "getDataNetworkTypeForSubscriber";
5654 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5655 mApp, functionName)) {
5656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5657 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5658 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5659 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005660 }
5661
joonhunshin4ac60942023-11-15 15:23:39 +00005662 enforceTelephonyFeatureWithException(callingPackage,
5663 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 final long identity = Binder.clearCallingIdentity();
5666 try {
5667 final Phone phone = getPhone(subId);
5668 if (phone != null) {
5669 return phone.getServiceState().getDataNetworkType();
5670 } else {
5671 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5672 }
5673 } finally {
5674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005676 }
5677
5678 /**
Wink Saville36469e72014-06-11 15:17:00 -07005679 * Returns the Voice network type for a subId
5680 */
5681 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005682 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5683 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005684 String functionName = "getVoiceNetworkTypeForSubscriber";
5685 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5686 mApp, functionName)) {
5687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5688 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5689 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5690 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005691 }
5692
joonhunshin4ac60942023-11-15 15:23:39 +00005693 enforceTelephonyFeatureWithException(callingPackage,
5694 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 final Phone phone = getPhone(subId);
5699 if (phone != null) {
5700 return phone.getServiceState().getVoiceNetworkType();
5701 } else {
5702 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5703 }
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005707 }
5708
5709 /**
5710 * @return true if a ICC card is present
5711 */
5712 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005713 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005714 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005715 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005716 }
5717
5718 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005719 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005720 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005721 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005722 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005723 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5724 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 final Phone phone = PhoneFactory.getPhone(slotIndex);
5729 if (phone != null) {
5730 return phone.getIccCard().hasIccCard();
5731 } else {
5732 return false;
5733 }
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005737 }
5738
5739 /**
5740 * Return if the current radio is LTE on CDMA. This
5741 * is a tri-state return value as for a period of time
5742 * the mode may be unknown.
5743 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005744 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005745 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005746 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005747 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005749 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5750 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5751 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005752 }
5753
Sanket Padawe356d7632015-06-22 14:03:32 -07005754 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005755 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5756 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005757 try {
5758 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5759 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005760 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5761 }
5762
joonhunshin4ac60942023-11-15 15:23:39 +00005763 enforceTelephonyFeatureWithException(callingPackage,
5764 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 final Phone phone = getPhone(subId);
5769 if (phone == null) {
5770 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5771 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005772 return TelephonyProperties.lte_on_cdma_device()
5773 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 }
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005777 }
Wink Saville36469e72014-06-11 15:17:00 -07005778 }
5779
Wink Saville36469e72014-06-11 15:17:00 -07005780 /**
5781 * {@hide}
5782 * Returns Default subId, 0 in the case of single standby.
5783 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005784 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005785 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005786 }
5787
Shishir Agrawala9f32182016-04-12 12:00:16 -07005788 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005789 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005790 }
5791
Wink Savilleb564aae2014-10-23 10:18:09 -07005792 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005793 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005794 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005795
Pengquan Menge92a50d2018-09-21 15:54:48 -07005796 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005797 return getSubscriptionManagerService().isActiveSubId(subId,
5798 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005799 }
5800
Ihab Awadf2177b72013-11-25 13:33:23 -08005801 /**
5802 * @see android.telephony.TelephonyManager.WifiCallingChoices
5803 */
5804 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 final long identity = Binder.clearCallingIdentity();
5806 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005807 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5809 getWhenToMakeWifiCallsDefaultPreference());
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005813 }
5814
5815 /**
5816 * @see android.telephony.TelephonyManager.WifiCallingChoices
5817 */
5818 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 final long identity = Binder.clearCallingIdentity();
5820 try {
5821 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005822 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005827 }
5828
Sailesh Nepald1e68152013-12-12 19:08:02 -08005829 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005830 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005831 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005832 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005833
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005834 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5835 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5836 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005837 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005838 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005839 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005840 }
5841 return PhoneFactory.getPhone(phoneId);
5842 }
5843
Shishir Agrawal566b7612013-10-28 14:41:00 -07005844 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005845 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005846 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005847
Rambo Wanga1782702021-11-10 20:15:19 -08005848 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5849 /*message=*/ "iccOpenLogicalChannel");
5850
5851 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5852 // Verify that the callingPackage in the request belongs to the calling UID
5853 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5854
joonhunshin4ac60942023-11-15 15:23:39 +00005855 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5856 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5857
Rambo Wanga1782702021-11-10 20:15:19 -08005858 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005859 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005860
Rambo Wanga1782702021-11-10 20:15:19 -08005861 private Phone getPhoneFromValidIccLogicalChannelRequest(
5862 @NonNull IccLogicalChannelRequest request, String message) {
5863 Phone phone;
5864 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5866 mApp, request.subId, message);
5867 phone = getPhoneFromSubId(request.subId);
5868 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5869 enforceModifyPermission();
5870 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5871 } else {
5872 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005873 }
Rambo Wanga1782702021-11-10 20:15:19 -08005874 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005875 }
5876
5877 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005878 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 final long identity = Binder.clearCallingIdentity();
5880 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005881 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005883 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5884 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005885 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5886 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 loge("The calling package is not allowed to access ISD-R.");
5888 throw new SecurityException(
5889 "The calling package is not allowed to access ISD-R.");
5890 }
Derek Tan740e1672017-06-27 14:56:27 -07005891 }
Derek Tan740e1672017-06-27 14:56:27 -07005892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005894 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5895 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 return response;
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005900 }
5901
5902 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005903 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005904 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5905 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5906
Rambo Wanga1782702021-11-10 20:15:19 -08005907 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5908 /*message=*/"iccCloseLogicalChannel");
5909
5910 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5911
5912 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005913 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005914
Rambo Wanga1782702021-11-10 20:15:19 -08005915 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5916 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005917 // before this feature is enabled, this API should only return false if
5918 // the operation fails instead of throwing runtime exception for
5919 // backward-compatibility.
5920 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5921 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 final long identity = Binder.clearCallingIdentity();
5923 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005924 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005925 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 }
Chen Xue9d737e2022-01-01 23:41:31 -08005927 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005928 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005929 Boolean success = false;
5930 if (result instanceof RuntimeException) {
5931 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005932 if (shouldThrowExceptionOnFailure) {
5933 throw (RuntimeException) result;
5934 } else {
5935 return false;
5936 }
Chen Xue9d737e2022-01-01 23:41:31 -08005937 } else if (result instanceof Boolean) {
5938 success = (Boolean) result;
5939 } else {
5940 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5941 }
Rambo Wanga1782702021-11-10 20:15:19 -08005942 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 return success;
5944 } finally {
5945 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005946 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005947 }
5948
5949 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005950 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005951 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5953 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00005954
5955 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5956 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
5957
Jordan Liu4c733742019-02-28 12:03:40 -08005958 if (DBG) {
5959 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5960 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5961 + p3 + " data=" + data);
5962 }
5963 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5964 command, p1, p2, p3, data);
5965 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005966
Jordan Liu4c733742019-02-28 12:03:40 -08005967 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005968 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005969 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005970 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00005971
5972 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5973 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
5974 "iccTransmitApduLogicalChannelBySlot");
5975
Jordan Liu4c733742019-02-28 12:03:40 -08005976 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005977 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005978 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5979 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005980 }
5981 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005982 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5983 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005984 }
5985
5986 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5987 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 final long identity = Binder.clearCallingIdentity();
5989 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005990 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 return "";
5992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005995 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5996 null /* workSource */);
5997 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 // Append the returned status code to the end of the response payload.
6000 String s = Integer.toHexString(
6001 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6002 if (response.payload != null) {
6003 s = IccUtils.bytesToHexString(response.payload) + s;
6004 }
6005 return s;
6006 } finally {
6007 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006008 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006009 }
Jake Hambye994d462014-02-03 13:10:13 -08006010
Evan Charltonc66da362014-05-16 14:06:40 -07006011 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006012 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6013 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6015 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006017
6018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6019 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6020
Jordan Liu4c733742019-02-28 12:03:40 -08006021 if (DBG) {
6022 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6023 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6024 }
6025 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6026 cla, command, p1, p2, p3, data);
6027 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006028
Jordan Liu4c733742019-02-28 12:03:40 -08006029 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006030 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006031 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006032 enforceModifyPermission();
6033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006034
6035 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6036 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6037
Jordan Liu4c733742019-02-28 12:03:40 -08006038 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006039 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006040 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6041 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006042 }
6043
6044 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006045 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6046 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006047 }
6048
6049 // open APDU basic channel assuming the caller has sufficient permissions
6050 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6051 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 final long identity = Binder.clearCallingIdentity();
6053 try {
6054 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6055 && TextUtils.equals(ISDR_AID, data)) {
6056 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006057 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6058 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 if (bestComponent == null
6060 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6061 loge("The calling package is not allowed to select ISD-R.");
6062 throw new SecurityException(
6063 "The calling package is not allowed to select ISD-R.");
6064 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006065 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006068 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6069 null /* workSource */);
6070 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 // Append the returned status code to the end of the response payload.
6073 String s = Integer.toHexString(
6074 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6075 if (response.payload != null) {
6076 s = IccUtils.bytesToHexString(response.payload) + s;
6077 }
6078 return s;
6079 } finally {
6080 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006081 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006082 }
6083
6084 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006085 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006086 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6088 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006089
joonhunshin4ac60942023-11-15 15:23:39 +00006090 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6091 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 if (DBG) {
6096 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6097 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6098 }
6099
6100 IccIoResult response =
6101 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6102 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6103 subId);
6104
6105 if (DBG) {
6106 log("Exchange SIM_IO [R]" + response);
6107 }
6108
6109 byte[] result = null;
6110 int length = 2;
6111 if (response.payload != null) {
6112 length = 2 + response.payload.length;
6113 result = new byte[length];
6114 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6115 } else {
6116 result = new byte[length];
6117 }
6118
6119 result[length - 1] = (byte) response.sw2;
6120 result[length - 2] = (byte) response.sw1;
6121 return result;
6122 } finally {
6123 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006124 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006125 }
6126
Nathan Haroldb3014052017-01-25 15:57:32 -08006127 /**
6128 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6129 * on a particular subscription
6130 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006131 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6132 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006134 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006135 return null;
6136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137
joonhunshin4ac60942023-11-15 15:23:39 +00006138 enforceTelephonyFeatureWithException(callingPackage,
6139 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 if (appType != TelephonyManager.APPTYPE_USIM
6144 && appType != TelephonyManager.APPTYPE_SIM) {
6145 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6146 return null;
6147 }
6148 Object response = sendRequest(
6149 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6150 if (response instanceof String[]) {
6151 return (String[]) response;
6152 }
yincheng zhao2737e882019-09-06 17:06:54 -07006153 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006155 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 } finally {
6157 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006158 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006159 }
6160
yincheng zhao2737e882019-09-06 17:06:54 -07006161 /**
6162 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6163 * subscription.
6164 *
6165 * @param subId the id of the subscription.
6166 * @param appType the uicc app type, must be USIM or SIM.
6167 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6168 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006169 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006170 * @return number of fplmns that is successfully written to the SIM.
6171 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006172 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6173 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6175 mApp, subId, "setForbiddenPlmns");
6176
joonhunshin4ac60942023-11-15 15:23:39 +00006177 enforceTelephonyFeatureWithException(callingPackage,
6178 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6179
yincheng zhao2737e882019-09-06 17:06:54 -07006180 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6181 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6182 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6183 }
6184 if (fplmns == null) {
6185 throw new IllegalArgumentException("Fplmn List provided is null");
6186 }
6187 for (String fplmn : fplmns) {
6188 if (!CellIdentity.isValidPlmn(fplmn)) {
6189 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6190 }
6191 }
6192 final long identity = Binder.clearCallingIdentity();
6193 try {
6194 Object response = sendRequest(
6195 CMD_SET_FORBIDDEN_PLMNS,
6196 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6197 subId);
6198 return (int) response;
6199 } finally {
6200 Binder.restoreCallingIdentity(identity);
6201 }
6202 }
6203
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006204 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006205 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6207 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006208
joonhunshin4ac60942023-11-15 15:23:39 +00006209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6210 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 final long identity = Binder.clearCallingIdentity();
6213 try {
6214 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6215 if (response.payload == null) {
6216 return "";
6217 }
Evan Charltonc66da362014-05-16 14:06:40 -07006218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 // Append the returned status code to the end of the response payload.
6220 String s = Integer.toHexString(
6221 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6222 s = IccUtils.bytesToHexString(response.payload) + s;
6223 return s;
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
Evan Charltonc66da362014-05-16 14:06:40 -07006227 }
6228
Jake Hambye994d462014-02-03 13:10:13 -08006229 /**
6230 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6231 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6232 *
6233 * @param itemID the ID of the item to read
6234 * @return the NV item as a String, or null on error.
6235 */
6236 @Override
6237 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006238 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6240 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241
6242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006245 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6247 return value;
6248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
Jake Hambye994d462014-02-03 13:10:13 -08006251 }
6252
6253 /**
6254 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6255 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6256 *
6257 * @param itemID the ID of the item to read
6258 * @param itemValue the value to write, as a String
6259 * @return true on success; false on any failure
6260 */
6261 @Override
6262 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6265 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6270 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006271 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6273 return success;
6274 } finally {
6275 Binder.restoreCallingIdentity(identity);
6276 }
Jake Hambye994d462014-02-03 13:10:13 -08006277 }
6278
6279 /**
6280 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6281 * Used for device configuration by some CDMA operators.
6282 *
6283 * @param preferredRoamingList byte array containing the new PRL
6284 * @return true on success; false on any failure
6285 */
6286 @Override
6287 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6289 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290
6291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6294 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6295 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6296 return success;
6297 } finally {
6298 Binder.restoreCallingIdentity(identity);
6299 }
Jake Hambye994d462014-02-03 13:10:13 -08006300 }
6301
6302 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006303 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006304 * Used for device configuration by some CDMA operators.
6305 *
chen xu6dac5ab2018-10-26 17:39:23 -07006306 * @param slotIndex - device slot.
6307 *
Jake Hambye994d462014-02-03 13:10:13 -08006308 * @return true on success; false on any failure
6309 */
6310 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006311 public boolean resetModemConfig(int slotIndex) {
6312 Phone phone = PhoneFactory.getPhone(slotIndex);
6313 if (phone != null) {
6314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6315 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316
joonhunshin4ac60942023-11-15 15:23:39 +00006317 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6318 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6319
chen xu6dac5ab2018-10-26 17:39:23 -07006320 final long identity = Binder.clearCallingIdentity();
6321 try {
6322 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6323 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6324 return success;
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 }
chen xu6dac5ab2018-10-26 17:39:23 -07006329 return false;
6330 }
6331
6332 /**
6333 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6334 *
6335 * @param slotIndex - device slot.
6336 *
6337 * @return true on success; false on any failure
6338 */
6339 @Override
6340 public boolean rebootModem(int slotIndex) {
6341 Phone phone = PhoneFactory.getPhone(slotIndex);
6342 if (phone != null) {
6343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6344 mApp, phone.getSubId(), "rebootModem");
6345
joonhunshin4ac60942023-11-15 15:23:39 +00006346 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6347 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6348
chen xu6dac5ab2018-10-26 17:39:23 -07006349 final long identity = Binder.clearCallingIdentity();
6350 try {
6351 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6352 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6353 return success;
6354 } finally {
6355 Binder.restoreCallingIdentity(identity);
6356 }
6357 }
6358 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006359 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006360
Brad Ebinger51f743a2017-01-23 13:50:20 -08006361 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006362 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6363 * {@link #disableIms(int)}.
6364 * @param slotIndex device slot.
6365 */
6366 public void resetIms(int slotIndex) {
6367 enforceModifyPermission();
6368
joonhunshin4ac60942023-11-15 15:23:39 +00006369 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6370 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6371
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006372 final long identity = Binder.clearCallingIdentity();
6373 try {
6374 if (mImsResolver == null) {
6375 // may happen if the does not support IMS.
6376 return;
6377 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006378 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
6382 }
6383
6384 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006385 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6386 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006387 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006388 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006389 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390
6391 final long identity = Binder.clearCallingIdentity();
6392 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006393 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006394 // may happen if the device does not support IMS.
6395 return;
6396 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006397 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398 } finally {
6399 Binder.restoreCallingIdentity(identity);
6400 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006401 }
6402
6403 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006404 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6405 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006406 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006407 public void disableIms(int slotId) {
6408 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006412 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006413 // may happen if the device does not support IMS.
6414 return;
6415 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006416 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006420 }
6421
6422 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006423 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6424 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006425 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006426 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006427 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006432 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006433 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6434 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006435 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006436 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006440 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006441 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006442 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6443 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006444 @Override
6445 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006446 enforceModifyPermission();
6447
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006451 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006452 } finally {
6453 Binder.restoreCallingIdentity(identity);
6454 }
6455 }
6456
6457 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006458 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006459 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006460 */
6461 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6462 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006463
6464 final long identity = Binder.clearCallingIdentity();
6465 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006466 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006467 // may happen if the device does not support IMS.
6468 return null;
6469 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006470 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006474 }
6475
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006476 /**
6477 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006478 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006479 */
6480 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6481 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482
6483 final long identity = Binder.clearCallingIdentity();
6484 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006485 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006486 // may happen if the device does not support IMS.
6487 return null;
6488 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006489 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006493 }
6494
Brad Ebinger884c07b2018-02-15 16:17:40 -08006495 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006496 * Sets the ImsService Package Name that Telephony will bind to.
6497 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006498 * @param slotIndex the slot ID that the ImsService should bind for.
6499 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006500 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006501 * @param featureTypes An integer array of feature types associated with a packageName.
6502 * @param packageName The name of the package that the current configuration will be replaced
6503 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006504 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006505 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006506 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6507 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006508 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006510 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 final long identity = Binder.clearCallingIdentity();
6513 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006514 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006515 // may happen if the device does not support IMS.
6516 return false;
6517 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006518 Map<Integer, String> featureConfig = new HashMap<>();
6519 for (int featureType : featureTypes) {
6520 featureConfig.put(featureType, packageName);
6521 }
6522 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6523 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 } finally {
6525 Binder.restoreCallingIdentity(identity);
6526 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006527 }
6528
6529 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006530 * Clears any carrier ImsService overrides for the slot index specified that were previously
6531 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6532 *
6533 * This should only be used for testing.
6534 *
6535 * @param slotIndex the slot ID that the ImsService should bind for.
6536 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6537 */
6538 @Override
6539 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006540 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6541 "clearCarrierImsServiceOverride");
6542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006543 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006544
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 if (mImsResolver == null) {
6548 // may happen if the device does not support IMS.
6549 return false;
6550 }
6551 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6552 } finally {
6553 Binder.restoreCallingIdentity(identity);
6554 }
6555 }
6556
6557 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006558 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006559 *
6560 * @param slotId The slot that the ImsService is associated with.
6561 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6562 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006563 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006564 * @return the package name of the ImsService configuration.
6565 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006566 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6567 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006568 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006569 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6570 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 final long identity = Binder.clearCallingIdentity();
6573 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006574 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006575 // may happen if the device does not support IMS.
6576 return "";
6577 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006578 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006579 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6580 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006584 }
6585
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006586 /**
6587 * Get the MmTelFeature state associated with the requested subscription id.
6588 * @param subId The subscription that the MmTelFeature is associated with.
6589 * @param callback A callback with an integer containing the
6590 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6591 */
6592 @Override
6593 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6594 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006595 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6596 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6597 "IMS not available on device.");
6598 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006599 final long token = Binder.clearCallingIdentity();
6600 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006601 int slotId = getSlotIndex(subId);
6602 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6603 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6604 + subId + "'");
6605 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6606 }
6607 verifyImsMmTelConfiguredOrThrow(slotId);
6608 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6609 try {
6610 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6611 } catch (RemoteException e) {
6612 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6613 + "Ignore");
6614 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006615 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006616 } catch (ImsException e) {
6617 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006618 } finally {
6619 Binder.restoreCallingIdentity(token);
6620 }
6621 }
6622
Daniel Brightbb5840b2021-01-12 15:48:18 -08006623 /**
6624 * Sets the ims registration state on all valid {@link Phone}s.
6625 */
6626 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628
6629 final long identity = Binder.clearCallingIdentity();
6630 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006631 // NOTE: Before S, this method only set the default phone.
6632 for (final Phone phone : PhoneFactory.getPhones()) {
6633 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6634 phone.setImsRegistrationState(registered);
6635 }
6636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
Wink Saville36469e72014-06-11 15:17:00 -07006640 }
6641
6642 /**
Stuart Scott54788802015-03-30 13:18:01 -07006643 * Set the network selection mode to automatic.
6644 *
6645 */
6646 @Override
6647 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6649 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650
joonhunshin4ac60942023-11-15 15:23:39 +00006651 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6652 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 final long identity = Binder.clearCallingIdentity();
6655 try {
shilufc958392020-01-20 11:36:01 -08006656 if (!isActiveSubscription(subId)) {
6657 return;
6658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006660 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6661 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 } finally {
6663 Binder.restoreCallingIdentity(identity);
6664 }
Stuart Scott54788802015-03-30 13:18:01 -07006665 }
6666
Jack Yud10cdd42020-09-28 20:28:01 -07006667 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006668 * Ask the radio to connect to the input network and change selection mode to manual.
6669 *
6670 * @param subId the id of the subscription.
6671 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6672 * the operator to attach to.
6673 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6674 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6675 * normal network selection next time.
6676 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006677 */
6678 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006679 public boolean setNetworkSelectionModeManual(
6680 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6682 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006683
joonhunshin4ac60942023-11-15 15:23:39 +00006684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6685 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6686
Jack Yu285100e2022-12-02 22:48:35 -08006687 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006688 if (!isActiveSubscription(subId)) {
6689 return false;
6690 }
6691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006693 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006695 if (DBG) {
6696 log("setNetworkSelectionModeManual: subId: " + subId
6697 + " operator: " + operatorInfo);
6698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6700 } finally {
6701 Binder.restoreCallingIdentity(identity);
6702 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006703 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006704 /**
shilu84f6e8b2019-12-19 13:58:01 -08006705 * Get the manual network selection
6706 *
6707 * @param subId the id of the subscription.
6708 *
6709 * @return the previously saved user selected PLMN
6710 */
6711 @Override
6712 public String getManualNetworkSelectionPlmn(int subId) {
6713 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006714 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6715 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006716
joonhunshin4ac60942023-11-15 15:23:39 +00006717 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6718 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6719
shilu84f6e8b2019-12-19 13:58:01 -08006720 final long identity = Binder.clearCallingIdentity();
6721 try {
6722 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006723 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006724 }
6725
6726 final Phone phone = getPhone(subId);
6727 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006728 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006729 }
6730 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6731 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006732 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
6736 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006737
6738 /**
6739 * Scans for available networks.
6740 */
6741 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006742 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6743 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6745 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006746 LocationAccessPolicy.LocationPermissionResult locationResult =
6747 LocationAccessPolicy.checkLocationPermission(mApp,
6748 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6749 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006750 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006751 .setCallingPid(Binder.getCallingPid())
6752 .setCallingUid(Binder.getCallingUid())
6753 .setMethod("getCellNetworkScanResults")
6754 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006755 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6756 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006757 .build());
6758 switch (locationResult) {
6759 case DENIED_HARD:
6760 throw new SecurityException("Not allowed to access scan results -- location");
6761 case DENIED_SOFT:
6762 return null;
6763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764
Pengquan Menga1bb6272018-09-06 09:59:22 -07006765 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 try {
6767 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006768 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 } finally {
6771 Binder.restoreCallingIdentity(identity);
6772 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006773 }
6774
6775 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006776 * Get the call forwarding info, given the call forwarding reason.
6777 */
6778 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006779 public void getCallForwarding(int subId, int callForwardingReason,
6780 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006781 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006782
6783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6784 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6785
Shuo Qian4a594052020-01-23 11:59:30 -08006786 long identity = Binder.clearCallingIdentity();
6787 try {
6788 if (DBG) {
6789 log("getCallForwarding: subId " + subId
6790 + " callForwardingReason" + callForwardingReason);
6791 }
Hall Liu27d24262020-09-18 19:04:59 -07006792
6793 Phone phone = getPhone(subId);
6794 if (phone == null) {
6795 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006796 callback.onError(
6797 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006798 } catch (RemoteException e) {
6799 // ignore
6800 }
6801 return;
6802 }
6803
6804 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6805 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6806 @Override
6807 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6808 try {
6809 callback.onCallForwardingInfoAvailable(info);
6810 } catch (RemoteException e) {
6811 // ignore
6812 }
6813 }
6814
6815 @Override
6816 public void onError(int error) {
6817 try {
6818 callback.onError(error);
6819 } catch (RemoteException e) {
6820 // ignore
6821 }
6822 }
6823 });
6824 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
6828 }
6829
6830 /**
6831 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6832 * reason, the number to forward, and the timeout before the forwarding is attempted.
6833 */
6834 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006835 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6836 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006837 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006838
6839 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6840 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6841
Shuo Qian4a594052020-01-23 11:59:30 -08006842 long identity = Binder.clearCallingIdentity();
6843 try {
6844 if (DBG) {
6845 log("setCallForwarding: subId " + subId
6846 + " callForwardingInfo" + callForwardingInfo);
6847 }
Hall Liu27d24262020-09-18 19:04:59 -07006848
6849 Phone phone = getPhone(subId);
6850 if (phone == null) {
6851 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006852 callback.accept(
6853 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006854 } catch (RemoteException e) {
6855 // ignore
6856 }
6857 return;
6858 }
6859
6860 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6861 FunctionalUtils.ignoreRemoteException(callback::accept));
6862
6863 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866 }
6867 }
6868
6869 /**
Hall Liu27d24262020-09-18 19:04:59 -07006870 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006871 */
6872 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006873 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006874 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006875
6876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6877 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6878
Shuo Qian4a594052020-01-23 11:59:30 -08006879 long identity = Binder.clearCallingIdentity();
6880 try {
Hall Liu27d24262020-09-18 19:04:59 -07006881 Phone phone = getPhone(subId);
6882 if (phone == null) {
6883 try {
6884 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6885 } catch (RemoteException e) {
6886 // ignore
6887 }
6888 return;
6889 }
SongFerngWang0e767992021-03-31 22:08:45 +08006890 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6891 PersistableBundle c = configManager.getConfigForSubId(subId);
6892 boolean requireUssd = c.getBoolean(
6893 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006894
Shuo Qian4a594052020-01-23 11:59:30 -08006895 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006896 if (requireUssd) {
6897 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6898 getSubscriptionCarrierId(subId));
6899 String newUssdCommand = "";
6900 try {
6901 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006902 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006903 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6904 } catch (NullPointerException e) {
6905 loge("Failed to generate USSD number" + e);
6906 }
6907 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6908 mMainThreadHandler, callback, carrierXmlParser,
6909 CarrierXmlParser.SsEntry.SSAction.QUERY);
6910 final String ussdCommand = newUssdCommand;
6911 Executors.newSingleThreadExecutor().execute(() -> {
6912 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6913 });
6914 } else {
6915 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6916 callback::accept);
6917 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6918 }
Shuo Qian4a594052020-01-23 11:59:30 -08006919 } finally {
6920 Binder.restoreCallingIdentity(identity);
6921 }
6922 }
6923
6924 /**
Hall Liu27d24262020-09-18 19:04:59 -07006925 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006926 */
6927 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006928 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006929 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006930
6931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6932 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
6933
Shuo Qian4a594052020-01-23 11:59:30 -08006934 long identity = Binder.clearCallingIdentity();
6935 try {
Hall Liu27d24262020-09-18 19:04:59 -07006936 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6937
6938 Phone phone = getPhone(subId);
6939 if (phone == null) {
6940 try {
6941 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6942 } catch (RemoteException e) {
6943 // ignore
6944 }
6945 return;
6946 }
6947
SongFerngWang0e767992021-03-31 22:08:45 +08006948 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6949 PersistableBundle c = configManager.getConfigForSubId(subId);
6950 boolean requireUssd = c.getBoolean(
6951 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006952
SongFerngWang0e767992021-03-31 22:08:45 +08006953 if (DBG) log("getCallWaitingStatus: subId " + subId);
6954 if (requireUssd) {
6955 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6956 getSubscriptionCarrierId(subId));
6957 CarrierXmlParser.SsEntry.SSAction ssAction =
6958 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6959 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6960 String newUssdCommand = "";
6961 try {
6962 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006963 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006964 .makeCommand(ssAction, null);
6965 } catch (NullPointerException e) {
6966 loge("Failed to generate USSD number" + e);
6967 }
6968 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6969 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6970 final String ussdCommand = newUssdCommand;
6971 Executors.newSingleThreadExecutor().execute(() -> {
6972 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6973 });
6974 } else {
6975 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6976 FunctionalUtils.ignoreRemoteException(callback::accept));
6977
6978 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6979 }
Shuo Qian4a594052020-01-23 11:59:30 -08006980 } finally {
6981 Binder.restoreCallingIdentity(identity);
6982 }
6983 }
6984
6985 /**
yinxub1bed742017-04-17 11:45:04 -07006986 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006987 *
yinxub1bed742017-04-17 11:45:04 -07006988 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006989 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6990 * location related information which will be sent if the caller already possess
6991 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006992 * @param request contains the radio access networks with bands/channels to scan
6993 * @param messenger callback messenger for scan results or errors
6994 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006995 * @return the id of the requested scan which can be used to stop the scan.
6996 */
6997 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006998 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6999 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007000 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7002 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007003 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007004 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7005 if (!renounceFineLocationAccess) {
7006 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007007 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7008 .setCallingPackage(callingPackage)
7009 .setCallingFeatureId(callingFeatureId)
7010 .setCallingPid(Binder.getCallingPid())
7011 .setCallingUid(Binder.getCallingUid())
7012 .setMethod("requestNetworkScan")
7013 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7014 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7015 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7016 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007017 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007018 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007019 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7020 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007021 if (e != null) {
7022 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7023 throw e;
7024 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007025 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007026 return TelephonyScanManager.INVALID_SCAN_ID;
7027 }
7028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 }
joonhunshin4ac60942023-11-15 15:23:39 +00007030
7031 enforceTelephonyFeatureWithException(callingPackage,
7032 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7033
Hall Liu912dfd32019-04-25 14:02:26 -07007034 int callingUid = Binder.getCallingUid();
7035 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007039 renounceFineLocationAccess, request, messenger, binder,
7040 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007041 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007042 } finally {
7043 Binder.restoreCallingIdentity(identity);
7044 }
yinxu504e1392017-04-12 16:03:22 -07007045 }
7046
Hall Liub2ac8ef2019-02-28 15:56:23 -08007047 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007048 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007049 boolean hasCarrierPriv;
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7053 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7054 } finally {
7055 Binder.restoreCallingIdentity(identity);
7056 }
Hall Liu558027f2019-05-15 19:14:05 -07007057 boolean hasNetworkScanPermission =
7058 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007059 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007060
7061 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7062 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7063 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007064 }
7065
7066 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7067 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007068 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7069 return new SecurityException("Specific channels must not be"
7070 + " scanned without location access.");
7071 }
7072 }
7073 }
7074
Hall Liub2ac8ef2019-02-28 15:56:23 -08007075 return null;
7076 }
7077
yinxu504e1392017-04-12 16:03:22 -07007078 /**
7079 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007080 *
7081 * @param subId id of the subscription
7082 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007083 */
7084 @Override
7085 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7087 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088
Hall Liu912dfd32019-04-25 14:02:26 -07007089 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 final long identity = Binder.clearCallingIdentity();
7091 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007092 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 } finally {
7094 Binder.restoreCallingIdentity(identity);
7095 }
yinxu504e1392017-04-12 16:03:22 -07007096 }
7097
7098 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007099 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007100 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007101 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007102 */
7103 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007104 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007105 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007106 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007107 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108
joonhunshin4ac60942023-11-15 15:23:39 +00007109 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7110 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 final long identity = Binder.clearCallingIdentity();
7113 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007114 if (DBG) log("getAllowedNetworkTypesBitmask");
7115 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7116 int networkTypesBitmask = (result != null ? result[0] : -1);
7117 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7118 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 } finally {
7120 Binder.restoreCallingIdentity(identity);
7121 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007122 }
7123
7124 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007125 * Get the allowed network types for certain reason.
7126 *
7127 * @param subId the id of the subscription.
7128 * @param reason the reason the allowed network type change is taking place
7129 * @return the allowed network types.
7130 */
7131 @Override
7132 public long getAllowedNetworkTypesForReason(int subId,
7133 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007134 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007135 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007136
7137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7138 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7139
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007140 final long identity = Binder.clearCallingIdentity();
7141 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007142 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145 }
7146 }
7147
7148 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007149 * Enable/Disable E-UTRA-NR Dual Connectivity
7150 * @param subId subscription id of the sim card
7151 * @param nrDualConnectivityState expected NR dual connectivity state
7152 * This can be passed following states
7153 * <ol>
7154 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7155 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7156 * <li>Disable NR dual connectivity and force secondary cell to be released
7157 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7158 * </ol>
7159 * @return operation result.
7160 */
7161 @Override
7162 public int setNrDualConnectivityState(int subId,
7163 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7165 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007166 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007167 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7168 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7169 }
7170
Sooraj Sasindran37444802020-08-11 10:40:43 -07007171 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7175 nrDualConnectivityState, subId,
7176 workSource);
7177 if (DBG) log("enableNRDualConnectivity result: " + result);
7178 return result;
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
7181 }
7182 }
7183
7184 /**
7185 * Is E-UTRA-NR Dual Connectivity enabled
7186 * @return true if dual connectivity is enabled else false
7187 */
7188 @Override
7189 public boolean isNrDualConnectivityEnabled(int subId) {
7190 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007191 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007192 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007193 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007194 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7195 return false;
7196 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007197 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7201 null, subId, workSource);
7202 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7203 return isEnabled;
7204 } finally {
7205 Binder.restoreCallingIdentity(identity);
7206 }
7207 }
7208
7209 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007210 * Set the allowed network types of the device and
7211 * provide the reason triggering the allowed network change.
7212 *
7213 * @param subId the id of the subscription.
7214 * @param reason the reason the allowed network type change is taking place
7215 * @param allowedNetworkTypes the allowed network types.
7216 * @return true on success; false on any failure.
7217 */
7218 @Override
7219 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007220 @TelephonyManager.AllowedNetworkTypesReason int reason,
7221 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7223 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007224 // If the caller only has carrier privileges, then they should not be able to override
7225 // any network types which were set for security reasons.
7226 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7227 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007228 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007229 throw new SecurityException(
7230 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007231 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007232 }
joonhunshin4ac60942023-11-15 15:23:39 +00007233
7234 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7235 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7236
SongFerngWang3ef3e072020-12-21 16:41:52 +08007237 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007238 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007239 return false;
7240 }
7241 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7242 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007243 return false;
7244 }
7245
Jack Yu5b494332023-01-23 18:18:04 +00007246 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7247 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007248
Jack Yue37dd262022-12-16 11:53:37 -08007249 Phone phone = getPhone(subId);
7250 if (phone == null) {
7251 return false;
7252 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007253
Jack Yue37dd262022-12-16 11:53:37 -08007254 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007255 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007256 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007257 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007258
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007259 final long identity = Binder.clearCallingIdentity();
7260 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007261 Boolean success = (Boolean) sendRequest(
7262 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7263 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7264
7265 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7266 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007267 } finally {
7268 Binder.restoreCallingIdentity(identity);
7269 }
7270 }
7271
7272 /**
Miaoa84611c2019-03-15 09:21:10 +08007273 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007274 *
Miaoa84611c2019-03-15 09:21:10 +08007275 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007276 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007277 * @hide
7278 */
7279 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007280 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007281 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007282
7283 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7284 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007287 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288 try {
Miaoa84611c2019-03-15 09:21:10 +08007289 if (phone != null) {
7290 return phone.hasMatchedTetherApnSetting();
7291 } else {
7292 return false;
7293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294 } finally {
7295 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007296 }
Junda Liu475951f2014-11-07 16:45:03 -08007297 }
7298
7299 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007300 * Get the user enabled state of Mobile Data.
7301 *
7302 * TODO: remove and use isUserDataEnabled.
7303 * This can't be removed now because some vendor codes
7304 * calls through ITelephony directly while they should
7305 * use TelephonyManager.
7306 *
7307 * @return true on enabled
7308 */
7309 @Override
7310 public boolean getDataEnabled(int subId) {
7311 return isUserDataEnabled(subId);
7312 }
7313
7314 /**
7315 * Get whether mobile data is enabled per user setting.
7316 *
7317 * There are other factors deciding whether mobile data is actually enabled, but they are
7318 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007319 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007320 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7321 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007322 *
7323 * @return {@code true} if data is enabled else {@code false}
7324 */
7325 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007326 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007327 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007328 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007329 try {
7330 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7331 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007332 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007333 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7334 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007335 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007337 mApp, subId, functionName);
7338
Robert Greenwalt646120a2014-05-23 11:54:03 -07007339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340
7341 final long identity = Binder.clearCallingIdentity();
7342 try {
Jack Yu285100e2022-12-02 22:48:35 -08007343 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7345 Phone phone = PhoneFactory.getPhone(phoneId);
7346 if (phone != null) {
7347 boolean retVal = phone.isUserDataEnabled();
7348 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7349 return retVal;
7350 } else {
7351 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7352 return false;
7353 }
7354 } finally {
7355 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007356 }
7357 }
7358
7359 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007360 * Checks if the device is capable of mobile data by considering whether whether the
7361 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7362 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007363 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007364 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007365 */
7366 @Override
7367 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007368 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007369 try {
7370 try {
7371 mApp.enforceCallingOrSelfPermission(
7372 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007373 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007374 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007375 try {
7376 mApp.enforceCallingOrSelfPermission(
7377 android.Manifest.permission.READ_PHONE_STATE,
7378 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007379 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007380 mApp.enforceCallingOrSelfPermission(
7381 permission.READ_BASIC_PHONE_STATE, functionName);
7382 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007383 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007384 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007385 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387
joonhunshin4ac60942023-11-15 15:23:39 +00007388 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7389 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 final long identity = Binder.clearCallingIdentity();
7392 try {
Jack Yu285100e2022-12-02 22:48:35 -08007393 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394 Phone phone = PhoneFactory.getPhone(phoneId);
7395 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007396 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007397 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 return retVal;
7399 } else {
7400 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7401 return false;
7402 }
7403 } finally {
7404 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007405 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007406 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007407
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007408 /**
7409 * Check if data is enabled for a specific reason
7410 * @param subId Subscription index
7411 * @param reason the reason the data enable change is taking place
7412 * @return {@code true} if the overall data is enabled; {@code false} if not.
7413 */
7414 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007415 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007416 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007417 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007418 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007419 try {
7420 mApp.enforceCallingOrSelfPermission(
7421 android.Manifest.permission.ACCESS_NETWORK_STATE,
7422 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007423 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007424 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7425 functionName);
7426 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007427 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007428 try {
7429 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007430 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007431 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007433 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007434 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007435 }
7436
joonhunshin4ac60942023-11-15 15:23:39 +00007437 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7438 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007439
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
Jack Yu285100e2022-12-02 22:48:35 -08007442 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007443 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007444 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007445 + " reason=" + reason);
7446 }
7447 Phone phone = PhoneFactory.getPhone(phoneId);
7448 if (phone != null) {
7449 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007450 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007451 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007452 return retVal;
7453 } else {
7454 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007455 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007456 + subId + " retVal=false");
7457 }
7458 return false;
7459 }
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
7463 }
7464
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007466 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007467 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7468 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7469
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007470 // No permission needed; this only lets the caller inspect their own status.
7471 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007472 }
Junda Liu29340342014-07-10 15:23:27 -07007473
7474 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007475 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007476 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007477
7478 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7479 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7480
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007481 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7482 }
7483
7484 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7485 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007486 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007487 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007488 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7489 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007490 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7491 if (cpt == null) {
7492 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007493 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7494 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007495 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007496 }
7497
7498 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007499 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007500 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007501
7502 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7503 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7504
chen xuf7e9fe82019-05-09 19:31:02 -07007505 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007506 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007507 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007508 Phone phone = getPhone(subId);
7509 if (phone == null) {
7510 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7511 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7512 }
7513 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7514 if (cpt == null) {
7515 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007516 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7517 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007518 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007519 }
7520
7521 @Override
7522 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007523 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007524
7525 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7526 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7527 "checkCarrierPrivilegesForPackageAnyPhone");
7528
Rambo Wange7209ce2022-02-23 13:41:02 -08007529 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7530 }
7531
7532 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007533 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007534 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007535 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007536 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007537 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7538 Phone phone = PhoneFactory.getPhone(phoneId);
7539 if (phone == null) {
7540 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007541 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007542 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7543 if (cpt == null) {
7544 continue;
7545 }
7546 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007547 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7548 break;
7549 }
7550 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007551 return result;
Junda Liu29340342014-07-10 15:23:27 -07007552 }
Derek Tan89e89d42014-07-08 17:00:10 -07007553
7554 @Override
Junda Liue64de782015-04-16 17:19:16 -07007555 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007556 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007557
7558 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7559 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7560 "getCarrierPackageNamesForIntentAndPhone");
7561
Rambo Wang8a247eb2022-02-08 21:11:18 +00007562 Phone phone = PhoneFactory.getPhone(phoneId);
7563 if (phone == null) {
7564 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007565 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007566 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7567 if (cpt == null) {
7568 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007569 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007570 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007571 }
7572
Amith Yamasani6e118872016-02-19 12:53:51 -08007573 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007574 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007575 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007576 Phone phone = PhoneFactory.getPhone(phoneId);
7577 if (phone == null) {
7578 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007579 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007580 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7581 if (cpt == null) {
7582 return Collections.emptyList();
7583 }
7584 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007585 }
7586
chen xuf7e9fe82019-05-09 19:31:02 -07007587 @Override
7588 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007589 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007590
7591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7592 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7593 "getPackagesWithCarrierPrivilegesForAllPhones");
7594
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007595 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007596 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007597 try {
7598 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7599 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7600 }
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007603 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007604 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007605 }
7606
Rambo Wang6812ffb2022-03-15 16:54:17 -07007607 @Override
7608 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7609 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7610
joonhunshin4ac60942023-11-15 15:23:39 +00007611 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7612 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7613 "getCarrierServicePackageNameForLogicalSlot");
7614
Rambo Wang6812ffb2022-03-15 16:54:17 -07007615 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7616 if (phone == null) {
7617 return null;
7618 }
7619 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7620 if (cpt == null) {
7621 return null;
7622 }
7623 return cpt.getCarrierServicePackageName();
7624 }
7625
Wink Savilleb564aae2014-10-23 10:18:09 -07007626 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007627 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007628 UiccPort port = phone == null ? null : phone.getUiccPort();
7629 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007630 return null;
7631 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007632 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007633 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007634 return null;
7635 }
7636 return iccId;
7637 }
7638
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007639 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007640 public void setCallComposerStatus(int subId, int status) {
7641 enforceModifyPermission();
7642
joonhunshin4ac60942023-11-15 15:23:39 +00007643 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7644 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7645
Shuo Qiane4e11672020-12-15 22:15:33 -08007646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 Phone phone = getPhone(subId);
7649 if (phone != null) {
7650 Phone defaultPhone = phone.getImsPhone();
7651 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7652 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7653 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007654 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7655 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007656 }
7657 }
Shuo Qian284ae752020-12-22 19:10:14 -08007658 } catch (ImsException e) {
7659 throw new ServiceSpecificException(e.getCode());
7660 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007661 Binder.restoreCallingIdentity(identity);
7662 }
7663 }
7664
7665 @Override
7666 public int getCallComposerStatus(int subId) {
7667 enforceReadPrivilegedPermission("getCallComposerStatus");
7668
joonhunshin4ac60942023-11-15 15:23:39 +00007669 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7670 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7671
Shuo Qiane4e11672020-12-15 22:15:33 -08007672 final long identity = Binder.clearCallingIdentity();
7673 try {
7674 Phone phone = getPhone(subId);
7675 if (phone != null) {
7676 Phone defaultPhone = phone.getImsPhone();
7677 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7678 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7679 return imsPhone.getCallComposerStatus();
7680 }
7681 }
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
7684 }
7685 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7686 }
7687
7688 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007689 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7690 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007691 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007692 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007693
joonhunshin4ac60942023-11-15 15:23:39 +00007694 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7695 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7696 "setLine1NumberForDisplayForSubscriber");
7697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 final long identity = Binder.clearCallingIdentity();
7699 try {
7700 final String iccId = getIccId(subId);
7701 final Phone phone = getPhone(subId);
7702 if (phone == null) {
7703 return false;
7704 }
7705 final String subscriberId = phone.getSubscriberId();
7706
7707 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007708 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709 + subscriberId + " to " + number);
7710 }
7711
7712 if (TextUtils.isEmpty(iccId)) {
7713 return false;
7714 }
7715
7716 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7717
7718 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7719 if (alphaTag == null) {
7720 editor.remove(alphaTagPrefKey);
7721 } else {
7722 editor.putString(alphaTagPrefKey, alphaTag);
7723 }
7724
7725 // Record both the line number and IMSI for this ICCID, since we need to
7726 // track all merged IMSIs based on line number
7727 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7728 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7729 if (number == null) {
7730 editor.remove(numberPrefKey);
7731 editor.remove(subscriberPrefKey);
7732 } else {
7733 editor.putString(numberPrefKey, number);
7734 editor.putString(subscriberPrefKey, subscriberId);
7735 }
7736
7737 editor.commit();
7738 return true;
7739 } finally {
7740 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007741 }
Derek Tan7226c842014-07-02 17:42:23 -07007742 }
7743
7744 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007745 public String getLine1NumberForDisplay(int subId, String callingPackage,
7746 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007747 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007749 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007750 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007751 return null;
7752 }
Derek Tan97ebb422014-09-05 16:55:38 -07007753
joonhunshin4ac60942023-11-15 15:23:39 +00007754 enforceTelephonyFeatureWithException(callingPackage,
7755 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 String iccId = getIccId(subId);
7760 if (iccId != null) {
7761 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7762 if (DBG_MERGE) {
7763 log("getLine1NumberForDisplay returning "
7764 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7765 }
7766 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7769 return null;
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007772 }
Derek Tan7226c842014-07-02 17:42:23 -07007773 }
7774
7775 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007776 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7777 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007779 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007780 return null;
7781 }
Derek Tan97ebb422014-09-05 16:55:38 -07007782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 final long identity = Binder.clearCallingIdentity();
7784 try {
7785 String iccId = getIccId(subId);
7786 if (iccId != null) {
7787 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7788 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7789 }
7790 return null;
7791 } finally {
7792 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007793 }
Derek Tan7226c842014-07-02 17:42:23 -07007794 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007795
7796 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007797 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7798 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007799 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7800 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007802 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007803 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007804 return null;
7805 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007806
Jordan Liub49b04b2019-05-06 14:45:15 -07007807 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7808 // the process, where TelephonyManager was instantiated.
7809 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007810 final long identity = Binder.clearCallingIdentity();
7811 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007812 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 final TelephonyManager tele = TelephonyManager.from(context);
7814 final SubscriptionManager sub = SubscriptionManager.from(context);
7815
7816 // Figure out what subscribers are currently active
7817 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818
Jordan Liub49b04b2019-05-06 14:45:15 -07007819 // Only consider subs which match the current subId
7820 // This logic can be simplified. See b/131189269 for progress.
7821 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007822 activeSubscriberIds.add(tele.getSubscriberId(subId));
7823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824
7825 // First pass, find a number override for an active subscriber
7826 String mergeNumber = null;
7827 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7828 for (String key : prefs.keySet()) {
7829 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7830 final String subscriberId = (String) prefs.get(key);
7831 if (activeSubscriberIds.contains(subscriberId)) {
7832 final String iccId = key.substring(
7833 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7834 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7835 mergeNumber = (String) prefs.get(numberKey);
7836 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007837 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 + " for active subscriber " + subscriberId);
7839 }
7840 if (!TextUtils.isEmpty(mergeNumber)) {
7841 break;
7842 }
7843 }
7844 }
7845 }
7846
7847 // Shortcut when no active merged subscribers
7848 if (TextUtils.isEmpty(mergeNumber)) {
7849 return null;
7850 }
7851
7852 // Second pass, find all subscribers under that line override
7853 final ArraySet<String> result = new ArraySet<>();
7854 for (String key : prefs.keySet()) {
7855 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7856 final String number = (String) prefs.get(key);
7857 if (mergeNumber.equals(number)) {
7858 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7859 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7860 final String subscriberId = (String) prefs.get(subscriberKey);
7861 if (!TextUtils.isEmpty(subscriberId)) {
7862 result.add(subscriberId);
7863 }
7864 }
7865 }
7866 }
7867
7868 final String[] resultArray = result.toArray(new String[result.size()]);
7869 Arrays.sort(resultArray);
7870 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007871 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007872 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7873 }
7874 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007875 } finally {
7876 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007877 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007878 }
7879
7880 @Override
zoey chen38003472019-12-13 17:16:31 +08007881 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7882 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007883
joonhunshin4ac60942023-11-15 15:23:39 +00007884 enforceTelephonyFeatureWithException(callingPackage,
7885 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7886
Malcolm Chen6ca97372019-07-01 16:28:21 -07007887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 final TelephonyManager telephonyManager = mApp.getSystemService(
7890 TelephonyManager.class);
7891 String subscriberId = telephonyManager.getSubscriberId(subId);
7892 if (subscriberId == null) {
7893 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007894 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007895 + subId);
7896 }
7897 return null;
7898 }
7899
Jack Yu3beaf9d2023-04-14 09:17:27 -07007900 final SubscriptionInfo info = getSubscriptionManagerService()
7901 .getSubscriptionInfo(subId);
7902 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007903 // If it doesn't belong to any group, return just subscriberId of itself.
7904 if (groupUuid == null) {
7905 return new String[]{subscriberId};
7906 }
7907
7908 // Get all subscriberIds from the group.
7909 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007910 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7911 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7912 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007913 for (SubscriptionInfo subInfo : groupInfos) {
7914 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7915 if (subscriberId != null) {
7916 mergedSubscriberIds.add(subscriberId);
7917 }
7918 }
7919
7920 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7921 } finally {
7922 Binder.restoreCallingIdentity(identity);
7923
7924 }
7925 }
7926
7927 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007928 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007930 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931
joonhunshin4ac60942023-11-15 15:23:39 +00007932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7933 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
7934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 final long identity = Binder.clearCallingIdentity();
7936 try {
7937 final Phone phone = getPhone(subId);
7938 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007942 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007943
7944 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007945 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007946 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7947 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7949 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950
7951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 final Phone phone = getPhone(subId);
7954 if (phone == null) {
7955 return false;
7956 }
7957 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7958 cdmaNonRoamingList);
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007961 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007962 }
7963
7964 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007965 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007966 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007967 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007968 if (phone == null) {
7969 return raf;
7970 }
7971
Shuo Qiandee53402020-05-29 14:08:15 -07007972 try {
7973 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007974 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007975 mApp, phone.getSubId(), "getRadioAccessFamily");
7976 } catch (SecurityException e) {
7977 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7978 throw e;
7979 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007980
joonhunshin4ac60942023-11-15 15:23:39 +00007981 enforceTelephonyFeatureWithException(callingPackage,
7982 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
7983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984 final long identity = Binder.clearCallingIdentity();
7985 try {
chen xub97461a2018-10-26 14:17:57 -07007986 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 } finally {
7988 Binder.restoreCallingIdentity(identity);
7989 }
chen xub97461a2018-10-26 14:17:57 -07007990 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007991 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007992
7993 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007994 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007995 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007996 try {
7997 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7998 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007999 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008000 }
8001 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008002 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008003 }
joonhunshin4ac60942023-11-15 15:23:39 +00008004
8005 enforceTelephonyFeatureWithException(callingPackage,
8006 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8007
Hall Liu82694d52020-12-11 18:22:04 -08008008 RoleManager rm = mApp.getSystemService(RoleManager.class);
8009 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8010 if (!dialerRoleHolders.contains(callingPackage)) {
8011 throw new SecurityException("App must be the dialer role holder to"
8012 + " upload a call composer pic");
8013 }
8014
8015 Executors.newSingleThreadExecutor().execute(() -> {
8016 ByteArrayOutputStream output = new ByteArrayOutputStream(
8017 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8018 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8019 boolean readUntilEnd = false;
8020 int totalBytesRead = 0;
8021 byte[] buffer = new byte[16 * 1024];
8022 while (true) {
8023 int numRead;
8024 try {
8025 numRead = input.read(buffer);
8026 } catch (IOException e) {
8027 try {
8028 fd.checkError();
8029 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8030 null);
8031 } catch (IOException e1) {
8032 // This means that the other side closed explicitly with an error. If this
8033 // happens, log and ignore.
8034 loge("Remote end of call composer picture pipe closed: " + e1);
8035 }
8036 break;
8037 }
8038 if (numRead == -1) {
8039 readUntilEnd = true;
8040 break;
8041 }
8042 totalBytesRead += numRead;
8043 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8044 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8045 try {
8046 input.close();
8047 } catch (IOException e) {
8048 // ignore
8049 }
8050 break;
8051 }
8052 output.write(buffer, 0, numRead);
8053 }
8054 // Generally, the remote end will close the file descriptors. The only case where we
8055 // close is above, where the picture size is too big.
8056
8057 try {
8058 fd.checkError();
8059 } catch (IOException e) {
8060 loge("Remote end for call composer closed with an error: " + e);
8061 return;
8062 }
8063
Hall Liuaa4211e2021-01-20 15:43:39 -08008064 if (!readUntilEnd) {
8065 loge("Did not finish reading entire image; aborting");
8066 return;
8067 }
Hall Liu82694d52020-12-11 18:22:04 -08008068
Hall Liuaa4211e2021-01-20 15:43:39 -08008069 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8070 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8071 new CallComposerPictureTransfer.Factory() {},
8072 imageData,
8073 (result) -> {
8074 if (result.first != null) {
8075 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8076 Bundle outputResult = new Bundle();
8077 outputResult.putParcelable(
8078 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8079 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8080 outputResult);
8081 } else {
8082 callback.send(result.second, null);
8083 }
8084 }
8085 );
Hall Liu82694d52020-12-11 18:22:04 -08008086 });
8087 }
8088
8089 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008090 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008091 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008092 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093
joonhunshin4ac60942023-11-15 15:23:39 +00008094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8095 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 final long identity = Binder.clearCallingIdentity();
8098 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008099 ImsManager.getInstance(defaultPhone.getContext(),
8100 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008104 }
8105
8106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008107 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008108 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8110 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008111 return false;
8112 }
Svet Ganovb320e182015-04-16 12:30:10 -07008113
joonhunshin4ac60942023-11-15 15:23:39 +00008114 enforceTelephonyFeatureWithException(callingPackage,
8115 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 // Check the user preference and the system-level IMS setting. Even if the user has
8120 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8121 // In the long run, we may instead need to check if there exists a connection service
8122 // which can support video calling.
8123 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008124 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 return imsManager.isVtEnabledByPlatform()
8126 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8127 && imsManager.isVtEnabledByUser();
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008131 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008132
Andrew Leea1239f22015-03-02 17:44:07 -08008133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008134 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8135 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008137 mApp, subId, callingPackage, callingFeatureId,
8138 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 return false;
8140 }
8141
joonhunshin4ac60942023-11-15 15:23:39 +00008142 enforceTelephonyFeatureWithException(callingPackage,
8143 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008145 final long identity = Binder.clearCallingIdentity();
8146 try {
8147 CarrierConfigManager configManager =
8148 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008149 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8151 } finally {
8152 Binder.restoreCallingIdentity(identity);
8153 }
Andrew Leea1239f22015-03-02 17:44:07 -08008154 }
8155
8156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008157 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008159 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008160 return false;
8161 }
8162
joonhunshin4ac60942023-11-15 15:23:39 +00008163 enforceTelephonyFeatureWithException(callingPackage,
8164 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 final long identity = Binder.clearCallingIdentity();
8167 try {
8168 CarrierConfigManager configManager =
8169 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008170 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008171 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8172 } finally {
8173 Binder.restoreCallingIdentity(identity);
8174 }
Andrew Leea1239f22015-03-02 17:44:07 -08008175 }
8176
Andrew Lee9431b832015-03-09 18:46:45 -07008177 @Override
8178 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008179 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008180 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008181 }
8182
8183 @Override
8184 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008185 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8186 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188 final long identity = Binder.clearCallingIdentity();
8189 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008190 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191 } finally {
8192 Binder.restoreCallingIdentity(identity);
8193 }
Andrew Lee9431b832015-03-09 18:46:45 -07008194 }
8195
Hall Liuf6668912018-10-31 17:05:23 -07008196 /**
8197 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8198 * support for the feature and device firmware support.
8199 *
8200 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8201 */
8202 @Override
8203 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008204 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8205 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008208 final Phone phone = getPhone(subscriptionId);
8209 if (phone == null) {
8210 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8211 return false;
8212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008214 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008216 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8217 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8218 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 return isCarrierSupported && isDeviceSupported;
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
Hall Liu98187582018-01-22 19:15:32 -08008223 }
8224
Hall Liuf6668912018-10-31 17:05:23 -07008225 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008226 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8227 * RTT setting, will return true if the device and carrier both support RTT.
8228 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008229 */
8230 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 final long identity = Binder.clearCallingIdentity();
8232 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008233 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8234 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8235 return false;
8236 }
8237 }
8238
Hall Liu5bab75c2019-12-11 23:58:20 +00008239 boolean isRttSupported = isRttSupported(subscriptionId);
8240 boolean isUserRttSettingOn = Settings.Secure.getInt(
8241 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8242 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8243 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8244 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008248 }
8249
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008250 @Deprecated
8251 @Override
8252 public String getDeviceId(String callingPackage) {
8253 return getDeviceIdWithFeature(callingPackage, null);
8254 }
8255
Sanket Padawe7310cc72015-01-14 09:53:20 -08008256 /**
8257 * Returns the unique device ID of phone, for example, the IMEI for
8258 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8259 *
8260 * <p>Requires Permission:
8261 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8262 */
8263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008264 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008265 try {
8266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8267 } catch (SecurityException se) {
8268 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8269 throw new SecurityException("Package " + callingPackage + " does not belong to "
8270 + Binder.getCallingUid());
8271 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008272 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008273 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008274 return null;
8275 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008276 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008277 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008278 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008279 return null;
8280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281
8282 final long identity = Binder.clearCallingIdentity();
8283 try {
8284 return phone.getDeviceId();
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008288 }
8289
Ping Sunc67b7c22016-03-02 19:16:45 +08008290 /**
8291 * {@hide}
8292 * Returns the IMS Registration Status on a particular subid
8293 *
8294 * @param subId
8295 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008296 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008297 Phone phone = getPhone(subId);
8298 if (phone != null) {
8299 return phone.isImsRegistered();
8300 } else {
8301 return false;
8302 }
8303 }
8304
Santos Cordon7a1885b2015-02-03 11:15:19 -08008305 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008306 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008307 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008309 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008310 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8311 }
8312 final long identity = Binder.clearCallingIdentity();
8313 try {
8314 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
8318 }
8319
8320 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008321 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008322 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008323 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008324 mApp,
8325 subscriptionId,
8326 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8327 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008328
8329 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8330 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8331
Tyler Gunnf70ed162019-04-03 15:28:53 -07008332 final long identity = Binder.clearCallingIdentity();
8333 try {
8334 Phone phone = getPhone(subscriptionId);
8335 if (phone == null) {
8336 return null;
8337 }
8338 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008344 /**
8345 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008346 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008347 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348 final long identity = Binder.clearCallingIdentity();
8349 try {
8350 Phone phone = getPhone(subId);
8351 if (phone != null) {
8352 return phone.isWifiCallingEnabled();
8353 } else {
8354 return false;
8355 }
8356 } finally {
8357 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008358 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008359 }
8360
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008361 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008362 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008363 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008364 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365 final long identity = Binder.clearCallingIdentity();
8366 try {
8367 Phone phone = getPhone(subId);
8368 if (phone != null) {
8369 return phone.isVideoEnabled();
8370 } else {
8371 return false;
8372 }
8373 } finally {
8374 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008375 }
8376 }
8377
8378 /**
8379 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8380 * defined in {@link ImsRegistrationImplBase}.
8381 */
8382 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383 final long identity = Binder.clearCallingIdentity();
8384 try {
8385 Phone phone = getPhone(subId);
8386 if (phone != null) {
8387 return phone.getImsRegistrationTech();
8388 } else {
8389 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8390 }
8391 } finally {
8392 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008393 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008394 }
8395
Stuart Scott8eef64f2015-04-08 15:13:54 -07008396 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008397 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008398 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008399
8400 enforceTelephonyFeatureWithException(callingPackage,
8401 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8402
Stuart Scott981d8582015-04-21 14:09:50 -07008403 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8404 return;
8405 }
Kai Shif70f46f2021-03-03 13:59:46 -08008406 Phone defaultPhone = getDefaultPhone();
8407 if (defaultPhone != null) {
8408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8409 mApp, getDefaultPhone().getSubId(), "factoryReset");
8410 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008411 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008412
Svet Ganovcc087f82015-05-12 20:35:54 -07008413 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008414 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8415 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008416 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008417 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008418 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008419 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008420 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008421 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008422 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008423 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008424 // There has been issues when Sms raw table somehow stores orphan
8425 // fragments. They lead to garbled message when new fragments come
8426 // in and combined with those stale ones. In case this happens again,
8427 // user can reset all network settings which will clean up this table.
8428 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008429 // Clean up IMS settings as well here.
8430 int slotId = getSlotIndex(subId);
8431 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8432 ImsManager.getInstance(mApp, slotId).factoryReset();
8433 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008434
Kai Shif70f46f2021-03-03 13:59:46 -08008435 if (defaultPhone == null) {
8436 return;
8437 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008438 // Erase modem config if erase modem on network setting is enabled.
8439 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8440 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8441 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008442 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008443 }
Kai Shif70f46f2021-03-03 13:59:46 -08008444
8445 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008446 } finally {
8447 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008448 }
8449 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008450
SongFerngWangfd89b102021-05-27 22:44:54 +08008451 @VisibleForTesting
8452 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8453 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8454 return;
8455 }
8456 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8457 RILConstants.PREFERRED_NETWORK_MODE);
8458 SubscriptionManager.setSubscriptionProperty(subId,
8459 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8460 "user=" + defaultNetworkType);
8461 phone.loadAllowedNetworksFromSubscriptionDatabase();
8462 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8463 defaultNetworkType, null);
8464 }
8465
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008466 private void cleanUpSmsRawTable(Context context) {
8467 ContentResolver resolver = context.getContentResolver();
8468 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8469 resolver.delete(uri, null, null);
8470 }
8471
Narayan Kamath1c496c22015-04-16 14:40:19 +01008472 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008473 public String getSimLocaleForSubscriber(int subId) {
8474 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008475
8476 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8477 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8478
chen xu5d3637b2019-01-21 23:31:38 -08008479 final Phone phone = getPhone(subId);
8480 if (phone == null) {
8481 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008482 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008484 final long identity = Binder.clearCallingIdentity();
8485 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008486 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8487 phone.getContext().getOpPackageName(),
8488 phone.getContext().getAttributionTag());
8489 if (info == null) {
8490 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8491 return null;
chen xu6291c472019-02-04 12:55:53 -08008492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493 // Try and fetch the locale from the carrier properties or from the SIM language
8494 // preferences (EF-PL and EF-LI)...
8495 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008496 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008497 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8498 if (localeFromDefaultSim != null) {
8499 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8500 if (DBG) log("Using locale from subId: " + subId + " locale: "
8501 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008502 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008503 } else {
8504 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008505 }
8506 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 // The SIM language preferences only store a language (e.g. fr = French), not an
8509 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8510 // the SIM and carrier preferences does not include a country we add the country
8511 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008512 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008514 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008515 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516 }
8517
8518 if (DBG) log("No locale found - returning null");
8519 return null;
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008523 }
8524
tom hsu0b59d292022-09-29 23:49:21 +08008525 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008526 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008527 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008528 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008529 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008530 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8531 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008532 Locale.forLanguageTag(localeTag).getCountry())) {
8533 return localeTag;
8534 }
8535 }
8536 return inputLocale.toLanguageTag();
8537 }
8538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008539 /**
8540 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8541 */
8542 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008543 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008544 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008545 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008546
Gary Jian3aa9a762022-01-24 16:41:19 +08008547 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8548 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008549
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008550 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008551 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8552 * representing the state of the modem.
8553 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008554 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8555 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008556 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008557 */
8558 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008559 public void requestModemActivityInfo(ResultReceiver result) {
8560 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008561
8562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8563 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8564
vagdeviaf9a5b92018-08-15 16:01:53 -07008565 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008566
8567 final long identity = Binder.clearCallingIdentity();
8568 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008569 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570 } finally {
8571 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008572 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008573 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008574
Gary Jian76280a42022-12-07 16:18:33 +08008575 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008576 // less than total activity duration.
8577 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8578 if (info == null) {
8579 return false;
8580 }
8581 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008582 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008583 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8584
Hall Liu49656c02020-10-09 19:00:11 -07008585 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8586
Siddharth Rayb8114062018-06-17 15:02:38 -07008587 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008588 && (info.getSleepTimeMillis() <= activityDurationMs)
8589 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008590 }
8591
Gary Jian3aa9a762022-01-24 16:41:19 +08008592 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8593 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8594 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8595 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8596
8597 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8598 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8599 }
8600
8601 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8602 mLastModemActivityInfo.setReceiveTimeMillis(
8603 rat,
8604 freq,
8605 info.getReceiveTimeMillis(rat, freq)
8606 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8607 }
8608
8609 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8610 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8611 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8612 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8613
8614 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8615 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8616 }
8617 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8618 mLastModemActivityInfo.setReceiveTimeMillis(
8619 rat,
8620 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8621 }
8622
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008623 /**
8624 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8625 * @param info recent ModemActivityInfo
8626 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008627 private void mergeModemActivityInfo(ModemActivityInfo info) {
8628 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008629 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008630 boolean matched;
8631 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8632 matched = false;
8633 int rat = info.getSpecificInfoRat(i);
8634 int freq = info.getSpecificInfoFrequencyRange(i);
8635 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8636 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8637 //if it already exists
8638 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8639 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8640 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8641 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8642 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8643 updateLastModemActivityInfo(info, rat, freq);
8644 matched = true;
8645 }
8646 } else {
8647 updateLastModemActivityInfo(info, rat);
8648 matched = true;
8649 }
8650 }
8651 }
8652
8653 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008654 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008655 new ActivityStatsTechSpecificInfo(
8656 rat,
8657 freq,
8658 info.getTransmitTimeMillis(rat, freq),
8659 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008660 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008661 }
8662 }
8663 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8664 mLastModemActivitySpecificInfo =
8665 new ActivityStatsTechSpecificInfo[merged.size()];
8666 merged.toArray(mLastModemActivitySpecificInfo);
8667
8668 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8669 mLastModemActivityInfo.setSleepTimeMillis(
8670 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008671 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008672 mLastModemActivityInfo.setIdleTimeMillis(
8673 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008674 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008675
8676 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008677 new ModemActivityInfo(
8678 mLastModemActivityInfo.getTimestampMillis(),
8679 mLastModemActivityInfo.getSleepTimeMillis(),
8680 mLastModemActivityInfo.getIdleTimeMillis(),
8681 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008682 }
8683
8684 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8685 ActivityStatsTechSpecificInfo[] info) {
8686 int infoSize = info.length;
8687 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8688 for (int i = 0; i < infoSize; i++) {
8689 ret[i] = new ActivityStatsTechSpecificInfo(
8690 info[i].getRat(), info[i].getFrequencyRange(),
8691 info[i].getTransmitTimeMillis(),
8692 (int) info[i].getReceiveTimeMillis());
8693 }
8694 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008695 }
8696
Jack Yu85bd38a2015-11-09 11:34:32 -08008697 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008698 * Returns the service state information on specified subscription.
8699 */
8700 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008701 public ServiceState getServiceStateForSubscriber(int subId,
8702 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8703 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008705 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008706 return null;
8707 }
8708
joonhunshin4ac60942023-11-15 15:23:39 +00008709 enforceTelephonyFeatureWithException(callingPackage,
8710 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8711
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008712 boolean hasFinePermission = false;
8713 boolean hasCoarsePermission = false;
8714 if (!renounceFineLocationAccess) {
8715 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8716 LocationAccessPolicy.checkLocationPermission(mApp,
8717 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8718 .setCallingPackage(callingPackage)
8719 .setCallingFeatureId(callingFeatureId)
8720 .setCallingPid(Binder.getCallingPid())
8721 .setCallingUid(Binder.getCallingUid())
8722 .setMethod("getServiceStateForSubscriber")
8723 .setLogAsInfo(true)
8724 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8725 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8726 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8727 .build());
8728 hasFinePermission =
8729 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8730 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008731
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008732 if (!renounceCoarseLocationAccess) {
8733 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8734 LocationAccessPolicy.checkLocationPermission(mApp,
8735 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8736 .setCallingPackage(callingPackage)
8737 .setCallingFeatureId(callingFeatureId)
8738 .setCallingPid(Binder.getCallingPid())
8739 .setCallingUid(Binder.getCallingUid())
8740 .setMethod("getServiceStateForSubscriber")
8741 .setLogAsInfo(true)
8742 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8743 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8744 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8745 .build());
8746 hasCoarsePermission =
8747 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8748 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008749
Jack Yu479f40e2020-10-27 21:29:25 -07008750 final Phone phone = getPhone(subId);
8751 if (phone == null) {
8752 return null;
8753 }
8754
Jordan Liu0f2bc442020-11-18 16:47:37 -08008755 final long identity = Binder.clearCallingIdentity();
8756
Jack Yu479f40e2020-10-27 21:29:25 -07008757 boolean isCallingPackageDataService = phone.getDataServicePackages()
8758 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008759 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008760 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008761 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8762 .getSubscriptionInfoInternal(subId);
8763 if (subInfo == null || !subInfo.isActive()) {
8764 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8765 + "subId=" + subId);
8766 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008767 }
8768
Hall Liuf19c44f2018-11-27 14:38:17 -08008769 ServiceState ss = phone.getServiceState();
8770
8771 // Scrub out the location info in ServiceState depending on what level of access
8772 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008773 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008774 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8775 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008776 } finally {
8777 Binder.restoreCallingIdentity(identity);
8778 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008779 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008780
8781 /**
8782 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8783 *
8784 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8785 * voicemail ringtone.
8786 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8787 * PhoneAccount.
8788 */
8789 @Override
8790 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008791 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8792 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008794 final long identity = Binder.clearCallingIdentity();
8795 try {
8796 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8797 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008798 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008799 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008801 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8802 } finally {
8803 Binder.restoreCallingIdentity(identity);
8804 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008805 }
8806
8807 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008808 * Sets the per-account voicemail ringtone.
8809 *
8810 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8811 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8812 *
8813 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8814 * voicemail ringtone.
8815 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8816 * PhoneAccount.
8817 */
8818 @Override
8819 public void setVoicemailRingtoneUri(String callingPackage,
8820 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008821 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008823 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8824 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8826 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8827 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008829
joonhunshin4ac60942023-11-15 15:23:39 +00008830 enforceTelephonyFeatureWithException(callingPackage,
8831 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008833 final long identity = Binder.clearCallingIdentity();
8834 try {
8835 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8836 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008837 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008838 }
8839 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8840 } finally {
8841 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008842 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008843 }
8844
8845 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008846 * Returns whether vibration is set for voicemail notification in Phone settings.
8847 *
8848 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8849 * voicemail vibration setting.
8850 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8851 */
8852 @Override
8853 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008854 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8855 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857 final long identity = Binder.clearCallingIdentity();
8858 try {
8859 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8860 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008861 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008862 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008864 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8865 } finally {
8866 Binder.restoreCallingIdentity(identity);
8867 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008868 }
8869
Youhan Wange64578a2016-05-02 15:32:42 -07008870 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008871 * Sets the per-account voicemail vibration.
8872 *
8873 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8874 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8875 *
8876 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8877 * voicemail vibration setting.
8878 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8879 * specific PhoneAccount.
8880 */
8881 @Override
8882 public void setVoicemailVibrationEnabled(String callingPackage,
8883 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008884 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008885 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008886 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8887 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8889 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8890 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008891 }
8892
joonhunshin4ac60942023-11-15 15:23:39 +00008893 enforceTelephonyFeatureWithException(callingPackage,
8894 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008896 final long identity = Binder.clearCallingIdentity();
8897 try {
8898 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8899 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008900 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008901 }
8902 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8903 } finally {
8904 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008905 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008906 }
8907
8908 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008909 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8910 *
8911 * @throws SecurityException if the caller does not have the required permission
8912 */
arunvoddud7401012022-12-15 16:08:12 +00008913 @VisibleForTesting
8914 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008915 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008916 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008917 }
8918
8919 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008920 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8921 * permission.
8922 *
8923 * @throws SecurityException if the caller does not have the required permission
8924 */
8925 private void enforceSendSmsPermission() {
8926 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8927 }
8928
8929 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008930 * Make sure either called from same process as self (phone) or IPC caller has interact across
8931 * users permission.
8932 *
8933 * @throws SecurityException if the caller does not have the required permission
8934 */
8935 private void enforceInteractAcrossUsersPermission(String message) {
8936 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8937 }
8938
8939 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008940 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008941 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008942 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008943 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008944 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008948 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949 if (componentName == null) {
8950 throw new SecurityException(
8951 "Caller not current active visual voicemail package[null]");
8952 }
8953 String vvmPackage = componentName.getPackageName();
8954 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008955 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 }
8957 } finally {
8958 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008959 }
8960 }
8961
8962 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008963 * Return the application ID for the app type.
8964 *
8965 * @param subId the subscription ID that this request applies to.
8966 * @param appType the uicc app type.
8967 * @return Application ID for specificied app type, or null if no uicc.
8968 */
8969 @Override
8970 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008971 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00008972
8973 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8974 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
8975
Youhan Wange64578a2016-05-02 15:32:42 -07008976 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977
8978 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008979 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 if (phone == null) {
8981 return null;
8982 }
8983 String aid = null;
8984 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008985 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 .getApplicationByType(appType).getAid();
8987 } catch (Exception e) {
8988 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8989 }
8990 return aid;
8991 } finally {
8992 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008993 }
Youhan Wange64578a2016-05-02 15:32:42 -07008994 }
8995
Youhan Wang4001d252016-05-11 10:29:41 -07008996 /**
8997 * Return the Electronic Serial Number.
8998 *
8999 * @param subId the subscription ID that this request applies to.
9000 * @return ESN or null if error.
9001 */
9002 @Override
9003 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009004 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009005 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009006
9007 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009008 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009 if (phone == null) {
9010 return null;
9011 }
9012 String esn = null;
9013 try {
9014 esn = phone.getEsn();
9015 } catch (Exception e) {
9016 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9017 }
9018 return esn;
9019 } finally {
9020 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009021 }
Youhan Wang4001d252016-05-11 10:29:41 -07009022 }
9023
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009024 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009025 * Return the Preferred Roaming List Version.
9026 *
9027 * @param subId the subscription ID that this request applies to.
9028 * @return PRLVersion or null if error.
9029 */
9030 @Override
9031 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009032 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009033
9034 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9035 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9036
Youhan Wang66ad5d72016-07-18 17:56:58 -07009037 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038
9039 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009040 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 if (phone == null) {
9042 return null;
9043 }
9044 String cdmaPrlVersion = null;
9045 try {
9046 cdmaPrlVersion = phone.getCdmaPrlVersion();
9047 } catch (Exception e) {
9048 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9049 }
9050 return cdmaPrlVersion;
9051 } finally {
9052 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009053 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009054 }
9055
9056 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009057 * Get snapshot of Telephony histograms
9058 * @return List of Telephony histograms
9059 * @hide
9060 */
9061 @Override
9062 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9064 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065
9066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 return RIL.getTelephonyRILTimingHistograms();
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009072 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009073
9074 /**
9075 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009076 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9077 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009078 * Require system privileges. In the future we may add this to carrier APIs.
9079 *
Michele Berionne482f8202018-11-27 18:57:59 -08009080 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009081 */
9082 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009083 @TelephonyManager.SetCarrierRestrictionResult
9084 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009085 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009086
9087 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9088 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9089
vagdeviaf9a5b92018-08-15 16:01:53 -07009090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009091
Michele Berionne482f8202018-11-27 18:57:59 -08009092 if (carrierRestrictionRules == null) {
9093 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009094 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009096 final long identity = Binder.clearCallingIdentity();
9097 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009098 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009099 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009103 }
9104
9105 /**
9106 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009107 * Get the allowed carrier list and the excluded carrier list, including the priority between
9108 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009109 * Require system privileges. In the future we may add this to carrier APIs.
9110 *
Michele Berionne482f8202018-11-27 18:57:59 -08009111 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009112 */
9113 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009114 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009115 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009116
9117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9118 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9119
vagdeviaf9a5b92018-08-15 16:01:53 -07009120 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009121
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009124 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9125 if (response instanceof CarrierRestrictionRules) {
9126 return (CarrierRestrictionRules) response;
9127 }
9128 // Response is an Exception of some kind,
9129 // which is signalled to the user as a NULL retval
9130 return null;
9131 } catch (Exception e) {
9132 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9133 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134 } finally {
9135 Binder.restoreCallingIdentity(identity);
9136 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009137 }
9138
fionaxu59545b42016-05-25 15:53:37 -07009139 /**
arunvoddud7401012022-12-15 16:08:12 +00009140 * Fetches the carrier restriction status of the device and sends the status to the caller
9141 * through the callback.
9142 *
9143 * @param callback The callback that will be used to send the result.
9144 * @throws SecurityException if the caller does not have the required permission/privileges or
9145 * the caller is not allowlisted.
9146 */
9147 @Override
9148 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9149 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009150
9151 enforceTelephonyFeatureWithException(packageName,
9152 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9153
arunvoddud7401012022-12-15 16:08:12 +00009154 int carrierId = validateCallerAndGetCarrierId(packageName);
9155 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9156 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9157 throw new SecurityException("Not an authorized caller");
9158 }
9159 final long identity = Binder.clearCallingIdentity();
9160 try {
9161 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9162 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9163 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9164 } finally {
9165 Binder.restoreCallingIdentity(identity);
9166 }
9167 }
9168
arunvoddu567f2b42023-04-25 17:22:00 +00009169 @Override
9170 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9171 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9172 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9173 return allowListInfo.getShaIdList(pkgName, carrierId);
9174 }
9175
arunvoddud7401012022-12-15 16:08:12 +00009176 @VisibleForTesting
9177 public int validateCallerAndGetCarrierId(String packageName) {
9178 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9179 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9180 }
9181
9182 /**
fionaxu59545b42016-05-25 15:53:37 -07009183 * Action set from carrier signalling broadcast receivers to enable/disable radio
9184 * @param subId the subscription ID that this action applies to.
9185 * @param enabled control enable or disable radio.
9186 * {@hide}
9187 */
9188 @Override
9189 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9190 enforceModifyPermission();
9191 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009192
9193 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009194 if (phone == null) {
9195 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9196 return;
9197 }
9198 try {
9199 phone.carrierActionSetRadioEnabled(enabled);
9200 } catch (Exception e) {
9201 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009202 } finally {
9203 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009204 }
9205 }
9206
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009207 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009208 * Enable or disable Voice over NR (VoNR)
9209 * @param subId the subscription ID that this action applies to.
9210 * @param enabled enable or disable VoNR.
9211 * @return operation result.
9212 */
9213 @Override
9214 public int setVoNrEnabled(int subId, boolean enabled) {
9215 enforceModifyPermission();
9216 final Phone phone = getPhone(subId);
9217
9218 final long identity = Binder.clearCallingIdentity();
9219 if (phone == null) {
9220 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9221 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9222 }
9223
9224 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9225 try {
9226 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9227 workSource);
9228 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009229
9230 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9231 if (DBG) {
9232 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9233 }
9234 SubscriptionManager.setSubscriptionProperty(
9235 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9236 (enabled ? "1" : "0"));
9237 }
9238
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009239 return result;
9240 } finally {
9241 Binder.restoreCallingIdentity(identity);
9242 }
9243 }
9244
9245 /**
9246 * Is voice over NR enabled
9247 * @return true if VoNR is enabled else false
9248 */
9249 @Override
9250 public boolean isVoNrEnabled(int subId) {
9251 enforceReadPrivilegedPermission("isVoNrEnabled");
9252 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9253 final long identity = Binder.clearCallingIdentity();
9254 try {
9255 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9256 null, subId, workSource);
9257 if (DBG) log("isVoNrEnabled: " + isEnabled);
9258 return isEnabled;
9259 } finally {
9260 Binder.restoreCallingIdentity(identity);
9261 }
9262 }
9263
9264 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009265 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9266 * network status based on which carrier apps could apply actions accordingly,
9267 * enable/disable default url handler for example.
9268 *
9269 * @param subId the subscription ID that this action applies to.
9270 * @param report control start/stop reporting the default network status.
9271 * {@hide}
9272 */
9273 @Override
9274 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9275 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009276
9277 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9278 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9279 "carrierActionReportDefaultNetworkStatus");
9280
fionaxu8da9cb12017-05-23 15:02:46 -07009281 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009282
9283 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009284 if (phone == null) {
9285 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9286 return;
9287 }
9288 try {
9289 phone.carrierActionReportDefaultNetworkStatus(report);
9290 } catch (Exception e) {
9291 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009292 } finally {
9293 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009294 }
9295 }
9296
9297 /**
fionaxud9622282017-07-17 17:51:30 -07009298 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9299 * @param subId the subscription ID that this action applies to.
9300 * {@hide}
9301 */
9302 @Override
9303 public void carrierActionResetAll(int subId) {
9304 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009305
9306 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9307 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9308
fionaxud9622282017-07-17 17:51:30 -07009309 final Phone phone = getPhone(subId);
9310 if (phone == null) {
9311 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9312 return;
9313 }
9314 try {
9315 phone.carrierActionResetAll();
9316 } catch (Exception e) {
9317 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9318 }
9319 }
9320
9321 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009322 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9323 * bug report is being generated.
9324 */
9325 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009326 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009327 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9328 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009329 writer.println("Permission Denial: can't dump Phone from pid="
9330 + Binder.getCallingPid()
9331 + ", uid=" + Binder.getCallingUid()
9332 + "without permission "
9333 + android.Manifest.permission.DUMP);
9334 return;
9335 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009336 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009337 }
Jack Yueb89b242016-06-22 13:27:47 -07009338
Brad Ebingerdac2f002018-04-03 15:17:52 -07009339 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009340 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9341 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9342 @NonNull String[] args) {
9343 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9344 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009345 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009346 }
9347
Jack Yueb89b242016-06-22 13:27:47 -07009348 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009349 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009350 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009351 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009352 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009353 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009354 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009355 */
9356 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009357 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009358 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009359 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9360 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9361 try {
9362 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009363 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009364 } catch (SecurityException se) {
9365 enforceModifyPermission();
9366 }
9367 } else {
9368 enforceModifyPermission();
9369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009370
Nate Myrenae97d192023-06-09 15:22:31 -07009371 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9372 && null != callingPackage && opEnableMobileDataByUser()) {
9373 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
9374 callingPackage, null, null);
9375 }
9376
joonhunshin4ac60942023-11-15 15:23:39 +00009377 enforceTelephonyFeatureWithException(callingPackage,
9378 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009380 final long identity = Binder.clearCallingIdentity();
9381 try {
9382 Phone phone = getPhone(subId);
9383 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009384 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9385 phone.carrierActionSetMeteredApnsEnabled(enabled);
9386 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009387 phone.getDataSettingsManager().setDataEnabled(
9388 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009390 }
9391 } finally {
9392 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009393 }
9394 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009395
9396 /**
9397 * Get Client request stats
9398 * @return List of Client Request Stats
9399 * @hide
9400 */
9401 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009402 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9403 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009405 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009406 return null;
9407 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009408 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009410 final long identity = Binder.clearCallingIdentity();
9411 try {
9412 if (phone != null) {
9413 return phone.getClientRequestStats();
9414 }
9415
9416 return null;
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009420 }
9421
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009422 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009423 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009424 if (uid == Process.ROOT_UID && packageName == null) {
9425 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9426 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9427 // exception. ROOT_UID seems not to have a valid package name returned by
9428 // PackageManager, so just fake it here to avoid issues when running telephony shell
9429 // commands that plumb through the RIL as root, like so:
9430 // $ adb root
9431 // $ adb shell cmd phone ...
9432 packageName = "root";
9433 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009434 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009435 }
Jack Yueb4124c2017-02-16 15:32:43 -08009436
9437 /**
Grace Chen70990072017-03-24 17:21:30 -07009438 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009439 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009440 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009441 * @param state State of SIM (power down, power up, pass through)
9442 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9443 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9444 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009445 *
9446 **/
9447 @Override
Grace Chen70990072017-03-24 17:21:30 -07009448 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009449 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009450
9451 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9452 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9453
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009454 Phone phone = PhoneFactory.getPhone(slotIndex);
9455
vagdeviaf9a5b92018-08-15 16:01:53 -07009456 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009461 phone.setSimPowerState(state, null, workSource);
9462 }
9463 } finally {
9464 Binder.restoreCallingIdentity(identity);
9465 }
9466 }
9467
9468 /**
9469 * Set SIM card power state.
9470 *
9471 * @param slotIndex SIM slot id.
9472 * @param state State of SIM (power down, power up, pass through)
9473 * @param callback callback to trigger after success or failure
9474 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9475 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9476 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9477 *
9478 **/
9479 @Override
9480 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9481 IIntegerConsumer callback) {
9482 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009483
9484 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9485 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9486 "setSimPowerStateForSlotWithCallback");
9487
Jordan Liu109698e2020-11-24 14:50:34 -08009488 Phone phone = PhoneFactory.getPhone(slotIndex);
9489
9490 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9491
9492 final long identity = Binder.clearCallingIdentity();
9493 try {
9494 if (phone != null) {
9495 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9496 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009497 }
9498 } finally {
9499 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009500 }
9501 }
Shuo Qiandd210312017-04-12 22:11:33 +00009502
Tyler Gunn65d45c22017-06-05 11:22:26 -07009503 private boolean isUssdApiAllowed(int subId) {
9504 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009505 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009506 if (configManager == null) {
9507 return false;
9508 }
9509 PersistableBundle pb = configManager.getConfigForSubId(subId);
9510 if (pb == null) {
9511 return false;
9512 }
9513 return pb.getBoolean(
9514 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9515 }
9516
Shuo Qiandd210312017-04-12 22:11:33 +00009517 /**
Ling Mac28f0212023-03-24 16:07:15 -07009518 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009519 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009520 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009521 */
goneil9c5f4872017-12-05 14:07:56 -08009522 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009523 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009524 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009525
9526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9527 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009529 final long identity = Binder.clearCallingIdentity();
9530 try {
Ling Mac28f0212023-03-24 16:07:15 -07009531 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009532 } finally {
9533 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009534 }
9535 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009536
9537 /**
9538 * Get the current signal strength information for the given subscription.
9539 * Because this information is not updated when the device is in a low power state
9540 * it should not be relied-upon to be current.
9541 * @param subId Subscription index
9542 * @return the most recent cached signal strength info from the modem
9543 */
9544 @Override
9545 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009546 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9547 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009549 final long identity = Binder.clearCallingIdentity();
9550 try {
9551 Phone p = getPhone(subId);
9552 if (p == null) {
9553 return null;
9554 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009556 return p.getSignalStrength();
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009560 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009561
Pengquan Meng77b7f132018-08-22 14:49:57 -07009562 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009563 * Get the current modem radio state for the given slot.
9564 * @param slotIndex slot index.
9565 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009566 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009567 * @return the current radio power state from the modem
9568 */
9569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009570 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009571 Phone phone = PhoneFactory.getPhone(slotIndex);
9572 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9574 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009575 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9576 }
9577
joonhunshin4ac60942023-11-15 15:23:39 +00009578 enforceTelephonyFeatureWithException(callingPackage,
9579 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9580
Chen Xuf792fd62018-10-17 17:54:36 +00009581 final long identity = Binder.clearCallingIdentity();
9582 try {
9583 return phone.getRadioPowerState();
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
9586 }
9587 }
9588 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9589 }
9590
9591 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009592 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9593 *
9594 * <p>Requires one of the following permissions:
9595 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009596 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009597 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9598 * privileges.
9599 *
9600 * @param subId subscription id
9601 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9602 * {@code false}.
9603 */
9604 @Override
9605 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009606 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009607 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009608 try {
9609 mApp.enforceCallingOrSelfPermission(
9610 android.Manifest.permission.ACCESS_NETWORK_STATE,
9611 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009612 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009613 mApp.enforceCallingOrSelfPermission(
9614 permission.READ_BASIC_PHONE_STATE, functionName);
9615 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009616 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009617 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009618 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009619 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009620
joonhunshin4ac60942023-11-15 15:23:39 +00009621 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9622 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9623
Pengquan Menga1bb6272018-09-06 09:59:22 -07009624 boolean isEnabled = false;
9625 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009626 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009627 Phone phone = getPhone(subId);
9628 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009629 } finally {
9630 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009631 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009632 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009633 }
9634
9635
9636 /**
9637 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9638 *
9639 * <p> Requires permission:
9640 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9641 * privileges.
9642 *
9643 * @param subId subscription id
9644 * @param isEnabled {@code true} means enable, {@code false} means disable.
9645 */
9646 @Override
9647 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9649 mApp, subId, "setDataRoamingEnabled");
9650
joonhunshin4ac60942023-11-15 15:23:39 +00009651 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9652 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9653
Pengquan Menga1bb6272018-09-06 09:59:22 -07009654 final long identity = Binder.clearCallingIdentity();
9655 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009656 Phone phone = getPhone(subId);
9657 if (phone != null) {
9658 phone.setDataRoamingEnabled(isEnabled);
9659 }
9660 } finally {
9661 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009662 }
9663 }
9664
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009665 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009666 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009667 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009668 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009669 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009670
joonhunshin4ac60942023-11-15 15:23:39 +00009671 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9672 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9673
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009674 boolean isAllowed = true;
9675 final long identity = Binder.clearCallingIdentity();
9676 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009677 Phone phone = getPhone(subId);
9678 if (phone != null) {
9679 isAllowed = phone.isCspPlmnEnabled();
9680 }
9681 } finally {
9682 Binder.restoreCallingIdentity(identity);
9683 }
9684 return isAllowed;
9685 }
9686
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009687 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9688 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009689 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009690 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009691 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009692 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9693 if (phone == null) {
9694 return false;
9695 }
9696 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9697 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9698 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009699 }
9700
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009701 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009702 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009703 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009704 mApp.getSystemService(AppOpsManager.class)
9705 .checkPackage(Binder.getCallingUid(), callingPackage);
9706
Jordan Liu1e142fc2019-04-22 15:10:43 -07009707 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009708 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009709 try {
9710 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009711 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009712 } catch (SecurityException e) {
9713 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9714 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009715 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009716 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009717 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009718 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009719 }
joonhunshin4ac60942023-11-15 15:23:39 +00009720
9721 enforceTelephonyFeatureWithException(callingPackage,
9722 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9723
sandeepjsb6c87872021-09-27 15:34:44 +00009724 // checking compatibility, if calling app's target SDK is T and beyond.
9725 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9726 Binder.getCallingUid())) {
9727 isIccIdAccessRestricted = true;
9728 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009729 final long identity = Binder.clearCallingIdentity();
9730 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009731 UiccController uiccController = UiccController.getInstance();
9732 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009733 if (hasReadPermission) {
9734 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009735 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009736
9737 // Remove private info if the caller doesn't have access
9738 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9739 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009740 //setting the value after compatibility check
9741 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009742 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9743 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009744 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009745 if (card == null) {
9746 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009747 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009748 continue;
9749 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009750 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9751 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009752 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009753 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009754 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009755 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9756 for (UiccPortInfo portInfo : portInfos) {
9757 UiccPort port = uiccController.getUiccPortForSlot(
9758 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9759 if (port == null) {
9760 // assume no access if port is null
9761 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9762 continue;
9763 }
9764 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9765 uiccPortInfos.add(portInfo);
9766 } else {
9767 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9768 }
9769 }
9770 filteredInfos.add(new UiccCardInfo(
9771 cardInfo.isEuicc(),
9772 cardInfo.getCardId(),
9773 null,
9774 cardInfo.getPhysicalSlotIndex(),
9775 cardInfo.isRemovable(),
9776 cardInfo.isMultipleEnabledProfilesSupported(),
9777 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009778 }
9779 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009780 } finally {
9781 Binder.restoreCallingIdentity(identity);
9782 }
9783 }
9784
sandeepjsb6c87872021-09-27 15:34:44 +00009785 /**
9786 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9787 * generally private and require carrier privileges to view.
9788 *
9789 * @hide
9790 */
9791 @NonNull
9792 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9793 List<UiccPortInfo> portinfo = new ArrayList<>();
9794 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9795 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9796 }
9797 return new UiccCardInfo(
9798 cardInfo.isEuicc(),
9799 cardInfo.getCardId(),
9800 null,
9801 cardInfo.getPhysicalSlotIndex(),
9802 cardInfo.isRemovable(),
9803 cardInfo.isMultipleEnabledProfilesSupported(),
9804 portinfo
9805 );
9806 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009807
sandeepjsb6c87872021-09-27 15:34:44 +00009808 /**
9809 * @hide
9810 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9811 * These values are generally private and require carrier privileges to view.
9812 */
9813 @NonNull
9814 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9815 return new UiccPortInfo(
9816 UiccPortInfo.ICCID_REDACTED,
9817 portInfo.getPortIndex(),
9818 portInfo.getLogicalSlotIndex(),
9819 portInfo.isActive()
9820 );
9821 }
9822 @Override
9823 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009824 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009825 mApp.getSystemService(AppOpsManager.class)
9826 .checkPackage(Binder.getCallingUid(), callingPackage);
9827
sandeepjsb6c87872021-09-27 15:34:44 +00009828 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009829
Aman Guptaf3c90b32022-03-17 04:54:16 +00009830 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9831 // we are reading iccId which is PII data.
9832 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009833
joonhunshin4ac60942023-11-15 15:23:39 +00009834 enforceTelephonyFeatureWithException(callingPackage,
9835 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9836
sandeepjsb6c87872021-09-27 15:34:44 +00009837 // checking compatibility, if calling app's target SDK is T and beyond.
9838 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9839 Binder.getCallingUid())) {
9840 isLogicalSlotAccessRestricted = true;
9841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009842 final long identity = Binder.clearCallingIdentity();
9843 try {
9844 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009845 if (slots == null || slots.length == 0) {
9846 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009847 return null;
9848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009849 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9850 for (int i = 0; i < slots.length; i++) {
9851 UiccSlot slot = slots[i];
9852 if (slot == null) {
9853 continue;
9854 }
9855
Jordan Liu7be7e652019-05-06 18:55:02 +00009856 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009857 UiccCard card = slot.getUiccCard();
9858 if (card != null) {
9859 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009860 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009861 cardId = slot.getEid();
9862 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009863 // If cardId is null, use iccId of default port as cardId.
9864 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009866 }
9867
Jordan Liu857451f2019-05-09 16:35:35 -07009868 if (cardId != null) {
9869 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9870 // if cardId is an EID, it's all digits so this is fine
9871 cardId = IccUtils.stripTrailingFs(cardId);
9872 }
9873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009874 int cardState = 0;
9875 switch (slot.getCardState()) {
9876 case CARDSTATE_ABSENT:
9877 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9878 break;
9879 case CARDSTATE_PRESENT:
9880 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9881 break;
9882 case CARDSTATE_ERROR:
9883 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9884 break;
9885 case CARDSTATE_RESTRICTED:
9886 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9887 break;
9888 default:
9889 break;
9890
9891 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009892 List<UiccPortInfo> portInfos = new ArrayList<>();
9893 int[] portIndexes = slot.getPortList();
9894 for (int portIdx : portIndexes) {
9895 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009896 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009897 portInfos.add(new UiccPortInfo(iccId, portIdx,
9898 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009900 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009901 slot.isEuicc(),
9902 cardId,
9903 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009904 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009905 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009906 //setting the value after compatibility check
9907 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009908 }
9909 return infos;
9910 } finally {
9911 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009912 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009913 }
9914
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009915 /* Returns null if doesn't have read permission or carrier privilege access. */
9916 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9917 boolean hasReadPermission) {
9918 String iccId = slot.getIccId(portIndex);
9919 if (hasReadPermission) { // if has read permission
9920 return iccId;
9921 } else {
9922 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9923 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9924 // if no read permission, checking carrier privilege access
9925 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9926 return iccId;
9927 }
9928 }
9929 }
9930 // No read permission or carrier privilege access.
9931 return UiccPortInfo.ICCID_REDACTED;
9932 }
9933
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009934 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009935 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009936 public boolean switchSlots(int[] physicalSlots) {
9937 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009938
joonhunshin4ac60942023-11-15 15:23:39 +00009939 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9940 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
9941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009942 final long identity = Binder.clearCallingIdentity();
9943 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009944 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9945 for (int i = 0; i < physicalSlots.length; i++) {
9946 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9947 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9948 physicalSlots[i], i));
9949 }
9950 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009951 } finally {
9952 Binder.restoreCallingIdentity(identity);
9953 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009954 }
Jack Yu4c988042018-02-27 15:30:01 -08009955
9956 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009957 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9958 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9959 enforceModifyPermission();
9960
joonhunshin4ac60942023-11-15 15:23:39 +00009961 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9962 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
9963
sandeepjsb6c87872021-09-27 15:34:44 +00009964 final long identity = Binder.clearCallingIdentity();
9965 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009966 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009967 } finally {
9968 Binder.restoreCallingIdentity(identity);
9969 }
9970 }
9971
9972 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009973 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +00009974 enforceTelephonyFeatureWithException(callingPackage,
9975 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
9976
Jordan Liu7de49fa2018-12-06 14:48:49 -08009977 final long identity = Binder.clearCallingIdentity();
9978 try {
9979 return UiccController.getInstance().getCardIdForDefaultEuicc();
9980 } finally {
9981 Binder.restoreCallingIdentity(identity);
9982 }
9983 }
9984
Pengquan Meng85728fb2018-03-12 16:31:21 -07009985 /**
goneil47ffb6e2018-04-06 15:40:58 -07009986 * A test API to reload the UICC profile.
9987 *
9988 * <p>Requires that the calling app has permission
9989 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9990 * @hide
9991 */
9992 @Override
9993 public void refreshUiccProfile(int subId) {
9994 enforceModifyPermission();
9995
9996 final long identity = Binder.clearCallingIdentity();
9997 try {
9998 Phone phone = getPhone(subId);
9999 if (phone == null) {
10000 return;
10001 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010002 UiccPort uiccPort = phone.getUiccPort();
10003 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010004 return;
10005 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010006 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010007 if (uiccProfile == null) {
10008 return;
10009 }
10010 uiccProfile.refresh();
10011 } finally {
10012 Binder.restoreCallingIdentity(identity);
10013 }
10014 }
10015
10016 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010017 * Returns false if the mobile data is disabled by default, otherwise return true.
10018 */
10019 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010020 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010021 }
10022
10023 /**
10024 * Returns true if the data roaming is enabled by default, i.e the system property
10025 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10026 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10027 */
10028 private boolean getDefaultDataRoamingEnabled(int subId) {
10029 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010030 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010031 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010032 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10033 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10034 return isDataRoamingEnabled;
10035 }
10036
10037 /**
10038 * Returns the default network type for the given {@code subId}, if the default network type is
10039 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10040 */
10041 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010042 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010043 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010044 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10045 return list.get(phoneId);
10046 }
10047 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010048 }
fionaxua13278b2018-03-21 00:08:13 -070010049
10050 @Override
10051 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010052 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010054
10055 final long identity = Binder.clearCallingIdentity();
10056 try {
10057 final Phone phone = getPhone(subId);
10058 if (phone == null) {
10059 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10060 return;
10061 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010062 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10063 if (cpt != null) {
10064 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10065 }
10066 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010067 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10068 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010069 if (carrierPrivilegeRules == null) {
10070 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10071 } else {
10072 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010074 } finally {
10075 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010076 }
fionaxua13278b2018-03-21 00:08:13 -070010077 }
10078
10079 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010080 public void setCarrierServicePackageOverride(
10081 int subId, String carrierServicePackage, String callingPackage) {
10082 TelephonyPermissions.enforceShellOnly(
10083 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10084
Benedict Wong66477622023-02-03 23:30:57 +000010085 final long identity = Binder.clearCallingIdentity();
10086 try {
10087 final Phone phone = getPhone(subId);
10088 if (phone == null || phone.getSubId() != subId) {
10089 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10090 throw new IllegalArgumentException("No phone for subid");
10091 }
10092 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10093 if (cpt == null) {
10094 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10095 throw new IllegalStateException("No CPT for phone");
10096 }
10097 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
10102
10103 @Override
fionaxua13278b2018-03-21 00:08:13 -070010104 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010105 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010106
10107 final long identity = Binder.clearCallingIdentity();
10108 try {
10109 final Phone phone = getPhone(subId);
10110 if (phone == null) {
10111 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10112 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10113 }
10114 return phone.getCarrierIdListVersion();
10115 } finally {
10116 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010117 }
fionaxua13278b2018-03-21 00:08:13 -070010118 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010119
10120 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010121 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10122 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010124 mApp, subId, callingPackage, callingFeatureId,
10125 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010126 return -1;
10127 }
10128
10129 final long identity = Binder.clearCallingIdentity();
10130 try {
10131 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10132 } finally {
10133 Binder.restoreCallingIdentity(identity);
10134 }
10135 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010136
10137 @Override
10138 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010139 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010140 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010141 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010142
joonhunshin4ac60942023-11-15 15:23:39 +000010143 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10144 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10145
Pengquan Menga1bb6272018-09-06 09:59:22 -070010146 final long identity = Binder.clearCallingIdentity();
10147 try {
10148 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10149 } finally {
10150 Binder.restoreCallingIdentity(identity);
10151 }
10152 }
10153
10154 @Override
10155 public boolean setCdmaRoamingMode(int subId, int mode) {
10156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10157 mApp, subId, "setCdmaRoamingMode");
10158
joonhunshin4ac60942023-11-15 15:23:39 +000010159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10160 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10161
Pengquan Menga1bb6272018-09-06 09:59:22 -070010162 final long identity = Binder.clearCallingIdentity();
10163 try {
10164 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
10169
10170 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010171 public int getCdmaSubscriptionMode(int subId) {
10172 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010173 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010174 mApp, subId, "getCdmaSubscriptionMode");
10175
joonhunshin4ac60942023-11-15 15:23:39 +000010176 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10177 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10178
Sarah Chinbaab1432020-10-28 13:46:24 -070010179 final long identity = Binder.clearCallingIdentity();
10180 try {
10181 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10182 } finally {
10183 Binder.restoreCallingIdentity(identity);
10184 }
10185 }
10186
10187 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010188 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10190 mApp, subId, "setCdmaSubscriptionMode");
10191
joonhunshin4ac60942023-11-15 15:23:39 +000010192 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10193 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10194
Pengquan Menga1bb6272018-09-06 09:59:22 -070010195 final long identity = Binder.clearCallingIdentity();
10196 try {
10197 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10198 } finally {
10199 Binder.restoreCallingIdentity(identity);
10200 }
10201 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010202
sqianc5eccab2018-10-19 18:46:41 -070010203 @Override
sqian8c685422019-02-22 15:55:18 -080010204 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010205 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010207 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10208 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010209 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10210 }
joonhunshin4ac60942023-11-15 15:23:39 +000010211
10212 enforceTelephonyFeatureWithException(callingPackage,
10213 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10214
sqian11b7a0e2018-12-05 18:48:28 -080010215 final long identity = Binder.clearCallingIdentity();
10216 try {
sqian854d44b2018-12-12 16:48:18 -080010217 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10218 for (Phone phone: PhoneFactory.getPhones()) {
10219 if (phone.getEmergencyNumberTracker() != null
10220 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10221 emergencyNumberListInternal.put(
10222 phone.getSubId(),
10223 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10224 }
sqian11b7a0e2018-12-05 18:48:28 -080010225 }
sqian854d44b2018-12-12 16:48:18 -080010226 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010227 } finally {
10228 Binder.restoreCallingIdentity(identity);
10229 }
sqianc5eccab2018-10-19 18:46:41 -070010230 }
10231
10232 @Override
sqian8c685422019-02-22 15:55:18 -080010233 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010234 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010235 if (!exactMatch) {
10236 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010237 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010238 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010239 }
joonhunshin4ac60942023-11-15 15:23:39 +000010240
10241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10242 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10243
sqian11b7a0e2018-12-05 18:48:28 -080010244 final long identity = Binder.clearCallingIdentity();
10245 try {
sqian854d44b2018-12-12 16:48:18 -080010246 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010247 //Note: we ignore passed in param exactMatch. We can remove it once
10248 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010249 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010250 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010251 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010252 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010253 }
sqian11b7a0e2018-12-05 18:48:28 -080010254 }
10255 return false;
10256 } finally {
10257 Binder.restoreCallingIdentity(identity);
10258 }
10259 }
10260
sqianf4ca7ed2019-01-15 18:32:07 -080010261 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010262 * Start emergency callback mode for GsmCdmaPhone for testing.
10263 */
10264 @Override
10265 public void startEmergencyCallbackMode() {
10266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10267 "startEmergencyCallbackMode");
10268 enforceModifyPermission();
10269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 for (Phone phone : PhoneFactory.getPhones()) {
10272 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10273 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10274 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10275 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10276 gsmCdmaPhone.obtainMessage(
10277 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10278 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10279 }
10280 }
10281 } finally {
10282 Binder.restoreCallingIdentity(identity);
10283 }
10284 }
10285
10286 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010287 * Update emergency number list for test mode.
10288 */
10289 @Override
10290 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10291 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10292 "updateEmergencyNumberListTestMode");
10293
10294 final long identity = Binder.clearCallingIdentity();
10295 try {
10296 for (Phone phone: PhoneFactory.getPhones()) {
10297 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10298 if (tracker != null) {
10299 tracker.executeEmergencyNumberTestModeCommand(action, num);
10300 }
10301 }
10302 } finally {
10303 Binder.restoreCallingIdentity(identity);
10304 }
10305 }
10306
10307 /**
10308 * Get the full emergency number list for test mode.
10309 */
10310 @Override
10311 public List<String> getEmergencyNumberListTestMode() {
10312 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10313 "getEmergencyNumberListTestMode");
10314
10315 final long identity = Binder.clearCallingIdentity();
10316 try {
10317 Set<String> emergencyNumbers = new HashSet<>();
10318 for (Phone phone: PhoneFactory.getPhones()) {
10319 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10320 if (tracker != null) {
10321 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10322 emergencyNumbers.add(num.getNumber());
10323 }
10324 }
10325 }
10326 return new ArrayList<>(emergencyNumbers);
10327 } finally {
10328 Binder.restoreCallingIdentity(identity);
10329 }
10330 }
10331
chen xud6b45bd2018-10-30 22:27:10 -070010332 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010333 public int getEmergencyNumberDbVersion(int subId) {
10334 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10335
joonhunshin4ac60942023-11-15 15:23:39 +000010336 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10337 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10338
Shuo Qian3b6ee772019-11-13 17:43:31 -080010339 final long identity = Binder.clearCallingIdentity();
10340 try {
10341 final Phone phone = getPhone(subId);
10342 if (phone == null) {
10343 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10344 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10345 }
10346 return phone.getEmergencyNumberDbVersion();
10347 } finally {
10348 Binder.restoreCallingIdentity(identity);
10349 }
10350 }
10351
10352 @Override
10353 public void notifyOtaEmergencyNumberDbInstalled() {
10354 enforceModifyPermission();
10355
joonhunshin4ac60942023-11-15 15:23:39 +000010356 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10357 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10358
Shuo Qian3b6ee772019-11-13 17:43:31 -080010359 final long identity = Binder.clearCallingIdentity();
10360 try {
10361 for (Phone phone: PhoneFactory.getPhones()) {
10362 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10363 if (tracker != null) {
10364 tracker.updateOtaEmergencyNumberDatabase();
10365 }
10366 }
10367 } finally {
10368 Binder.restoreCallingIdentity(identity);
10369 }
10370 }
10371
10372 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010373 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010374 enforceActiveEmergencySessionPermission();
10375
joonhunshin4ac60942023-11-15 15:23:39 +000010376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10377 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10378
Shuo Qian3b6ee772019-11-13 17:43:31 -080010379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 for (Phone phone: PhoneFactory.getPhones()) {
10382 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10383 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010384 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10385 }
10386 }
10387 } finally {
10388 Binder.restoreCallingIdentity(identity);
10389 }
10390 }
10391
10392 @Override
10393 public void resetOtaEmergencyNumberDbFilePath() {
10394 enforceActiveEmergencySessionPermission();
10395
joonhunshin4ac60942023-11-15 15:23:39 +000010396 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10397 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10398
Shuo Qianc373f112020-03-05 17:55:34 -080010399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 for (Phone phone: PhoneFactory.getPhones()) {
10402 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10403 if (tracker != null) {
10404 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010405 }
10406 }
10407 } finally {
10408 Binder.restoreCallingIdentity(identity);
10409 }
10410 }
10411
10412 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010413 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10414 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10415 Phone phone = getPhone(subId);
10416 if (phone == null) {
10417 return null;
10418 }
10419 final long identity = Binder.clearCallingIdentity();
10420 try {
10421 UiccProfile profile = UiccController.getInstance()
10422 .getUiccProfileForPhone(phone.getPhoneId());
10423 if (profile != null) {
10424 return profile.getCertsFromCarrierPrivilegeAccessRules();
10425 }
10426 } finally {
10427 Binder.restoreCallingIdentity(identity);
10428 }
10429 return null;
10430 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010431
10432 /**
10433 * Enable or disable a modem stack.
10434 */
10435 @Override
10436 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10437 enforceModifyPermission();
10438
joonhunshin4ac60942023-11-15 15:23:39 +000010439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10440 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10441
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010442 final long identity = Binder.clearCallingIdentity();
10443 try {
10444 Phone phone = PhoneFactory.getPhone(slotIndex);
10445 if (phone == null) {
10446 return false;
10447 } else {
10448 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10449 }
10450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
Michelecea4cf22018-12-21 15:00:11 -080010454
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010455 /**
10456 * Whether a modem stack is enabled or not.
10457 */
10458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010459 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10460 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010461 Phone phone = PhoneFactory.getPhone(slotIndex);
10462 if (phone == null) return false;
10463
10464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010465 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10466 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010467 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10468 }
10469
joonhunshin4ac60942023-11-15 15:23:39 +000010470 enforceTelephonyFeatureWithException(callingPackage,
10471 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10472
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010473 final long identity = Binder.clearCallingIdentity();
10474 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010475 try {
10476 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10477 } catch (NoSuchElementException ex) {
10478 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10479 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
Michelecea4cf22018-12-21 15:00:11 -080010485 @Override
Michele0ea7d782019-03-19 14:58:42 -070010486 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010487 enforceModifyPermission();
10488
joonhunshin4ac60942023-11-15 15:23:39 +000010489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10490 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10491
Michelecea4cf22018-12-21 15:00:11 -080010492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010495 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010496 .commit();
10497 } finally {
10498 Binder.restoreCallingIdentity(identity);
10499 }
10500 }
10501
10502 @Override
Michele0ea7d782019-03-19 14:58:42 -070010503 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010504 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010506 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10507 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010508 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010509 }
Michelecea4cf22018-12-21 15:00:11 -080010510
joonhunshin4ac60942023-11-15 15:23:39 +000010511 enforceTelephonyFeatureWithException(callingPackage,
10512 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10513
Michelecea4cf22018-12-21 15:00:11 -080010514 final long identity = Binder.clearCallingIdentity();
10515 try {
Michele0ea7d782019-03-19 14:58:42 -070010516 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010517 } finally {
10518 Binder.restoreCallingIdentity(identity);
10519 }
10520 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010521
Michele0ea7d782019-03-19 14:58:42 -070010522 @TelephonyManager.IsMultiSimSupportedResult
10523 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010524 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10525 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10526 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010527 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10528 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010529 }
10530 // Check if the hardware supports multisim functionality. If usage of multisim is not
10531 // supported by the modem, indicate that it is restricted.
10532 PhoneCapability staticCapability =
10533 mPhoneConfigurationManager.getStaticPhoneCapability();
10534 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010535 loge("isMultiSimSupportedInternal: no static configuration available");
10536 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010537 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010538 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010539 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10540 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010541 }
10542 // Check if support of multiple SIMs is restricted by carrier
10543 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010544 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010545 }
10546
Michele0ea7d782019-03-19 14:58:42 -070010547 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010548 }
10549
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010550 /**
10551 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010552 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10553 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10554 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010555 * @param numOfSims number of active sims we want to switch to
10556 */
10557 @Override
10558 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010559 if (numOfSims == 1) {
10560 enforceModifyPermission();
10561 } else {
10562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10563 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10564 }
joonhunshin4ac60942023-11-15 15:23:39 +000010565
10566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10567 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10568
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010569 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010570
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010571 try {
Michele30b57b22019-03-01 12:01:14 -080010572 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010573 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010574 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10575 return;
10576 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010577 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10578 } finally {
10579 Binder.restoreCallingIdentity(identity);
10580 }
10581 }
10582
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010583 @Override
10584 public boolean isApplicationOnUicc(int subId, int appType) {
10585 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010586
10587 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10588 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10589
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010590 Phone phone = getPhone(subId);
10591 if (phone == null) {
10592 return false;
10593 }
10594 final long identity = Binder.clearCallingIdentity();
10595 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010596 UiccPort uiccPort = phone.getUiccPort();
10597 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010598 return false;
10599 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010600 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010601 if (uiccProfile == null) {
10602 return false;
10603 }
10604 if (TelephonyManager.APPTYPE_SIM <= appType
10605 && appType <= TelephonyManager.APPTYPE_ISIM) {
10606 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10607 }
10608 return false;
10609 } finally {
10610 Binder.restoreCallingIdentity(identity);
10611 }
10612 }
10613
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010614 /**
chen xub4baa772019-04-03 10:23:41 -070010615 * Get whether making changes to modem configurations will trigger reboot.
10616 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010617 */
10618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010619 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10620 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010622 mApp, subId, callingPackage, callingFeatureId,
10623 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010624 return false;
10625 }
joonhunshin4ac60942023-11-15 15:23:39 +000010626
10627 enforceTelephonyFeatureWithException(callingPackage,
10628 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10629 "doesSwitchMultiSimConfigTriggerReboot");
10630
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010631 final long identity = Binder.clearCallingIdentity();
10632 try {
10633 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10634 } finally {
10635 Binder.restoreCallingIdentity(identity);
10636 }
10637 }
10638
Nathan Harold29f5f052019-02-15 13:41:57 -080010639 private void updateModemStateMetrics() {
10640 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10641 // TODO: check the state for each modem if the api is ready.
10642 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10643 }
10644
Pengquan Meng3889a572019-01-23 11:16:29 -080010645 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010646 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010647 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010648 // Verify that the callingPackage belongs to the calling UID
10649 mApp.getSystemService(AppOpsManager.class)
10650 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010651
10652 enforceTelephonyFeatureWithException(callingPackage,
10653 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10654
Pengquan Meng3889a572019-01-23 11:16:29 -080010655 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010656 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010657 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010658 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10659 if (slotInfos != null) {
10660 for (int i = 0; i < slotInfos.length; i++) {
10661 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10662 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10663 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10664 portInfo.getLogicalSlotIndex()));
10665 }
10666 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010667 }
10668 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010669 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010674
10675 /**
10676 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010677 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010678 */
jimsunf9ec1622022-09-13 21:18:43 +080010679 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010680 @Override
10681 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010682 return getHalVersion(HAL_SERVICE_RADIO);
10683 }
10684
10685 /**
10686 * Get the HAL Version of a specific service
10687 */
10688 @Override
10689 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010690 Phone phone = getDefaultPhone();
10691 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010692 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010693 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10694 return hv.major * 100 + hv.minor;
10695 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010696
10697 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010698 * Get the current calling package name.
10699 * @return the current calling package name
10700 */
10701 @Override
10702 public String getCurrentPackageName() {
10703 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10704 }
10705
10706 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010707 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10708 * corresponding network requests on a subId.
10709 *
10710 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010711 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010712 * 2) APN is un-metered for this subscription, or
10713 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010714 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010715 *
10716 * @return whether data is allowed for a apn type.
10717 *
10718 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010719 */
10720 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010721 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010722 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10723 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010724
joonhunshin4ac60942023-11-15 15:23:39 +000010725 enforceTelephonyFeatureWithException(callingPackage,
10726 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10727
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010728 // Now that all security checks passes, perform the operation as ourselves.
10729 final long identity = Binder.clearCallingIdentity();
10730 try {
10731 Phone phone = getPhone(subId);
10732 if (phone == null) return false;
10733
Jack Yu27422a52022-03-21 10:38:05 -070010734 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010735 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010736 isMetered = phone.getDataNetworkController().getDataConfigManager()
10737 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10738 phone.getServiceState().getDataRoaming());
10739 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010740 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744 }
10745
10746 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010747 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010748 enforceReadPrivilegedPermission("isApnMetered");
10749
joonhunshin4ac60942023-11-15 15:23:39 +000010750 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10751 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10752
Malcolm Chene5ad5792019-04-18 13:51:02 -070010753 // Now that all security checks passes, perform the operation as ourselves.
10754 final long identity = Binder.clearCallingIdentity();
10755 try {
10756 Phone phone = getPhone(subId);
10757 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010758 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10759 DataUtils.apnTypeToNetworkCapability(apnType),
10760 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010761 } finally {
10762 Binder.restoreCallingIdentity(identity);
10763 }
10764 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010765
10766 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010767 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10768 int subscriptionId, IBooleanConsumer resultCallback) {
10769 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010770
10771 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10772 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10773
Hall Liu73f5d362020-01-20 13:42:00 -080010774 long token = Binder.clearCallingIdentity();
10775 try {
10776 Phone phone = getPhone(subscriptionId);
10777 if (phone == null) {
10778 try {
10779 if (resultCallback != null) {
10780 resultCallback.accept(false);
10781 }
10782 } catch (RemoteException e) {
10783 // ignore
10784 }
10785 return;
10786 }
10787 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10788 Pair.create(specifiers, (x) -> {
10789 try {
10790 if (resultCallback != null) {
10791 resultCallback.accept(x);
10792 }
10793 } catch (RemoteException e) {
10794 // ignore
10795 }
10796 });
10797 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10798 } finally {
10799 Binder.restoreCallingIdentity(token);
10800 }
10801 }
10802
10803 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010804 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10805 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010806 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010807 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010808
10809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10810 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10811
Sarah Chin679c08a2020-11-18 13:39:35 -080010812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10813 final long identity = Binder.clearCallingIdentity();
10814 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010815 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10816 if (result instanceof IllegalStateException) {
10817 throw (IllegalStateException) result;
10818 }
10819 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010820 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10821 return specifiers;
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
10827 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010828 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010829 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010830
10831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10832 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10833
Jack Yu8b766fc2022-03-21 09:42:33 -070010834 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010835 }
10836
10837 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010838 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10839 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010840 if (callingPackage == null) {
10841 callingPackage = getCurrentPackageName();
10842 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010843 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10844 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010845 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10846 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010847 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10848 }
10849 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10850 Intent intent = new Intent();
10851 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10852 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10853 // Bring up choose default SMS subscription dialog right now
10854 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10855 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10856 mApp.startActivity(intent);
10857 }
chen xud5ca2d52019-05-28 15:20:57 -070010858
10859 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010860 public void showSwitchToManagedProfileDialog() {
10861 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010862 try {
10863 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10864 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10865 // for work telephony.
10866 Intent intent = new Intent(Intent.ACTION_SENDTO);
10867 intent.setData(Uri.parse("smsto:"));
10868 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10869 mApp.startActivity(intent);
10870 } catch (ActivityNotFoundException e) {
10871 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10872 Intent intent = new Intent();
10873 intent.setClass(mApp, ErrorDialogActivity.class);
10874 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10875 mApp.startActivity(intent);
10876 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010877 }
10878
10879 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010880 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010881 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10882 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10883
chen xud5ca2d52019-05-28 15:20:57 -070010884 //TODO investigate if this API should require proper permission check in R b/133791609
10885 final long identity = Binder.clearCallingIdentity();
10886 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010887 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10888 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10889 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10890 return carrierUAProfUrl;
10891 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010892 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10893 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
10898
10899 @Override
10900 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010901 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10902 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10903
chen xud5ca2d52019-05-28 15:20:57 -070010904 //TODO investigate if this API should require proper permission check in R b/133791609
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010907 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10908 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10909 if (!TextUtils.isEmpty(carrierUserAgent)) {
10910 return carrierUserAgent;
10911 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010912 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10913 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
Jack Yub07d4972019-05-28 16:12:25 -070010918
10919 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010920 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10921 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010922
joonhunshin4ac60942023-11-15 15:23:39 +000010923 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10924 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
10925
Jack Yub07d4972019-05-28 16:12:25 -070010926 final long identity = Binder.clearCallingIdentity();
10927 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010928 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010929 if (phone == null) return false;
10930
Ling Maf188d502022-09-16 15:22:36 -070010931 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
10936
10937 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010938 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010939 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010940 enforceModifyPermission();
10941
joonhunshin4ac60942023-11-15 15:23:39 +000010942 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10943 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
10944
changbettyd5c246e2019-12-24 15:40:37 +080010945 final long identity = Binder.clearCallingIdentity();
10946 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010947 Phone phone = getPhone(subscriptionId);
10948 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010949
Ling Maf188d502022-09-16 15:22:36 -070010950 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010951 } finally {
10952 Binder.restoreCallingIdentity(identity);
10953 }
10954 }
10955
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010956 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010957 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010958 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10959 * otherwise.
10960 */
10961 @Override
10962 public void setCepEnabled(boolean isCepEnabled) {
10963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10964
10965 final long identity = Binder.clearCallingIdentity();
10966 try {
10967 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10968 for (Phone phone : PhoneFactory.getPhones()) {
10969 Phone defaultPhone = phone.getImsPhone();
10970 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10971 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10972 ImsPhoneCallTracker imsPhoneCallTracker =
10973 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10974 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10975 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10976 + imsPhone.getMsisdn());
10977 }
10978 }
10979 } finally {
10980 Binder.restoreCallingIdentity(identity);
10981 }
10982 }
allenwtsu46dcc572020-01-08 18:24:03 +080010983
10984 /**
10985 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10986 *
10987 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10988 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10989 * before being read.
10990 */
10991 @Override
10992 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10993 isCompressed) {
10994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10995 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010996 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10997 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10998 }
joonhunshin4ac60942023-11-15 15:23:39 +000010999
11000 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11001 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11002 Binder.getCallingUserHandle())) {
11003 if (!isImsAvailableOnDevice()) {
11004 // ProvisioningManager can not handle ServiceSpecificException.
11005 // Throw the IllegalStateException and annotate ProvisioningManager.
11006 throw new IllegalStateException("IMS not available on device.");
11007 }
11008 } else {
11009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11010 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11011 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011012 }
11013
11014 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011015 try {
Hui Wang761a6682020-10-31 05:12:53 +000011016 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11017 } finally {
11018 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011019 }
11020 }
zoey chene02881a2019-12-30 16:11:23 +080011021
11022 @Override
11023 public boolean isIccLockEnabled(int subId) {
11024 enforceReadPrivilegedPermission("isIccLockEnabled");
11025
joonhunshin4ac60942023-11-15 15:23:39 +000011026 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11027 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11028
zoey chene02881a2019-12-30 16:11:23 +080011029 // Now that all security checks passes, perform the operation as ourselves.
11030 final long identity = Binder.clearCallingIdentity();
11031 try {
11032 Phone phone = getPhone(subId);
11033 if (phone != null && phone.getIccCard() != null) {
11034 return phone.getIccCard().getIccLockEnabled();
11035 } else {
11036 return false;
11037 }
11038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
11043 /**
11044 * Set the ICC pin lock enabled or disabled.
11045 *
11046 * @return an integer representing the status of IccLock enabled or disabled in the following
11047 * three cases:
11048 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11049 * successfully.
11050 * - Positive number and zero for remaining password attempts.
11051 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11052 *
11053 */
11054 @Override
11055 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11056 enforceModifyPermission();
11057
joonhunshin4ac60942023-11-15 15:23:39 +000011058 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11059 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11060
zoey chene02881a2019-12-30 16:11:23 +080011061 Phone phone = getPhone(subId);
11062 if (phone == null) {
11063 return 0;
11064 }
11065 // Now that all security checks passes, perform the operation as ourselves.
11066 final long identity = Binder.clearCallingIdentity();
11067 try {
11068 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11069 new Pair<Boolean, String>(enabled, password), phone, null);
11070 return attemptsRemaining;
11071
11072 } catch (Exception e) {
11073 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11074 } finally {
11075 Binder.restoreCallingIdentity(identity);
11076 }
11077 return 0;
11078 }
11079
11080 /**
11081 * Change the ICC password used in ICC pin lock.
11082 *
11083 * @return an integer representing the status of IccLock changed in the following three cases:
11084 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11085 * - Positive number and zero for remaining password attempts.
11086 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11087 *
11088 */
11089 @Override
11090 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11091 enforceModifyPermission();
11092
joonhunshin4ac60942023-11-15 15:23:39 +000011093 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11094 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11095
zoey chene02881a2019-12-30 16:11:23 +080011096 Phone phone = getPhone(subId);
11097 if (phone == null) {
11098 return 0;
11099 }
11100 // Now that all security checks passes, perform the operation as ourselves.
11101 final long identity = Binder.clearCallingIdentity();
11102 try {
11103 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11104 new Pair<String, String>(oldPassword, newPassword), phone, null);
11105 return attemptsRemaining;
11106
11107 } catch (Exception e) {
11108 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 return 0;
11113 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011114
11115 /**
11116 * Request for receiving user activity notification
11117 */
11118 @Override
11119 public void requestUserActivityNotification() {
11120 if (!mNotifyUserActivity.get()
11121 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11122 mNotifyUserActivity.set(true);
11123 }
11124 }
11125
11126 /**
11127 * Called when userActivity is signalled in the power manager.
11128 * This is safe to call from any thread, with any window manager locks held or not.
11129 */
11130 @Override
11131 public void userActivity() {
11132 // ***************************************
11133 // * Inherited from PhoneWindowManager *
11134 // ***************************************
11135 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11136 // WITH ITS LOCKS HELD.
11137 //
11138 // This code must be VERY careful about the locks
11139 // it acquires.
11140 // In fact, the current code acquires way too many,
11141 // and probably has lurking deadlocks.
11142
11143 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11144 throw new SecurityException("Only the OS may call notifyUserActivity()");
11145 }
11146
11147 if (mNotifyUserActivity.getAndSet(false)) {
11148 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11149 USER_ACTIVITY_NOTIFICATION_DELAY);
11150 }
11151 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011152
11153 @Override
11154 public boolean canConnectTo5GInDsdsMode() {
11155 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11156 }
Jack Yud10cdd42020-09-28 20:28:01 -070011157
11158 @Override
11159 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11160 String callingFeatureId) {
11161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11162 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11163 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11164 }
11165
joonhunshin4ac60942023-11-15 15:23:39 +000011166 enforceTelephonyFeatureWithException(callingPackage,
11167 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11168
Jack Yud10cdd42020-09-28 20:28:01 -070011169 Phone phone = getPhone(subId);
11170 if (phone == null) {
11171 throw new RuntimeException("phone is not available");
11172 }
11173 // Now that all security checks passes, perform the operation as ourselves.
11174 final long identity = Binder.clearCallingIdentity();
11175 try {
11176 return phone.getEquivalentHomePlmns();
11177 } finally {
11178 Binder.restoreCallingIdentity(identity);
11179 }
11180 }
Daniel Bright59e67312020-11-13 11:49:37 -080011181
11182 @Override
11183 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011184 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011185 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11186 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11187 "isRadioInterfaceCapabilitySupported");
11188
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011189 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011190 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011191 if (radioInterfaceCapabilities == null) {
11192 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011193 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011194 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011195 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011196
Hui Wang641e81c2020-10-12 12:14:23 -070011197 @Override
11198 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11199 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011200 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11201 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11202 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11203 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11204 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011205
11206 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11207 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11208
Hui Wang641e81c2020-10-12 12:14:23 -070011209 if (DBG) {
11210 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11211 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11212 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11213 }
11214
11215 if (!SubscriptionManager.isValidSubscriptionId(subId)
11216 || appType < TelephonyManager.APPTYPE_UNKNOWN
11217 || appType > TelephonyManager.APPTYPE_ISIM
11218 || nafUrl == null || securityProtocol == null || callback == null) {
11219 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11220 if (callback != null) {
11221 try {
11222 callback.onAuthenticationFailure(
11223 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11224 } catch (RemoteException exception) {
11225 log("Fail to notify onAuthenticationFailure due to " + exception);
11226 }
11227 return;
11228 }
11229 }
11230
11231 final long token = Binder.clearCallingIdentity();
11232 try {
11233 getGbaManager(subId).bootstrapAuthenticationRequest(
11234 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011235 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011236 } finally {
11237 Binder.restoreCallingIdentity(token);
11238 }
11239 }
11240
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011241 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011242 * Attempts to set the radio power state for all phones for thermal reason.
11243 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011244 * requested radio power state will actually be set. See {@link
11245 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11246 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011247 * @param enable {@code true} if trying to turn radio on.
11248 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11249 * false}.
11250 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011251 private boolean setRadioPowerForThermal(boolean enable) {
11252 boolean isPhoneAvailable = false;
11253 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11254 Phone phone = PhoneFactory.getPhone(i);
11255 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011256 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011257 isPhoneAvailable = true;
11258 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011259 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011260
11261 // return true if successfully informed the phone object about the thermal radio power
11262 // request.
11263 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011264 }
11265
11266 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011267 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011268 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11269 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11270 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11271 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11272 throw new IllegalArgumentException("modem does not support data throttling");
11273 }
11274
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011275 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11276 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011277 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011278 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11279 }
11280
Sarah Chinecc78c42022-03-31 21:16:48 -070011281 setDataEnabledForReason(
11282 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011283
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011284 if (isDataThrottlingSupported) {
11285 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011286 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011287 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11288 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11289 } else if (thermalMitigationResult
11290 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011291 log("Modem likely does not support data throttling on secondary carrier. Data " +
11292 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11293 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011294 }
11295 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011296 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011297
11298 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011299 }
11300
Jack Nudelman644b91a2021-03-12 14:09:48 -080011301 private static List<String> getThermalMitigationAllowlist(Context context) {
11302 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11303 for (String pckg : context.getResources()
11304 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11305 sThermalMitigationAllowlistedPackages.add(pckg);
11306 }
11307 }
11308
11309 return sThermalMitigationAllowlistedPackages;
11310 }
11311
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011312 private boolean isAnyPhoneInEmergencyState() {
11313 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11314 if (tm.isInEmergencyCall()) {
11315 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11316 return true;
11317 }
11318 for (Phone phone : PhoneFactory.getPhones()) {
11319 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11320 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011321 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11322 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011323 return true;
11324 }
11325 }
11326
11327 return false;
11328 }
11329
Jack Nudelman644b91a2021-03-12 14:09:48 -080011330 /**
11331 * Used by shell commands to add an authorized package name for thermal mitigation.
11332 * @param packageName name of package to be allowlisted
11333 * @param context
11334 */
11335 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11336 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11337 sThermalMitigationAllowlistedPackages.add(packageName);
11338 }
11339
11340 /**
11341 * Used by shell commands to remove an authorized package name for thermal mitigation.
11342 * @param packageName name of package to remove from allowlist
11343 * @param context
11344 */
11345 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11346 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11347 sThermalMitigationAllowlistedPackages.remove(packageName);
11348 }
11349
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011350 /**
11351 * Thermal mitigation request to control functionalities at modem.
11352 *
11353 * @param subId the id of the subscription.
11354 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011355 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011356 *
11357 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11358 */
11359 @Override
11360 @ThermalMitigationResult
11361 public int sendThermalMitigationRequest(
11362 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011363 ThermalMitigationRequest thermalMitigationRequest,
11364 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365 enforceModifyPermission();
11366
Jack Nudelman644b91a2021-03-12 14:09:48 -080011367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011368
11369 enforceTelephonyFeatureWithException(callingPackage,
11370 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11371
Jack Nudelman644b91a2021-03-12 14:09:48 -080011372 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11373 .contains(callingPackage)) {
11374 throw new SecurityException("Calling package must be configured in the device config. "
11375 + "calling package: " + callingPackage);
11376 }
11377
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011378 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11379 final long identity = Binder.clearCallingIdentity();
11380
11381 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11382 try {
11383 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11384 switch (thermalMitigationAction) {
11385 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11386 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011387 handleDataThrottlingRequest(subId,
11388 thermalMitigationRequest.getDataThrottlingRequest(),
11389 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011390 break;
11391 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11392 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11393 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11394 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11395 }
11396
11397 // Ensure that radio is on. If not able to power on due to phone being
11398 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011399 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011400 thermalMitigationResult =
11401 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11402 break;
11403 }
11404
11405 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011406 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011407 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11408 break;
11409 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11410 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11411 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11412 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11413 }
11414
11415 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11416 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011417 Phone phone = getPhone(subId);
11418 if (phone == null) {
11419 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011420 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011421 break;
11422 }
11423
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011424 TelephonyConnectionService service =
11425 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011426 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011427 Log.e(LOG_TAG, "An emergency call is pending");
11428 thermalMitigationResult =
11429 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11430 break;
11431 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011432 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011433 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011434 break;
11435 }
11436 } else {
11437 thermalMitigationResult =
11438 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11439 break;
11440 }
11441
11442 // Turn radio off. If not able to power off due to phone being unavailable,
11443 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011444 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011445 thermalMitigationResult =
11446 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11447 break;
11448 }
11449 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011450 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011451 break;
11452 default:
11453 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11454 + "not exist. Requested action: " + thermalMitigationAction);
11455 }
11456 } catch (IllegalArgumentException e) {
11457 throw e;
11458 } catch (Exception e) {
11459 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11460 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11461 } finally {
11462 Binder.restoreCallingIdentity(identity);
11463 }
11464
11465 if (DBG) {
11466 log("thermalMitigationRequest returning with thermalMitigationResult: "
11467 + thermalMitigationResult);
11468 }
11469
11470 return thermalMitigationResult;
11471 }
Hui Wang641e81c2020-10-12 12:14:23 -070011472
11473 /**
11474 * Set the GbaService Package Name that Telephony will bind to.
11475 *
11476 * @param subId The sim that the GbaService is associated with.
11477 * @param packageName The name of the package to be replaced with.
11478 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11479 */
11480 @Override
11481 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11482 enforceModifyPermission();
11483
11484 final long identity = Binder.clearCallingIdentity();
11485 try {
11486 return getGbaManager(subId).overrideServicePackage(packageName);
11487 } finally {
11488 Binder.restoreCallingIdentity(identity);
11489 }
11490 }
11491
11492 /**
11493 * Return the package name of the currently bound GbaService.
11494 *
11495 * @param subId The sim that the GbaService is associated with.
11496 * @return the package name of the GbaService configuration, null if GBA is not supported.
11497 */
11498 @Override
11499 public String getBoundGbaService(int subId) {
11500 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11501
11502 final long identity = Binder.clearCallingIdentity();
11503 try {
11504 return getGbaManager(subId).getServicePackage();
11505 } finally {
11506 Binder.restoreCallingIdentity(identity);
11507 }
11508 }
11509
11510 /**
11511 * Set the release time for telephony to unbind GbaService.
11512 *
11513 * @param subId The sim that the GbaService is associated with.
11514 * @param interval The release time to unbind GbaService by millisecond.
11515 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11516 */
11517 @Override
11518 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11519 enforceModifyPermission();
11520
11521 final long identity = Binder.clearCallingIdentity();
11522 try {
11523 return getGbaManager(subId).overrideReleaseTime(interval);
11524 } finally {
11525 Binder.restoreCallingIdentity(identity);
11526 }
11527 }
11528
11529 /**
11530 * Return the release time for telephony to unbind GbaService.
11531 *
11532 * @param subId The sim that the GbaService is associated with.
11533 * @return The release time to unbind GbaService by millisecond.
11534 */
11535 @Override
11536 public int getGbaReleaseTime(int subId) {
11537 enforceReadPrivilegedPermission("getGbaReleaseTime");
11538
11539 final long identity = Binder.clearCallingIdentity();
11540 try {
11541 return getGbaManager(subId).getReleaseTime();
11542 } finally {
11543 Binder.restoreCallingIdentity(identity);
11544 }
11545 }
11546
11547 private GbaManager getGbaManager(int subId) {
11548 GbaManager instance = GbaManager.getInstance(subId);
11549 if (instance == null) {
11550 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11551 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11552 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11553 }
11554 return instance;
11555 }
Hui Wang761a6682020-10-31 05:12:53 +000011556
11557 /**
11558 * indicate whether the device and the carrier can support
11559 * RCS VoLTE single registration.
11560 */
11561 @Override
11562 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011563 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11564 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11565 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11566 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011567
11568 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11569 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11570 }
11571
11572 final long identity = Binder.clearCallingIdentity();
11573 try {
11574 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11575 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011576 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11577 if (isCapable != null) {
11578 return isCapable;
11579 }
Hui Wang761a6682020-10-31 05:12:53 +000011580 }
Hui Wang67af90e2021-06-04 16:57:15 -070011581 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11582 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011583 } finally {
11584 Binder.restoreCallingIdentity(identity);
11585 }
11586 }
11587
11588 /**
11589 * Register RCS provisioning callback.
11590 */
11591 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011592 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011593 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011594 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011595 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011596 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11597 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011598
11599 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11600 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11601 }
joonhunshin4ac60942023-11-15 15:23:39 +000011602 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11603 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11604 Binder.getCallingUserHandle())) {
11605 if (!isImsAvailableOnDevice()) {
11606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11607 "IMS not available on device.");
11608 }
11609 } else {
11610 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11611 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011612 }
11613
11614 final long identity = Binder.clearCallingIdentity();
11615 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011616 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011617 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011618 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11619 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011620 }
Hui Wang761a6682020-10-31 05:12:53 +000011621 } finally {
11622 Binder.restoreCallingIdentity(identity);
11623 }
11624 }
11625
11626 /**
11627 * Unregister RCS provisioning callback.
11628 */
11629 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011630 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011631 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011632 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011633 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011634 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11635 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011636
11637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11638 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11639 }
joonhunshin4ac60942023-11-15 15:23:39 +000011640
11641 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11642 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11643 Binder.getCallingUserHandle())) {
11644 if (!isImsAvailableOnDevice()) {
11645 // operation failed silently
11646 Rlog.w(LOG_TAG, "IMS not available on device.");
11647 return;
11648 }
11649 } else {
11650 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11651 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11652 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011653 }
11654
11655 final long identity = Binder.clearCallingIdentity();
11656 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011657 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011658 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011659 } finally {
11660 Binder.restoreCallingIdentity(identity);
11661 }
11662 }
11663
11664 /**
11665 * trigger RCS reconfiguration.
11666 */
11667 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011668 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11669 "triggerRcsReconfiguration",
11670 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011671
11672 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11673 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11674 }
joonhunshin4ac60942023-11-15 15:23:39 +000011675 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11676 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11677 Binder.getCallingUserHandle())) {
11678 if (!isImsAvailableOnDevice()) {
11679 // ProvisioningManager can not handle ServiceSpecificException.
11680 // Throw the IllegalStateException and annotate ProvisioningManager.
11681 throw new IllegalStateException("IMS not available on device.");
11682 }
11683 } else {
11684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11685 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011686 }
11687
11688 final long identity = Binder.clearCallingIdentity();
11689 try {
11690 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11691 } finally {
11692 Binder.restoreCallingIdentity(identity);
11693 }
11694 }
11695
11696 /**
11697 * Provide the client configuration parameters of the RCS application.
11698 */
11699 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011700 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11701 "setRcsClientConfiguration",
11702 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011703
11704 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11705 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11706 }
joonhunshin4ac60942023-11-15 15:23:39 +000011707 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11708 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11709 Binder.getCallingUserHandle())) {
11710 if (!isImsAvailableOnDevice()) {
11711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11712 "IMS not available on device.");
11713 }
11714 } else {
11715 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11716 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011717 }
11718
11719 final long identity = Binder.clearCallingIdentity();
11720
11721 try {
11722 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11723 if (configBinder == null) {
11724 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011725 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11726 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011727 } else {
11728 configBinder.setRcsClientConfiguration(rcc);
11729 }
joonhunshin3e154242021-09-17 06:33:39 +000011730
11731 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11732 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011733 } catch (RemoteException e) {
11734 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011735 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11736 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011737 } finally {
11738 Binder.restoreCallingIdentity(identity);
11739 }
11740 }
11741
11742 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011743 * Enables or disables the test mode for RCS VoLTE single registration.
11744 */
11745 @Override
11746 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11747 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11748 "setRcsSingleRegistrationTestModeEnabled");
11749
11750 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11751 }
11752
11753 /**
11754 * Gets the test mode for RCS VoLTE single registration.
11755 */
11756 @Override
11757 public boolean getRcsSingleRegistrationTestModeEnabled() {
11758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11759 "getRcsSingleRegistrationTestModeEnabled");
11760
11761 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11762 }
11763
11764 /**
Hui Wang761a6682020-10-31 05:12:53 +000011765 * Overrides the config of RCS VoLTE single registration enabled for the device.
11766 */
11767 @Override
11768 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11770 "setDeviceSingleRegistrationEnabledOverride");
11771 enforceModifyPermission();
11772
11773 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11774 : Boolean.parseBoolean(enabledStr);
11775 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011776 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011777 }
11778
11779 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011780 * Sends a device to device communication message. Only usable via shell.
11781 * @param message message to send.
11782 * @param value message value.
11783 */
11784 @Override
11785 public void sendDeviceToDeviceMessage(int message, int value) {
11786 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011787 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011788 enforceModifyPermission();
11789
11790 final long identity = Binder.clearCallingIdentity();
11791 try {
11792 TelephonyConnectionService service =
11793 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11794 if (service == null) {
11795 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11796 return;
11797 }
11798 service.sendTestDeviceToDeviceMessage(message, value);
11799 } finally {
11800 Binder.restoreCallingIdentity(identity);
11801 }
11802 }
11803
Tyler Gunnbabbda02021-02-10 11:05:02 -080011804 /**
11805 * Sets the specified device to device transport active.
11806 * @param transport The transport to set active.
11807 */
11808 @Override
11809 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11811 "setActiveDeviceToDeviceTransport");
11812 enforceModifyPermission();
11813
11814 final long identity = Binder.clearCallingIdentity();
11815 try {
11816 TelephonyConnectionService service =
11817 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11818 if (service == null) {
11819 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11820 return;
11821 }
11822 service.setActiveDeviceToDeviceTransport(transport);
11823 } finally {
11824 Binder.restoreCallingIdentity(identity);
11825 }
11826 }
Tyler Gunn92479152021-01-20 16:30:10 -080011827
Tyler Gunnd4339262021-05-03 14:46:49 -070011828 @Override
11829 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11830 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11831 "setDeviceToDeviceForceEnabled");
11832
11833 final long identity = Binder.clearCallingIdentity();
11834 try {
11835 Arrays.stream(PhoneFactory.getPhones()).forEach(
11836 p -> {
11837 Phone thePhone = p.getImsPhone();
11838 if (thePhone != null && thePhone instanceof ImsPhone) {
11839 ImsPhone imsPhone = (ImsPhone) thePhone;
11840 CallTracker tracker = imsPhone.getCallTracker();
11841 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11842 ImsPhoneCallTracker imsPhoneCallTracker =
11843 (ImsPhoneCallTracker) tracker;
11844 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11845 }
11846 }
11847 }
11848 );
11849 } finally {
11850 Binder.restoreCallingIdentity(identity);
11851 }
11852 }
11853
Tyler Gunn92479152021-01-20 16:30:10 -080011854 /**
Hui Wang761a6682020-10-31 05:12:53 +000011855 * Gets the config of RCS VoLTE single registration enabled for the device.
11856 */
11857 @Override
11858 public boolean getDeviceSingleRegistrationEnabled() {
11859 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11860 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11861 }
11862
11863 /**
11864 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11865 */
11866 @Override
11867 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11868 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11869 "setCarrierSingleRegistrationEnabledOverride");
11870 enforceModifyPermission();
11871
11872 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11873 : Boolean.parseBoolean(enabledStr);
11874 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11875 subId, enabled);
11876 }
11877
11878 /**
11879 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11880 */
11881 @Override
11882 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11883 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11884 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11885 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011886
11887 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011888 * Overrides the ims feature validation result
11889 */
11890 @Override
11891 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11892 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11893 "setImsFeatureValidationOverride");
11894
11895 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11896 : Boolean.parseBoolean(enabledStr);
11897 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11898 subId, enabled);
11899 }
11900
11901 /**
11902 * Gets the ims feature validation override value
11903 */
11904 @Override
11905 public boolean getImsFeatureValidationOverride(int subId) {
11906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11907 "getImsFeatureValidationOverride");
11908 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11909 }
11910
11911 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011912 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11913 * their mobile plan.
11914 */
11915 @Override
11916 public String getMobileProvisioningUrl() {
11917 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11918 final long identity = Binder.clearCallingIdentity();
11919 try {
11920 return getDefaultPhone().getMobileProvisioningUrl();
11921 } finally {
11922 Binder.restoreCallingIdentity(identity);
11923 }
11924 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011925
James.cf Linbcdf8b32021-01-14 16:44:13 +080011926 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011927 * Get the EAB contact from the EAB database.
11928 */
11929 @Override
11930 public String getContactFromEab(String contact) {
11931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11932 enforceModifyPermission();
11933 final long identity = Binder.clearCallingIdentity();
11934 try {
11935 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11936 } finally {
11937 Binder.restoreCallingIdentity(identity);
11938 }
11939 }
11940
11941 /**
Calvin Pana1434322021-07-01 19:27:01 +080011942 * Get the EAB capability from the EAB database.
11943 */
11944 @Override
11945 public String getCapabilityFromEab(String contact) {
11946 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11947 enforceModifyPermission();
11948 final long identity = Binder.clearCallingIdentity();
11949 try {
11950 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11951 } finally {
11952 Binder.restoreCallingIdentity(identity);
11953 }
11954 }
11955
11956 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011957 * Remove the EAB contacts from the EAB database.
11958 */
11959 @Override
11960 public int removeContactFromEab(int subId, String contacts) {
11961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11962 enforceModifyPermission();
11963 final long identity = Binder.clearCallingIdentity();
11964 try {
11965 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11966 } finally {
11967 Binder.restoreCallingIdentity(identity);
11968 }
11969 }
11970
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011971 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011972 public boolean getDeviceUceEnabled() {
11973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11974 final long identity = Binder.clearCallingIdentity();
11975 try {
11976 return mApp.getDeviceUceEnabled();
11977 } finally {
11978 Binder.restoreCallingIdentity(identity);
11979 }
11980 }
11981
11982 @Override
11983 public void setDeviceUceEnabled(boolean isEnabled) {
11984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11985 final long identity = Binder.clearCallingIdentity();
11986 try {
11987 mApp.setDeviceUceEnabled(isEnabled);
11988 } finally {
11989 Binder.restoreCallingIdentity(identity);
11990 }
11991 }
11992
Brad Ebinger14d467f2021-02-12 06:18:28 +000011993 /**
11994 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11995 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11996 */
11997 // Used for SHELL command only right now.
11998 @Override
11999 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12000 List<String> featureTags) {
12001 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12002 "addUceRegistrationOverrideShell");
12003 final long identity = Binder.clearCallingIdentity();
12004 try {
12005 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12006 new ArraySet<>(featureTags));
12007 } catch (ImsException e) {
12008 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12009 } finally {
12010 Binder.restoreCallingIdentity(identity);
12011 }
12012 }
12013
12014 /**
12015 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12016 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12017 */
12018 // Used for SHELL command only right now.
12019 @Override
12020 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12021 List<String> featureTags) {
12022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12023 "removeUceRegistrationOverrideShell");
12024 final long identity = Binder.clearCallingIdentity();
12025 try {
12026 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12027 new ArraySet<>(featureTags));
12028 } catch (ImsException e) {
12029 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12030 } finally {
12031 Binder.restoreCallingIdentity(identity);
12032 }
12033 }
12034
12035 /**
12036 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12037 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12038 */
12039 // Used for SHELL command only right now.
12040 @Override
12041 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12042 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12043 "clearUceRegistrationOverrideShell");
12044 final long identity = Binder.clearCallingIdentity();
12045 try {
12046 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12047 } catch (ImsException e) {
12048 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12049 } finally {
12050 Binder.restoreCallingIdentity(identity);
12051 }
12052 }
12053
12054 /**
12055 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12056 */
12057 // Used for SHELL command only right now.
12058 @Override
12059 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12061 "getLatestRcsContactUceCapabilityShell");
12062 final long identity = Binder.clearCallingIdentity();
12063 try {
12064 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12065 } catch (ImsException e) {
12066 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12067 } finally {
12068 Binder.restoreCallingIdentity(identity);
12069 }
12070 }
12071
12072 /**
12073 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12074 * device does not have an active PUBLISH.
12075 */
12076 // Used for SHELL command only right now.
12077 @Override
12078 public String getLastUcePidfXmlShell(int subId) {
12079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12080 final long identity = Binder.clearCallingIdentity();
12081 try {
12082 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12083 } catch (ImsException e) {
12084 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12085 } finally {
12086 Binder.restoreCallingIdentity(identity);
12087 }
12088 }
12089
James.cf Line8713a42021-04-29 16:04:26 +080012090 /**
12091 * Remove UCE requests cannot be sent to the network status.
12092 */
12093 // Used for SHELL command only right now.
12094 @Override
12095 public boolean removeUceRequestDisallowedStatus(int subId) {
12096 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12097 final long identity = Binder.clearCallingIdentity();
12098 try {
12099 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12100 } catch (ImsException e) {
12101 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12102 } finally {
12103 Binder.restoreCallingIdentity(identity);
12104 }
12105 }
12106
James.cf Lin18bb9002021-05-25 01:37:38 +080012107 /**
12108 * Remove UCE requests cannot be sent to the network status.
12109 */
12110 // Used for SHELL command only.
12111 @Override
12112 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12113 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12114 final long identity = Binder.clearCallingIdentity();
12115 try {
12116 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12117 } catch (ImsException e) {
12118 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12119 } finally {
12120 Binder.restoreCallingIdentity(identity);
12121 }
12122 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012123
James.cf Lin4b784aa2021-01-31 03:25:15 +080012124 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012125 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12126 String callingPackage) {
12127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12128 mApp, subId, "setSignalStrengthUpdateRequest");
12129
joonhunshin4ac60942023-11-15 15:23:39 +000012130 enforceTelephonyFeatureWithException(callingPackage,
12131 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12132
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012133 final int callingUid = Binder.getCallingUid();
12134 // Verify that tha callingPackage belongs to the calling UID
12135 mApp.getSystemService(AppOpsManager.class)
12136 .checkPackage(callingUid, callingPackage);
12137
Rambo Wang3607f502021-02-01 21:51:40 -080012138 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012139
12140 final long identity = Binder.clearCallingIdentity();
12141 try {
12142 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12143 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12144
12145 if (result instanceof IllegalStateException) {
12146 throw (IllegalStateException) result;
12147 }
12148 } finally {
12149 Binder.restoreCallingIdentity(identity);
12150 }
12151 }
12152
12153 @Override
12154 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12155 String callingPackage) {
12156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12157 mApp, subId, "clearSignalStrengthUpdateRequest");
12158
joonhunshin4ac60942023-11-15 15:23:39 +000012159 enforceTelephonyFeatureWithException(callingPackage,
12160 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12161
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012162 final int callingUid = Binder.getCallingUid();
12163 // Verify that tha callingPackage belongs to the calling UID
12164 mApp.getSystemService(AppOpsManager.class)
12165 .checkPackage(callingUid, callingPackage);
12166
12167 final long identity = Binder.clearCallingIdentity();
12168 try {
12169 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12170 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12171
12172 if (result instanceof IllegalStateException) {
12173 throw (IllegalStateException) result;
12174 }
12175 } finally {
12176 Binder.restoreCallingIdentity(identity);
12177 }
12178 }
12179
Rambo Wang3607f502021-02-01 21:51:40 -080012180 private static void validateSignalStrengthUpdateRequest(Context context,
12181 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012182 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12183 // phone/system process do not have further restriction on request
12184 return;
12185 }
12186
12187 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012188 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012189 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012190 context.enforceCallingOrSelfPermission(
12191 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12192 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012193 }
12194
12195 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012196 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012197 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012198 || info.isEnabled()) {
12199 throw new IllegalArgumentException(
12200 "Only system can set hide fields in SignalThresholdInfo");
12201 }
12202
12203 // Thresholds length for each RAN need in range. This has been validated in
12204 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12205 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12206 final int[] thresholds = info.getThresholds();
12207 Objects.requireNonNull(thresholds);
12208 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12209 || thresholds.length
12210 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12211 throw new IllegalArgumentException(
12212 "thresholds length is out of range: " + thresholds.length);
12213 }
12214 }
12215 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012216
12217 /**
12218 * Gets the current phone capability.
12219 *
12220 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12221 * @return the PhoneCapability which describes the data connection capability of modem.
12222 * It's used to evaluate possible phone config change, for example from single
12223 * SIM device to multi-SIM device.
12224 */
12225 @Override
12226 public PhoneCapability getPhoneCapability() {
12227 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012228
12229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12230 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12231
SongFerngWang8236caa2021-01-17 21:51:44 +080012232 final long identity = Binder.clearCallingIdentity();
12233 try {
12234 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12235 } finally {
12236 Binder.restoreCallingIdentity(identity);
12237 }
12238 }
Michele Berionne5e411512020-11-13 02:36:59 +000012239
12240 /**
12241 * Prepare TelephonyManager for an unattended reboot. The reboot is
12242 * required to be done shortly after the API is invoked.
12243 */
12244 @Override
12245 @TelephonyManager.PrepareUnattendedRebootResult
12246 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012247 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012248 enforceRebootPermission();
12249
joonhunshin4ac60942023-11-15 15:23:39 +000012250 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12251 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12252
Michele Berionne5e411512020-11-13 02:36:59 +000012253 final long identity = Binder.clearCallingIdentity();
12254 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012255 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012256 } finally {
12257 Binder.restoreCallingIdentity(identity);
12258 }
12259 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012260
12261 /**
12262 * Request to get the current slicing configuration including URSP rules and
12263 * NSSAIs (configured, allowed and rejected).
12264 *
12265 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12266 */
12267 @Override
12268 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012269 TelephonyPermissions
12270 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12271 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012272
joonhunshin4ac60942023-11-15 15:23:39 +000012273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12274 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12275 "getSlicingConfig");
12276
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012277 final long identity = Binder.clearCallingIdentity();
12278 try {
12279 Phone phone = getDefaultPhone();
12280 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12281 } finally {
12282 Binder.restoreCallingIdentity(identity);
12283 }
12284 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012285
12286 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012287 * Check whether the given premium capability is available for purchase from the carrier.
12288 *
12289 * @param capability The premium capability to check.
12290 * @param subId The subId to check the premium capability for.
12291 *
12292 * @return Whether the given premium capability is available to purchase.
12293 */
12294 @Override
12295 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12296 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12297 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12298 log("Premium capability "
12299 + TelephonyManager.convertPremiumCapabilityToString(capability)
12300 + " is not available for purchase due to missing permissions.");
12301 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12302 + "permission READ_BASIC_PHONE_STATE.");
12303 }
12304
joonhunshin4ac60942023-11-15 15:23:39 +000012305 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12306 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12307
Sarah Chin2ec39f62022-08-31 17:03:26 -070012308 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012309 if (phone == null) {
12310 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12311 return false;
12312 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012313 final long identity = Binder.clearCallingIdentity();
12314 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012315 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012316 .isPremiumCapabilityAvailableForPurchase(capability);
12317 } finally {
12318 Binder.restoreCallingIdentity(identity);
12319 }
12320 }
12321
12322 /**
12323 * Purchase the given premium capability from the carrier.
12324 *
12325 * @param capability The premium capability to purchase.
12326 * @param callback The result of the purchase request.
12327 * @param subId The subId to purchase the premium capability for.
12328 */
12329 @Override
12330 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12331 log("purchasePremiumCapability: capability="
12332 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12333 + getCurrentPackageName());
12334
12335 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12336 mApp, "purchasePremiumCapability")) {
12337 log("purchasePremiumCapability "
12338 + TelephonyManager.convertPremiumCapabilityToString(capability)
12339 + " failed due to missing permissions.");
12340 throw new SecurityException("purchasePremiumCapability requires permission "
12341 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012342 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12343 mApp, "purchasePremiumCapability")) {
12344 log("purchasePremiumCapability "
12345 + TelephonyManager.convertPremiumCapabilityToString(capability)
12346 + " failed due to missing permissions.");
12347 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012348 }
12349
joonhunshin4ac60942023-11-15 15:23:39 +000012350 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12351 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12352
Sarah Chin2ec39f62022-08-31 17:03:26 -070012353 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012354 if (phone == null) {
12355 try {
12356 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12357 callback.accept(result);
12358 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12359 } catch (RemoteException e) {
12360 String logStr = "Purchase premium capability "
12361 + TelephonyManager.convertPremiumCapabilityToString(capability)
12362 + " failed due to RemoteException handling null phone: " + e;
12363 if (DBG) log(logStr);
12364 AnomalyReporter.reportAnomaly(
12365 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12366 }
12367 return;
12368 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012369
12370 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012371 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012372 callingProcess = mApp.getPackageManager().getApplicationInfo(
12373 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012374 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012375 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012376 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012377
12378 boolean isVisible = false;
12379 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12380 if (am != null) {
12381 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12382 if (processes != null) {
12383 for (ActivityManager.RunningAppProcessInfo process : processes) {
12384 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012385 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012386 if (process.processName.equals(callingProcess) && process.importance
12387 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12388 isVisible = true;
12389 break;
12390 }
12391 }
12392 }
12393 }
12394
12395 if (!isVisible) {
12396 try {
12397 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12398 callback.accept(result);
12399 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12400 } catch (RemoteException e) {
12401 String logStr = "Purchase premium capability "
12402 + TelephonyManager.convertPremiumCapabilityToString(capability)
12403 + " failed due to RemoteException handling background application: " + e;
12404 if (DBG) log(logStr);
12405 AnomalyReporter.reportAnomaly(
12406 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12407 }
12408 return;
12409 }
12410
Sarah Chin71b3a852022-09-28 15:54:19 -070012411 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012412 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012413 }
12414
12415 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012416 * Register an IMS connection state callback
12417 */
12418 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012419 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12420 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012421 if (feature == ImsFeature.FEATURE_MMTEL) {
12422 // ImsMmTelManager
12423 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12424 TelephonyPermissions
12425 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12426 mApp, subId, "registerImsStateCallback");
12427 } else if (feature == ImsFeature.FEATURE_RCS) {
12428 // ImsRcsManager or SipDelegateManager
12429 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12430 Binder.getCallingUid(), "registerImsStateCallback",
12431 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12432 Manifest.permission.READ_PRECISE_PHONE_STATE,
12433 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12434 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12435 }
12436
12437 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12438 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12439 "IMS not available on device.");
12440 }
12441
12442 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12443 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12444 }
12445
12446 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12447 if (controller == null) {
12448 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12449 "IMS not available on device.");
12450 }
12451
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012452 if (callingPackage == null) {
12453 callingPackage = getCurrentPackageName();
12454 }
12455
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012456 final long token = Binder.clearCallingIdentity();
12457 try {
12458 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012459 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012460 } catch (ImsException e) {
12461 throw new ServiceSpecificException(e.getCode());
12462 } finally {
12463 Binder.restoreCallingIdentity(token);
12464 }
12465 }
12466
12467 /**
12468 * Unregister an IMS connection state callback
12469 */
12470 @Override
12471 public void unregisterImsStateCallback(IImsStateCallback cb) {
12472 final long token = Binder.clearCallingIdentity();
12473 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12474 if (controller == null) {
12475 return;
12476 }
12477 try {
12478 controller.unregisterImsStateCallback(cb);
12479 } finally {
12480 Binder.restoreCallingIdentity(token);
12481 }
12482 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012483
12484 /**
12485 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12486 *
12487 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12488 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12489 * SecurityException.
12490 * If there is current registered network this value will be same as the registered cell
12491 * identity. If the device goes out of service the previous cell identity is cached and
12492 * will be returned. If the cache age of the Cell identity is more than 24 hours
12493 * it will be cleared and null will be returned.
12494 *
12495 */
12496 @Override
12497 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12498 String callingFeatureId) {
12499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12500 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12501 LocationAccessPolicy.checkLocationPermission(mApp,
12502 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12503 .setCallingPackage(callingPackage)
12504 .setCallingFeatureId(callingFeatureId)
12505 .setCallingPid(Binder.getCallingPid())
12506 .setCallingUid(Binder.getCallingUid())
12507 .setMethod("getLastKnownCellIdentity")
12508 .setLogAsInfo(true)
12509 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12510 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12511 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12512 .build());
12513
12514 boolean hasFinePermission =
12515 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12516 if (!hasFinePermission
12517 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12518 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012519 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012520 }
12521
12522 final long identity = Binder.clearCallingIdentity();
12523 try {
Ling Mac28f0212023-03-24 16:07:15 -070012524 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012525 if (sst == null) return null;
12526 return sst.getLastKnownCellIdentity();
12527 } finally {
12528 Binder.restoreCallingIdentity(identity);
12529 }
12530 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012531
jimsun3b9ccac2021-10-26 15:01:23 +080012532 /**
12533 * Sets the modem service class Name that Telephony will bind to.
12534 *
12535 * @param serviceName The class name of the modem service.
12536 * @return true if the operation is succeed, otherwise false.
12537 */
12538 public boolean setModemService(String serviceName) {
12539 Log.d(LOG_TAG, "setModemService - " + serviceName);
12540 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012542 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12543 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012544 return mPhoneConfigurationManager.setModemService(serviceName);
12545 }
12546
12547 /**
12548 * Return the class name of the currently bounded modem service.
12549 *
12550 * @return the class name of the modem service.
12551 */
12552 public String getModemService() {
12553 String result;
12554 Log.d(LOG_TAG, "getModemService");
12555 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12556 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012557 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012558 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12559 "getModemService");
12560 result = mPhoneConfigurationManager.getModemService();
12561 Log.d(LOG_TAG, "result = " + result);
12562 return result;
12563 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012564
12565 @Override
12566 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12567 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12568 mApp.enforceCallingOrSelfPermission(
12569 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12570 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12571
12572 final long identity = Binder.clearCallingIdentity();
12573 try {
12574 Phone phone = getPhone(subId);
12575 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012576 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12577 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012578 phone.setVoiceServiceStateOverride(hasService);
12579 } finally {
12580 Binder.restoreCallingIdentity(identity);
12581 }
12582 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012583
12584 /**
12585 * set removable eSIM as default eUICC.
12586 *
12587 * @hide
12588 */
12589 @Override
12590 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12591 enforceModifyPermission();
12592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12593
12594 final long identity = Binder.clearCallingIdentity();
12595 try {
12596 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12597 } finally {
12598 Binder.restoreCallingIdentity(identity);
12599 }
12600 }
12601
12602 /**
12603 * Returns whether the removable eSIM is default eUICC or not.
12604 *
12605 * @hide
12606 */
12607 @Override
12608 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12609 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12611
12612 final long identity = Binder.clearCallingIdentity();
12613 try {
12614 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12615 } finally {
12616 Binder.restoreCallingIdentity(identity);
12617 }
12618 }
12619
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012620 /**
12621 * Get the component name of the default app to direct respond-via-message intent for the
12622 * user associated with this subscription, update the cache if there is no respond-via-message
12623 * application currently configured for this user.
12624 * @return component name of the app and class to direct Respond Via Message intent to, or
12625 * {@code null} if the functionality is not supported.
12626 * @hide
12627 */
12628 @Override
12629 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12630 boolean updateIfNeeded) {
12631 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012632
joonhunshin4ac60942023-11-15 15:23:39 +000012633 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12634 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12635 "getDefaultRespondViaMessageApplication");
12636
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012637 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12638
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012639 UserHandle userHandle = null;
12640 final long identity = Binder.clearCallingIdentity();
12641 try {
12642 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12643 } finally {
12644 Binder.restoreCallingIdentity(identity);
12645 }
12646 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12647 updateIfNeeded, userHandle);
12648 }
Jack Yuf5badd92022-12-08 00:50:53 -080012649
12650 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012651 * Set whether the device is able to connect with null ciphering or integrity
12652 * algorithms. This is a global setting and will apply to all active subscriptions
12653 * and all new subscriptions after this.
12654 *
12655 * @param enabled when true, null cipher and integrity algorithms are allowed.
12656 * @hide
12657 */
12658 @Override
12659 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12660 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12661 enforceModifyPermission();
12662 checkForNullCipherAndIntegritySupport();
12663
12664 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12665 // for listening to these preference changes and applying them immediately.
12666 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12667 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12668 editor.apply();
12669
12670 for (Phone phone: PhoneFactory.getPhones()) {
12671 phone.handleNullCipherEnabledChange();
12672 }
12673 }
12674
12675
12676 /**
12677 * Get whether the device is able to connect with null ciphering or integrity
12678 * algorithms. Note that this retrieves the phone-global preference and not
12679 * the state of the radio.
12680 *
12681 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12682 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12683 * version for this feature.
12684 * @hide
12685 */
12686 @Override
12687 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12688 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12689 enforceReadPermission();
12690 checkForNullCipherAndIntegritySupport();
12691 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12692 }
12693
12694 private void checkForNullCipherAndIntegritySupport() {
12695 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12696 throw new UnsupportedOperationException(
12697 "Null cipher and integrity operations require HAL 2.1 or above");
12698 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012699 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12700 throw new UnsupportedOperationException(
12701 "Null cipher and integrity operations unsupported by modem");
12702 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012703 }
12704
Gil Cukierman06403e12023-11-29 16:33:03 +000012705 private void checkForIdentifierDisclosureNotificationSupport() {
12706 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12707 throw new UnsupportedOperationException(
12708 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12709 + "above");
12710 }
12711 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12712 throw new UnsupportedOperationException(
12713 "Cellular identifier disclosure transparency operations unsupported by modem");
12714 }
12715 }
12716
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012717 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012718 * Get the SIM state for the slot index.
12719 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12720 *
12721 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12722 */
12723 @Override
12724 @SimState
12725 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012726 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12727 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12728
Jack Yuf5badd92022-12-08 00:50:53 -080012729 IccCardConstants.State simState;
12730 if (slotIndex < 0) {
12731 simState = IccCardConstants.State.UNKNOWN;
12732 } else {
12733 Phone phone = null;
12734 try {
12735 phone = PhoneFactory.getPhone(slotIndex);
12736 } catch (IllegalStateException e) {
12737 // ignore
12738 }
12739 if (phone == null) {
12740 simState = IccCardConstants.State.UNKNOWN;
12741 } else {
12742 IccCard icc = phone.getIccCard();
12743 if (icc == null) {
12744 simState = IccCardConstants.State.UNKNOWN;
12745 } else {
12746 simState = icc.getState();
12747 }
12748 }
12749 }
12750 return simState.ordinal();
12751 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012752
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012753 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12754 boolean enableLogcat,
12755 long logcatStartTimestampMillis, boolean enableTelecomDump,
12756 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012757 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12758 TelephonyManager.EmergencyCallDiagnosticParams edp =
12759 new TelephonyManager.EmergencyCallDiagnosticParams();
12760 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12761 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12762 edp.setTelecomDumpSysCollection(enableTelecomDump);
12763 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12764 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12765 Executors.newCachedThreadPool(), db,
12766 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12767 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012768 }
12769
12770 /**
12771 * Request telephony to persist state for debugging emergency call failures.
12772 *
12773 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12774 * @param enableLogcat whether to collect logcat output
12775 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12776 * @param enableTelecomDump whether to collect telecom dumpsys
12777 * @param enableTelephonyDump whether to collect telephony dumpsys
12778 */
12779 @Override
12780 @RequiresPermission(android.Manifest.permission.DUMP)
12781 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12782 long logcatStartTimestampMillis, boolean enableTelecomDump,
12783 boolean enableTelephonyDump) {
12784 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12785 "persistEmergencyCallDiagnosticData");
12786 final long identity = Binder.clearCallingIdentity();
12787 try {
12788 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12789 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12790
12791 } finally {
12792 Binder.restoreCallingIdentity(identity);
12793 }
12794 }
12795
Hui Wang9b5793a2022-12-05 14:38:06 -060012796 /**
12797 * Get current cell broadcast ranges.
12798 */
12799 @Override
12800 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12801 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12802 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12803 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012804
12805 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12806 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12807
Hui Wang9b5793a2022-12-05 14:38:06 -060012808 final long identity = Binder.clearCallingIdentity();
12809 try {
12810 return getPhone(subId).getCellBroadcastIdRanges();
12811 } finally {
12812 Binder.restoreCallingIdentity(identity);
12813 }
12814 }
12815
12816 /**
12817 * Set reception of cell broadcast messages with the list of the given ranges
12818 *
12819 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12820 */
12821 @Override
12822 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12823 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12824 @Nullable IIntegerConsumer callback) {
12825 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12826 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012827
12828 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12829 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12830
Hui Wang9b5793a2022-12-05 14:38:06 -060012831 final long identity = Binder.clearCallingIdentity();
12832 try {
12833 Phone phone = getPhoneFromSubId(subId);
12834 if (DBG) {
12835 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12836 }
12837 phone.setCellBroadcastIdRanges(ranges, result -> {
12838 if (callback != null) {
12839 try {
12840 callback.accept(result);
12841 } catch (RemoteException e) {
12842 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12843 }
12844 }
12845 });
12846 } finally {
12847 Binder.restoreCallingIdentity(identity);
12848 }
12849 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012850
12851 /**
12852 * Returns whether the device supports the domain selection service.
12853 *
12854 * @return {@code true} if the device supports the domain selection service.
12855 */
12856 @Override
12857 public boolean isDomainSelectionSupported() {
12858 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12859 "isDomainSelectionSupported");
12860
12861 final long identity = Binder.clearCallingIdentity();
12862 try {
12863 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12864 } finally {
12865 Binder.restoreCallingIdentity(identity);
12866 }
12867 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012868
12869 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012870 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12871 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12872 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012873 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012874 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012875 * @param enableSatellite {@code true} to enable the satellite modem and
12876 * {@code false} to disable.
12877 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12878 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012879 *
12880 * @throws SecurityException if the caller doesn't have the required permission.
12881 */
12882 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012883 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12884 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012885 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012886 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12887 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012888 }
12889
12890 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012891 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012892 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012893 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012894 * @param result The result receiver that returns whether the satellite modem is enabled
12895 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012896 *
12897 * @throws SecurityException if the caller doesn't have the required permission.
12898 */
12899 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012900 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12901 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012902 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012903 }
12904
12905 /**
Sarah Chin43457982023-02-15 17:50:38 -080012906 * Request to get whether the satellite service demo mode is enabled.
12907 *
12908 * @param subId The subId of the subscription to check whether the satellite demo mode
12909 * is enabled for.
12910 * @param result The result receiver that returns whether the satellite demo mode is enabled
12911 * if the request is successful or an error code if the request failed.
12912 *
12913 * @throws SecurityException if the caller doesn't have the required permission.
12914 */
12915 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012916 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12917 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12918 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012919 }
12920
12921 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012922 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012923 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012924 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012925 * @param result The result receiver that returns whether the satellite service is supported on
12926 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012927 */
12928 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012929 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012930 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012931 }
12932
12933 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012934 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012935 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012936 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012937 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12938 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012939 *
12940 * @throws SecurityException if the caller doesn't have required permission.
12941 */
12942 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012943 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12944 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012945 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012946 }
12947
12948 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012949 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012950 * This can be called by the pointing UI when the user starts pointing to the satellite.
12951 * Modem should continue to report the pointing input as the device or satellite moves.
12952 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012953 * @param subId The subId of the subscription to start satellite transmission updates for.
12954 * @param resultCallback The callback to get the result of the request.
12955 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012956 *
12957 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012958 */
12959 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012960 public void startSatelliteTransmissionUpdates(int subId,
12961 @NonNull IIntegerConsumer resultCallback,
12962 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12963 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12964 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012965 }
12966
12967 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012968 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012969 * This can be called by the pointing UI when the user stops pointing to the satellite.
12970 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012971 * @param subId The subId of the subscription to stop satellite transmission updates for.
12972 * @param resultCallback The callback to get the result of the request.
12973 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12974 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012975 *
12976 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012977 */
12978 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012979 public void stopSatelliteTransmissionUpdates(int subId,
12980 @NonNull IIntegerConsumer resultCallback,
12981 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12982 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12983 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012984 }
12985
12986 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012987 * Register the subscription with a satellite provider.
12988 * This is needed to register the subscription if the provider allows dynamic registration.
12989 *
12990 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012991 * @param token The token to be used as a unique identifier for provisioning with satellite
12992 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012993 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012994 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012995 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012996 * @return The signal transport used by the caller to cancel the provision request,
12997 * or {@code null} if the request failed.
12998 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012999 * @throws SecurityException if the caller doesn't have the required permission.
13000 */
13001 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013002 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013003 @NonNull String token, @NonNull byte[] provisionData,
13004 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013005 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013006 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13007 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013008 }
13009
13010 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013011 * Unregister the device/subscription with the satellite provider.
13012 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013013 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013014 * should report as deprovisioned.
13015 *
13016 * @param subId The subId of the subscription to be deprovisioned.
13017 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013018 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013019 *
13020 * @throws SecurityException if the caller doesn't have the required permission.
13021 */
13022 @Override
13023 public void deprovisionSatelliteService(int subId,
13024 @NonNull String token, @NonNull IIntegerConsumer callback) {
13025 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013026 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013027 }
13028
13029 /**
Sarah Chin43457982023-02-15 17:50:38 -080013030 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013031 *
Sarah Chin43457982023-02-15 17:50:38 -080013032 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013033 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013034 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013035 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013036 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013037 * @throws SecurityException if the caller doesn't have the required permission.
13038 */
13039 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013040 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13041 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013042 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013043 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013044 }
13045
13046 /**
Sarah Chin43457982023-02-15 17:50:38 -080013047 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013048 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013049 *
Sarah Chin43457982023-02-15 17:50:38 -080013050 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013051 * @param callback The callback that was passed to
13052 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013053 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013054 * @throws SecurityException if the caller doesn't have the required permission.
13055 */
13056 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013057 public void unregisterForSatelliteProvisionStateChanged(
13058 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013059 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013060 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013061 }
13062
13063 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013064 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013065 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013066 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013067 * @param result The result receiver that returns whether the device is provisioned with a
13068 * satellite provider if the request is successful or an error code if the
13069 * request failed.
13070 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013071 * @throws SecurityException if the caller doesn't have the required permission.
13072 */
13073 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013074 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13075 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013076 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013077 }
13078
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013079 /**
Sarah Chin43457982023-02-15 17:50:38 -080013080 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013081 *
Sarah Chin43457982023-02-15 17:50:38 -080013082 * @param subId The subId of the subscription to register for satellite modem state changed.
13083 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013084 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013085 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013086 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013087 * @throws SecurityException if the caller doesn't have the required permission.
13088 */
13089 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013090 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013091 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013092 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013093 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013094 }
13095
13096 /**
Sarah Chin43457982023-02-15 17:50:38 -080013097 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013098 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013099 *
Sarah Chin43457982023-02-15 17:50:38 -080013100 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013101 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080013102 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013103 *
13104 * @throws SecurityException if the caller doesn't have the required permission.
13105 */
13106 @Override
Sarah Chin43457982023-02-15 17:50:38 -080013107 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013108 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013109 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013110 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013111 }
13112
13113 /**
13114 * Register to receive incoming datagrams over satellite.
13115 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013116 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013117 * @param callback The callback to handle incoming datagrams over satellite.
13118 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013119 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013120 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013121 * @throws SecurityException if the caller doesn't have the required permission.
13122 */
13123 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013124 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013125 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013126 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080013127 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013128 }
13129
13130 /**
13131 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013132 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013133 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013134 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13135 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080013136 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013137 *
13138 * @throws SecurityException if the caller doesn't have the required permission.
13139 */
13140 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013141 public void unregisterForSatelliteDatagram(int subId,
13142 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013143 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013144 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013145 }
13146
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013147 /**
13148 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013149 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013150 * This method requests modem to check if there are any pending datagrams to be received over
13151 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013152 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013153 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013154 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013155 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013156 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013157 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013158 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013159 @Override
13160 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013161 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013162 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013163 }
13164
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013165 /**
13166 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013167 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013168 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13169 * input to this method. Datagram received here will be passed down to modem without any
13170 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013171 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013172 * @param subId The subId of the subscription to send satellite datagrams for.
13173 * @param datagramType datagram type indicating whether the datagram is of type
13174 * SOS_SMS or LOCATION_SHARING.
13175 * @param datagram encoded gateway datagram which is encrypted by the caller.
13176 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013177 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13178 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013179 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013180 *
13181 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013182 */
13183 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013184 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
13185 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13186 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013187 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013188 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
13189 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013190 }
13191
Sarah Chindf715ec2023-02-13 13:46:24 -080013192 /**
13193 * Request to get whether satellite communication is allowed for the current location.
13194 *
13195 * @param subId The subId of the subscription to check whether satellite communication is
13196 * allowed for the current location for.
13197 * @param result The result receiver that returns whether satellite communication is allowed
13198 * for the current location if the request is successful or an error code
13199 * if the request failed.
13200 *
13201 * @throws SecurityException if the caller doesn't have the required permission.
13202 */
13203 @Override
13204 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
13205 @NonNull ResultReceiver result) {
13206 enforceSatelliteCommunicationPermission(
13207 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013208 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
13209 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013210 }
13211
13212 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013213 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013214 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013215 * @param subId The subId to get the time after which the satellite will be visible for.
13216 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013217 * be visible if the request is successful or an error code if the request failed.
13218 *
13219 * @throws SecurityException if the caller doesn't have the required permission.
13220 */
13221 @Override
13222 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13223 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013224 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013225 }
13226
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013227 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013228 * Inform that Device is aligned to satellite for demo mode.
13229 *
13230 * @param subId The subId to get the time after which the satellite will be visible for.
13231 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13232 * {@code false} Device fails to align with the satellite for demo mode.
13233 *
13234 * @throws SecurityException if the caller doesn't have required permission.
13235 */
13236 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13237
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013238 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013239 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013240 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013241 }
13242
13243 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013244 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13245 * by modem.
13246 *
13247 * @param subId The subId of the subscription to request for.
13248 * @param reason Reason for disallowing satellite communication for carrier.
13249 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13250 * operation.
13251 *
13252 * @throws SecurityException if the caller doesn't have required permission.
13253 */
13254 public void addSatelliteAttachRestrictionForCarrier(int subId,
13255 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13256 @NonNull IIntegerConsumer callback) {
13257 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
13258 final long identity = Binder.clearCallingIdentity();
13259 try {
13260 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
13261 } finally {
13262 Binder.restoreCallingIdentity(identity);
13263 }
13264 }
13265
13266 /**
13267 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13268 * by modem.
13269 *
13270 * @param subId The subId of the subscription to request for.
13271 * @param reason Reason for disallowing satellite communication.
13272 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13273 * operation.
13274 *
13275 * @throws SecurityException if the caller doesn't have required permission.
13276 */
13277 public void removeSatelliteAttachRestrictionForCarrier(int subId,
13278 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13279 @NonNull IIntegerConsumer callback) {
13280 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
13281 final long identity = Binder.clearCallingIdentity();
13282 try {
13283 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
13284 callback);
13285 } finally {
13286 Binder.restoreCallingIdentity(identity);
13287 }
13288 }
13289
13290 /**
13291 * Get reasons for disallowing satellite communication, as requested by
13292 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13293 *
13294 * @param subId The subId of the subscription to request for.
13295 *
13296 * @return Integer array of reasons for disallowing satellite communication.
13297 *
13298 * @throws SecurityException if the caller doesn't have the required permission.
13299 */
13300 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
13301 int subId) {
13302 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
13303 final long identity = Binder.clearCallingIdentity();
13304 try {
13305 Set<Integer> reasonSet =
13306 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
13307 return reasonSet.stream().mapToInt(i->i).toArray();
13308 } finally {
13309 Binder.restoreCallingIdentity(identity);
13310 }
13311 }
13312
13313 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013314 * Request to get the signal strength of the satellite connection.
13315 *
13316 * @param subId The subId of the subscription to request for.
13317 * @param result Result receiver to get the error code of the request and the current signal
13318 * strength of the satellite connection.
13319 *
13320 * @throws SecurityException if the caller doesn't have required permission.
13321 */
13322 @Override
13323 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13324 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13325 final long identity = Binder.clearCallingIdentity();
13326 try {
13327 mSatelliteController.requestNtnSignalStrength(subId, result);
13328 } finally {
13329 Binder.restoreCallingIdentity(identity);
13330 }
13331 }
13332
13333 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013334 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13335 * is not successful, a {@link ServiceSpecificException} that contains
13336 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013337 *
13338 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013339 * @param callback The callback to handle the NTN signal strength changed event. If the
13340 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13341 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13342 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13343 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013344 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013345 * @throws SecurityException If the caller doesn't have the required permission.
13346 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013347 */
13348 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013349 public void registerForNtnSignalStrengthChanged(int subId,
13350 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013351 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13352 final long identity = Binder.clearCallingIdentity();
13353 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013354 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013355 } finally {
13356 Binder.restoreCallingIdentity(identity);
13357 }
13358 }
13359
13360 /**
13361 * Unregisters for NTN signal strength changed from satellite modem.
13362 * If callback was not registered before, the request will be ignored.
13363 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013364 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13365 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013366 * @param callback The callback that was passed to
13367 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13368 *
13369 * @throws SecurityException if the caller doesn't have the required permission.
13370 */
13371 @Override
13372 public void unregisterForNtnSignalStrengthChanged(
13373 int subId, @NonNull INtnSignalStrengthCallback callback) {
13374 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13375 final long identity = Binder.clearCallingIdentity();
13376 try {
13377 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13378 } finally {
13379 Binder.restoreCallingIdentity(identity);
13380 }
13381 }
13382
13383 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013384 * Registers for satellite capabilities change event from the satellite service.
13385 *
13386 * @param subId The subId of the subscription to request for.
13387 * @param callback The callback to handle the satellite capabilities changed event.
13388 *
13389 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13390 *
13391 * @throws SecurityException if the caller doesn't have required permission.
13392 */
13393 @Override
13394 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
13395 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
13396 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
13397 final long identity = Binder.clearCallingIdentity();
13398 try {
13399 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
13400 } finally {
13401 Binder.restoreCallingIdentity(identity);
13402 }
13403 }
13404
13405 /**
13406 * Unregisters for satellite capabilities change event from the satellite service.
13407 * If callback was not registered before, the request will be ignored.
13408 *
13409 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13410 * @param callback The callback that was passed to.
13411 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
13412 *
13413 * @throws SecurityException if the caller doesn't have required permission.
13414 */
13415 @Override
13416 public void unregisterForSatelliteCapabilitiesChanged(
13417 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
13418 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
13419 final long identity = Binder.clearCallingIdentity();
13420 try {
13421 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
13422 } finally {
13423 Binder.restoreCallingIdentity(identity);
13424 }
13425 }
13426
13427 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013428 * This API can be used by only CTS to update satellite vendor service package name.
13429 *
13430 * @param servicePackageName The package name of the satellite vendor service.
13431 * @return {@code true} if the satellite vendor service is set successfully,
13432 * {@code false} otherwise.
13433 */
13434 public boolean setSatelliteServicePackageName(String servicePackageName) {
13435 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13436 TelephonyPermissions.enforceShellOnly(
13437 Binder.getCallingUid(), "setSatelliteServicePackageName");
13438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13439 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13440 "setSatelliteServicePackageName");
13441 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13442 }
13443
13444 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013445 * This API can be used by only CTS to update satellite gateway service package name.
13446 *
13447 * @param servicePackageName The package name of the satellite gateway service.
13448 * @return {@code true} if the satellite gateway service is set successfully,
13449 * {@code false} otherwise.
13450 */
13451 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13452 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13453 TelephonyPermissions.enforceShellOnly(
13454 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13456 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13457 "setSatelliteGatewayServicePackageName");
13458 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13459 }
13460
13461 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013462 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13463 *
13464 * @param packageName The package name of the satellite pointing UI app.
13465 * @param className The class name of the satellite pointing UI app.
13466 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13467 * {@code false} otherwise.
13468 */
13469 public boolean setSatellitePointingUiClassName(
13470 @Nullable String packageName, @Nullable String className) {
13471 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13472 + ", className=" + className);
13473 TelephonyPermissions.enforceShellOnly(
13474 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13476 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13477 "setSatelliteGatewayServicePackageName");
13478 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13479 }
13480
13481 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013482 * This API can be used by only CTS to update the timeout duration in milliseconds that
13483 * satellite should stay at listening mode to wait for the next incoming page before disabling
13484 * listening mode.
13485 *
13486 * @param timeoutMillis The timeout duration in millisecond.
13487 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13488 */
13489 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13490 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13491 TelephonyPermissions.enforceShellOnly(
13492 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13494 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13495 "setSatelliteListeningTimeoutDuration");
13496 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13497 }
13498
13499 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013500 * This API can be used by only CTS to update the timeout duration in milliseconds whether
13501 * the device is aligned with the satellite for demo mode
13502 *
13503 * @param timeoutMillis The timeout duration in millisecond.
13504 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13505 */
13506 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
13507 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
13508 TelephonyPermissions.enforceShellOnly(
13509 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
13510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13511 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13512 "setDeviceAlignedTimeoutDuration");
13513 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
13514 }
13515
13516 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013517 * This API can be used in only testing to override connectivity status in monitoring emergency
13518 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13519 *
13520 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13521 * of the following values to enable the override:
13522 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13523 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13524 * To disable the override, use -1 for handoverType.
13525 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13526 * delaySeconds after the emergency call starts.
13527 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13528 */
13529 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13530 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13531 TelephonyPermissions.enforceShellOnly(
13532 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13534 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13535 "setEmergencyCallToSatelliteHandoverType");
13536 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13537 handoverType, delaySeconds);
13538 }
13539
13540 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013541 * This API can be used by only CTS to override the cached value for the device overlay config
13542 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13543 * outgoing satellite datagrams should be sent to modem in demo mode.
13544 *
13545 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13546 * satellite modem or not.
13547 *
13548 * @return {@code true} if the operation is successful, {@code false} otherwise.
13549 */
13550 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13551 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13552 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13553 + "disabled");
13554 return false;
13555 }
13556 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13557 TelephonyPermissions.enforceShellOnly(
13558 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13560 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13561 "setShouldSendDatagramToModemInDemoMode");
13562 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13563 shouldSendToModemInDemoMode);
13564 }
13565
13566 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013567 * Enable or disable notifications sent for cellular identifier disclosure events.
13568 *
13569 * Disclosure events are defined as instances where a device has sent a cellular identifier
13570 * on the Non-access stratum (NAS) before a security context is established. As a result the
13571 * identifier is sent in the clear, which has privacy implications for the user.
13572 *
13573 * @param enable if notifications about disclosure events should be enabled
13574 * @throws SecurityException if the caller does not have the required privileges
13575 * @throws UnsupportedOperationException if the modem does not support this feature.
13576 */
13577 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013578 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013579 enforceModifyPermission();
13580 checkForIdentifierDisclosureNotificationSupport();
13581
13582 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13583 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13584 editor.apply();
13585
13586 // Each phone instance is responsible for updating its respective modem immediately
13587 // after we've made a preference change.
13588 for (Phone phone : PhoneFactory.getPhones()) {
13589 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13590 }
13591 }
13592
13593 /**
13594 * Get whether or not cellular identifier disclosure notifications are enabled.
13595 *
13596 * @throws SecurityException if the caller does not have the required privileges
13597 * @throws UnsupportedOperationException if the modem does not support this feature.
13598 */
13599 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013600 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013601 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13602 checkForIdentifierDisclosureNotificationSupport();
13603 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13604 }
13605
13606 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013607 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13608 *
13609 * <p>This method behaves in one of the following ways:
13610 * <ul>
13611 * <li>return true : if the calling package has the appop permission {@link
13612 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13613 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13614 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13615 * Owner device identifier access check, or the calling package has carrier privileges</>
13616 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13617 * </ul>
13618 */
13619 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13620 String callingPackage, @Nullable String callingFeatureId, String message) {
13621 for (Phone phone : PhoneFactory.getPhones()) {
13622 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13623 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13624 return true;
13625 }
13626 }
13627 return false;
13628 }
arunvoddud7401012022-12-15 16:08:12 +000013629
13630 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013631 * @return The subscription manager service instance.
13632 */
13633 public SubscriptionManagerService getSubscriptionManagerService() {
13634 return SubscriptionManagerService.getInstance();
13635 }
13636
13637 /**
arunvoddud7401012022-12-15 16:08:12 +000013638 * Class binds the consumer[callback] and carrierId.
13639 */
13640 private static class CallerCallbackInfo {
13641 private final Consumer<Integer> mConsumer;
13642 private final int mCarrierId;
13643
13644 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13645 mConsumer = consumer;
13646 mCarrierId = carrierId;
13647 }
13648
13649 public Consumer<Integer> getConsumer() {
13650 return mConsumer;
13651 }
13652
13653 public int getCarrierId() {
13654 return mCarrierId;
13655 }
13656 }
joonhunshin4ac60942023-11-15 15:23:39 +000013657
13658 /*
13659 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
13660 * But the context that is passed in is unused if the phone app is already alive.
13661 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
13662 */
13663 @VisibleForTesting
13664 public void setPackageManager(PackageManager packageManager) {
13665 mPackageManager = packageManager;
13666 }
13667
13668 /*
13669 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
13670 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
13671 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
13672 */
13673 @VisibleForTesting
13674 public void setFeatureFlags(FeatureFlags featureFlags) {
13675 mFeatureFlags = featureFlags;
13676 }
13677
13678 /**
13679 * Make sure the device has required telephony feature
13680 *
13681 * @throws UnsupportedOperationException if the device does not have required telephony feature
13682 */
13683 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
13684 @NonNull String telephonyFeature, @NonNull String methodName) {
13685 if (callingPackage == null || mPackageManager == null) {
13686 return;
13687 }
13688
13689 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
13690 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
13691 Binder.getCallingUserHandle())) {
13692 return;
13693 }
13694
13695 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
13696 throw new UnsupportedOperationException(
13697 methodName + " is unsupported without " + telephonyFeature);
13698 }
13699 }
Jack Yufa8ed012023-02-11 15:42:28 -080013700}