blob: ec853617076c6a311184b210c84b432e8f102f4c [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 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004572 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4573 * @param subId The subscription to use to check the configuration.
4574 * @param c The callback that will be used to send the result.
4575 */
4576 @Override
4577 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4578 throws RemoteException {
4579 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4580 mApp, subId, "registerImsEmergencyRegistrationCallback");
4581
4582 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4583 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4584 "IMS not available on device.");
4585 }
4586 final long token = Binder.clearCallingIdentity();
4587 try {
4588 int slotId = getSlotIndexOrException(subId);
4589 verifyImsMmTelConfiguredOrThrow(slotId);
4590
4591 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4592 if (controller != null) {
4593 ImsManager imsManager = controller.getImsManager(subId);
4594 if (imsManager != null) {
4595 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4596 } else {
4597 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4598 }
4599 } else {
4600 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4601 }
4602 } catch (ImsException e) {
4603 throw new ServiceSpecificException(e.getCode());
4604 } finally {
4605 Binder.restoreCallingIdentity(token);
4606 }
4607 }
4608
4609 /**
4610 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4611 * @param subId The subscription to use to check the configuration.
4612 * @param c The callback that will be used to send the result.
4613 */
4614 @Override
4615 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4616 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4617 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4619 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4620 }
4621 final long token = Binder.clearCallingIdentity();
4622
4623 try {
4624 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4625 if (controller != null) {
4626 ImsManager imsManager = controller.getImsManager(subId);
4627 if (imsManager != null) {
4628 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4629 } else {
4630 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4631 + "is inactive, ignoring unregister.");
4632 // If the ImsManager is not valid, just return, since the callback
4633 // will already have been removed internally.
4634 }
4635 }
4636 } finally {
4637 Binder.restoreCallingIdentity(token);
4638 }
4639 }
4640
4641 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004642 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4643 */
4644 @Override
4645 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4646 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4647 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4648 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4649 "IMS not available on device.");
4650 }
4651 final long token = Binder.clearCallingIdentity();
4652 try {
4653 Phone phone = getPhone(subId);
4654 if (phone == null) {
4655 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4656 + subId + "'");
4657 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4658 }
4659 phone.getImsRegistrationState(regState -> {
4660 try {
4661 consumer.accept((regState == null)
4662 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4663 } catch (RemoteException e) {
4664 // Ignore if the remote process is no longer available to call back.
4665 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4666 }
4667 });
4668 } finally {
4669 Binder.restoreCallingIdentity(token);
4670 }
4671 }
4672
4673 /**
4674 * Get the transport type for the IMS service registration state.
4675 */
4676 @Override
4677 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004678 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004679 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004680 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4682 "IMS not available on device.");
4683 }
4684 final long token = Binder.clearCallingIdentity();
4685 try {
4686 Phone phone = getPhone(subId);
4687 if (phone == null) {
4688 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4689 + subId + "'");
4690 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4691 }
4692 phone.getImsRegistrationTech(regTech -> {
4693 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4694 int regTechConverted = (regTech == null)
4695 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4696 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4697 regTechConverted);
4698 try {
4699 consumer.accept(regTechConverted);
4700 } catch (RemoteException e) {
4701 // Ignore if the remote process is no longer available to call back.
4702 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4703 }
4704 });
4705 } finally {
4706 Binder.restoreCallingIdentity(token);
4707 }
4708 }
4709
shilu366312e2019-12-17 09:28:10 -08004710 /**
4711 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4712 * @param subId The subscription to use to check the configuration.
4713 * @param c The callback that will be used to send the result.
4714 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004715 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004716 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4717 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004718 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004719 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004720 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4721 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4722 "IMS not available on device.");
4723 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004724 final long token = Binder.clearCallingIdentity();
4725 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004726 int slotId = getSlotIndexOrException(subId);
4727 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004728
4729 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4730 if (controller != null) {
4731 ImsManager imsManager = controller.getImsManager(subId);
4732 if (imsManager != null) {
4733 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4734 } else {
4735 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4736 }
4737 } else {
4738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4739 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004740 } catch (ImsException e) {
4741 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 } finally {
4743 Binder.restoreCallingIdentity(token);
4744 }
4745 }
4746
shilu366312e2019-12-17 09:28:10 -08004747 /**
4748 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4749 * @param subId The subscription to use to check the configuration.
4750 * @param c The callback that will be used to send the result.
4751 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004752 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004753 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004754 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004755 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4757 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4758 }
Meng Wangafbc5852019-09-19 17:37:13 -07004759
4760 final long token = Binder.clearCallingIdentity();
4761 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004762 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4763 if (controller != null) {
4764 ImsManager imsManager = controller.getImsManager(subId);
4765 if (imsManager != null) {
4766 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4767 } else {
4768 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4769 + " is inactive, ignoring unregister.");
4770 // If the ImsManager is not valid, just return, since the callback
4771 // will already have been removed internally.
4772 }
4773 }
Meng Wangafbc5852019-09-19 17:37:13 -07004774 } finally {
4775 Binder.restoreCallingIdentity(token);
4776 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004777 }
4778
4779 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004780 public boolean isCapable(int subId, int capability, int regTech) {
4781 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004782
4783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4784 FEATURE_TELEPHONY_IMS, "isCapable");
4785
Brad Ebinger35c841c2018-10-01 10:40:55 -07004786 final long token = Binder.clearCallingIdentity();
4787 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004788 int slotId = getSlotIndexOrException(subId);
4789 verifyImsMmTelConfiguredOrThrow(slotId);
4790 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4791 } catch (com.android.ims.ImsException e) {
4792 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4793 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004794 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004795 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4796 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004797 } finally {
4798 Binder.restoreCallingIdentity(token);
4799 }
4800 }
4801
4802 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004803 public boolean isAvailable(int subId, int capability, int regTech) {
4804 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004805
4806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4807 FEATURE_TELEPHONY_IMS, "isAvailable");
4808
Brad Ebinger35c841c2018-10-01 10:40:55 -07004809 final long token = Binder.clearCallingIdentity();
4810 try {
4811 Phone phone = getPhone(subId);
4812 if (phone == null) return false;
4813 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004814 } catch (com.android.ims.ImsException e) {
4815 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4816 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004817 } finally {
4818 Binder.restoreCallingIdentity(token);
4819 }
4820 }
4821
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004822 /**
4823 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4824 * subscription.
4825 * @param subId The subscription to use to check the configuration.
4826 * @param callback The callback that will be used to send the result.
4827 * @param capability The MmTelFeature capability that will be used to send the result.
4828 * @param transportType The transport type of the MmTelFeature capability.
4829 */
4830 @Override
4831 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4832 int transportType) {
4833 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004834 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4836 "IMS not available on device.");
4837 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004838 final long token = Binder.clearCallingIdentity();
4839 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004840 int slotId = getSlotIndex(subId);
4841 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4842 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4843 + subId + "'");
4844 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4845 }
4846 verifyImsMmTelConfiguredOrThrow(slotId);
4847 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4848 transportType, aBoolean -> {
4849 try {
4850 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4851 } catch (RemoteException e) {
4852 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4853 + "running. Ignore");
4854 }
4855 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004856 } catch (ImsException e) {
4857 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004858 } finally {
4859 Binder.restoreCallingIdentity(token);
4860 }
4861 }
4862
shilu366312e2019-12-17 09:28:10 -08004863 /**
4864 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4865 * @param subId The subscription to use to check the configuration.
4866 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004867 @Override
4868 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004869 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004870 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004871
joonhunshin4ac60942023-11-15 15:23:39 +00004872 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4873 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4874
Brad Ebinger35c841c2018-10-01 10:40:55 -07004875 final long token = Binder.clearCallingIdentity();
4876 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004877 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004878 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004879 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004880 } catch (ImsException e) {
4881 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004882 } finally {
4883 Binder.restoreCallingIdentity(token);
4884 }
4885 }
4886
4887 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004888 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004890 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004891
4892 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4893 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
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. The
4899 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004900 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004901 } catch (ImsException e) {
4902 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
4906 }
4907
shilu366312e2019-12-17 09:28:10 -08004908 /**
4909 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4910 * @param subId The subscription to use to check the configuration.
4911 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004912 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004913 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004914 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004915 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004916
4917 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4918 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4919
Brad Ebinger35c841c2018-10-01 10:40:55 -07004920 final long identity = Binder.clearCallingIdentity();
4921 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004922 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004923 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004924 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004925 } catch (ImsException e) {
4926 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
4930 }
4931
4932 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004933 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004935 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004936
4937 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4938 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4939
Brad Ebinger35c841c2018-10-01 10:40:55 -07004940 final long identity = Binder.clearCallingIdentity();
4941 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004942 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004943 // This setting doesn't require an active ImsService connection, so do not verify. The
4944 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004945 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004946 } catch (ImsException e) {
4947 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
4951 }
4952
shilu366312e2019-12-17 09:28:10 -08004953 /**
4954 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4955 * @param subId The subscription to use to check the configuration.
4956 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004957 @Override
4958 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004959 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004960 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004961
4962 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4963 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4964
Brad Ebinger35c841c2018-10-01 10:40:55 -07004965 final long identity = Binder.clearCallingIdentity();
4966 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004967 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004968 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004969 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004970 } catch (ImsException e) {
4971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
4975 }
4976
4977 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004978 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004980 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004981
4982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4983 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
4984
Brad Ebinger35c841c2018-10-01 10:40:55 -07004985 final long identity = Binder.clearCallingIdentity();
4986 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004987 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004988 // This setting doesn't require an active ImsService connection, so do not verify. The
4989 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004990 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004991 } catch (ImsException e) {
4992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
4996 }
4997
shilu366312e2019-12-17 09:28:10 -08004998 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004999 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5000 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5001 * @param subId The subscription to use to check the configuration.
5002 */
5003 @Override
5004 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005005 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005006 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005007
5008 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5009 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5010
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005011 final long identity = Binder.clearCallingIdentity();
5012 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005013 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005014 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005015 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005016 } catch (ImsException e) {
5017 throw new ServiceSpecificException(e.getCode());
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
5021 }
5022
5023 /**
5024 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5025 * Requires MODIFY_PHONE_STATE permission.
5026 * @param subId The subscription to use to check the configuration.
5027 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5028 * false otherwise
5029 */
5030 @Override
5031 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5033 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005034
5035 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5036 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5037
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005040 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005041 // This setting doesn't require an active ImsService connection, so do not verify. The
5042 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005043 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005044 } catch (ImsException e) {
5045 throw new ServiceSpecificException(e.getCode());
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
5049 }
5050
5051 /**
shilu366312e2019-12-17 09:28:10 -08005052 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5053 * @param subId The subscription to use to check the configuration.
5054 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005055 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005056
Brad Ebinger35c841c2018-10-01 10:40:55 -07005057 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005058 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005059 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005060
5061 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5062 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5063
Brad Ebinger35c841c2018-10-01 10:40:55 -07005064 final long identity = Binder.clearCallingIdentity();
5065 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005066 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005067 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005068 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005069 } catch (ImsException e) {
5070 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005071 } finally {
5072 Binder.restoreCallingIdentity(identity);
5073 }
5074 }
5075
5076 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005077 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005079 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005080
5081 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5082 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5083
Brad Ebinger35c841c2018-10-01 10:40:55 -07005084 final long identity = Binder.clearCallingIdentity();
5085 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005086 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005087 // This setting doesn't require an active ImsService connection, so do not verify. The
5088 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005089 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005090 } catch (ImsException e) {
5091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005092 } finally {
5093 Binder.restoreCallingIdentity(identity);
5094 }
5095 }
5096
5097 @Override
5098 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5100 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005101
5102 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5103 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5104
Brad Ebinger35c841c2018-10-01 10:40:55 -07005105 final long identity = Binder.clearCallingIdentity();
5106 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005107 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005108 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005109 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005110 } catch (ImsException e) {
5111 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
5115 }
5116
shilu366312e2019-12-17 09:28:10 -08005117 /**
5118 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5119 * @param subId The subscription to use to check the configuration.
5120 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005121 @Override
5122 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005123 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005124 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005125
5126 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5127 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5128
Brad Ebinger35c841c2018-10-01 10:40:55 -07005129 final long identity = Binder.clearCallingIdentity();
5130 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005131 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005132 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005133 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005134 } catch (ImsException e) {
5135 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
5139 }
5140
5141 @Override
5142 public void setVoWiFiModeSetting(int subId, int mode) {
5143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5144 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005145
5146 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5147 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5148
Brad Ebinger35c841c2018-10-01 10:40:55 -07005149 final long identity = Binder.clearCallingIdentity();
5150 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005151 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005152 // This setting doesn't require an active ImsService connection, so do not verify. The
5153 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005154 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005155 } catch (ImsException e) {
5156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
5160 }
5161
5162 @Override
5163 public int getVoWiFiRoamingModeSetting(int subId) {
5164 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005165
5166 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5167 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5168
Brad Ebinger35c841c2018-10-01 10:40:55 -07005169 final long identity = Binder.clearCallingIdentity();
5170 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005171 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005172 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005173 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005174 } catch (ImsException e) {
5175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
5181 @Override
5182 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5184 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005185
5186 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5187 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5188
Brad Ebinger35c841c2018-10-01 10:40:55 -07005189 final long identity = Binder.clearCallingIdentity();
5190 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005191 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005192 // This setting doesn't require an active ImsService connection, so do not verify. The
5193 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005195 } catch (ImsException e) {
5196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
5200 }
5201
5202 @Override
5203 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5205 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005206
5207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5208 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5209
Brad Ebinger35c841c2018-10-01 10:40:55 -07005210 final long identity = Binder.clearCallingIdentity();
5211 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005212 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005213 // This setting doesn't require an active ImsService connection, so do not verify. The
5214 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005215 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005216 } catch (ImsException e) {
5217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
5221 }
5222
shilu366312e2019-12-17 09:28:10 -08005223 /**
5224 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5225 * @param subId The subscription to use to check the configuration.
5226 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005227 @Override
5228 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005229 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005230 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005231
5232 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5233 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5234
Brad Ebinger35c841c2018-10-01 10:40:55 -07005235 final long identity = Binder.clearCallingIdentity();
5236 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005237 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005238 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005239 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005240 } catch (ImsException e) {
5241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
5245 }
5246
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005247 @Override
5248 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5249 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005250
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005251 final long identity = Binder.clearCallingIdentity();
5252 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005253 if (!isImsAvailableOnDevice()) {
5254 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5255 "IMS not available on device.");
5256 }
5257 int slotId = getSlotIndexOrException(subId);
5258 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005259
5260 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5261 if (controller != null) {
5262 ImsManager imsManager = controller.getImsManager(subId);
5263 if (imsManager != null) {
5264 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5265 } else {
5266 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5267 }
5268 } else {
5269 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5270 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005271 } catch (ImsException e) {
5272 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
5276 }
5277
5278 @Override
5279 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5280 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005281
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005282 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005283 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5284 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5285 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005286 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005287 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5288 if (controller != null) {
5289 ImsManager imsManager = controller.getImsManager(subId);
5290 if (imsManager != null) {
5291 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5292 } else {
5293 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5294 + " is inactive, ignoring unregister.");
5295 // If the ImsManager is not valid, just return, since the callback will already
5296 // have been removed internally.
5297 }
5298 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
5302 }
5303
joonhunshincffb7fc2021-11-28 07:32:01 +00005304 @Override
5305 public void registerFeatureProvisioningChangedCallback(int subId,
5306 IFeatureProvisioningCallback callback) {
5307 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5308 mApp, subId, "registerFeatureProvisioningChangedCallback");
5309
5310 final long identity = Binder.clearCallingIdentity();
5311 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5312 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5313 }
5314
joonhunshin91bc1952022-04-29 08:47:15 +00005315 try {
5316 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5317 if (controller == null) {
5318 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5319 "Device does not support IMS");
5320 }
5321 controller.addFeatureProvisioningChangedCallback(subId, callback);
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005325 }
5326
5327 @Override
5328 public void unregisterFeatureProvisioningChangedCallback(int subId,
5329 IFeatureProvisioningCallback callback) {
5330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5331 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5332
5333 final long identity = Binder.clearCallingIdentity();
5334 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5335 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5336 }
5337
joonhunshin91bc1952022-04-29 08:47:15 +00005338 try {
5339 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5340 if (controller == null) {
5341 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5342 return;
5343 }
5344 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005348 }
allenwtsu99c623b2020-01-03 18:24:23 +08005349
5350 private void checkModifyPhoneStatePermission(int subId, String message) {
5351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5352 message);
5353 }
5354
allenwtsu99c623b2020-01-03 18:24:23 +08005355 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005356 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005357 boolean isProvisioned) {
5358 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5359
joonhunshin4ac60942023-11-15 15:23:39 +00005360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5361 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5362
allenwtsu99c623b2020-01-03 18:24:23 +08005363 final long identity = Binder.clearCallingIdentity();
5364 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005365 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5366 if (controller == null) {
5367 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5368 return;
5369 }
5370 controller.setRcsProvisioningStatusForCapability(
5371 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
allenwtsu99c623b2020-01-03 18:24:23 +08005375 }
5376
5377
5378 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005379 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5380 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5381 mApp, subId, "getRcsProvisioningStatusForCapability");
5382
joonhunshin4ac60942023-11-15 15:23:39 +00005383 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5384 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5385
allenwtsu99c623b2020-01-03 18:24:23 +08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005388 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5389 if (controller == null) {
5390 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5391
5392 // device does not support IMS, this method will return true always.
5393 return true;
5394 }
5395 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
5399 }
5400
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005401 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005402 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5403 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005404 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005405
joonhunshin4ac60942023-11-15 15:23:39 +00005406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5407 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5408
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005409 final long identity = Binder.clearCallingIdentity();
5410 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005411 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5412 if (controller == null) {
5413 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5414 return;
5415 }
5416 controller.setImsProvisioningStatusForCapability(
5417 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
5421 }
5422
5423 @Override
5424 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005425 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5426 mApp, subId, "getProvisioningStatusForCapability");
5427
joonhunshin4ac60942023-11-15 15:23:39 +00005428 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5429 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5430
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005431 final long identity = Binder.clearCallingIdentity();
5432 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005433 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5434 if (controller == null) {
5435 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005436
joonhunshin91bc1952022-04-29 08:47:15 +00005437 // device does not support IMS, this method will return true always.
5438 return true;
5439 }
5440 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
5444 }
5445
5446 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005447 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5448 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5449 mApp, subId, "isProvisioningRequiredForCapability");
5450
joonhunshin4ac60942023-11-15 15:23:39 +00005451 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5452 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5453
joonhunshincffb7fc2021-11-28 07:32:01 +00005454 final long identity = Binder.clearCallingIdentity();
5455 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005456 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5457 if (controller == null) {
5458 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5459
5460 // device does not support IMS, this method will return false
5461 return false;
5462 }
5463 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005464 } finally {
5465 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005466 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005467 }
5468
5469 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005470 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5471 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5472 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005473
joonhunshin4ac60942023-11-15 15:23:39 +00005474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5475 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5476
joonhunshincffb7fc2021-11-28 07:32:01 +00005477 final long identity = Binder.clearCallingIdentity();
5478 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005479 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5480 if (controller == null) {
5481 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5482
5483 // device does not support IMS, this method will return false
5484 return false;
5485 }
5486 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005490 }
5491
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005492 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005493 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005494 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5495 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5496 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005497 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5498 mApp, subId, "getImsProvisioningInt");
5499
joonhunshin4ac60942023-11-15 15:23:39 +00005500 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5501 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5502
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005503 final long identity = Binder.clearCallingIdentity();
5504 try {
5505 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005506 int slotId = getSlotIndex(subId);
5507 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5508 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5509 + subId + "' for key:" + key);
5510 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5511 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005512
joonhunshin91bc1952022-04-29 08:47:15 +00005513 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5514 if (controller == null) {
5515 loge("getImsProvisioningInt: Device does not support IMS");
5516
5517 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5518 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5519 }
5520 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005521 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5522 return retVal;
5523 }
5524
calvinpanb5a34062021-02-08 19:59:36 +08005525 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005526 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005527 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5528 + subId + "' for key:" + key);
5529 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
5533 }
5534
5535 @Override
5536 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005537 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5538 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5539 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005540 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5541 mApp, subId, "getImsProvisioningString");
5542
joonhunshin4ac60942023-11-15 15:23:39 +00005543 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5544 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5545
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005549 int slotId = getSlotIndex(subId);
5550 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5551 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5552 + subId + "' for key:" + key);
5553 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5554 }
calvinpanb5a34062021-02-08 19:59:36 +08005555 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005556 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005557 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5558 + subId + "' for key:" + key);
5559 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
5563 }
5564
5565 @Override
5566 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5568 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5569 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5571 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005572
joonhunshin4ac60942023-11-15 15:23:39 +00005573 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5574 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5575
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005576 final long identity = Binder.clearCallingIdentity();
5577 try {
5578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005579 int slotId = getSlotIndex(subId);
5580 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5581 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5582 + subId + "' for key:" + key);
5583 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5584 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005585
joonhunshin91bc1952022-04-29 08:47:15 +00005586 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5587 if (controller == null) {
5588 loge("setImsProvisioningInt: Device does not support IMS");
5589
5590 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5591 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5592 }
5593 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005594 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5595 return retVal;
5596 }
5597
calvinpanb5a34062021-02-08 19:59:36 +08005598 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5599 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005600 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005601 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005602 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005603 } finally {
5604 Binder.restoreCallingIdentity(identity);
5605 }
5606 }
5607
5608 @Override
5609 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5611 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5612 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5614 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005615
5616 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5617 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5618
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005622 int slotId = getSlotIndex(subId);
5623 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5624 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5625 + subId + "' for key:" + key);
5626 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5627 }
calvinpanb5a34062021-02-08 19:59:36 +08005628 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5629 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005630 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005631 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005632 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
5636 }
5637
Brad Ebinger919631e2021-06-02 17:46:35 -07005638 /**
5639 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5640 * for the given slot ID or no ImsResolver instance has been created.
5641 * @param slotId The slot ID that the IMS service is created for.
5642 * @throws ImsException If there is no ImsService configured for this slot.
5643 */
5644 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5645 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5646 ImsFeature.FEATURE_MMTEL)) {
5647 throw new ImsException("This subscription does not support MMTEL over IMS",
5648 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5649 }
5650 }
5651
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005652 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005653 int slotId = SubscriptionManager.getSlotIndex(subId);
5654 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005655 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5656 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005657 }
5658 return slotId;
5659 }
5660
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005661 private int getSlotIndex(int subId) {
5662 int slotId = SubscriptionManager.getSlotIndex(subId);
5663 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5664 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5665 }
5666 return slotId;
5667 }
5668
Wink Saville36469e72014-06-11 15:17:00 -07005669 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005670 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005671 */
5672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005673 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5674 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005675 try {
5676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5677 } catch (SecurityException se) {
5678 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5679 throw new SecurityException("Package " + callingPackage + " does not belong to "
5680 + Binder.getCallingUid());
5681 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005682 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005683 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005684 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005685 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005686 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005687 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005688 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005689 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5690 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005691
joonhunshin4ac60942023-11-15 15:23:39 +00005692 enforceTelephonyFeatureWithException(callingPackage,
5693 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 final Phone phone = getPhone(subId);
5698 if (phone != null) {
5699 return phone.getServiceState().getDataNetworkType();
5700 } else {
5701 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5702 }
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005706 }
5707
5708 /**
5709 * Returns the data network type
5710 */
5711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005712 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005713 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005714 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005715 }
5716
5717 /**
5718 * Returns the data network type for a subId
5719 */
5720 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005721 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5722 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005723 String functionName = "getDataNetworkTypeForSubscriber";
5724 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5725 mApp, functionName)) {
5726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5727 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5728 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5729 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005730 }
5731
joonhunshin4ac60942023-11-15 15:23:39 +00005732 enforceTelephonyFeatureWithException(callingPackage,
5733 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 final Phone phone = getPhone(subId);
5738 if (phone != null) {
5739 return phone.getServiceState().getDataNetworkType();
5740 } else {
5741 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5742 }
5743 } finally {
5744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005746 }
5747
5748 /**
Wink Saville36469e72014-06-11 15:17:00 -07005749 * Returns the Voice network type for a subId
5750 */
5751 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005752 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5753 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005754 String functionName = "getVoiceNetworkTypeForSubscriber";
5755 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5756 mApp, functionName)) {
5757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5758 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5759 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5760 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005761 }
5762
joonhunshin4ac60942023-11-15 15:23:39 +00005763 enforceTelephonyFeatureWithException(callingPackage,
5764 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
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 phone.getServiceState().getVoiceNetworkType();
5771 } else {
5772 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5773 }
5774 } finally {
5775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005777 }
5778
5779 /**
5780 * @return true if a ICC card is present
5781 */
5782 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005783 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005784 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005785 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005786 }
5787
5788 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005789 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005790 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005791 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005792 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5794 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 final Phone phone = PhoneFactory.getPhone(slotIndex);
5799 if (phone != null) {
5800 return phone.getIccCard().hasIccCard();
5801 } else {
5802 return false;
5803 }
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005807 }
5808
5809 /**
5810 * Return if the current radio is LTE on CDMA. This
5811 * is a tri-state return value as for a period of time
5812 * the mode may be unknown.
5813 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005814 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005815 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005816 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005817 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005819 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5820 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5821 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005822 }
5823
Sanket Padawe356d7632015-06-22 14:03:32 -07005824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005825 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5826 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005827 try {
5828 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5829 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005830 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5831 }
5832
joonhunshin4ac60942023-11-15 15:23:39 +00005833 enforceTelephonyFeatureWithException(callingPackage,
5834 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 final long identity = Binder.clearCallingIdentity();
5837 try {
5838 final Phone phone = getPhone(subId);
5839 if (phone == null) {
5840 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5841 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005842 return TelephonyProperties.lte_on_cdma_device()
5843 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 }
5845 } finally {
5846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005847 }
Wink Saville36469e72014-06-11 15:17:00 -07005848 }
5849
Wink Saville36469e72014-06-11 15:17:00 -07005850 /**
5851 * {@hide}
5852 * Returns Default subId, 0 in the case of single standby.
5853 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005854 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005855 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005856 }
5857
Shishir Agrawala9f32182016-04-12 12:00:16 -07005858 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005859 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005860 }
5861
Wink Savilleb564aae2014-10-23 10:18:09 -07005862 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005863 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005864 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005865
Pengquan Menge92a50d2018-09-21 15:54:48 -07005866 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005867 return getSubscriptionManagerService().isActiveSubId(subId,
5868 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005869 }
5870
Ihab Awadf2177b72013-11-25 13:33:23 -08005871 /**
5872 * @see android.telephony.TelephonyManager.WifiCallingChoices
5873 */
5874 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 final long identity = Binder.clearCallingIdentity();
5876 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005877 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5879 getWhenToMakeWifiCallsDefaultPreference());
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005883 }
5884
5885 /**
5886 * @see android.telephony.TelephonyManager.WifiCallingChoices
5887 */
5888 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889 final long identity = Binder.clearCallingIdentity();
5890 try {
5891 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005892 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005897 }
5898
Sailesh Nepald1e68152013-12-12 19:08:02 -08005899 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005900 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005901 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005902 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005903
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005904 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5905 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5906 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005907 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005908 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005909 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005910 }
5911 return PhoneFactory.getPhone(phoneId);
5912 }
5913
Shishir Agrawal566b7612013-10-28 14:41:00 -07005914 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005915 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005916 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005917
Rambo Wanga1782702021-11-10 20:15:19 -08005918 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5919 /*message=*/ "iccOpenLogicalChannel");
5920
5921 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5922 // Verify that the callingPackage in the request belongs to the calling UID
5923 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5924
joonhunshin4ac60942023-11-15 15:23:39 +00005925 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5926 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5927
Rambo Wanga1782702021-11-10 20:15:19 -08005928 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005929 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005930
Rambo Wanga1782702021-11-10 20:15:19 -08005931 private Phone getPhoneFromValidIccLogicalChannelRequest(
5932 @NonNull IccLogicalChannelRequest request, String message) {
5933 Phone phone;
5934 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5936 mApp, request.subId, message);
5937 phone = getPhoneFromSubId(request.subId);
5938 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5939 enforceModifyPermission();
5940 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5941 } else {
5942 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005943 }
Rambo Wanga1782702021-11-10 20:15:19 -08005944 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005945 }
5946
5947 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005948 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005951 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005953 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5954 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005955 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5956 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 loge("The calling package is not allowed to access ISD-R.");
5958 throw new SecurityException(
5959 "The calling package is not allowed to access ISD-R.");
5960 }
Derek Tan740e1672017-06-27 14:56:27 -07005961 }
Derek Tan740e1672017-06-27 14:56:27 -07005962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005964 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5965 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 return response;
5967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005970 }
5971
5972 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005973 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005974 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5975 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
5976
Rambo Wanga1782702021-11-10 20:15:19 -08005977 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5978 /*message=*/"iccCloseLogicalChannel");
5979
5980 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5981
5982 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005983 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005984
Rambo Wanga1782702021-11-10 20:15:19 -08005985 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5986 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005987 // before this feature is enabled, this API should only return false if
5988 // the operation fails instead of throwing runtime exception for
5989 // backward-compatibility.
5990 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5991 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 final long identity = Binder.clearCallingIdentity();
5993 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005994 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005995 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 }
Chen Xue9d737e2022-01-01 23:41:31 -08005997 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005998 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005999 Boolean success = false;
6000 if (result instanceof RuntimeException) {
6001 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006002 if (shouldThrowExceptionOnFailure) {
6003 throw (RuntimeException) result;
6004 } else {
6005 return false;
6006 }
Chen Xue9d737e2022-01-01 23:41:31 -08006007 } else if (result instanceof Boolean) {
6008 success = (Boolean) result;
6009 } else {
6010 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6011 }
Rambo Wanga1782702021-11-10 20:15:19 -08006012 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 return success;
6014 } finally {
6015 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006016 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006017 }
6018
6019 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006020 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006021 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6023 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006024
6025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6026 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6027
Jordan Liu4c733742019-02-28 12:03:40 -08006028 if (DBG) {
6029 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6030 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6031 + p3 + " data=" + data);
6032 }
6033 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6034 command, p1, p2, p3, data);
6035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006036
Jordan Liu4c733742019-02-28 12:03:40 -08006037 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006038 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006039 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006040 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006041
6042 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6043 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6044 "iccTransmitApduLogicalChannelBySlot");
6045
Jordan Liu4c733742019-02-28 12:03:40 -08006046 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006047 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006048 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6049 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006050 }
6051 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006052 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6053 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006054 }
6055
6056 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6057 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 final long identity = Binder.clearCallingIdentity();
6059 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006060 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 return "";
6062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006065 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6066 null /* workSource */);
6067 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 // Append the returned status code to the end of the response payload.
6070 String s = Integer.toHexString(
6071 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6072 if (response.payload != null) {
6073 s = IccUtils.bytesToHexString(response.payload) + s;
6074 }
6075 return s;
6076 } finally {
6077 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006078 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006079 }
Jake Hambye994d462014-02-03 13:10:13 -08006080
Evan Charltonc66da362014-05-16 14:06:40 -07006081 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006082 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6083 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6085 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006087
6088 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6089 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6090
Jordan Liu4c733742019-02-28 12:03:40 -08006091 if (DBG) {
6092 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6093 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6094 }
6095 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6096 cla, command, p1, p2, p3, data);
6097 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006098
Jordan Liu4c733742019-02-28 12:03:40 -08006099 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006100 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006101 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006102 enforceModifyPermission();
6103 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006104
6105 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6106 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6107
Jordan Liu4c733742019-02-28 12:03:40 -08006108 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006109 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006110 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6111 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006112 }
6113
6114 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006115 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6116 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006117 }
6118
6119 // open APDU basic channel assuming the caller has sufficient permissions
6120 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6121 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 final long identity = Binder.clearCallingIdentity();
6123 try {
6124 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6125 && TextUtils.equals(ISDR_AID, data)) {
6126 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006127 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6128 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 if (bestComponent == null
6130 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6131 loge("The calling package is not allowed to select ISD-R.");
6132 throw new SecurityException(
6133 "The calling package is not allowed to select ISD-R.");
6134 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006135 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006138 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6139 null /* workSource */);
6140 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 // Append the returned status code to the end of the response payload.
6143 String s = Integer.toHexString(
6144 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6145 if (response.payload != null) {
6146 s = IccUtils.bytesToHexString(response.payload) + s;
6147 }
6148 return s;
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006151 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006152 }
6153
6154 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006155 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006156 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6158 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006159
joonhunshin4ac60942023-11-15 15:23:39 +00006160 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6161 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 if (DBG) {
6166 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6167 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6168 }
6169
6170 IccIoResult response =
6171 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6172 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6173 subId);
6174
6175 if (DBG) {
6176 log("Exchange SIM_IO [R]" + response);
6177 }
6178
6179 byte[] result = null;
6180 int length = 2;
6181 if (response.payload != null) {
6182 length = 2 + response.payload.length;
6183 result = new byte[length];
6184 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6185 } else {
6186 result = new byte[length];
6187 }
6188
6189 result[length - 1] = (byte) response.sw2;
6190 result[length - 2] = (byte) response.sw1;
6191 return result;
6192 } finally {
6193 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006194 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006195 }
6196
Nathan Haroldb3014052017-01-25 15:57:32 -08006197 /**
6198 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6199 * on a particular subscription
6200 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006201 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6202 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006204 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006205 return null;
6206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207
joonhunshin4ac60942023-11-15 15:23:39 +00006208 enforceTelephonyFeatureWithException(callingPackage,
6209 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 final long identity = Binder.clearCallingIdentity();
6212 try {
6213 if (appType != TelephonyManager.APPTYPE_USIM
6214 && appType != TelephonyManager.APPTYPE_SIM) {
6215 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6216 return null;
6217 }
6218 Object response = sendRequest(
6219 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6220 if (response instanceof String[]) {
6221 return (String[]) response;
6222 }
yincheng zhao2737e882019-09-06 17:06:54 -07006223 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006225 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 } finally {
6227 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006228 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006229 }
6230
yincheng zhao2737e882019-09-06 17:06:54 -07006231 /**
6232 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6233 * subscription.
6234 *
6235 * @param subId the id of the subscription.
6236 * @param appType the uicc app type, must be USIM or SIM.
6237 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6238 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006239 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006240 * @return number of fplmns that is successfully written to the SIM.
6241 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006242 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6243 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6245 mApp, subId, "setForbiddenPlmns");
6246
joonhunshin4ac60942023-11-15 15:23:39 +00006247 enforceTelephonyFeatureWithException(callingPackage,
6248 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6249
yincheng zhao2737e882019-09-06 17:06:54 -07006250 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6251 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6252 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6253 }
6254 if (fplmns == null) {
6255 throw new IllegalArgumentException("Fplmn List provided is null");
6256 }
6257 for (String fplmn : fplmns) {
6258 if (!CellIdentity.isValidPlmn(fplmn)) {
6259 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6260 }
6261 }
6262 final long identity = Binder.clearCallingIdentity();
6263 try {
6264 Object response = sendRequest(
6265 CMD_SET_FORBIDDEN_PLMNS,
6266 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6267 subId);
6268 return (int) response;
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
6272 }
6273
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006274 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006275 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6277 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006278
joonhunshin4ac60942023-11-15 15:23:39 +00006279 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6280 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 final long identity = Binder.clearCallingIdentity();
6283 try {
6284 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6285 if (response.payload == null) {
6286 return "";
6287 }
Evan Charltonc66da362014-05-16 14:06:40 -07006288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 // Append the returned status code to the end of the response payload.
6290 String s = Integer.toHexString(
6291 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6292 s = IccUtils.bytesToHexString(response.payload) + s;
6293 return s;
6294 } finally {
6295 Binder.restoreCallingIdentity(identity);
6296 }
Evan Charltonc66da362014-05-16 14:06:40 -07006297 }
6298
Jake Hambye994d462014-02-03 13:10:13 -08006299 /**
6300 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6301 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6302 *
6303 * @param itemID the ID of the item to read
6304 * @return the NV item as a String, or null on error.
6305 */
6306 @Override
6307 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6310 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311
6312 final long identity = Binder.clearCallingIdentity();
6313 try {
6314 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006315 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6317 return value;
6318 } finally {
6319 Binder.restoreCallingIdentity(identity);
6320 }
Jake Hambye994d462014-02-03 13:10:13 -08006321 }
6322
6323 /**
6324 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6325 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6326 *
6327 * @param itemID the ID of the item to read
6328 * @param itemValue the value to write, as a String
6329 * @return true on success; false on any failure
6330 */
6331 @Override
6332 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6335 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336
6337 final long identity = Binder.clearCallingIdentity();
6338 try {
6339 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6340 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006341 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6343 return success;
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
6346 }
Jake Hambye994d462014-02-03 13:10:13 -08006347 }
6348
6349 /**
6350 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6351 * Used for device configuration by some CDMA operators.
6352 *
6353 * @param preferredRoamingList byte array containing the new PRL
6354 * @return true on success; false on any failure
6355 */
6356 @Override
6357 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6359 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360
6361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6364 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6365 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6366 return success;
6367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
Jake Hambye994d462014-02-03 13:10:13 -08006370 }
6371
6372 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006373 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006374 * Used for device configuration by some CDMA operators.
6375 *
chen xu6dac5ab2018-10-26 17:39:23 -07006376 * @param slotIndex - device slot.
6377 *
Jake Hambye994d462014-02-03 13:10:13 -08006378 * @return true on success; false on any failure
6379 */
6380 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006381 public boolean resetModemConfig(int slotIndex) {
6382 Phone phone = PhoneFactory.getPhone(slotIndex);
6383 if (phone != null) {
6384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6385 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386
joonhunshin4ac60942023-11-15 15:23:39 +00006387 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6388 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6389
chen xu6dac5ab2018-10-26 17:39:23 -07006390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6393 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6394 return success;
6395 } finally {
6396 Binder.restoreCallingIdentity(identity);
6397 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398 }
chen xu6dac5ab2018-10-26 17:39:23 -07006399 return false;
6400 }
6401
6402 /**
6403 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6404 *
6405 * @param slotIndex - device slot.
6406 *
6407 * @return true on success; false on any failure
6408 */
6409 @Override
6410 public boolean rebootModem(int slotIndex) {
6411 Phone phone = PhoneFactory.getPhone(slotIndex);
6412 if (phone != null) {
6413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6414 mApp, phone.getSubId(), "rebootModem");
6415
joonhunshin4ac60942023-11-15 15:23:39 +00006416 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6417 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6418
chen xu6dac5ab2018-10-26 17:39:23 -07006419 final long identity = Binder.clearCallingIdentity();
6420 try {
6421 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6422 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6423 return success;
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
6427 }
6428 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006429 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006430
Brad Ebinger51f743a2017-01-23 13:50:20 -08006431 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006432 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6433 * {@link #disableIms(int)}.
6434 * @param slotIndex device slot.
6435 */
6436 public void resetIms(int slotIndex) {
6437 enforceModifyPermission();
6438
joonhunshin4ac60942023-11-15 15:23:39 +00006439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6440 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6441
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 if (mImsResolver == null) {
6445 // may happen if the does not support IMS.
6446 return;
6447 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006448 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
6452 }
6453
6454 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006455 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6456 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006457 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006458 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006459 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460
6461 final long identity = Binder.clearCallingIdentity();
6462 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006463 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006464 // may happen if the device does not support IMS.
6465 return;
6466 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006467 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006471 }
6472
6473 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006474 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6475 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006476 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006477 public void disableIms(int slotId) {
6478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006482 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006483 // may happen if the device does not support IMS.
6484 return;
6485 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006486 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006490 }
6491
6492 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006493 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6494 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006495 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006496 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006497 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006498 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499
6500 final long identity = Binder.clearCallingIdentity();
6501 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006502 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006503 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6504 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006505 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006506 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507 } finally {
6508 Binder.restoreCallingIdentity(identity);
6509 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006510 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006511 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006512 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6513 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006514 @Override
6515 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006516 enforceModifyPermission();
6517
6518 final long identity = Binder.clearCallingIdentity();
6519 try {
6520 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006521 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
6525 }
6526
6527 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006528 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006529 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006530 */
6531 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6532 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533
6534 final long identity = Binder.clearCallingIdentity();
6535 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006536 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006537 // may happen if the device does not support IMS.
6538 return null;
6539 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006540 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006544 }
6545
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006546 /**
6547 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006548 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006549 */
6550 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552
6553 final long identity = Binder.clearCallingIdentity();
6554 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006555 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 // may happen if the device does not support IMS.
6557 return null;
6558 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006559 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006563 }
6564
Brad Ebinger884c07b2018-02-15 16:17:40 -08006565 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006566 * Sets the ImsService Package Name that Telephony will bind to.
6567 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006568 * @param slotIndex the slot ID that the ImsService should bind for.
6569 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006570 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006571 * @param featureTypes An integer array of feature types associated with a packageName.
6572 * @param packageName The name of the package that the current configuration will be replaced
6573 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006574 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006575 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006576 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6577 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006578 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006580 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 final long identity = Binder.clearCallingIdentity();
6583 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006584 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006585 // may happen if the device does not support IMS.
6586 return false;
6587 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006588 Map<Integer, String> featureConfig = new HashMap<>();
6589 for (int featureType : featureTypes) {
6590 featureConfig.put(featureType, packageName);
6591 }
6592 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6593 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006597 }
6598
6599 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006600 * Clears any carrier ImsService overrides for the slot index specified that were previously
6601 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6602 *
6603 * This should only be used for testing.
6604 *
6605 * @param slotIndex the slot ID that the ImsService should bind for.
6606 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6607 */
6608 @Override
6609 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006610 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6611 "clearCarrierImsServiceOverride");
6612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006613 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006614
6615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 if (mImsResolver == null) {
6618 // may happen if the device does not support IMS.
6619 return false;
6620 }
6621 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6622 } finally {
6623 Binder.restoreCallingIdentity(identity);
6624 }
6625 }
6626
6627 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006628 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006629 *
6630 * @param slotId The slot that the ImsService is associated with.
6631 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6632 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006633 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006634 * @return the package name of the ImsService configuration.
6635 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006636 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6637 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006638 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006639 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6640 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642 final long identity = Binder.clearCallingIdentity();
6643 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006644 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006645 // may happen if the device does not support IMS.
6646 return "";
6647 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006648 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006649 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6650 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006654 }
6655
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006656 /**
6657 * Get the MmTelFeature state associated with the requested subscription id.
6658 * @param subId The subscription that the MmTelFeature is associated with.
6659 * @param callback A callback with an integer containing the
6660 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6661 */
6662 @Override
6663 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6664 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006665 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6667 "IMS not available on device.");
6668 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006669 final long token = Binder.clearCallingIdentity();
6670 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006671 int slotId = getSlotIndex(subId);
6672 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6673 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6674 + subId + "'");
6675 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6676 }
6677 verifyImsMmTelConfiguredOrThrow(slotId);
6678 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6679 try {
6680 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6681 } catch (RemoteException e) {
6682 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6683 + "Ignore");
6684 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006685 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006686 } catch (ImsException e) {
6687 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006688 } finally {
6689 Binder.restoreCallingIdentity(token);
6690 }
6691 }
6692
Daniel Brightbb5840b2021-01-12 15:48:18 -08006693 /**
6694 * Sets the ims registration state on all valid {@link Phone}s.
6695 */
6696 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006697 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698
6699 final long identity = Binder.clearCallingIdentity();
6700 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006701 // NOTE: Before S, this method only set the default phone.
6702 for (final Phone phone : PhoneFactory.getPhones()) {
6703 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6704 phone.setImsRegistrationState(registered);
6705 }
6706 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 } finally {
6708 Binder.restoreCallingIdentity(identity);
6709 }
Wink Saville36469e72014-06-11 15:17:00 -07006710 }
6711
6712 /**
Stuart Scott54788802015-03-30 13:18:01 -07006713 * Set the network selection mode to automatic.
6714 *
6715 */
6716 @Override
6717 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6719 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720
joonhunshin4ac60942023-11-15 15:23:39 +00006721 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6722 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 final long identity = Binder.clearCallingIdentity();
6725 try {
shilufc958392020-01-20 11:36:01 -08006726 if (!isActiveSubscription(subId)) {
6727 return;
6728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006730 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6731 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
Stuart Scott54788802015-03-30 13:18:01 -07006735 }
6736
Jack Yud10cdd42020-09-28 20:28:01 -07006737 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006738 * Ask the radio to connect to the input network and change selection mode to manual.
6739 *
6740 * @param subId the id of the subscription.
6741 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6742 * the operator to attach to.
6743 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6744 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6745 * normal network selection next time.
6746 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006747 */
6748 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006749 public boolean setNetworkSelectionModeManual(
6750 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6752 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006753
joonhunshin4ac60942023-11-15 15:23:39 +00006754 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6755 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6756
Jack Yu285100e2022-12-02 22:48:35 -08006757 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006758 if (!isActiveSubscription(subId)) {
6759 return false;
6760 }
6761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006763 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006765 if (DBG) {
6766 log("setNetworkSelectionModeManual: subId: " + subId
6767 + " operator: " + operatorInfo);
6768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6770 } finally {
6771 Binder.restoreCallingIdentity(identity);
6772 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006773 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006774 /**
shilu84f6e8b2019-12-19 13:58:01 -08006775 * Get the manual network selection
6776 *
6777 * @param subId the id of the subscription.
6778 *
6779 * @return the previously saved user selected PLMN
6780 */
6781 @Override
6782 public String getManualNetworkSelectionPlmn(int subId) {
6783 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006784 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6785 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006786
joonhunshin4ac60942023-11-15 15:23:39 +00006787 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6788 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6789
shilu84f6e8b2019-12-19 13:58:01 -08006790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006793 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006794 }
6795
6796 final Phone phone = getPhone(subId);
6797 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006798 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006799 }
6800 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6801 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006802 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
6806 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006807
6808 /**
6809 * Scans for available networks.
6810 */
6811 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006812 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6813 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6815 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006816 LocationAccessPolicy.LocationPermissionResult locationResult =
6817 LocationAccessPolicy.checkLocationPermission(mApp,
6818 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6819 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006820 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006821 .setCallingPid(Binder.getCallingPid())
6822 .setCallingUid(Binder.getCallingUid())
6823 .setMethod("getCellNetworkScanResults")
6824 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006825 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6826 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006827 .build());
6828 switch (locationResult) {
6829 case DENIED_HARD:
6830 throw new SecurityException("Not allowed to access scan results -- location");
6831 case DENIED_SOFT:
6832 return null;
6833 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834
Pengquan Menga1bb6272018-09-06 09:59:22 -07006835 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 try {
6837 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006838 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006843 }
6844
6845 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006846 * Get the call forwarding info, given the call forwarding reason.
6847 */
6848 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006849 public void getCallForwarding(int subId, int callForwardingReason,
6850 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006851 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006852
6853 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6854 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6855
Shuo Qian4a594052020-01-23 11:59:30 -08006856 long identity = Binder.clearCallingIdentity();
6857 try {
6858 if (DBG) {
6859 log("getCallForwarding: subId " + subId
6860 + " callForwardingReason" + callForwardingReason);
6861 }
Hall Liu27d24262020-09-18 19:04:59 -07006862
6863 Phone phone = getPhone(subId);
6864 if (phone == null) {
6865 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006866 callback.onError(
6867 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006868 } catch (RemoteException e) {
6869 // ignore
6870 }
6871 return;
6872 }
6873
6874 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6875 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6876 @Override
6877 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6878 try {
6879 callback.onCallForwardingInfoAvailable(info);
6880 } catch (RemoteException e) {
6881 // ignore
6882 }
6883 }
6884
6885 @Override
6886 public void onError(int error) {
6887 try {
6888 callback.onError(error);
6889 } catch (RemoteException e) {
6890 // ignore
6891 }
6892 }
6893 });
6894 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
6899
6900 /**
6901 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6902 * reason, the number to forward, and the timeout before the forwarding is attempted.
6903 */
6904 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006905 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6906 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006907 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006908
6909 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6910 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6911
Shuo Qian4a594052020-01-23 11:59:30 -08006912 long identity = Binder.clearCallingIdentity();
6913 try {
6914 if (DBG) {
6915 log("setCallForwarding: subId " + subId
6916 + " callForwardingInfo" + callForwardingInfo);
6917 }
Hall Liu27d24262020-09-18 19:04:59 -07006918
6919 Phone phone = getPhone(subId);
6920 if (phone == null) {
6921 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006922 callback.accept(
6923 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006924 } catch (RemoteException e) {
6925 // ignore
6926 }
6927 return;
6928 }
6929
6930 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6931 FunctionalUtils.ignoreRemoteException(callback::accept));
6932
6933 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006934 } finally {
6935 Binder.restoreCallingIdentity(identity);
6936 }
6937 }
6938
6939 /**
Hall Liu27d24262020-09-18 19:04:59 -07006940 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006941 */
6942 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006943 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006944 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006945
6946 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6947 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6948
Shuo Qian4a594052020-01-23 11:59:30 -08006949 long identity = Binder.clearCallingIdentity();
6950 try {
Hall Liu27d24262020-09-18 19:04:59 -07006951 Phone phone = getPhone(subId);
6952 if (phone == null) {
6953 try {
6954 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6955 } catch (RemoteException e) {
6956 // ignore
6957 }
6958 return;
6959 }
SongFerngWang0e767992021-03-31 22:08:45 +08006960 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6961 PersistableBundle c = configManager.getConfigForSubId(subId);
6962 boolean requireUssd = c.getBoolean(
6963 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006964
Shuo Qian4a594052020-01-23 11:59:30 -08006965 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006966 if (requireUssd) {
6967 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6968 getSubscriptionCarrierId(subId));
6969 String newUssdCommand = "";
6970 try {
6971 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006972 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006973 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6974 } catch (NullPointerException e) {
6975 loge("Failed to generate USSD number" + e);
6976 }
6977 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6978 mMainThreadHandler, callback, carrierXmlParser,
6979 CarrierXmlParser.SsEntry.SSAction.QUERY);
6980 final String ussdCommand = newUssdCommand;
6981 Executors.newSingleThreadExecutor().execute(() -> {
6982 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6983 });
6984 } else {
6985 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6986 callback::accept);
6987 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6988 }
Shuo Qian4a594052020-01-23 11:59:30 -08006989 } finally {
6990 Binder.restoreCallingIdentity(identity);
6991 }
6992 }
6993
6994 /**
Hall Liu27d24262020-09-18 19:04:59 -07006995 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006996 */
6997 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006998 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006999 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007000
7001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7002 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7003
Shuo Qian4a594052020-01-23 11:59:30 -08007004 long identity = Binder.clearCallingIdentity();
7005 try {
Hall Liu27d24262020-09-18 19:04:59 -07007006 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7007
7008 Phone phone = getPhone(subId);
7009 if (phone == null) {
7010 try {
7011 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7012 } catch (RemoteException e) {
7013 // ignore
7014 }
7015 return;
7016 }
7017
SongFerngWang0e767992021-03-31 22:08:45 +08007018 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7019 PersistableBundle c = configManager.getConfigForSubId(subId);
7020 boolean requireUssd = c.getBoolean(
7021 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007022
SongFerngWang0e767992021-03-31 22:08:45 +08007023 if (DBG) log("getCallWaitingStatus: subId " + subId);
7024 if (requireUssd) {
7025 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7026 getSubscriptionCarrierId(subId));
7027 CarrierXmlParser.SsEntry.SSAction ssAction =
7028 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7029 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7030 String newUssdCommand = "";
7031 try {
7032 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007033 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007034 .makeCommand(ssAction, null);
7035 } catch (NullPointerException e) {
7036 loge("Failed to generate USSD number" + e);
7037 }
7038 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7039 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7040 final String ussdCommand = newUssdCommand;
7041 Executors.newSingleThreadExecutor().execute(() -> {
7042 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7043 });
7044 } else {
7045 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7046 FunctionalUtils.ignoreRemoteException(callback::accept));
7047
7048 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7049 }
Shuo Qian4a594052020-01-23 11:59:30 -08007050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
7053 }
7054
7055 /**
yinxub1bed742017-04-17 11:45:04 -07007056 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007057 *
yinxub1bed742017-04-17 11:45:04 -07007058 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007059 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7060 * location related information which will be sent if the caller already possess
7061 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007062 * @param request contains the radio access networks with bands/channels to scan
7063 * @param messenger callback messenger for scan results or errors
7064 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007065 * @return the id of the requested scan which can be used to stop the scan.
7066 */
7067 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007068 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7069 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007070 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7072 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007073 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007074 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7075 if (!renounceFineLocationAccess) {
7076 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007077 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7078 .setCallingPackage(callingPackage)
7079 .setCallingFeatureId(callingFeatureId)
7080 .setCallingPid(Binder.getCallingPid())
7081 .setCallingUid(Binder.getCallingUid())
7082 .setMethod("requestNetworkScan")
7083 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7084 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7085 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7086 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007087 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007088 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007089 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7090 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007091 if (e != null) {
7092 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7093 throw e;
7094 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007095 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007096 return TelephonyScanManager.INVALID_SCAN_ID;
7097 }
7098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 }
joonhunshin4ac60942023-11-15 15:23:39 +00007100
7101 enforceTelephonyFeatureWithException(callingPackage,
7102 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7103
Hall Liu912dfd32019-04-25 14:02:26 -07007104 int callingUid = Binder.getCallingUid();
7105 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007109 renounceFineLocationAccess, request, messenger, binder,
7110 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007111 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114 }
yinxu504e1392017-04-12 16:03:22 -07007115 }
7116
Hall Liub2ac8ef2019-02-28 15:56:23 -08007117 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007118 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007119 boolean hasCarrierPriv;
7120 final long identity = Binder.clearCallingIdentity();
7121 try {
7122 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7123 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
Hall Liu558027f2019-05-15 19:14:05 -07007127 boolean hasNetworkScanPermission =
7128 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007129 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007130
7131 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7132 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7133 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007134 }
7135
7136 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7137 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007138 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7139 return new SecurityException("Specific channels must not be"
7140 + " scanned without location access.");
7141 }
7142 }
7143 }
7144
Hall Liub2ac8ef2019-02-28 15:56:23 -08007145 return null;
7146 }
7147
yinxu504e1392017-04-12 16:03:22 -07007148 /**
7149 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007150 *
7151 * @param subId id of the subscription
7152 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007153 */
7154 @Override
7155 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7157 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158
Hall Liu912dfd32019-04-25 14:02:26 -07007159 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 final long identity = Binder.clearCallingIdentity();
7161 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007162 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
yinxu504e1392017-04-12 16:03:22 -07007166 }
7167
7168 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007169 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007170 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007171 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007172 */
7173 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007174 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007175 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007176 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007177 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178
joonhunshin4ac60942023-11-15 15:23:39 +00007179 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7180 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 final long identity = Binder.clearCallingIdentity();
7183 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007184 if (DBG) log("getAllowedNetworkTypesBitmask");
7185 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7186 int networkTypesBitmask = (result != null ? result[0] : -1);
7187 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7188 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 } finally {
7190 Binder.restoreCallingIdentity(identity);
7191 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007192 }
7193
7194 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007195 * Get the allowed network types for certain reason.
7196 *
7197 * @param subId the id of the subscription.
7198 * @param reason the reason the allowed network type change is taking place
7199 * @return the allowed network types.
7200 */
7201 @Override
7202 public long getAllowedNetworkTypesForReason(int subId,
7203 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007204 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007205 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007206
7207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7208 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7209
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007210 final long identity = Binder.clearCallingIdentity();
7211 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007212 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007213 } finally {
7214 Binder.restoreCallingIdentity(identity);
7215 }
7216 }
7217
7218 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007219 * Enable/Disable E-UTRA-NR Dual Connectivity
7220 * @param subId subscription id of the sim card
7221 * @param nrDualConnectivityState expected NR dual connectivity state
7222 * This can be passed following states
7223 * <ol>
7224 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7225 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7226 * <li>Disable NR dual connectivity and force secondary cell to be released
7227 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7228 * </ol>
7229 * @return operation result.
7230 */
7231 @Override
7232 public int setNrDualConnectivityState(int subId,
7233 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7235 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007236 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007237 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7238 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7239 }
7240
Sooraj Sasindran37444802020-08-11 10:40:43 -07007241 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7242 final long identity = Binder.clearCallingIdentity();
7243 try {
7244 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7245 nrDualConnectivityState, subId,
7246 workSource);
7247 if (DBG) log("enableNRDualConnectivity result: " + result);
7248 return result;
7249 } finally {
7250 Binder.restoreCallingIdentity(identity);
7251 }
7252 }
7253
7254 /**
7255 * Is E-UTRA-NR Dual Connectivity enabled
7256 * @return true if dual connectivity is enabled else false
7257 */
7258 @Override
7259 public boolean isNrDualConnectivityEnabled(int subId) {
7260 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007261 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007262 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007263 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007264 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7265 return false;
7266 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007267 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7271 null, subId, workSource);
7272 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7273 return isEnabled;
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
7276 }
7277 }
7278
7279 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007280 * Set the allowed network types of the device and
7281 * provide the reason triggering the allowed network change.
7282 *
7283 * @param subId the id of the subscription.
7284 * @param reason the reason the allowed network type change is taking place
7285 * @param allowedNetworkTypes the allowed network types.
7286 * @return true on success; false on any failure.
7287 */
7288 @Override
7289 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007290 @TelephonyManager.AllowedNetworkTypesReason int reason,
7291 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7293 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007294 // If the caller only has carrier privileges, then they should not be able to override
7295 // any network types which were set for security reasons.
7296 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7297 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007298 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007299 throw new SecurityException(
7300 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007301 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007302 }
joonhunshin4ac60942023-11-15 15:23:39 +00007303
7304 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7305 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7306
SongFerngWang3ef3e072020-12-21 16:41:52 +08007307 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007308 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007309 return false;
7310 }
7311 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7312 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007313 return false;
7314 }
7315
Jack Yu5b494332023-01-23 18:18:04 +00007316 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7317 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007318
Jack Yue37dd262022-12-16 11:53:37 -08007319 Phone phone = getPhone(subId);
7320 if (phone == null) {
7321 return false;
7322 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007323
Jack Yue37dd262022-12-16 11:53:37 -08007324 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007325 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007326 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007327 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007328
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007329 final long identity = Binder.clearCallingIdentity();
7330 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007331 Boolean success = (Boolean) sendRequest(
7332 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7333 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7334
7335 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7336 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
7340 }
7341
7342 /**
Miaoa84611c2019-03-15 09:21:10 +08007343 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007344 *
Miaoa84611c2019-03-15 09:21:10 +08007345 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007346 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007347 * @hide
7348 */
7349 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007350 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007351 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007352
7353 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7354 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007357 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 try {
Miaoa84611c2019-03-15 09:21:10 +08007359 if (phone != null) {
7360 return phone.hasMatchedTetherApnSetting();
7361 } else {
7362 return false;
7363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364 } finally {
7365 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007366 }
Junda Liu475951f2014-11-07 16:45:03 -08007367 }
7368
7369 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007370 * Get the user enabled state of Mobile Data.
7371 *
7372 * TODO: remove and use isUserDataEnabled.
7373 * This can't be removed now because some vendor codes
7374 * calls through ITelephony directly while they should
7375 * use TelephonyManager.
7376 *
7377 * @return true on enabled
7378 */
7379 @Override
7380 public boolean getDataEnabled(int subId) {
7381 return isUserDataEnabled(subId);
7382 }
7383
7384 /**
7385 * Get whether mobile data is enabled per user setting.
7386 *
7387 * There are other factors deciding whether mobile data is actually enabled, but they are
7388 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007389 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007390 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7391 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007392 *
7393 * @return {@code true} if data is enabled else {@code false}
7394 */
7395 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007396 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007397 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007398 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007399 try {
7400 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7401 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007402 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007403 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7404 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007405 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007407 mApp, subId, functionName);
7408
Robert Greenwalt646120a2014-05-23 11:54:03 -07007409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410
7411 final long identity = Binder.clearCallingIdentity();
7412 try {
Jack Yu285100e2022-12-02 22:48:35 -08007413 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7415 Phone phone = PhoneFactory.getPhone(phoneId);
7416 if (phone != null) {
7417 boolean retVal = phone.isUserDataEnabled();
7418 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7419 return retVal;
7420 } else {
7421 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7422 return false;
7423 }
7424 } finally {
7425 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007426 }
7427 }
7428
7429 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007430 * Checks if the device is capable of mobile data by considering whether whether the
7431 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7432 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007433 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007434 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007435 */
7436 @Override
7437 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007438 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007439 try {
7440 try {
7441 mApp.enforceCallingOrSelfPermission(
7442 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007443 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007444 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007445 try {
7446 mApp.enforceCallingOrSelfPermission(
7447 android.Manifest.permission.READ_PHONE_STATE,
7448 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007449 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007450 mApp.enforceCallingOrSelfPermission(
7451 permission.READ_BASIC_PHONE_STATE, functionName);
7452 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007453 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007454 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007455 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457
joonhunshin4ac60942023-11-15 15:23:39 +00007458 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7459 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 final long identity = Binder.clearCallingIdentity();
7462 try {
Jack Yu285100e2022-12-02 22:48:35 -08007463 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 Phone phone = PhoneFactory.getPhone(phoneId);
7465 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007466 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007467 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 return retVal;
7469 } else {
7470 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7471 return false;
7472 }
7473 } finally {
7474 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007475 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007476 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007477
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007478 /**
7479 * Check if data is enabled for a specific reason
7480 * @param subId Subscription index
7481 * @param reason the reason the data enable change is taking place
7482 * @return {@code true} if the overall data is enabled; {@code false} if not.
7483 */
7484 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007485 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007486 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007487 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007488 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007489 try {
7490 mApp.enforceCallingOrSelfPermission(
7491 android.Manifest.permission.ACCESS_NETWORK_STATE,
7492 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007493 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007494 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7495 functionName);
7496 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007497 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007498 try {
7499 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007500 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007501 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007503 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007504 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007505 }
7506
joonhunshin4ac60942023-11-15 15:23:39 +00007507 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7508 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007509
7510 final long identity = Binder.clearCallingIdentity();
7511 try {
Jack Yu285100e2022-12-02 22:48:35 -08007512 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007513 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007514 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007515 + " reason=" + reason);
7516 }
7517 Phone phone = PhoneFactory.getPhone(phoneId);
7518 if (phone != null) {
7519 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007520 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007521 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007522 return retVal;
7523 } else {
7524 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007525 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007526 + subId + " retVal=false");
7527 }
7528 return false;
7529 }
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
7533 }
7534
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007535 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007536 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007537 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7538 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7539
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007540 // No permission needed; this only lets the caller inspect their own status.
7541 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007542 }
Junda Liu29340342014-07-10 15:23:27 -07007543
7544 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007545 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007546 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007547
7548 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7549 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7550
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007551 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7552 }
7553
7554 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7555 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007556 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007557 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007558 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7559 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007560 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7561 if (cpt == null) {
7562 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007563 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7564 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007565 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007566 }
7567
7568 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007569 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007570 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007571
7572 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7573 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7574
chen xuf7e9fe82019-05-09 19:31:02 -07007575 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007576 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007577 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007578 Phone phone = getPhone(subId);
7579 if (phone == null) {
7580 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7581 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7582 }
7583 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7584 if (cpt == null) {
7585 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007586 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7587 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007588 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007589 }
7590
7591 @Override
7592 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007593 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007594
7595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7596 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7597 "checkCarrierPrivilegesForPackageAnyPhone");
7598
Rambo Wange7209ce2022-02-23 13:41:02 -08007599 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7600 }
7601
7602 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007603 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007604 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007605 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007606 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007607 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7608 Phone phone = PhoneFactory.getPhone(phoneId);
7609 if (phone == null) {
7610 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007611 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007612 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7613 if (cpt == null) {
7614 continue;
7615 }
7616 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007617 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7618 break;
7619 }
7620 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007621 return result;
Junda Liu29340342014-07-10 15:23:27 -07007622 }
Derek Tan89e89d42014-07-08 17:00:10 -07007623
7624 @Override
Junda Liue64de782015-04-16 17:19:16 -07007625 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007626 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007627
7628 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7629 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7630 "getCarrierPackageNamesForIntentAndPhone");
7631
Rambo Wang8a247eb2022-02-08 21:11:18 +00007632 Phone phone = PhoneFactory.getPhone(phoneId);
7633 if (phone == null) {
7634 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007635 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007636 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7637 if (cpt == null) {
7638 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007639 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007640 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007641 }
7642
Amith Yamasani6e118872016-02-19 12:53:51 -08007643 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007644 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007645 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007646 Phone phone = PhoneFactory.getPhone(phoneId);
7647 if (phone == null) {
7648 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007649 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007650 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7651 if (cpt == null) {
7652 return Collections.emptyList();
7653 }
7654 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007655 }
7656
chen xuf7e9fe82019-05-09 19:31:02 -07007657 @Override
7658 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007659 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007660
7661 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7662 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7663 "getPackagesWithCarrierPrivilegesForAllPhones");
7664
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007665 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007666 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007667 try {
7668 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7669 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7670 }
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007673 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007674 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007675 }
7676
Rambo Wang6812ffb2022-03-15 16:54:17 -07007677 @Override
7678 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7679 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7680
joonhunshin4ac60942023-11-15 15:23:39 +00007681 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7682 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7683 "getCarrierServicePackageNameForLogicalSlot");
7684
Rambo Wang6812ffb2022-03-15 16:54:17 -07007685 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7686 if (phone == null) {
7687 return null;
7688 }
7689 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7690 if (cpt == null) {
7691 return null;
7692 }
7693 return cpt.getCarrierServicePackageName();
7694 }
7695
Wink Savilleb564aae2014-10-23 10:18:09 -07007696 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007697 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007698 UiccPort port = phone == null ? null : phone.getUiccPort();
7699 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007700 return null;
7701 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007702 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007703 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007704 return null;
7705 }
7706 return iccId;
7707 }
7708
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007709 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007710 public void setCallComposerStatus(int subId, int status) {
7711 enforceModifyPermission();
7712
joonhunshin4ac60942023-11-15 15:23:39 +00007713 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7714 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7715
Shuo Qiane4e11672020-12-15 22:15:33 -08007716 final long identity = Binder.clearCallingIdentity();
7717 try {
7718 Phone phone = getPhone(subId);
7719 if (phone != null) {
7720 Phone defaultPhone = phone.getImsPhone();
7721 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7722 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7723 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007724 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7725 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007726 }
7727 }
Shuo Qian284ae752020-12-22 19:10:14 -08007728 } catch (ImsException e) {
7729 throw new ServiceSpecificException(e.getCode());
7730 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007731 Binder.restoreCallingIdentity(identity);
7732 }
7733 }
7734
7735 @Override
7736 public int getCallComposerStatus(int subId) {
7737 enforceReadPrivilegedPermission("getCallComposerStatus");
7738
joonhunshin4ac60942023-11-15 15:23:39 +00007739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7740 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7741
Shuo Qiane4e11672020-12-15 22:15:33 -08007742 final long identity = Binder.clearCallingIdentity();
7743 try {
7744 Phone phone = getPhone(subId);
7745 if (phone != null) {
7746 Phone defaultPhone = phone.getImsPhone();
7747 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7748 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7749 return imsPhone.getCallComposerStatus();
7750 }
7751 }
7752 } finally {
7753 Binder.restoreCallingIdentity(identity);
7754 }
7755 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7756 }
7757
7758 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007759 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7760 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007761 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007762 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007763
joonhunshin4ac60942023-11-15 15:23:39 +00007764 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7765 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7766 "setLine1NumberForDisplayForSubscriber");
7767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 final long identity = Binder.clearCallingIdentity();
7769 try {
7770 final String iccId = getIccId(subId);
7771 final Phone phone = getPhone(subId);
7772 if (phone == null) {
7773 return false;
7774 }
7775 final String subscriberId = phone.getSubscriberId();
7776
7777 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007778 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 + subscriberId + " to " + number);
7780 }
7781
7782 if (TextUtils.isEmpty(iccId)) {
7783 return false;
7784 }
7785
7786 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7787
7788 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7789 if (alphaTag == null) {
7790 editor.remove(alphaTagPrefKey);
7791 } else {
7792 editor.putString(alphaTagPrefKey, alphaTag);
7793 }
7794
7795 // Record both the line number and IMSI for this ICCID, since we need to
7796 // track all merged IMSIs based on line number
7797 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7798 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7799 if (number == null) {
7800 editor.remove(numberPrefKey);
7801 editor.remove(subscriberPrefKey);
7802 } else {
7803 editor.putString(numberPrefKey, number);
7804 editor.putString(subscriberPrefKey, subscriberId);
7805 }
7806
7807 editor.commit();
7808 return true;
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007811 }
Derek Tan7226c842014-07-02 17:42:23 -07007812 }
7813
7814 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007815 public String getLine1NumberForDisplay(int subId, String callingPackage,
7816 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007817 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007819 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007820 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007821 return null;
7822 }
Derek Tan97ebb422014-09-05 16:55:38 -07007823
joonhunshin4ac60942023-11-15 15:23:39 +00007824 enforceTelephonyFeatureWithException(callingPackage,
7825 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827 final long identity = Binder.clearCallingIdentity();
7828 try {
7829 String iccId = getIccId(subId);
7830 if (iccId != null) {
7831 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7832 if (DBG_MERGE) {
7833 log("getLine1NumberForDisplay returning "
7834 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7835 }
7836 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7839 return null;
7840 } finally {
7841 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007842 }
Derek Tan7226c842014-07-02 17:42:23 -07007843 }
7844
7845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007846 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7847 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007849 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007850 return null;
7851 }
Derek Tan97ebb422014-09-05 16:55:38 -07007852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 String iccId = getIccId(subId);
7856 if (iccId != null) {
7857 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7858 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7859 }
7860 return null;
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007863 }
Derek Tan7226c842014-07-02 17:42:23 -07007864 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007865
7866 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007867 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7868 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007869 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7870 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007872 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007873 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007874 return null;
7875 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007876
Jordan Liub49b04b2019-05-06 14:45:15 -07007877 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7878 // the process, where TelephonyManager was instantiated.
7879 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007880 final long identity = Binder.clearCallingIdentity();
7881 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007882 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007883 final TelephonyManager tele = TelephonyManager.from(context);
7884 final SubscriptionManager sub = SubscriptionManager.from(context);
7885
7886 // Figure out what subscribers are currently active
7887 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888
Jordan Liub49b04b2019-05-06 14:45:15 -07007889 // Only consider subs which match the current subId
7890 // This logic can be simplified. See b/131189269 for progress.
7891 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007892 activeSubscriberIds.add(tele.getSubscriberId(subId));
7893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894
7895 // First pass, find a number override for an active subscriber
7896 String mergeNumber = null;
7897 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7898 for (String key : prefs.keySet()) {
7899 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7900 final String subscriberId = (String) prefs.get(key);
7901 if (activeSubscriberIds.contains(subscriberId)) {
7902 final String iccId = key.substring(
7903 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7904 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7905 mergeNumber = (String) prefs.get(numberKey);
7906 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007907 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 + " for active subscriber " + subscriberId);
7909 }
7910 if (!TextUtils.isEmpty(mergeNumber)) {
7911 break;
7912 }
7913 }
7914 }
7915 }
7916
7917 // Shortcut when no active merged subscribers
7918 if (TextUtils.isEmpty(mergeNumber)) {
7919 return null;
7920 }
7921
7922 // Second pass, find all subscribers under that line override
7923 final ArraySet<String> result = new ArraySet<>();
7924 for (String key : prefs.keySet()) {
7925 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7926 final String number = (String) prefs.get(key);
7927 if (mergeNumber.equals(number)) {
7928 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7929 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7930 final String subscriberId = (String) prefs.get(subscriberKey);
7931 if (!TextUtils.isEmpty(subscriberId)) {
7932 result.add(subscriberId);
7933 }
7934 }
7935 }
7936 }
7937
7938 final String[] resultArray = result.toArray(new String[result.size()]);
7939 Arrays.sort(resultArray);
7940 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007941 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7943 }
7944 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007945 } finally {
7946 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007947 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007948 }
7949
7950 @Override
zoey chen38003472019-12-13 17:16:31 +08007951 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7952 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007953
joonhunshin4ac60942023-11-15 15:23:39 +00007954 enforceTelephonyFeatureWithException(callingPackage,
7955 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7956
Malcolm Chen6ca97372019-07-01 16:28:21 -07007957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 final TelephonyManager telephonyManager = mApp.getSystemService(
7960 TelephonyManager.class);
7961 String subscriberId = telephonyManager.getSubscriberId(subId);
7962 if (subscriberId == null) {
7963 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007964 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007965 + subId);
7966 }
7967 return null;
7968 }
7969
Jack Yu3beaf9d2023-04-14 09:17:27 -07007970 final SubscriptionInfo info = getSubscriptionManagerService()
7971 .getSubscriptionInfo(subId);
7972 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007973 // If it doesn't belong to any group, return just subscriberId of itself.
7974 if (groupUuid == null) {
7975 return new String[]{subscriberId};
7976 }
7977
7978 // Get all subscriberIds from the group.
7979 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007980 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7981 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7982 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007983 for (SubscriptionInfo subInfo : groupInfos) {
7984 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7985 if (subscriberId != null) {
7986 mergedSubscriberIds.add(subscriberId);
7987 }
7988 }
7989
7990 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
7993
7994 }
7995 }
7996
7997 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007998 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007999 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008000 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001
joonhunshin4ac60942023-11-15 15:23:39 +00008002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8003 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 final Phone phone = getPhone(subId);
8008 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8009 } finally {
8010 Binder.restoreCallingIdentity(identity);
8011 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008012 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008013
8014 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008015 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008016 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8017 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008018 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8019 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020
8021 final long identity = Binder.clearCallingIdentity();
8022 try {
8023 final Phone phone = getPhone(subId);
8024 if (phone == null) {
8025 return false;
8026 }
8027 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8028 cdmaNonRoamingList);
8029 } finally {
8030 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008031 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008032 }
8033
8034 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008035 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008036 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008037 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008038 if (phone == null) {
8039 return raf;
8040 }
8041
Shuo Qiandee53402020-05-29 14:08:15 -07008042 try {
8043 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008044 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008045 mApp, phone.getSubId(), "getRadioAccessFamily");
8046 } catch (SecurityException e) {
8047 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8048 throw e;
8049 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008050
joonhunshin4ac60942023-11-15 15:23:39 +00008051 enforceTelephonyFeatureWithException(callingPackage,
8052 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
chen xub97461a2018-10-26 14:17:57 -07008056 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
chen xub97461a2018-10-26 14:17:57 -07008060 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008061 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008062
8063 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008064 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008065 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008066 try {
8067 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8068 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008069 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008070 }
8071 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008072 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008073 }
joonhunshin4ac60942023-11-15 15:23:39 +00008074
8075 enforceTelephonyFeatureWithException(callingPackage,
8076 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8077
Hall Liu82694d52020-12-11 18:22:04 -08008078 RoleManager rm = mApp.getSystemService(RoleManager.class);
8079 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8080 if (!dialerRoleHolders.contains(callingPackage)) {
8081 throw new SecurityException("App must be the dialer role holder to"
8082 + " upload a call composer pic");
8083 }
8084
8085 Executors.newSingleThreadExecutor().execute(() -> {
8086 ByteArrayOutputStream output = new ByteArrayOutputStream(
8087 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8088 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8089 boolean readUntilEnd = false;
8090 int totalBytesRead = 0;
8091 byte[] buffer = new byte[16 * 1024];
8092 while (true) {
8093 int numRead;
8094 try {
8095 numRead = input.read(buffer);
8096 } catch (IOException e) {
8097 try {
8098 fd.checkError();
8099 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8100 null);
8101 } catch (IOException e1) {
8102 // This means that the other side closed explicitly with an error. If this
8103 // happens, log and ignore.
8104 loge("Remote end of call composer picture pipe closed: " + e1);
8105 }
8106 break;
8107 }
8108 if (numRead == -1) {
8109 readUntilEnd = true;
8110 break;
8111 }
8112 totalBytesRead += numRead;
8113 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8114 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8115 try {
8116 input.close();
8117 } catch (IOException e) {
8118 // ignore
8119 }
8120 break;
8121 }
8122 output.write(buffer, 0, numRead);
8123 }
8124 // Generally, the remote end will close the file descriptors. The only case where we
8125 // close is above, where the picture size is too big.
8126
8127 try {
8128 fd.checkError();
8129 } catch (IOException e) {
8130 loge("Remote end for call composer closed with an error: " + e);
8131 return;
8132 }
8133
Hall Liuaa4211e2021-01-20 15:43:39 -08008134 if (!readUntilEnd) {
8135 loge("Did not finish reading entire image; aborting");
8136 return;
8137 }
Hall Liu82694d52020-12-11 18:22:04 -08008138
Hall Liuaa4211e2021-01-20 15:43:39 -08008139 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8140 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8141 new CallComposerPictureTransfer.Factory() {},
8142 imageData,
8143 (result) -> {
8144 if (result.first != null) {
8145 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8146 Bundle outputResult = new Bundle();
8147 outputResult.putParcelable(
8148 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8149 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8150 outputResult);
8151 } else {
8152 callback.send(result.second, null);
8153 }
8154 }
8155 );
Hall Liu82694d52020-12-11 18:22:04 -08008156 });
8157 }
8158
8159 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008160 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008161 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008162 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163
joonhunshin4ac60942023-11-15 15:23:39 +00008164 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8165 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167 final long identity = Binder.clearCallingIdentity();
8168 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008169 ImsManager.getInstance(defaultPhone.getContext(),
8170 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008171 } finally {
8172 Binder.restoreCallingIdentity(identity);
8173 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008174 }
8175
8176 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008177 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008178 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8180 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008181 return false;
8182 }
Svet Ganovb320e182015-04-16 12:30:10 -07008183
joonhunshin4ac60942023-11-15 15:23:39 +00008184 enforceTelephonyFeatureWithException(callingPackage,
8185 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187 final long identity = Binder.clearCallingIdentity();
8188 try {
8189 // Check the user preference and the system-level IMS setting. Even if the user has
8190 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8191 // In the long run, we may instead need to check if there exists a connection service
8192 // which can support video calling.
8193 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008194 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195 return imsManager.isVtEnabledByPlatform()
8196 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8197 && imsManager.isVtEnabledByUser();
8198 } finally {
8199 Binder.restoreCallingIdentity(identity);
8200 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008201 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008202
Andrew Leea1239f22015-03-02 17:44:07 -08008203 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008204 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8205 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008207 mApp, subId, callingPackage, callingFeatureId,
8208 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 return false;
8210 }
8211
joonhunshin4ac60942023-11-15 15:23:39 +00008212 enforceTelephonyFeatureWithException(callingPackage,
8213 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215 final long identity = Binder.clearCallingIdentity();
8216 try {
8217 CarrierConfigManager configManager =
8218 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008219 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Andrew Leea1239f22015-03-02 17:44:07 -08008224 }
8225
8226 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008227 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008229 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230 return false;
8231 }
8232
joonhunshin4ac60942023-11-15 15:23:39 +00008233 enforceTelephonyFeatureWithException(callingPackage,
8234 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 final long identity = Binder.clearCallingIdentity();
8237 try {
8238 CarrierConfigManager configManager =
8239 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008240 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8242 } finally {
8243 Binder.restoreCallingIdentity(identity);
8244 }
Andrew Leea1239f22015-03-02 17:44:07 -08008245 }
8246
Andrew Lee9431b832015-03-09 18:46:45 -07008247 @Override
8248 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008249 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008250 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008251 }
8252
8253 @Override
8254 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008255 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8256 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 final long identity = Binder.clearCallingIdentity();
8259 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008260 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 } finally {
8262 Binder.restoreCallingIdentity(identity);
8263 }
Andrew Lee9431b832015-03-09 18:46:45 -07008264 }
8265
Hall Liuf6668912018-10-31 17:05:23 -07008266 /**
8267 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8268 * support for the feature and device firmware support.
8269 *
8270 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8271 */
8272 @Override
8273 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8275 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008278 final Phone phone = getPhone(subscriptionId);
8279 if (phone == null) {
8280 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8281 return false;
8282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008284 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008286 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8287 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8288 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008289 return isCarrierSupported && isDeviceSupported;
8290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
Hall Liu98187582018-01-22 19:15:32 -08008293 }
8294
Hall Liuf6668912018-10-31 17:05:23 -07008295 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008296 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8297 * RTT setting, will return true if the device and carrier both support RTT.
8298 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008299 */
8300 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 final long identity = Binder.clearCallingIdentity();
8302 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008303 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8304 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8305 return false;
8306 }
8307 }
8308
Hall Liu5bab75c2019-12-11 23:58:20 +00008309 boolean isRttSupported = isRttSupported(subscriptionId);
8310 boolean isUserRttSettingOn = Settings.Secure.getInt(
8311 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8312 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8313 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8314 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008318 }
8319
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008320 @Deprecated
8321 @Override
8322 public String getDeviceId(String callingPackage) {
8323 return getDeviceIdWithFeature(callingPackage, null);
8324 }
8325
Sanket Padawe7310cc72015-01-14 09:53:20 -08008326 /**
8327 * Returns the unique device ID of phone, for example, the IMEI for
8328 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8329 *
8330 * <p>Requires Permission:
8331 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8332 */
8333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008334 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008335 try {
8336 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8337 } catch (SecurityException se) {
8338 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8339 throw new SecurityException("Package " + callingPackage + " does not belong to "
8340 + Binder.getCallingUid());
8341 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008342 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008343 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008344 return null;
8345 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008346 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008347 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008348 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008349 return null;
8350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008351
8352 final long identity = Binder.clearCallingIdentity();
8353 try {
8354 return phone.getDeviceId();
8355 } finally {
8356 Binder.restoreCallingIdentity(identity);
8357 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008358 }
8359
Ping Sunc67b7c22016-03-02 19:16:45 +08008360 /**
8361 * {@hide}
8362 * Returns the IMS Registration Status on a particular subid
8363 *
8364 * @param subId
8365 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008366 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008367 Phone phone = getPhone(subId);
8368 if (phone != null) {
8369 return phone.isImsRegistered();
8370 } else {
8371 return false;
8372 }
8373 }
8374
Santos Cordon7a1885b2015-02-03 11:15:19 -08008375 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008376 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008377 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008379 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008380 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8381 }
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8385 } finally {
8386 Binder.restoreCallingIdentity(identity);
8387 }
8388 }
8389
8390 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008391 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008392 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008393 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008394 mApp,
8395 subscriptionId,
8396 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8397 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008398
8399 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8400 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8401
Tyler Gunnf70ed162019-04-03 15:28:53 -07008402 final long identity = Binder.clearCallingIdentity();
8403 try {
8404 Phone phone = getPhone(subscriptionId);
8405 if (phone == null) {
8406 return null;
8407 }
8408 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8409 } finally {
8410 Binder.restoreCallingIdentity(identity);
8411 }
8412 }
8413
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008414 /**
8415 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008416 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008417 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008418 final long identity = Binder.clearCallingIdentity();
8419 try {
8420 Phone phone = getPhone(subId);
8421 if (phone != null) {
8422 return phone.isWifiCallingEnabled();
8423 } else {
8424 return false;
8425 }
8426 } finally {
8427 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008428 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008429 }
8430
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008431 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008432 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008433 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008434 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 final long identity = Binder.clearCallingIdentity();
8436 try {
8437 Phone phone = getPhone(subId);
8438 if (phone != null) {
8439 return phone.isVideoEnabled();
8440 } else {
8441 return false;
8442 }
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008445 }
8446 }
8447
8448 /**
8449 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8450 * defined in {@link ImsRegistrationImplBase}.
8451 */
8452 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 final long identity = Binder.clearCallingIdentity();
8454 try {
8455 Phone phone = getPhone(subId);
8456 if (phone != null) {
8457 return phone.getImsRegistrationTech();
8458 } else {
8459 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8460 }
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008463 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008464 }
8465
Stuart Scott8eef64f2015-04-08 15:13:54 -07008466 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008467 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008468 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008469
8470 enforceTelephonyFeatureWithException(callingPackage,
8471 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8472
Stuart Scott981d8582015-04-21 14:09:50 -07008473 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8474 return;
8475 }
Kai Shif70f46f2021-03-03 13:59:46 -08008476 Phone defaultPhone = getDefaultPhone();
8477 if (defaultPhone != null) {
8478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8479 mApp, getDefaultPhone().getSubId(), "factoryReset");
8480 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008481 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008482
Svet Ganovcc087f82015-05-12 20:35:54 -07008483 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008484 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8485 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008486 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008487 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008488 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008489 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008490 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008491 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008492 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008493 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008494 // There has been issues when Sms raw table somehow stores orphan
8495 // fragments. They lead to garbled message when new fragments come
8496 // in and combined with those stale ones. In case this happens again,
8497 // user can reset all network settings which will clean up this table.
8498 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008499 // Clean up IMS settings as well here.
8500 int slotId = getSlotIndex(subId);
8501 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8502 ImsManager.getInstance(mApp, slotId).factoryReset();
8503 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008504
Kai Shif70f46f2021-03-03 13:59:46 -08008505 if (defaultPhone == null) {
8506 return;
8507 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008508 // Erase modem config if erase modem on network setting is enabled.
8509 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8510 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8511 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008512 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008513 }
Kai Shif70f46f2021-03-03 13:59:46 -08008514
8515 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008516 } finally {
8517 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008518 }
8519 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008520
SongFerngWangfd89b102021-05-27 22:44:54 +08008521 @VisibleForTesting
8522 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8523 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8524 return;
8525 }
8526 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8527 RILConstants.PREFERRED_NETWORK_MODE);
8528 SubscriptionManager.setSubscriptionProperty(subId,
8529 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8530 "user=" + defaultNetworkType);
8531 phone.loadAllowedNetworksFromSubscriptionDatabase();
8532 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8533 defaultNetworkType, null);
8534 }
8535
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008536 private void cleanUpSmsRawTable(Context context) {
8537 ContentResolver resolver = context.getContentResolver();
8538 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8539 resolver.delete(uri, null, null);
8540 }
8541
Narayan Kamath1c496c22015-04-16 14:40:19 +01008542 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008543 public String getSimLocaleForSubscriber(int subId) {
8544 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008545
8546 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8547 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8548
chen xu5d3637b2019-01-21 23:31:38 -08008549 final Phone phone = getPhone(subId);
8550 if (phone == null) {
8551 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008552 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008554 final long identity = Binder.clearCallingIdentity();
8555 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008556 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8557 phone.getContext().getOpPackageName(),
8558 phone.getContext().getAttributionTag());
8559 if (info == null) {
8560 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8561 return null;
chen xu6291c472019-02-04 12:55:53 -08008562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563 // Try and fetch the locale from the carrier properties or from the SIM language
8564 // preferences (EF-PL and EF-LI)...
8565 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008566 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008567 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8568 if (localeFromDefaultSim != null) {
8569 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8570 if (DBG) log("Using locale from subId: " + subId + " locale: "
8571 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008572 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008573 } else {
8574 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575 }
8576 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 // The SIM language preferences only store a language (e.g. fr = French), not an
8579 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8580 // the SIM and carrier preferences does not include a country we add the country
8581 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008582 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008584 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008585 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008586 }
8587
8588 if (DBG) log("No locale found - returning null");
8589 return null;
8590 } finally {
8591 Binder.restoreCallingIdentity(identity);
8592 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008593 }
8594
tom hsu0b59d292022-09-29 23:49:21 +08008595 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008596 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008597 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008598 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008599 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008600 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8601 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008602 Locale.forLanguageTag(localeTag).getCountry())) {
8603 return localeTag;
8604 }
8605 }
8606 return inputLocale.toLanguageTag();
8607 }
8608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 /**
8610 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8611 */
8612 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008613 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008614 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008615 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008616
Gary Jian3aa9a762022-01-24 16:41:19 +08008617 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8618 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008619
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008620 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008621 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8622 * representing the state of the modem.
8623 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008624 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8625 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008626 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008627 */
8628 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008629 public void requestModemActivityInfo(ResultReceiver result) {
8630 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008631
8632 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8633 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8634
vagdeviaf9a5b92018-08-15 16:01:53 -07008635 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636
8637 final long identity = Binder.clearCallingIdentity();
8638 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008639 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008640 } finally {
8641 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008642 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008643 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008644
Gary Jian76280a42022-12-07 16:18:33 +08008645 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008646 // less than total activity duration.
8647 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8648 if (info == null) {
8649 return false;
8650 }
8651 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008652 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008653 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8654
Hall Liu49656c02020-10-09 19:00:11 -07008655 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8656
Siddharth Rayb8114062018-06-17 15:02:38 -07008657 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008658 && (info.getSleepTimeMillis() <= activityDurationMs)
8659 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008660 }
8661
Gary Jian3aa9a762022-01-24 16:41:19 +08008662 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8663 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8664 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8665 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8666
8667 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8668 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8669 }
8670
8671 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8672 mLastModemActivityInfo.setReceiveTimeMillis(
8673 rat,
8674 freq,
8675 info.getReceiveTimeMillis(rat, freq)
8676 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8677 }
8678
8679 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8680 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8681 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8682 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8683
8684 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8685 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8686 }
8687 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8688 mLastModemActivityInfo.setReceiveTimeMillis(
8689 rat,
8690 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8691 }
8692
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008693 /**
8694 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8695 * @param info recent ModemActivityInfo
8696 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008697 private void mergeModemActivityInfo(ModemActivityInfo info) {
8698 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008699 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008700 boolean matched;
8701 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8702 matched = false;
8703 int rat = info.getSpecificInfoRat(i);
8704 int freq = info.getSpecificInfoFrequencyRange(i);
8705 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8706 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8707 //if it already exists
8708 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8709 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8710 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8711 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8712 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8713 updateLastModemActivityInfo(info, rat, freq);
8714 matched = true;
8715 }
8716 } else {
8717 updateLastModemActivityInfo(info, rat);
8718 matched = true;
8719 }
8720 }
8721 }
8722
8723 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008724 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008725 new ActivityStatsTechSpecificInfo(
8726 rat,
8727 freq,
8728 info.getTransmitTimeMillis(rat, freq),
8729 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008730 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008731 }
8732 }
8733 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8734 mLastModemActivitySpecificInfo =
8735 new ActivityStatsTechSpecificInfo[merged.size()];
8736 merged.toArray(mLastModemActivitySpecificInfo);
8737
8738 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8739 mLastModemActivityInfo.setSleepTimeMillis(
8740 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008741 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008742 mLastModemActivityInfo.setIdleTimeMillis(
8743 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008744 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008745
8746 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008747 new ModemActivityInfo(
8748 mLastModemActivityInfo.getTimestampMillis(),
8749 mLastModemActivityInfo.getSleepTimeMillis(),
8750 mLastModemActivityInfo.getIdleTimeMillis(),
8751 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008752 }
8753
8754 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8755 ActivityStatsTechSpecificInfo[] info) {
8756 int infoSize = info.length;
8757 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8758 for (int i = 0; i < infoSize; i++) {
8759 ret[i] = new ActivityStatsTechSpecificInfo(
8760 info[i].getRat(), info[i].getFrequencyRange(),
8761 info[i].getTransmitTimeMillis(),
8762 (int) info[i].getReceiveTimeMillis());
8763 }
8764 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008765 }
8766
Jack Yu85bd38a2015-11-09 11:34:32 -08008767 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008768 * Returns the service state information on specified subscription.
8769 */
8770 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008771 public ServiceState getServiceStateForSubscriber(int subId,
8772 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8773 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008775 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008776 return null;
8777 }
8778
joonhunshin4ac60942023-11-15 15:23:39 +00008779 enforceTelephonyFeatureWithException(callingPackage,
8780 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8781
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008782 boolean hasFinePermission = false;
8783 boolean hasCoarsePermission = false;
8784 if (!renounceFineLocationAccess) {
8785 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8786 LocationAccessPolicy.checkLocationPermission(mApp,
8787 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8788 .setCallingPackage(callingPackage)
8789 .setCallingFeatureId(callingFeatureId)
8790 .setCallingPid(Binder.getCallingPid())
8791 .setCallingUid(Binder.getCallingUid())
8792 .setMethod("getServiceStateForSubscriber")
8793 .setLogAsInfo(true)
8794 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8795 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8796 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8797 .build());
8798 hasFinePermission =
8799 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8800 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008801
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008802 if (!renounceCoarseLocationAccess) {
8803 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8804 LocationAccessPolicy.checkLocationPermission(mApp,
8805 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8806 .setCallingPackage(callingPackage)
8807 .setCallingFeatureId(callingFeatureId)
8808 .setCallingPid(Binder.getCallingPid())
8809 .setCallingUid(Binder.getCallingUid())
8810 .setMethod("getServiceStateForSubscriber")
8811 .setLogAsInfo(true)
8812 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8813 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8814 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8815 .build());
8816 hasCoarsePermission =
8817 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8818 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008819
Jack Yu479f40e2020-10-27 21:29:25 -07008820 final Phone phone = getPhone(subId);
8821 if (phone == null) {
8822 return null;
8823 }
8824
Jordan Liu0f2bc442020-11-18 16:47:37 -08008825 final long identity = Binder.clearCallingIdentity();
8826
Jack Yu479f40e2020-10-27 21:29:25 -07008827 boolean isCallingPackageDataService = phone.getDataServicePackages()
8828 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008829 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008830 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008831 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8832 .getSubscriptionInfoInternal(subId);
8833 if (subInfo == null || !subInfo.isActive()) {
8834 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8835 + "subId=" + subId);
8836 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008837 }
8838
Hall Liuf19c44f2018-11-27 14:38:17 -08008839 ServiceState ss = phone.getServiceState();
8840
8841 // Scrub out the location info in ServiceState depending on what level of access
8842 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008843 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008844 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8845 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008846 } finally {
8847 Binder.restoreCallingIdentity(identity);
8848 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008849 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008850
8851 /**
8852 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8853 *
8854 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8855 * voicemail ringtone.
8856 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8857 * PhoneAccount.
8858 */
8859 @Override
8860 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008861 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8862 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008864 final long identity = Binder.clearCallingIdentity();
8865 try {
8866 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8867 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008868 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008869 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008871 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8872 } finally {
8873 Binder.restoreCallingIdentity(identity);
8874 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008875 }
8876
8877 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008878 * Sets the per-account voicemail ringtone.
8879 *
8880 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8881 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8882 *
8883 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8884 * voicemail ringtone.
8885 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8886 * PhoneAccount.
8887 */
8888 @Override
8889 public void setVoicemailRingtoneUri(String callingPackage,
8890 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008891 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008893 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8894 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8896 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8897 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899
joonhunshin4ac60942023-11-15 15:23:39 +00008900 enforceTelephonyFeatureWithException(callingPackage,
8901 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008903 final long identity = Binder.clearCallingIdentity();
8904 try {
8905 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8906 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008907 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008908 }
8909 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8910 } finally {
8911 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008912 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008913 }
8914
8915 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008916 * Returns whether vibration is set for voicemail notification in Phone settings.
8917 *
8918 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8919 * voicemail vibration setting.
8920 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8921 */
8922 @Override
8923 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008924 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8925 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 final long identity = Binder.clearCallingIdentity();
8928 try {
8929 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8930 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008931 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008932 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008934 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8935 } finally {
8936 Binder.restoreCallingIdentity(identity);
8937 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008938 }
8939
Youhan Wange64578a2016-05-02 15:32:42 -07008940 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008941 * Sets the per-account voicemail vibration.
8942 *
8943 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8944 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8945 *
8946 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8947 * voicemail vibration setting.
8948 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8949 * specific PhoneAccount.
8950 */
8951 @Override
8952 public void setVoicemailVibrationEnabled(String callingPackage,
8953 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008954 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008955 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008956 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8957 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8959 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8960 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008961 }
8962
joonhunshin4ac60942023-11-15 15:23:39 +00008963 enforceTelephonyFeatureWithException(callingPackage,
8964 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8969 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008970 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008971 }
8972 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8973 } finally {
8974 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008975 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008976 }
8977
8978 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008979 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8980 *
8981 * @throws SecurityException if the caller does not have the required permission
8982 */
arunvoddud7401012022-12-15 16:08:12 +00008983 @VisibleForTesting
8984 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008985 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008986 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008987 }
8988
8989 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008990 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8991 * permission.
8992 *
8993 * @throws SecurityException if the caller does not have the required permission
8994 */
8995 private void enforceSendSmsPermission() {
8996 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8997 }
8998
8999 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009000 * Make sure either called from same process as self (phone) or IPC caller has interact across
9001 * users permission.
9002 *
9003 * @throws SecurityException if the caller does not have the required permission
9004 */
9005 private void enforceInteractAcrossUsersPermission(String message) {
9006 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9007 }
9008
9009 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009010 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009011 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009012 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009013 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009014 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009015 final long identity = Binder.clearCallingIdentity();
9016 try {
9017 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009018 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009019 if (componentName == null) {
9020 throw new SecurityException(
9021 "Caller not current active visual voicemail package[null]");
9022 }
9023 String vvmPackage = componentName.getPackageName();
9024 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009025 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009026 }
9027 } finally {
9028 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009029 }
9030 }
9031
9032 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009033 * Return the application ID for the app type.
9034 *
9035 * @param subId the subscription ID that this request applies to.
9036 * @param appType the uicc app type.
9037 * @return Application ID for specificied app type, or null if no uicc.
9038 */
9039 @Override
9040 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009041 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009042
9043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9044 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9045
Youhan Wange64578a2016-05-02 15:32:42 -07009046 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047
9048 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009049 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009050 if (phone == null) {
9051 return null;
9052 }
9053 String aid = null;
9054 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009055 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056 .getApplicationByType(appType).getAid();
9057 } catch (Exception e) {
9058 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9059 }
9060 return aid;
9061 } finally {
9062 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009063 }
Youhan Wange64578a2016-05-02 15:32:42 -07009064 }
9065
Youhan Wang4001d252016-05-11 10:29:41 -07009066 /**
9067 * Return the Electronic Serial Number.
9068 *
9069 * @param subId the subscription ID that this request applies to.
9070 * @return ESN or null if error.
9071 */
9072 @Override
9073 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009074 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009075 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076
9077 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009078 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079 if (phone == null) {
9080 return null;
9081 }
9082 String esn = null;
9083 try {
9084 esn = phone.getEsn();
9085 } catch (Exception e) {
9086 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9087 }
9088 return esn;
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009091 }
Youhan Wang4001d252016-05-11 10:29:41 -07009092 }
9093
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009094 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009095 * Return the Preferred Roaming List Version.
9096 *
9097 * @param subId the subscription ID that this request applies to.
9098 * @return PRLVersion or null if error.
9099 */
9100 @Override
9101 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009102 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009103
9104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9105 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9106
Youhan Wang66ad5d72016-07-18 17:56:58 -07009107 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009108
9109 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009110 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009111 if (phone == null) {
9112 return null;
9113 }
9114 String cdmaPrlVersion = null;
9115 try {
9116 cdmaPrlVersion = phone.getCdmaPrlVersion();
9117 } catch (Exception e) {
9118 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9119 }
9120 return cdmaPrlVersion;
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009123 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009124 }
9125
9126 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009127 * Get snapshot of Telephony histograms
9128 * @return List of Telephony histograms
9129 * @hide
9130 */
9131 @Override
9132 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9134 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009135
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 return RIL.getTelephonyRILTimingHistograms();
9139 } finally {
9140 Binder.restoreCallingIdentity(identity);
9141 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009142 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009143
9144 /**
9145 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009146 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9147 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009148 * Require system privileges. In the future we may add this to carrier APIs.
9149 *
Michele Berionne482f8202018-11-27 18:57:59 -08009150 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009151 */
9152 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009153 @TelephonyManager.SetCarrierRestrictionResult
9154 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009155 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009156
9157 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9158 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9159
vagdeviaf9a5b92018-08-15 16:01:53 -07009160 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009161
Michele Berionne482f8202018-11-27 18:57:59 -08009162 if (carrierRestrictionRules == null) {
9163 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009164 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009166 final long identity = Binder.clearCallingIdentity();
9167 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009168 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009169 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009173 }
9174
9175 /**
9176 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009177 * Get the allowed carrier list and the excluded carrier list, including the priority between
9178 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009179 * Require system privileges. In the future we may add this to carrier APIs.
9180 *
Michele Berionne482f8202018-11-27 18:57:59 -08009181 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009182 */
9183 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009184 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009185 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009186
9187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9188 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9189
vagdeviaf9a5b92018-08-15 16:01:53 -07009190 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009191
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009194 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9195 if (response instanceof CarrierRestrictionRules) {
9196 return (CarrierRestrictionRules) response;
9197 }
9198 // Response is an Exception of some kind,
9199 // which is signalled to the user as a NULL retval
9200 return null;
9201 } catch (Exception e) {
9202 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9203 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009204 } finally {
9205 Binder.restoreCallingIdentity(identity);
9206 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009207 }
9208
fionaxu59545b42016-05-25 15:53:37 -07009209 /**
arunvoddud7401012022-12-15 16:08:12 +00009210 * Fetches the carrier restriction status of the device and sends the status to the caller
9211 * through the callback.
9212 *
9213 * @param callback The callback that will be used to send the result.
9214 * @throws SecurityException if the caller does not have the required permission/privileges or
9215 * the caller is not allowlisted.
9216 */
9217 @Override
9218 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9219 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009220
9221 enforceTelephonyFeatureWithException(packageName,
9222 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9223
arunvoddud7401012022-12-15 16:08:12 +00009224 int carrierId = validateCallerAndGetCarrierId(packageName);
9225 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9226 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9227 throw new SecurityException("Not an authorized caller");
9228 }
9229 final long identity = Binder.clearCallingIdentity();
9230 try {
9231 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9232 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9233 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9234 } finally {
9235 Binder.restoreCallingIdentity(identity);
9236 }
9237 }
9238
arunvoddu567f2b42023-04-25 17:22:00 +00009239 @Override
9240 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9241 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9242 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9243 return allowListInfo.getShaIdList(pkgName, carrierId);
9244 }
9245
arunvoddud7401012022-12-15 16:08:12 +00009246 @VisibleForTesting
9247 public int validateCallerAndGetCarrierId(String packageName) {
9248 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9249 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9250 }
9251
9252 /**
fionaxu59545b42016-05-25 15:53:37 -07009253 * Action set from carrier signalling broadcast receivers to enable/disable radio
9254 * @param subId the subscription ID that this action applies to.
9255 * @param enabled control enable or disable radio.
9256 * {@hide}
9257 */
9258 @Override
9259 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9260 enforceModifyPermission();
9261 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009262
9263 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009264 if (phone == null) {
9265 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9266 return;
9267 }
9268 try {
9269 phone.carrierActionSetRadioEnabled(enabled);
9270 } catch (Exception e) {
9271 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009272 } finally {
9273 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009274 }
9275 }
9276
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009277 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009278 * Enable or disable Voice over NR (VoNR)
9279 * @param subId the subscription ID that this action applies to.
9280 * @param enabled enable or disable VoNR.
9281 * @return operation result.
9282 */
9283 @Override
9284 public int setVoNrEnabled(int subId, boolean enabled) {
9285 enforceModifyPermission();
9286 final Phone phone = getPhone(subId);
9287
9288 final long identity = Binder.clearCallingIdentity();
9289 if (phone == null) {
9290 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9291 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9292 }
9293
9294 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9295 try {
9296 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9297 workSource);
9298 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009299
9300 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9301 if (DBG) {
9302 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9303 }
9304 SubscriptionManager.setSubscriptionProperty(
9305 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9306 (enabled ? "1" : "0"));
9307 }
9308
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009309 return result;
9310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
9313 }
9314
9315 /**
9316 * Is voice over NR enabled
9317 * @return true if VoNR is enabled else false
9318 */
9319 @Override
9320 public boolean isVoNrEnabled(int subId) {
9321 enforceReadPrivilegedPermission("isVoNrEnabled");
9322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9326 null, subId, workSource);
9327 if (DBG) log("isVoNrEnabled: " + isEnabled);
9328 return isEnabled;
9329 } finally {
9330 Binder.restoreCallingIdentity(identity);
9331 }
9332 }
9333
9334 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009335 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9336 * network status based on which carrier apps could apply actions accordingly,
9337 * enable/disable default url handler for example.
9338 *
9339 * @param subId the subscription ID that this action applies to.
9340 * @param report control start/stop reporting the default network status.
9341 * {@hide}
9342 */
9343 @Override
9344 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9345 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009346
9347 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9348 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9349 "carrierActionReportDefaultNetworkStatus");
9350
fionaxu8da9cb12017-05-23 15:02:46 -07009351 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009352
9353 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009354 if (phone == null) {
9355 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9356 return;
9357 }
9358 try {
9359 phone.carrierActionReportDefaultNetworkStatus(report);
9360 } catch (Exception e) {
9361 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009362 } finally {
9363 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009364 }
9365 }
9366
9367 /**
fionaxud9622282017-07-17 17:51:30 -07009368 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9369 * @param subId the subscription ID that this action applies to.
9370 * {@hide}
9371 */
9372 @Override
9373 public void carrierActionResetAll(int subId) {
9374 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009375
9376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9377 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9378
fionaxud9622282017-07-17 17:51:30 -07009379 final Phone phone = getPhone(subId);
9380 if (phone == null) {
9381 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9382 return;
9383 }
9384 try {
9385 phone.carrierActionResetAll();
9386 } catch (Exception e) {
9387 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9388 }
9389 }
9390
9391 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009392 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9393 * bug report is being generated.
9394 */
9395 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009396 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009397 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9398 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009399 writer.println("Permission Denial: can't dump Phone from pid="
9400 + Binder.getCallingPid()
9401 + ", uid=" + Binder.getCallingUid()
9402 + "without permission "
9403 + android.Manifest.permission.DUMP);
9404 return;
9405 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009406 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009407 }
Jack Yueb89b242016-06-22 13:27:47 -07009408
Brad Ebingerdac2f002018-04-03 15:17:52 -07009409 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009410 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9411 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9412 @NonNull String[] args) {
9413 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9414 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009415 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009416 }
9417
Jack Yueb89b242016-06-22 13:27:47 -07009418 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009419 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009420 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009421 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009422 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009423 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009424 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009425 */
9426 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009427 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009428 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009429 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9430 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9431 try {
9432 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009433 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009434 } catch (SecurityException se) {
9435 enforceModifyPermission();
9436 }
9437 } else {
9438 enforceModifyPermission();
9439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009440
Nate Myrenae97d192023-06-09 15:22:31 -07009441 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9442 && null != callingPackage && opEnableMobileDataByUser()) {
9443 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
9444 callingPackage, null, null);
9445 }
9446
joonhunshin4ac60942023-11-15 15:23:39 +00009447 enforceTelephonyFeatureWithException(callingPackage,
9448 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009450 final long identity = Binder.clearCallingIdentity();
9451 try {
9452 Phone phone = getPhone(subId);
9453 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009454 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9455 phone.carrierActionSetMeteredApnsEnabled(enabled);
9456 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009457 phone.getDataSettingsManager().setDataEnabled(
9458 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009460 }
9461 } finally {
9462 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009463 }
9464 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009465
9466 /**
9467 * Get Client request stats
9468 * @return List of Client Request Stats
9469 * @hide
9470 */
9471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009472 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9473 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009475 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009476 return null;
9477 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009478 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009480 final long identity = Binder.clearCallingIdentity();
9481 try {
9482 if (phone != null) {
9483 return phone.getClientRequestStats();
9484 }
9485
9486 return null;
9487 } finally {
9488 Binder.restoreCallingIdentity(identity);
9489 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009490 }
9491
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009492 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009493 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009494 if (uid == Process.ROOT_UID && packageName == null) {
9495 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9496 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9497 // exception. ROOT_UID seems not to have a valid package name returned by
9498 // PackageManager, so just fake it here to avoid issues when running telephony shell
9499 // commands that plumb through the RIL as root, like so:
9500 // $ adb root
9501 // $ adb shell cmd phone ...
9502 packageName = "root";
9503 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009504 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009505 }
Jack Yueb4124c2017-02-16 15:32:43 -08009506
9507 /**
Grace Chen70990072017-03-24 17:21:30 -07009508 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009509 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009510 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009511 * @param state State of SIM (power down, power up, pass through)
9512 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9513 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9514 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009515 *
9516 **/
9517 @Override
Grace Chen70990072017-03-24 17:21:30 -07009518 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009519 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009520
9521 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9522 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9523
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009524 Phone phone = PhoneFactory.getPhone(slotIndex);
9525
vagdeviaf9a5b92018-08-15 16:01:53 -07009526 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009528 final long identity = Binder.clearCallingIdentity();
9529 try {
9530 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009531 phone.setSimPowerState(state, null, workSource);
9532 }
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
9538 /**
9539 * Set SIM card power state.
9540 *
9541 * @param slotIndex SIM slot id.
9542 * @param state State of SIM (power down, power up, pass through)
9543 * @param callback callback to trigger after success or failure
9544 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9545 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9546 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9547 *
9548 **/
9549 @Override
9550 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9551 IIntegerConsumer callback) {
9552 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009553
9554 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9555 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9556 "setSimPowerStateForSlotWithCallback");
9557
Jordan Liu109698e2020-11-24 14:50:34 -08009558 Phone phone = PhoneFactory.getPhone(slotIndex);
9559
9560 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9561
9562 final long identity = Binder.clearCallingIdentity();
9563 try {
9564 if (phone != null) {
9565 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9566 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009567 }
9568 } finally {
9569 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009570 }
9571 }
Shuo Qiandd210312017-04-12 22:11:33 +00009572
Tyler Gunn65d45c22017-06-05 11:22:26 -07009573 private boolean isUssdApiAllowed(int subId) {
9574 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009575 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009576 if (configManager == null) {
9577 return false;
9578 }
9579 PersistableBundle pb = configManager.getConfigForSubId(subId);
9580 if (pb == null) {
9581 return false;
9582 }
9583 return pb.getBoolean(
9584 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9585 }
9586
Shuo Qiandd210312017-04-12 22:11:33 +00009587 /**
Ling Mac28f0212023-03-24 16:07:15 -07009588 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009589 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009590 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009591 */
goneil9c5f4872017-12-05 14:07:56 -08009592 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009593 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009594 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009595
9596 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9597 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009599 final long identity = Binder.clearCallingIdentity();
9600 try {
Ling Mac28f0212023-03-24 16:07:15 -07009601 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009602 } finally {
9603 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009604 }
9605 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009606
9607 /**
9608 * Get the current signal strength information for the given subscription.
9609 * Because this information is not updated when the device is in a low power state
9610 * it should not be relied-upon to be current.
9611 * @param subId Subscription index
9612 * @return the most recent cached signal strength info from the modem
9613 */
9614 @Override
9615 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009616 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9617 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009619 final long identity = Binder.clearCallingIdentity();
9620 try {
9621 Phone p = getPhone(subId);
9622 if (p == null) {
9623 return null;
9624 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009626 return p.getSignalStrength();
9627 } finally {
9628 Binder.restoreCallingIdentity(identity);
9629 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009630 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009631
Pengquan Meng77b7f132018-08-22 14:49:57 -07009632 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009633 * Get the current modem radio state for the given slot.
9634 * @param slotIndex slot index.
9635 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009636 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009637 * @return the current radio power state from the modem
9638 */
9639 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009640 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009641 Phone phone = PhoneFactory.getPhone(slotIndex);
9642 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009643 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9644 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009645 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9646 }
9647
joonhunshin4ac60942023-11-15 15:23:39 +00009648 enforceTelephonyFeatureWithException(callingPackage,
9649 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9650
Chen Xuf792fd62018-10-17 17:54:36 +00009651 final long identity = Binder.clearCallingIdentity();
9652 try {
9653 return phone.getRadioPowerState();
9654 } finally {
9655 Binder.restoreCallingIdentity(identity);
9656 }
9657 }
9658 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9659 }
9660
9661 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009662 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9663 *
9664 * <p>Requires one of the following permissions:
9665 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009666 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009667 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9668 * privileges.
9669 *
9670 * @param subId subscription id
9671 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9672 * {@code false}.
9673 */
9674 @Override
9675 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009676 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009677 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009678 try {
9679 mApp.enforceCallingOrSelfPermission(
9680 android.Manifest.permission.ACCESS_NETWORK_STATE,
9681 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009682 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009683 mApp.enforceCallingOrSelfPermission(
9684 permission.READ_BASIC_PHONE_STATE, functionName);
9685 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009686 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009687 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009688 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009689 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009690
joonhunshin4ac60942023-11-15 15:23:39 +00009691 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9692 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9693
Pengquan Menga1bb6272018-09-06 09:59:22 -07009694 boolean isEnabled = false;
9695 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009696 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009697 Phone phone = getPhone(subId);
9698 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009699 } finally {
9700 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009702 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009703 }
9704
9705
9706 /**
9707 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9708 *
9709 * <p> Requires permission:
9710 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9711 * privileges.
9712 *
9713 * @param subId subscription id
9714 * @param isEnabled {@code true} means enable, {@code false} means disable.
9715 */
9716 @Override
9717 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9719 mApp, subId, "setDataRoamingEnabled");
9720
joonhunshin4ac60942023-11-15 15:23:39 +00009721 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9722 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9723
Pengquan Menga1bb6272018-09-06 09:59:22 -07009724 final long identity = Binder.clearCallingIdentity();
9725 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009726 Phone phone = getPhone(subId);
9727 if (phone != null) {
9728 phone.setDataRoamingEnabled(isEnabled);
9729 }
9730 } finally {
9731 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009732 }
9733 }
9734
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009735 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009736 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009737 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009738 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009739 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009740
joonhunshin4ac60942023-11-15 15:23:39 +00009741 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9742 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9743
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009744 boolean isAllowed = true;
9745 final long identity = Binder.clearCallingIdentity();
9746 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009747 Phone phone = getPhone(subId);
9748 if (phone != null) {
9749 isAllowed = phone.isCspPlmnEnabled();
9750 }
9751 } finally {
9752 Binder.restoreCallingIdentity(identity);
9753 }
9754 return isAllowed;
9755 }
9756
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009757 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9758 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009759 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009760 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009761 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009762 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9763 if (phone == null) {
9764 return false;
9765 }
9766 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9767 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9768 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009769 }
9770
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009771 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009772 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009773 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009774 mApp.getSystemService(AppOpsManager.class)
9775 .checkPackage(Binder.getCallingUid(), callingPackage);
9776
Jordan Liu1e142fc2019-04-22 15:10:43 -07009777 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009778 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009779 try {
9780 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009781 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009782 } catch (SecurityException e) {
9783 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9784 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009785 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009786 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009787 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009788 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009789 }
joonhunshin4ac60942023-11-15 15:23:39 +00009790
9791 enforceTelephonyFeatureWithException(callingPackage,
9792 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9793
sandeepjsb6c87872021-09-27 15:34:44 +00009794 // checking compatibility, if calling app's target SDK is T and beyond.
9795 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9796 Binder.getCallingUid())) {
9797 isIccIdAccessRestricted = true;
9798 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009799 final long identity = Binder.clearCallingIdentity();
9800 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009801 UiccController uiccController = UiccController.getInstance();
9802 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009803 if (hasReadPermission) {
9804 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009805 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009806
9807 // Remove private info if the caller doesn't have access
9808 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9809 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009810 //setting the value after compatibility check
9811 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009812 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9813 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009814 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009815 if (card == null) {
9816 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009817 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009818 continue;
9819 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009820 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9821 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009822 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009823 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009824 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009825 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9826 for (UiccPortInfo portInfo : portInfos) {
9827 UiccPort port = uiccController.getUiccPortForSlot(
9828 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9829 if (port == null) {
9830 // assume no access if port is null
9831 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9832 continue;
9833 }
9834 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9835 uiccPortInfos.add(portInfo);
9836 } else {
9837 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9838 }
9839 }
9840 filteredInfos.add(new UiccCardInfo(
9841 cardInfo.isEuicc(),
9842 cardInfo.getCardId(),
9843 null,
9844 cardInfo.getPhysicalSlotIndex(),
9845 cardInfo.isRemovable(),
9846 cardInfo.isMultipleEnabledProfilesSupported(),
9847 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009848 }
9849 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009850 } finally {
9851 Binder.restoreCallingIdentity(identity);
9852 }
9853 }
9854
sandeepjsb6c87872021-09-27 15:34:44 +00009855 /**
9856 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9857 * generally private and require carrier privileges to view.
9858 *
9859 * @hide
9860 */
9861 @NonNull
9862 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9863 List<UiccPortInfo> portinfo = new ArrayList<>();
9864 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9865 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9866 }
9867 return new UiccCardInfo(
9868 cardInfo.isEuicc(),
9869 cardInfo.getCardId(),
9870 null,
9871 cardInfo.getPhysicalSlotIndex(),
9872 cardInfo.isRemovable(),
9873 cardInfo.isMultipleEnabledProfilesSupported(),
9874 portinfo
9875 );
9876 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009877
sandeepjsb6c87872021-09-27 15:34:44 +00009878 /**
9879 * @hide
9880 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9881 * These values are generally private and require carrier privileges to view.
9882 */
9883 @NonNull
9884 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9885 return new UiccPortInfo(
9886 UiccPortInfo.ICCID_REDACTED,
9887 portInfo.getPortIndex(),
9888 portInfo.getLogicalSlotIndex(),
9889 portInfo.isActive()
9890 );
9891 }
9892 @Override
9893 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009894 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009895 mApp.getSystemService(AppOpsManager.class)
9896 .checkPackage(Binder.getCallingUid(), callingPackage);
9897
sandeepjsb6c87872021-09-27 15:34:44 +00009898 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009899
Aman Guptaf3c90b32022-03-17 04:54:16 +00009900 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9901 // we are reading iccId which is PII data.
9902 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009903
joonhunshin4ac60942023-11-15 15:23:39 +00009904 enforceTelephonyFeatureWithException(callingPackage,
9905 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9906
sandeepjsb6c87872021-09-27 15:34:44 +00009907 // checking compatibility, if calling app's target SDK is T and beyond.
9908 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9909 Binder.getCallingUid())) {
9910 isLogicalSlotAccessRestricted = true;
9911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009912 final long identity = Binder.clearCallingIdentity();
9913 try {
9914 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009915 if (slots == null || slots.length == 0) {
9916 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009917 return null;
9918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009919 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9920 for (int i = 0; i < slots.length; i++) {
9921 UiccSlot slot = slots[i];
9922 if (slot == null) {
9923 continue;
9924 }
9925
Jordan Liu7be7e652019-05-06 18:55:02 +00009926 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009927 UiccCard card = slot.getUiccCard();
9928 if (card != null) {
9929 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009930 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009931 cardId = slot.getEid();
9932 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009933 // If cardId is null, use iccId of default port as cardId.
9934 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009936 }
9937
Jordan Liu857451f2019-05-09 16:35:35 -07009938 if (cardId != null) {
9939 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9940 // if cardId is an EID, it's all digits so this is fine
9941 cardId = IccUtils.stripTrailingFs(cardId);
9942 }
9943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009944 int cardState = 0;
9945 switch (slot.getCardState()) {
9946 case CARDSTATE_ABSENT:
9947 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9948 break;
9949 case CARDSTATE_PRESENT:
9950 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9951 break;
9952 case CARDSTATE_ERROR:
9953 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9954 break;
9955 case CARDSTATE_RESTRICTED:
9956 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9957 break;
9958 default:
9959 break;
9960
9961 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009962 List<UiccPortInfo> portInfos = new ArrayList<>();
9963 int[] portIndexes = slot.getPortList();
9964 for (int portIdx : portIndexes) {
9965 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009966 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009967 portInfos.add(new UiccPortInfo(iccId, portIdx,
9968 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009970 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009971 slot.isEuicc(),
9972 cardId,
9973 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009974 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009975 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009976 //setting the value after compatibility check
9977 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009978 }
9979 return infos;
9980 } finally {
9981 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009982 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009983 }
9984
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009985 /* Returns null if doesn't have read permission or carrier privilege access. */
9986 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9987 boolean hasReadPermission) {
9988 String iccId = slot.getIccId(portIndex);
9989 if (hasReadPermission) { // if has read permission
9990 return iccId;
9991 } else {
9992 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9993 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9994 // if no read permission, checking carrier privilege access
9995 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9996 return iccId;
9997 }
9998 }
9999 }
10000 // No read permission or carrier privilege access.
10001 return UiccPortInfo.ICCID_REDACTED;
10002 }
10003
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010004 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010005 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010006 public boolean switchSlots(int[] physicalSlots) {
10007 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010008
joonhunshin4ac60942023-11-15 15:23:39 +000010009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10010 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10011
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010012 final long identity = Binder.clearCallingIdentity();
10013 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010014 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10015 for (int i = 0; i < physicalSlots.length; i++) {
10016 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10017 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10018 physicalSlots[i], i));
10019 }
10020 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010024 }
Jack Yu4c988042018-02-27 15:30:01 -080010025
10026 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010027 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10028 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10029 enforceModifyPermission();
10030
joonhunshin4ac60942023-11-15 15:23:39 +000010031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10032 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10033
sandeepjsb6c87872021-09-27 15:34:44 +000010034 final long identity = Binder.clearCallingIdentity();
10035 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010036 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010037 } finally {
10038 Binder.restoreCallingIdentity(identity);
10039 }
10040 }
10041
10042 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010043 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010044 enforceTelephonyFeatureWithException(callingPackage,
10045 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10046
Jordan Liu7de49fa2018-12-06 14:48:49 -080010047 final long identity = Binder.clearCallingIdentity();
10048 try {
10049 return UiccController.getInstance().getCardIdForDefaultEuicc();
10050 } finally {
10051 Binder.restoreCallingIdentity(identity);
10052 }
10053 }
10054
Pengquan Meng85728fb2018-03-12 16:31:21 -070010055 /**
goneil47ffb6e2018-04-06 15:40:58 -070010056 * A test API to reload the UICC profile.
10057 *
10058 * <p>Requires that the calling app has permission
10059 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10060 * @hide
10061 */
10062 @Override
10063 public void refreshUiccProfile(int subId) {
10064 enforceModifyPermission();
10065
10066 final long identity = Binder.clearCallingIdentity();
10067 try {
10068 Phone phone = getPhone(subId);
10069 if (phone == null) {
10070 return;
10071 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010072 UiccPort uiccPort = phone.getUiccPort();
10073 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010074 return;
10075 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010076 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010077 if (uiccProfile == null) {
10078 return;
10079 }
10080 uiccProfile.refresh();
10081 } finally {
10082 Binder.restoreCallingIdentity(identity);
10083 }
10084 }
10085
10086 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010087 * Returns false if the mobile data is disabled by default, otherwise return true.
10088 */
10089 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010090 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010091 }
10092
10093 /**
10094 * Returns true if the data roaming is enabled by default, i.e the system property
10095 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10096 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10097 */
10098 private boolean getDefaultDataRoamingEnabled(int subId) {
10099 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010100 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010101 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010102 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10103 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10104 return isDataRoamingEnabled;
10105 }
10106
10107 /**
10108 * Returns the default network type for the given {@code subId}, if the default network type is
10109 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10110 */
10111 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010112 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010113 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010114 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10115 return list.get(phoneId);
10116 }
10117 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010118 }
fionaxua13278b2018-03-21 00:08:13 -070010119
10120 @Override
10121 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010122 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010123 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010124
10125 final long identity = Binder.clearCallingIdentity();
10126 try {
10127 final Phone phone = getPhone(subId);
10128 if (phone == null) {
10129 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10130 return;
10131 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010132 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10133 if (cpt != null) {
10134 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10135 }
10136 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010137 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10138 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010139 if (carrierPrivilegeRules == null) {
10140 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10141 } else {
10142 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10143 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010144 } finally {
10145 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010146 }
fionaxua13278b2018-03-21 00:08:13 -070010147 }
10148
10149 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010150 public void setCarrierServicePackageOverride(
10151 int subId, String carrierServicePackage, String callingPackage) {
10152 TelephonyPermissions.enforceShellOnly(
10153 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10154
Benedict Wong66477622023-02-03 23:30:57 +000010155 final long identity = Binder.clearCallingIdentity();
10156 try {
10157 final Phone phone = getPhone(subId);
10158 if (phone == null || phone.getSubId() != subId) {
10159 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10160 throw new IllegalArgumentException("No phone for subid");
10161 }
10162 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10163 if (cpt == null) {
10164 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10165 throw new IllegalStateException("No CPT for phone");
10166 }
10167 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10168 } finally {
10169 Binder.restoreCallingIdentity(identity);
10170 }
10171 }
10172
10173 @Override
fionaxua13278b2018-03-21 00:08:13 -070010174 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010175 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010176
10177 final long identity = Binder.clearCallingIdentity();
10178 try {
10179 final Phone phone = getPhone(subId);
10180 if (phone == null) {
10181 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10182 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10183 }
10184 return phone.getCarrierIdListVersion();
10185 } finally {
10186 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010187 }
fionaxua13278b2018-03-21 00:08:13 -070010188 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010189
10190 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010191 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10192 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010194 mApp, subId, callingPackage, callingFeatureId,
10195 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010196 return -1;
10197 }
10198
10199 final long identity = Binder.clearCallingIdentity();
10200 try {
10201 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10202 } finally {
10203 Binder.restoreCallingIdentity(identity);
10204 }
10205 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010206
10207 @Override
10208 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010209 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010210 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010211 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010212
joonhunshin4ac60942023-11-15 15:23:39 +000010213 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10214 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10215
Pengquan Menga1bb6272018-09-06 09:59:22 -070010216 final long identity = Binder.clearCallingIdentity();
10217 try {
10218 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222 }
10223
10224 @Override
10225 public boolean setCdmaRoamingMode(int subId, int mode) {
10226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10227 mApp, subId, "setCdmaRoamingMode");
10228
joonhunshin4ac60942023-11-15 15:23:39 +000010229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10230 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10231
Pengquan Menga1bb6272018-09-06 09:59:22 -070010232 final long identity = Binder.clearCallingIdentity();
10233 try {
10234 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10235 } finally {
10236 Binder.restoreCallingIdentity(identity);
10237 }
10238 }
10239
10240 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010241 public int getCdmaSubscriptionMode(int subId) {
10242 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010243 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010244 mApp, subId, "getCdmaSubscriptionMode");
10245
joonhunshin4ac60942023-11-15 15:23:39 +000010246 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10247 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10248
Sarah Chinbaab1432020-10-28 13:46:24 -070010249 final long identity = Binder.clearCallingIdentity();
10250 try {
10251 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10252 } finally {
10253 Binder.restoreCallingIdentity(identity);
10254 }
10255 }
10256
10257 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010258 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10260 mApp, subId, "setCdmaSubscriptionMode");
10261
joonhunshin4ac60942023-11-15 15:23:39 +000010262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10263 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10264
Pengquan Menga1bb6272018-09-06 09:59:22 -070010265 final long identity = Binder.clearCallingIdentity();
10266 try {
10267 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010272
sqianc5eccab2018-10-19 18:46:41 -070010273 @Override
sqian8c685422019-02-22 15:55:18 -080010274 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010275 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010277 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10278 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010279 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10280 }
joonhunshin4ac60942023-11-15 15:23:39 +000010281
10282 enforceTelephonyFeatureWithException(callingPackage,
10283 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10284
sqian11b7a0e2018-12-05 18:48:28 -080010285 final long identity = Binder.clearCallingIdentity();
10286 try {
sqian854d44b2018-12-12 16:48:18 -080010287 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10288 for (Phone phone: PhoneFactory.getPhones()) {
10289 if (phone.getEmergencyNumberTracker() != null
10290 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10291 emergencyNumberListInternal.put(
10292 phone.getSubId(),
10293 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10294 }
sqian11b7a0e2018-12-05 18:48:28 -080010295 }
sqian854d44b2018-12-12 16:48:18 -080010296 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010297 } finally {
10298 Binder.restoreCallingIdentity(identity);
10299 }
sqianc5eccab2018-10-19 18:46:41 -070010300 }
10301
10302 @Override
sqian8c685422019-02-22 15:55:18 -080010303 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010304 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010305 if (!exactMatch) {
10306 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010307 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010308 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010309 }
joonhunshin4ac60942023-11-15 15:23:39 +000010310
10311 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10312 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10313
sqian11b7a0e2018-12-05 18:48:28 -080010314 final long identity = Binder.clearCallingIdentity();
10315 try {
sqian854d44b2018-12-12 16:48:18 -080010316 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010317 //Note: we ignore passed in param exactMatch. We can remove it once
10318 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010319 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010320 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010321 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010322 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010323 }
sqian11b7a0e2018-12-05 18:48:28 -080010324 }
10325 return false;
10326 } finally {
10327 Binder.restoreCallingIdentity(identity);
10328 }
10329 }
10330
sqianf4ca7ed2019-01-15 18:32:07 -080010331 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010332 * Start emergency callback mode for GsmCdmaPhone for testing.
10333 */
10334 @Override
10335 public void startEmergencyCallbackMode() {
10336 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10337 "startEmergencyCallbackMode");
10338 enforceModifyPermission();
10339 final long identity = Binder.clearCallingIdentity();
10340 try {
10341 for (Phone phone : PhoneFactory.getPhones()) {
10342 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10343 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10344 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10345 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10346 gsmCdmaPhone.obtainMessage(
10347 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10348 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10349 }
10350 }
10351 } finally {
10352 Binder.restoreCallingIdentity(identity);
10353 }
10354 }
10355
10356 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010357 * Update emergency number list for test mode.
10358 */
10359 @Override
10360 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10361 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10362 "updateEmergencyNumberListTestMode");
10363
10364 final long identity = Binder.clearCallingIdentity();
10365 try {
10366 for (Phone phone: PhoneFactory.getPhones()) {
10367 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10368 if (tracker != null) {
10369 tracker.executeEmergencyNumberTestModeCommand(action, num);
10370 }
10371 }
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 }
10376
10377 /**
10378 * Get the full emergency number list for test mode.
10379 */
10380 @Override
10381 public List<String> getEmergencyNumberListTestMode() {
10382 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10383 "getEmergencyNumberListTestMode");
10384
10385 final long identity = Binder.clearCallingIdentity();
10386 try {
10387 Set<String> emergencyNumbers = new HashSet<>();
10388 for (Phone phone: PhoneFactory.getPhones()) {
10389 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10390 if (tracker != null) {
10391 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10392 emergencyNumbers.add(num.getNumber());
10393 }
10394 }
10395 }
10396 return new ArrayList<>(emergencyNumbers);
10397 } finally {
10398 Binder.restoreCallingIdentity(identity);
10399 }
10400 }
10401
chen xud6b45bd2018-10-30 22:27:10 -070010402 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010403 public int getEmergencyNumberDbVersion(int subId) {
10404 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10405
joonhunshin4ac60942023-11-15 15:23:39 +000010406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10407 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10408
Shuo Qian3b6ee772019-11-13 17:43:31 -080010409 final long identity = Binder.clearCallingIdentity();
10410 try {
10411 final Phone phone = getPhone(subId);
10412 if (phone == null) {
10413 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10414 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10415 }
10416 return phone.getEmergencyNumberDbVersion();
10417 } finally {
10418 Binder.restoreCallingIdentity(identity);
10419 }
10420 }
10421
10422 @Override
10423 public void notifyOtaEmergencyNumberDbInstalled() {
10424 enforceModifyPermission();
10425
joonhunshin4ac60942023-11-15 15:23:39 +000010426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10427 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10428
Shuo Qian3b6ee772019-11-13 17:43:31 -080010429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 for (Phone phone: PhoneFactory.getPhones()) {
10432 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10433 if (tracker != null) {
10434 tracker.updateOtaEmergencyNumberDatabase();
10435 }
10436 }
10437 } finally {
10438 Binder.restoreCallingIdentity(identity);
10439 }
10440 }
10441
10442 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010443 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010444 enforceActiveEmergencySessionPermission();
10445
joonhunshin4ac60942023-11-15 15:23:39 +000010446 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10447 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10448
Shuo Qian3b6ee772019-11-13 17:43:31 -080010449 final long identity = Binder.clearCallingIdentity();
10450 try {
10451 for (Phone phone: PhoneFactory.getPhones()) {
10452 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10453 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010454 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10455 }
10456 }
10457 } finally {
10458 Binder.restoreCallingIdentity(identity);
10459 }
10460 }
10461
10462 @Override
10463 public void resetOtaEmergencyNumberDbFilePath() {
10464 enforceActiveEmergencySessionPermission();
10465
joonhunshin4ac60942023-11-15 15:23:39 +000010466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10467 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10468
Shuo Qianc373f112020-03-05 17:55:34 -080010469 final long identity = Binder.clearCallingIdentity();
10470 try {
10471 for (Phone phone: PhoneFactory.getPhones()) {
10472 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10473 if (tracker != null) {
10474 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010475 }
10476 }
10477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
10481
10482 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010483 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10484 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10485 Phone phone = getPhone(subId);
10486 if (phone == null) {
10487 return null;
10488 }
10489 final long identity = Binder.clearCallingIdentity();
10490 try {
10491 UiccProfile profile = UiccController.getInstance()
10492 .getUiccProfileForPhone(phone.getPhoneId());
10493 if (profile != null) {
10494 return profile.getCertsFromCarrierPrivilegeAccessRules();
10495 }
10496 } finally {
10497 Binder.restoreCallingIdentity(identity);
10498 }
10499 return null;
10500 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010501
10502 /**
10503 * Enable or disable a modem stack.
10504 */
10505 @Override
10506 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10507 enforceModifyPermission();
10508
joonhunshin4ac60942023-11-15 15:23:39 +000010509 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10510 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10511
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010512 final long identity = Binder.clearCallingIdentity();
10513 try {
10514 Phone phone = PhoneFactory.getPhone(slotIndex);
10515 if (phone == null) {
10516 return false;
10517 } else {
10518 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10519 }
10520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
Michelecea4cf22018-12-21 15:00:11 -080010524
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010525 /**
10526 * Whether a modem stack is enabled or not.
10527 */
10528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010529 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10530 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010531 Phone phone = PhoneFactory.getPhone(slotIndex);
10532 if (phone == null) return false;
10533
10534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010535 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10536 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010537 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10538 }
10539
joonhunshin4ac60942023-11-15 15:23:39 +000010540 enforceTelephonyFeatureWithException(callingPackage,
10541 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10542
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010543 final long identity = Binder.clearCallingIdentity();
10544 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010545 try {
10546 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10547 } catch (NoSuchElementException ex) {
10548 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10549 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010550 } finally {
10551 Binder.restoreCallingIdentity(identity);
10552 }
10553 }
10554
Michelecea4cf22018-12-21 15:00:11 -080010555 @Override
Michele0ea7d782019-03-19 14:58:42 -070010556 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010557 enforceModifyPermission();
10558
joonhunshin4ac60942023-11-15 15:23:39 +000010559 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10560 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10561
Michelecea4cf22018-12-21 15:00:11 -080010562 final long identity = Binder.clearCallingIdentity();
10563 try {
10564 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010565 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010566 .commit();
10567 } finally {
10568 Binder.restoreCallingIdentity(identity);
10569 }
10570 }
10571
10572 @Override
Michele0ea7d782019-03-19 14:58:42 -070010573 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010574 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010576 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10577 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010578 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010579 }
Michelecea4cf22018-12-21 15:00:11 -080010580
joonhunshin4ac60942023-11-15 15:23:39 +000010581 enforceTelephonyFeatureWithException(callingPackage,
10582 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10583
Michelecea4cf22018-12-21 15:00:11 -080010584 final long identity = Binder.clearCallingIdentity();
10585 try {
Michele0ea7d782019-03-19 14:58:42 -070010586 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010587 } finally {
10588 Binder.restoreCallingIdentity(identity);
10589 }
10590 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010591
Michele0ea7d782019-03-19 14:58:42 -070010592 @TelephonyManager.IsMultiSimSupportedResult
10593 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010594 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10595 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10596 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010597 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10598 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010599 }
10600 // Check if the hardware supports multisim functionality. If usage of multisim is not
10601 // supported by the modem, indicate that it is restricted.
10602 PhoneCapability staticCapability =
10603 mPhoneConfigurationManager.getStaticPhoneCapability();
10604 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010605 loge("isMultiSimSupportedInternal: no static configuration available");
10606 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010607 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010608 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010609 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10610 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010611 }
10612 // Check if support of multiple SIMs is restricted by carrier
10613 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010615 }
10616
Michele0ea7d782019-03-19 14:58:42 -070010617 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010618 }
10619
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010620 /**
10621 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010622 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10623 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10624 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010625 * @param numOfSims number of active sims we want to switch to
10626 */
10627 @Override
10628 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010629 if (numOfSims == 1) {
10630 enforceModifyPermission();
10631 } else {
10632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10633 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10634 }
joonhunshin4ac60942023-11-15 15:23:39 +000010635
10636 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10637 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10638
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010639 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010640
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010641 try {
Michele30b57b22019-03-01 12:01:14 -080010642 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010643 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010644 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10645 return;
10646 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010647 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10648 } finally {
10649 Binder.restoreCallingIdentity(identity);
10650 }
10651 }
10652
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010653 @Override
10654 public boolean isApplicationOnUicc(int subId, int appType) {
10655 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010656
10657 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10658 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10659
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010660 Phone phone = getPhone(subId);
10661 if (phone == null) {
10662 return false;
10663 }
10664 final long identity = Binder.clearCallingIdentity();
10665 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010666 UiccPort uiccPort = phone.getUiccPort();
10667 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010668 return false;
10669 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010670 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010671 if (uiccProfile == null) {
10672 return false;
10673 }
10674 if (TelephonyManager.APPTYPE_SIM <= appType
10675 && appType <= TelephonyManager.APPTYPE_ISIM) {
10676 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10677 }
10678 return false;
10679 } finally {
10680 Binder.restoreCallingIdentity(identity);
10681 }
10682 }
10683
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010684 /**
chen xub4baa772019-04-03 10:23:41 -070010685 * Get whether making changes to modem configurations will trigger reboot.
10686 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010687 */
10688 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010689 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10690 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010692 mApp, subId, callingPackage, callingFeatureId,
10693 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010694 return false;
10695 }
joonhunshin4ac60942023-11-15 15:23:39 +000010696
10697 enforceTelephonyFeatureWithException(callingPackage,
10698 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10699 "doesSwitchMultiSimConfigTriggerReboot");
10700
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010701 final long identity = Binder.clearCallingIdentity();
10702 try {
10703 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10704 } finally {
10705 Binder.restoreCallingIdentity(identity);
10706 }
10707 }
10708
Nathan Harold29f5f052019-02-15 13:41:57 -080010709 private void updateModemStateMetrics() {
10710 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10711 // TODO: check the state for each modem if the api is ready.
10712 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10713 }
10714
Pengquan Meng3889a572019-01-23 11:16:29 -080010715 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010716 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010717 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010718 // Verify that the callingPackage belongs to the calling UID
10719 mApp.getSystemService(AppOpsManager.class)
10720 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010721
10722 enforceTelephonyFeatureWithException(callingPackage,
10723 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10724
Pengquan Meng3889a572019-01-23 11:16:29 -080010725 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010726 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010727 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010728 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10729 if (slotInfos != null) {
10730 for (int i = 0; i < slotInfos.length; i++) {
10731 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10732 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10733 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10734 portInfo.getLogicalSlotIndex()));
10735 }
10736 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010737 }
10738 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010739 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010740 } finally {
10741 Binder.restoreCallingIdentity(identity);
10742 }
10743 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010744
10745 /**
10746 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010747 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010748 */
jimsunf9ec1622022-09-13 21:18:43 +080010749 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010750 @Override
10751 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010752 return getHalVersion(HAL_SERVICE_RADIO);
10753 }
10754
10755 /**
10756 * Get the HAL Version of a specific service
10757 */
10758 @Override
10759 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010760 Phone phone = getDefaultPhone();
10761 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010762 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010763 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10764 return hv.major * 100 + hv.minor;
10765 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010766
10767 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010768 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010769 *
10770 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010771 */
10772 @Override
sangyun097dcf72024-01-04 10:35:49 +090010773 public @Nullable String getCurrentPackageName() {
10774 PackageManager pm = mApp.getPackageManager();
10775 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10776 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010777 }
10778
10779 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010780 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10781 * corresponding network requests on a subId.
10782 *
10783 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010784 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010785 * 2) APN is un-metered for this subscription, or
10786 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010787 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010788 *
10789 * @return whether data is allowed for a apn type.
10790 *
10791 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010792 */
10793 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010794 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010795 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10796 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010797
joonhunshin4ac60942023-11-15 15:23:39 +000010798 enforceTelephonyFeatureWithException(callingPackage,
10799 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10800
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010801 // Now that all security checks passes, perform the operation as ourselves.
10802 final long identity = Binder.clearCallingIdentity();
10803 try {
10804 Phone phone = getPhone(subId);
10805 if (phone == null) return false;
10806
Jack Yu27422a52022-03-21 10:38:05 -070010807 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010808 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010809 isMetered = phone.getDataNetworkController().getDataConfigManager()
10810 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10811 phone.getServiceState().getDataRoaming());
10812 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010813 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010814 } finally {
10815 Binder.restoreCallingIdentity(identity);
10816 }
10817 }
10818
10819 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010820 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010821 enforceReadPrivilegedPermission("isApnMetered");
10822
joonhunshin4ac60942023-11-15 15:23:39 +000010823 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10824 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10825
Malcolm Chene5ad5792019-04-18 13:51:02 -070010826 // Now that all security checks passes, perform the operation as ourselves.
10827 final long identity = Binder.clearCallingIdentity();
10828 try {
10829 Phone phone = getPhone(subId);
10830 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010831 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10832 DataUtils.apnTypeToNetworkCapability(apnType),
10833 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010834 } finally {
10835 Binder.restoreCallingIdentity(identity);
10836 }
10837 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010838
10839 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010840 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10841 int subscriptionId, IBooleanConsumer resultCallback) {
10842 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010843
10844 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10845 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10846
Hall Liu73f5d362020-01-20 13:42:00 -080010847 long token = Binder.clearCallingIdentity();
10848 try {
10849 Phone phone = getPhone(subscriptionId);
10850 if (phone == null) {
10851 try {
10852 if (resultCallback != null) {
10853 resultCallback.accept(false);
10854 }
10855 } catch (RemoteException e) {
10856 // ignore
10857 }
10858 return;
10859 }
10860 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10861 Pair.create(specifiers, (x) -> {
10862 try {
10863 if (resultCallback != null) {
10864 resultCallback.accept(x);
10865 }
10866 } catch (RemoteException e) {
10867 // ignore
10868 }
10869 });
10870 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10871 } finally {
10872 Binder.restoreCallingIdentity(token);
10873 }
10874 }
10875
10876 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010877 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10878 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010879 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010880 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010881
10882 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10883 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10884
Sarah Chin679c08a2020-11-18 13:39:35 -080010885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10886 final long identity = Binder.clearCallingIdentity();
10887 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010888 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10889 if (result instanceof IllegalStateException) {
10890 throw (IllegalStateException) result;
10891 }
10892 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010893 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10894 return specifiers;
10895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
10899
10900 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010901 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010902 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010903
10904 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10905 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10906
Jack Yu8b766fc2022-03-21 09:42:33 -070010907 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010908 }
10909
10910 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010911 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10912 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010913 if (callingPackage == null) {
10914 callingPackage = getCurrentPackageName();
10915 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010916 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10917 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010918 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10919 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010920 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10921 }
10922 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10923 Intent intent = new Intent();
10924 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10925 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10926 // Bring up choose default SMS subscription dialog right now
10927 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10928 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10929 mApp.startActivity(intent);
10930 }
chen xud5ca2d52019-05-28 15:20:57 -070010931
10932 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010933 public void showSwitchToManagedProfileDialog() {
10934 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010935 try {
10936 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10937 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10938 // for work telephony.
10939 Intent intent = new Intent(Intent.ACTION_SENDTO);
10940 intent.setData(Uri.parse("smsto:"));
10941 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10942 mApp.startActivity(intent);
10943 } catch (ActivityNotFoundException e) {
10944 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10945 Intent intent = new Intent();
10946 intent.setClass(mApp, ErrorDialogActivity.class);
10947 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10948 mApp.startActivity(intent);
10949 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010950 }
10951
10952 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010953 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10955 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10956
chen xud5ca2d52019-05-28 15:20:57 -070010957 //TODO investigate if this API should require proper permission check in R b/133791609
10958 final long identity = Binder.clearCallingIdentity();
10959 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010960 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10961 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10962 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10963 return carrierUAProfUrl;
10964 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010965 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10966 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
10972 @Override
10973 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010974 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10975 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10976
chen xud5ca2d52019-05-28 15:20:57 -070010977 //TODO investigate if this API should require proper permission check in R b/133791609
10978 final long identity = Binder.clearCallingIdentity();
10979 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010980 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10981 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10982 if (!TextUtils.isEmpty(carrierUserAgent)) {
10983 return carrierUserAgent;
10984 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010985 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10986 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010987 } finally {
10988 Binder.restoreCallingIdentity(identity);
10989 }
10990 }
Jack Yub07d4972019-05-28 16:12:25 -070010991
10992 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010993 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10994 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010995
joonhunshin4ac60942023-11-15 15:23:39 +000010996 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10997 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
10998
Jack Yub07d4972019-05-28 16:12:25 -070010999 final long identity = Binder.clearCallingIdentity();
11000 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011001 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011002 if (phone == null) return false;
11003
Ling Maf188d502022-09-16 15:22:36 -070011004 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011005 } finally {
11006 Binder.restoreCallingIdentity(identity);
11007 }
11008 }
11009
11010 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011011 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011012 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011013 enforceModifyPermission();
11014
joonhunshin4ac60942023-11-15 15:23:39 +000011015 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11016 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11017
changbettyd5c246e2019-12-24 15:40:37 +080011018 final long identity = Binder.clearCallingIdentity();
11019 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011020 Phone phone = getPhone(subscriptionId);
11021 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011022
Ling Maf188d502022-09-16 15:22:36 -070011023 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011024 } finally {
11025 Binder.restoreCallingIdentity(identity);
11026 }
11027 }
11028
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011029 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011030 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011031 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11032 * otherwise.
11033 */
11034 @Override
11035 public void setCepEnabled(boolean isCepEnabled) {
11036 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11037
11038 final long identity = Binder.clearCallingIdentity();
11039 try {
11040 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11041 for (Phone phone : PhoneFactory.getPhones()) {
11042 Phone defaultPhone = phone.getImsPhone();
11043 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11044 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11045 ImsPhoneCallTracker imsPhoneCallTracker =
11046 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11047 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11048 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11049 + imsPhone.getMsisdn());
11050 }
11051 }
11052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
allenwtsu46dcc572020-01-08 18:24:03 +080011056
11057 /**
11058 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11059 *
11060 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11061 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11062 * before being read.
11063 */
11064 @Override
11065 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11066 isCompressed) {
11067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11068 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011069 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11070 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11071 }
joonhunshin4ac60942023-11-15 15:23:39 +000011072
11073 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11074 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11075 Binder.getCallingUserHandle())) {
11076 if (!isImsAvailableOnDevice()) {
11077 // ProvisioningManager can not handle ServiceSpecificException.
11078 // Throw the IllegalStateException and annotate ProvisioningManager.
11079 throw new IllegalStateException("IMS not available on device.");
11080 }
11081 } else {
11082 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11083 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11084 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011085 }
11086
11087 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011088 try {
Hui Wang761a6682020-10-31 05:12:53 +000011089 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011092 }
11093 }
zoey chene02881a2019-12-30 16:11:23 +080011094
11095 @Override
11096 public boolean isIccLockEnabled(int subId) {
11097 enforceReadPrivilegedPermission("isIccLockEnabled");
11098
joonhunshin4ac60942023-11-15 15:23:39 +000011099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11100 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11101
zoey chene02881a2019-12-30 16:11:23 +080011102 // Now that all security checks passes, perform the operation as ourselves.
11103 final long identity = Binder.clearCallingIdentity();
11104 try {
11105 Phone phone = getPhone(subId);
11106 if (phone != null && phone.getIccCard() != null) {
11107 return phone.getIccCard().getIccLockEnabled();
11108 } else {
11109 return false;
11110 }
11111 } finally {
11112 Binder.restoreCallingIdentity(identity);
11113 }
11114 }
11115
11116 /**
11117 * Set the ICC pin lock enabled or disabled.
11118 *
11119 * @return an integer representing the status of IccLock enabled or disabled in the following
11120 * three cases:
11121 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11122 * successfully.
11123 * - Positive number and zero for remaining password attempts.
11124 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11125 *
11126 */
11127 @Override
11128 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11129 enforceModifyPermission();
11130
joonhunshin4ac60942023-11-15 15:23:39 +000011131 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11132 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11133
zoey chene02881a2019-12-30 16:11:23 +080011134 Phone phone = getPhone(subId);
11135 if (phone == null) {
11136 return 0;
11137 }
11138 // Now that all security checks passes, perform the operation as ourselves.
11139 final long identity = Binder.clearCallingIdentity();
11140 try {
11141 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11142 new Pair<Boolean, String>(enabled, password), phone, null);
11143 return attemptsRemaining;
11144
11145 } catch (Exception e) {
11146 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11147 } finally {
11148 Binder.restoreCallingIdentity(identity);
11149 }
11150 return 0;
11151 }
11152
11153 /**
11154 * Change the ICC password used in ICC pin lock.
11155 *
11156 * @return an integer representing the status of IccLock changed in the following three cases:
11157 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11158 * - Positive number and zero for remaining password attempts.
11159 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11160 *
11161 */
11162 @Override
11163 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11164 enforceModifyPermission();
11165
joonhunshin4ac60942023-11-15 15:23:39 +000011166 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11167 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11168
zoey chene02881a2019-12-30 16:11:23 +080011169 Phone phone = getPhone(subId);
11170 if (phone == null) {
11171 return 0;
11172 }
11173 // Now that all security checks passes, perform the operation as ourselves.
11174 final long identity = Binder.clearCallingIdentity();
11175 try {
11176 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11177 new Pair<String, String>(oldPassword, newPassword), phone, null);
11178 return attemptsRemaining;
11179
11180 } catch (Exception e) {
11181 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11182 } finally {
11183 Binder.restoreCallingIdentity(identity);
11184 }
11185 return 0;
11186 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011187
11188 /**
11189 * Request for receiving user activity notification
11190 */
11191 @Override
11192 public void requestUserActivityNotification() {
11193 if (!mNotifyUserActivity.get()
11194 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11195 mNotifyUserActivity.set(true);
11196 }
11197 }
11198
11199 /**
11200 * Called when userActivity is signalled in the power manager.
11201 * This is safe to call from any thread, with any window manager locks held or not.
11202 */
11203 @Override
11204 public void userActivity() {
11205 // ***************************************
11206 // * Inherited from PhoneWindowManager *
11207 // ***************************************
11208 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11209 // WITH ITS LOCKS HELD.
11210 //
11211 // This code must be VERY careful about the locks
11212 // it acquires.
11213 // In fact, the current code acquires way too many,
11214 // and probably has lurking deadlocks.
11215
11216 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11217 throw new SecurityException("Only the OS may call notifyUserActivity()");
11218 }
11219
11220 if (mNotifyUserActivity.getAndSet(false)) {
11221 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11222 USER_ACTIVITY_NOTIFICATION_DELAY);
11223 }
11224 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011225
11226 @Override
11227 public boolean canConnectTo5GInDsdsMode() {
11228 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11229 }
Jack Yud10cdd42020-09-28 20:28:01 -070011230
11231 @Override
11232 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11233 String callingFeatureId) {
11234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11235 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11236 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11237 }
11238
joonhunshin4ac60942023-11-15 15:23:39 +000011239 enforceTelephonyFeatureWithException(callingPackage,
11240 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11241
Jack Yud10cdd42020-09-28 20:28:01 -070011242 Phone phone = getPhone(subId);
11243 if (phone == null) {
11244 throw new RuntimeException("phone is not available");
11245 }
11246 // Now that all security checks passes, perform the operation as ourselves.
11247 final long identity = Binder.clearCallingIdentity();
11248 try {
11249 return phone.getEquivalentHomePlmns();
11250 } finally {
11251 Binder.restoreCallingIdentity(identity);
11252 }
11253 }
Daniel Bright59e67312020-11-13 11:49:37 -080011254
11255 @Override
11256 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011257 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011258 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11259 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11260 "isRadioInterfaceCapabilitySupported");
11261
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011262 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011263 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011264 if (radioInterfaceCapabilities == null) {
11265 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011266 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011267 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011268 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011269
Hui Wang641e81c2020-10-12 12:14:23 -070011270 @Override
11271 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11272 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011273 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11274 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11275 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11276 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11277 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011278
11279 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11280 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11281
Hui Wang641e81c2020-10-12 12:14:23 -070011282 if (DBG) {
11283 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11284 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11285 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11286 }
11287
11288 if (!SubscriptionManager.isValidSubscriptionId(subId)
11289 || appType < TelephonyManager.APPTYPE_UNKNOWN
11290 || appType > TelephonyManager.APPTYPE_ISIM
11291 || nafUrl == null || securityProtocol == null || callback == null) {
11292 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11293 if (callback != null) {
11294 try {
11295 callback.onAuthenticationFailure(
11296 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11297 } catch (RemoteException exception) {
11298 log("Fail to notify onAuthenticationFailure due to " + exception);
11299 }
11300 return;
11301 }
11302 }
11303
11304 final long token = Binder.clearCallingIdentity();
11305 try {
11306 getGbaManager(subId).bootstrapAuthenticationRequest(
11307 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011308 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011309 } finally {
11310 Binder.restoreCallingIdentity(token);
11311 }
11312 }
11313
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011314 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011315 * Attempts to set the radio power state for all phones for thermal reason.
11316 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011317 * requested radio power state will actually be set. See {@link
11318 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11319 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011320 * @param enable {@code true} if trying to turn radio on.
11321 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11322 * false}.
11323 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011324 private boolean setRadioPowerForThermal(boolean enable) {
11325 boolean isPhoneAvailable = false;
11326 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11327 Phone phone = PhoneFactory.getPhone(i);
11328 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011329 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011330 isPhoneAvailable = true;
11331 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011332 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011333
11334 // return true if successfully informed the phone object about the thermal radio power
11335 // request.
11336 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011337 }
11338
11339 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011340 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011341 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11342 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11343 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11344 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11345 throw new IllegalArgumentException("modem does not support data throttling");
11346 }
11347
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011348 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11349 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011350 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011351 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11352 }
11353
Sarah Chinecc78c42022-03-31 21:16:48 -070011354 setDataEnabledForReason(
11355 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011356
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011357 if (isDataThrottlingSupported) {
11358 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011359 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011360 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11361 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11362 } else if (thermalMitigationResult
11363 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011364 log("Modem likely does not support data throttling on secondary carrier. Data " +
11365 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11366 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011367 }
11368 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011369 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011370
11371 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011372 }
11373
Jack Nudelman644b91a2021-03-12 14:09:48 -080011374 private static List<String> getThermalMitigationAllowlist(Context context) {
11375 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11376 for (String pckg : context.getResources()
11377 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11378 sThermalMitigationAllowlistedPackages.add(pckg);
11379 }
11380 }
11381
11382 return sThermalMitigationAllowlistedPackages;
11383 }
11384
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011385 private boolean isAnyPhoneInEmergencyState() {
11386 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11387 if (tm.isInEmergencyCall()) {
11388 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11389 return true;
11390 }
11391 for (Phone phone : PhoneFactory.getPhones()) {
11392 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11393 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011394 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11395 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011396 return true;
11397 }
11398 }
11399
11400 return false;
11401 }
11402
Jack Nudelman644b91a2021-03-12 14:09:48 -080011403 /**
11404 * Used by shell commands to add an authorized package name for thermal mitigation.
11405 * @param packageName name of package to be allowlisted
11406 * @param context
11407 */
11408 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11409 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11410 sThermalMitigationAllowlistedPackages.add(packageName);
11411 }
11412
11413 /**
11414 * Used by shell commands to remove an authorized package name for thermal mitigation.
11415 * @param packageName name of package to remove from allowlist
11416 * @param context
11417 */
11418 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11419 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11420 sThermalMitigationAllowlistedPackages.remove(packageName);
11421 }
11422
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011423 /**
11424 * Thermal mitigation request to control functionalities at modem.
11425 *
11426 * @param subId the id of the subscription.
11427 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011428 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011429 *
11430 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11431 */
11432 @Override
11433 @ThermalMitigationResult
11434 public int sendThermalMitigationRequest(
11435 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011436 ThermalMitigationRequest thermalMitigationRequest,
11437 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011438 enforceModifyPermission();
11439
Jack Nudelman644b91a2021-03-12 14:09:48 -080011440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011441
11442 enforceTelephonyFeatureWithException(callingPackage,
11443 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11444
Jack Nudelman644b91a2021-03-12 14:09:48 -080011445 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11446 .contains(callingPackage)) {
11447 throw new SecurityException("Calling package must be configured in the device config. "
11448 + "calling package: " + callingPackage);
11449 }
11450
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011451 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11452 final long identity = Binder.clearCallingIdentity();
11453
11454 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11455 try {
11456 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11457 switch (thermalMitigationAction) {
11458 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11459 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011460 handleDataThrottlingRequest(subId,
11461 thermalMitigationRequest.getDataThrottlingRequest(),
11462 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011463 break;
11464 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11465 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11466 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11467 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11468 }
11469
11470 // Ensure that radio is on. If not able to power on due to phone being
11471 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011472 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011473 thermalMitigationResult =
11474 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11475 break;
11476 }
11477
11478 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011479 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011480 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11481 break;
11482 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11483 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11484 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11485 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11486 }
11487
11488 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11489 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011490 Phone phone = getPhone(subId);
11491 if (phone == null) {
11492 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011493 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011494 break;
11495 }
11496
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011497 TelephonyConnectionService service =
11498 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011499 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011500 Log.e(LOG_TAG, "An emergency call is pending");
11501 thermalMitigationResult =
11502 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11503 break;
11504 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011505 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011506 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011507 break;
11508 }
11509 } else {
11510 thermalMitigationResult =
11511 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11512 break;
11513 }
11514
11515 // Turn radio off. If not able to power off due to phone being unavailable,
11516 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011517 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011518 thermalMitigationResult =
11519 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11520 break;
11521 }
11522 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011523 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011524 break;
11525 default:
11526 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11527 + "not exist. Requested action: " + thermalMitigationAction);
11528 }
11529 } catch (IllegalArgumentException e) {
11530 throw e;
11531 } catch (Exception e) {
11532 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11533 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11534 } finally {
11535 Binder.restoreCallingIdentity(identity);
11536 }
11537
11538 if (DBG) {
11539 log("thermalMitigationRequest returning with thermalMitigationResult: "
11540 + thermalMitigationResult);
11541 }
11542
11543 return thermalMitigationResult;
11544 }
Hui Wang641e81c2020-10-12 12:14:23 -070011545
11546 /**
11547 * Set the GbaService Package Name that Telephony will bind to.
11548 *
11549 * @param subId The sim that the GbaService is associated with.
11550 * @param packageName The name of the package to be replaced with.
11551 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11552 */
11553 @Override
11554 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11555 enforceModifyPermission();
11556
11557 final long identity = Binder.clearCallingIdentity();
11558 try {
11559 return getGbaManager(subId).overrideServicePackage(packageName);
11560 } finally {
11561 Binder.restoreCallingIdentity(identity);
11562 }
11563 }
11564
11565 /**
11566 * Return the package name of the currently bound GbaService.
11567 *
11568 * @param subId The sim that the GbaService is associated with.
11569 * @return the package name of the GbaService configuration, null if GBA is not supported.
11570 */
11571 @Override
11572 public String getBoundGbaService(int subId) {
11573 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11574
11575 final long identity = Binder.clearCallingIdentity();
11576 try {
11577 return getGbaManager(subId).getServicePackage();
11578 } finally {
11579 Binder.restoreCallingIdentity(identity);
11580 }
11581 }
11582
11583 /**
11584 * Set the release time for telephony to unbind GbaService.
11585 *
11586 * @param subId The sim that the GbaService is associated with.
11587 * @param interval The release time to unbind GbaService by millisecond.
11588 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11589 */
11590 @Override
11591 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11592 enforceModifyPermission();
11593
11594 final long identity = Binder.clearCallingIdentity();
11595 try {
11596 return getGbaManager(subId).overrideReleaseTime(interval);
11597 } finally {
11598 Binder.restoreCallingIdentity(identity);
11599 }
11600 }
11601
11602 /**
11603 * Return the release time for telephony to unbind GbaService.
11604 *
11605 * @param subId The sim that the GbaService is associated with.
11606 * @return The release time to unbind GbaService by millisecond.
11607 */
11608 @Override
11609 public int getGbaReleaseTime(int subId) {
11610 enforceReadPrivilegedPermission("getGbaReleaseTime");
11611
11612 final long identity = Binder.clearCallingIdentity();
11613 try {
11614 return getGbaManager(subId).getReleaseTime();
11615 } finally {
11616 Binder.restoreCallingIdentity(identity);
11617 }
11618 }
11619
11620 private GbaManager getGbaManager(int subId) {
11621 GbaManager instance = GbaManager.getInstance(subId);
11622 if (instance == null) {
11623 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11624 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11625 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11626 }
11627 return instance;
11628 }
Hui Wang761a6682020-10-31 05:12:53 +000011629
11630 /**
11631 * indicate whether the device and the carrier can support
11632 * RCS VoLTE single registration.
11633 */
11634 @Override
11635 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011636 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11637 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11638 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11639 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011640
11641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11642 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11643 }
11644
11645 final long identity = Binder.clearCallingIdentity();
11646 try {
11647 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11648 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011649 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11650 if (isCapable != null) {
11651 return isCapable;
11652 }
Hui Wang761a6682020-10-31 05:12:53 +000011653 }
Hui Wang67af90e2021-06-04 16:57:15 -070011654 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11655 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011656 } finally {
11657 Binder.restoreCallingIdentity(identity);
11658 }
11659 }
11660
11661 /**
11662 * Register RCS provisioning callback.
11663 */
11664 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011665 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011666 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011667 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011668 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011669 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11670 permission.READ_PRIVILEGED_PHONE_STATE);
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 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11680 "IMS not available on device.");
11681 }
11682 } else {
11683 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11684 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011685 }
11686
11687 final long identity = Binder.clearCallingIdentity();
11688 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011689 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011690 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011691 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11692 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011693 }
Hui Wang761a6682020-10-31 05:12:53 +000011694 } finally {
11695 Binder.restoreCallingIdentity(identity);
11696 }
11697 }
11698
11699 /**
11700 * Unregister RCS provisioning callback.
11701 */
11702 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011703 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011704 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011705 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011706 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011707 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11708 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011709
11710 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11711 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11712 }
joonhunshin4ac60942023-11-15 15:23:39 +000011713
11714 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11715 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11716 Binder.getCallingUserHandle())) {
11717 if (!isImsAvailableOnDevice()) {
11718 // operation failed silently
11719 Rlog.w(LOG_TAG, "IMS not available on device.");
11720 return;
11721 }
11722 } else {
11723 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11724 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11725 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011726 }
11727
11728 final long identity = Binder.clearCallingIdentity();
11729 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011730 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011731 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011732 } finally {
11733 Binder.restoreCallingIdentity(identity);
11734 }
11735 }
11736
11737 /**
11738 * trigger RCS reconfiguration.
11739 */
11740 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011741 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11742 "triggerRcsReconfiguration",
11743 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011744
11745 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11746 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11747 }
joonhunshin4ac60942023-11-15 15:23:39 +000011748 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11749 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11750 Binder.getCallingUserHandle())) {
11751 if (!isImsAvailableOnDevice()) {
11752 // ProvisioningManager can not handle ServiceSpecificException.
11753 // Throw the IllegalStateException and annotate ProvisioningManager.
11754 throw new IllegalStateException("IMS not available on device.");
11755 }
11756 } else {
11757 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11758 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011759 }
11760
11761 final long identity = Binder.clearCallingIdentity();
11762 try {
11763 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11764 } finally {
11765 Binder.restoreCallingIdentity(identity);
11766 }
11767 }
11768
11769 /**
11770 * Provide the client configuration parameters of the RCS application.
11771 */
11772 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011773 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11774 "setRcsClientConfiguration",
11775 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011776
11777 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11778 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11779 }
joonhunshin4ac60942023-11-15 15:23:39 +000011780 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11781 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11782 Binder.getCallingUserHandle())) {
11783 if (!isImsAvailableOnDevice()) {
11784 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11785 "IMS not available on device.");
11786 }
11787 } else {
11788 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11789 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011790 }
11791
11792 final long identity = Binder.clearCallingIdentity();
11793
11794 try {
11795 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11796 if (configBinder == null) {
11797 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011798 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11799 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011800 } else {
11801 configBinder.setRcsClientConfiguration(rcc);
11802 }
joonhunshin3e154242021-09-17 06:33:39 +000011803
11804 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11805 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011806 } catch (RemoteException e) {
11807 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011808 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11809 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011810 } finally {
11811 Binder.restoreCallingIdentity(identity);
11812 }
11813 }
11814
11815 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011816 * Enables or disables the test mode for RCS VoLTE single registration.
11817 */
11818 @Override
11819 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11820 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11821 "setRcsSingleRegistrationTestModeEnabled");
11822
11823 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11824 }
11825
11826 /**
11827 * Gets the test mode for RCS VoLTE single registration.
11828 */
11829 @Override
11830 public boolean getRcsSingleRegistrationTestModeEnabled() {
11831 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11832 "getRcsSingleRegistrationTestModeEnabled");
11833
11834 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11835 }
11836
11837 /**
Hui Wang761a6682020-10-31 05:12:53 +000011838 * Overrides the config of RCS VoLTE single registration enabled for the device.
11839 */
11840 @Override
11841 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11842 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11843 "setDeviceSingleRegistrationEnabledOverride");
11844 enforceModifyPermission();
11845
11846 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11847 : Boolean.parseBoolean(enabledStr);
11848 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011849 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011850 }
11851
11852 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011853 * Sends a device to device communication message. Only usable via shell.
11854 * @param message message to send.
11855 * @param value message value.
11856 */
11857 @Override
11858 public void sendDeviceToDeviceMessage(int message, int value) {
11859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011860 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011861 enforceModifyPermission();
11862
11863 final long identity = Binder.clearCallingIdentity();
11864 try {
11865 TelephonyConnectionService service =
11866 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11867 if (service == null) {
11868 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11869 return;
11870 }
11871 service.sendTestDeviceToDeviceMessage(message, value);
11872 } finally {
11873 Binder.restoreCallingIdentity(identity);
11874 }
11875 }
11876
Tyler Gunnbabbda02021-02-10 11:05:02 -080011877 /**
11878 * Sets the specified device to device transport active.
11879 * @param transport The transport to set active.
11880 */
11881 @Override
11882 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11884 "setActiveDeviceToDeviceTransport");
11885 enforceModifyPermission();
11886
11887 final long identity = Binder.clearCallingIdentity();
11888 try {
11889 TelephonyConnectionService service =
11890 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11891 if (service == null) {
11892 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11893 return;
11894 }
11895 service.setActiveDeviceToDeviceTransport(transport);
11896 } finally {
11897 Binder.restoreCallingIdentity(identity);
11898 }
11899 }
Tyler Gunn92479152021-01-20 16:30:10 -080011900
Tyler Gunnd4339262021-05-03 14:46:49 -070011901 @Override
11902 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11904 "setDeviceToDeviceForceEnabled");
11905
11906 final long identity = Binder.clearCallingIdentity();
11907 try {
11908 Arrays.stream(PhoneFactory.getPhones()).forEach(
11909 p -> {
11910 Phone thePhone = p.getImsPhone();
11911 if (thePhone != null && thePhone instanceof ImsPhone) {
11912 ImsPhone imsPhone = (ImsPhone) thePhone;
11913 CallTracker tracker = imsPhone.getCallTracker();
11914 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11915 ImsPhoneCallTracker imsPhoneCallTracker =
11916 (ImsPhoneCallTracker) tracker;
11917 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11918 }
11919 }
11920 }
11921 );
11922 } finally {
11923 Binder.restoreCallingIdentity(identity);
11924 }
11925 }
11926
Tyler Gunn92479152021-01-20 16:30:10 -080011927 /**
Hui Wang761a6682020-10-31 05:12:53 +000011928 * Gets the config of RCS VoLTE single registration enabled for the device.
11929 */
11930 @Override
11931 public boolean getDeviceSingleRegistrationEnabled() {
11932 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11933 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11934 }
11935
11936 /**
11937 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11938 */
11939 @Override
11940 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11941 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11942 "setCarrierSingleRegistrationEnabledOverride");
11943 enforceModifyPermission();
11944
11945 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11946 : Boolean.parseBoolean(enabledStr);
11947 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11948 subId, enabled);
11949 }
11950
11951 /**
11952 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11953 */
11954 @Override
11955 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11956 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11957 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11958 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011959
11960 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011961 * Overrides the ims feature validation result
11962 */
11963 @Override
11964 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11966 "setImsFeatureValidationOverride");
11967
11968 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11969 : Boolean.parseBoolean(enabledStr);
11970 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11971 subId, enabled);
11972 }
11973
11974 /**
11975 * Gets the ims feature validation override value
11976 */
11977 @Override
11978 public boolean getImsFeatureValidationOverride(int subId) {
11979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11980 "getImsFeatureValidationOverride");
11981 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11982 }
11983
11984 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011985 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11986 * their mobile plan.
11987 */
11988 @Override
11989 public String getMobileProvisioningUrl() {
11990 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11991 final long identity = Binder.clearCallingIdentity();
11992 try {
11993 return getDefaultPhone().getMobileProvisioningUrl();
11994 } finally {
11995 Binder.restoreCallingIdentity(identity);
11996 }
11997 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011998
James.cf Linbcdf8b32021-01-14 16:44:13 +080011999 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012000 * Get the EAB contact from the EAB database.
12001 */
12002 @Override
12003 public String getContactFromEab(String contact) {
12004 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12005 enforceModifyPermission();
12006 final long identity = Binder.clearCallingIdentity();
12007 try {
12008 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12009 } finally {
12010 Binder.restoreCallingIdentity(identity);
12011 }
12012 }
12013
12014 /**
Calvin Pana1434322021-07-01 19:27:01 +080012015 * Get the EAB capability from the EAB database.
12016 */
12017 @Override
12018 public String getCapabilityFromEab(String contact) {
12019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12020 enforceModifyPermission();
12021 final long identity = Binder.clearCallingIdentity();
12022 try {
12023 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12024 } finally {
12025 Binder.restoreCallingIdentity(identity);
12026 }
12027 }
12028
12029 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012030 * Remove the EAB contacts from the EAB database.
12031 */
12032 @Override
12033 public int removeContactFromEab(int subId, String contacts) {
12034 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12035 enforceModifyPermission();
12036 final long identity = Binder.clearCallingIdentity();
12037 try {
12038 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12039 } finally {
12040 Binder.restoreCallingIdentity(identity);
12041 }
12042 }
12043
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012044 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012045 public boolean getDeviceUceEnabled() {
12046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12047 final long identity = Binder.clearCallingIdentity();
12048 try {
12049 return mApp.getDeviceUceEnabled();
12050 } finally {
12051 Binder.restoreCallingIdentity(identity);
12052 }
12053 }
12054
12055 @Override
12056 public void setDeviceUceEnabled(boolean isEnabled) {
12057 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12058 final long identity = Binder.clearCallingIdentity();
12059 try {
12060 mApp.setDeviceUceEnabled(isEnabled);
12061 } finally {
12062 Binder.restoreCallingIdentity(identity);
12063 }
12064 }
12065
Brad Ebinger14d467f2021-02-12 06:18:28 +000012066 /**
12067 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12068 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12069 */
12070 // Used for SHELL command only right now.
12071 @Override
12072 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12073 List<String> featureTags) {
12074 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12075 "addUceRegistrationOverrideShell");
12076 final long identity = Binder.clearCallingIdentity();
12077 try {
12078 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12079 new ArraySet<>(featureTags));
12080 } catch (ImsException e) {
12081 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12082 } finally {
12083 Binder.restoreCallingIdentity(identity);
12084 }
12085 }
12086
12087 /**
12088 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12089 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12090 */
12091 // Used for SHELL command only right now.
12092 @Override
12093 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12094 List<String> featureTags) {
12095 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12096 "removeUceRegistrationOverrideShell");
12097 final long identity = Binder.clearCallingIdentity();
12098 try {
12099 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12100 new ArraySet<>(featureTags));
12101 } catch (ImsException e) {
12102 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12103 } finally {
12104 Binder.restoreCallingIdentity(identity);
12105 }
12106 }
12107
12108 /**
12109 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12110 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12111 */
12112 // Used for SHELL command only right now.
12113 @Override
12114 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12115 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12116 "clearUceRegistrationOverrideShell");
12117 final long identity = Binder.clearCallingIdentity();
12118 try {
12119 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12120 } catch (ImsException e) {
12121 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12122 } finally {
12123 Binder.restoreCallingIdentity(identity);
12124 }
12125 }
12126
12127 /**
12128 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12129 */
12130 // Used for SHELL command only right now.
12131 @Override
12132 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12134 "getLatestRcsContactUceCapabilityShell");
12135 final long identity = Binder.clearCallingIdentity();
12136 try {
12137 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12138 } catch (ImsException e) {
12139 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12140 } finally {
12141 Binder.restoreCallingIdentity(identity);
12142 }
12143 }
12144
12145 /**
12146 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12147 * device does not have an active PUBLISH.
12148 */
12149 // Used for SHELL command only right now.
12150 @Override
12151 public String getLastUcePidfXmlShell(int subId) {
12152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12153 final long identity = Binder.clearCallingIdentity();
12154 try {
12155 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12156 } catch (ImsException e) {
12157 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12158 } finally {
12159 Binder.restoreCallingIdentity(identity);
12160 }
12161 }
12162
James.cf Line8713a42021-04-29 16:04:26 +080012163 /**
12164 * Remove UCE requests cannot be sent to the network status.
12165 */
12166 // Used for SHELL command only right now.
12167 @Override
12168 public boolean removeUceRequestDisallowedStatus(int subId) {
12169 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12170 final long identity = Binder.clearCallingIdentity();
12171 try {
12172 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12173 } catch (ImsException e) {
12174 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12175 } finally {
12176 Binder.restoreCallingIdentity(identity);
12177 }
12178 }
12179
James.cf Lin18bb9002021-05-25 01:37:38 +080012180 /**
12181 * Remove UCE requests cannot be sent to the network status.
12182 */
12183 // Used for SHELL command only.
12184 @Override
12185 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12186 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12187 final long identity = Binder.clearCallingIdentity();
12188 try {
12189 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12190 } catch (ImsException e) {
12191 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12192 } finally {
12193 Binder.restoreCallingIdentity(identity);
12194 }
12195 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012196
James.cf Lin4b784aa2021-01-31 03:25:15 +080012197 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012198 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12199 String callingPackage) {
12200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12201 mApp, subId, "setSignalStrengthUpdateRequest");
12202
joonhunshin4ac60942023-11-15 15:23:39 +000012203 enforceTelephonyFeatureWithException(callingPackage,
12204 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12205
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012206 final int callingUid = Binder.getCallingUid();
12207 // Verify that tha callingPackage belongs to the calling UID
12208 mApp.getSystemService(AppOpsManager.class)
12209 .checkPackage(callingUid, callingPackage);
12210
Rambo Wang3607f502021-02-01 21:51:40 -080012211 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012212
12213 final long identity = Binder.clearCallingIdentity();
12214 try {
12215 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12216 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12217
12218 if (result instanceof IllegalStateException) {
12219 throw (IllegalStateException) result;
12220 }
12221 } finally {
12222 Binder.restoreCallingIdentity(identity);
12223 }
12224 }
12225
12226 @Override
12227 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12228 String callingPackage) {
12229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12230 mApp, subId, "clearSignalStrengthUpdateRequest");
12231
joonhunshin4ac60942023-11-15 15:23:39 +000012232 enforceTelephonyFeatureWithException(callingPackage,
12233 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12234
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012235 final int callingUid = Binder.getCallingUid();
12236 // Verify that tha callingPackage belongs to the calling UID
12237 mApp.getSystemService(AppOpsManager.class)
12238 .checkPackage(callingUid, callingPackage);
12239
12240 final long identity = Binder.clearCallingIdentity();
12241 try {
12242 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12243 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12244
12245 if (result instanceof IllegalStateException) {
12246 throw (IllegalStateException) result;
12247 }
12248 } finally {
12249 Binder.restoreCallingIdentity(identity);
12250 }
12251 }
12252
Rambo Wang3607f502021-02-01 21:51:40 -080012253 private static void validateSignalStrengthUpdateRequest(Context context,
12254 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012255 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12256 // phone/system process do not have further restriction on request
12257 return;
12258 }
12259
12260 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012261 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012262 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012263 context.enforceCallingOrSelfPermission(
12264 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12265 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012266 }
12267
12268 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012269 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012270 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012271 || info.isEnabled()) {
12272 throw new IllegalArgumentException(
12273 "Only system can set hide fields in SignalThresholdInfo");
12274 }
12275
12276 // Thresholds length for each RAN need in range. This has been validated in
12277 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12278 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12279 final int[] thresholds = info.getThresholds();
12280 Objects.requireNonNull(thresholds);
12281 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12282 || thresholds.length
12283 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12284 throw new IllegalArgumentException(
12285 "thresholds length is out of range: " + thresholds.length);
12286 }
12287 }
12288 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012289
12290 /**
12291 * Gets the current phone capability.
12292 *
12293 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12294 * @return the PhoneCapability which describes the data connection capability of modem.
12295 * It's used to evaluate possible phone config change, for example from single
12296 * SIM device to multi-SIM device.
12297 */
12298 @Override
12299 public PhoneCapability getPhoneCapability() {
12300 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012301
12302 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12303 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12304
SongFerngWang8236caa2021-01-17 21:51:44 +080012305 final long identity = Binder.clearCallingIdentity();
12306 try {
12307 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12308 } finally {
12309 Binder.restoreCallingIdentity(identity);
12310 }
12311 }
Michele Berionne5e411512020-11-13 02:36:59 +000012312
12313 /**
12314 * Prepare TelephonyManager for an unattended reboot. The reboot is
12315 * required to be done shortly after the API is invoked.
12316 */
12317 @Override
12318 @TelephonyManager.PrepareUnattendedRebootResult
12319 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012320 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012321 enforceRebootPermission();
12322
joonhunshin4ac60942023-11-15 15:23:39 +000012323 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12324 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12325
Michele Berionne5e411512020-11-13 02:36:59 +000012326 final long identity = Binder.clearCallingIdentity();
12327 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012328 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012329 } finally {
12330 Binder.restoreCallingIdentity(identity);
12331 }
12332 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012333
12334 /**
12335 * Request to get the current slicing configuration including URSP rules and
12336 * NSSAIs (configured, allowed and rejected).
12337 *
12338 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12339 */
12340 @Override
12341 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012342 TelephonyPermissions
12343 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12344 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012345
joonhunshin4ac60942023-11-15 15:23:39 +000012346 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12347 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12348 "getSlicingConfig");
12349
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012350 final long identity = Binder.clearCallingIdentity();
12351 try {
12352 Phone phone = getDefaultPhone();
12353 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12354 } finally {
12355 Binder.restoreCallingIdentity(identity);
12356 }
12357 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012358
12359 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012360 * Check whether the given premium capability is available for purchase from the carrier.
12361 *
12362 * @param capability The premium capability to check.
12363 * @param subId The subId to check the premium capability for.
12364 *
12365 * @return Whether the given premium capability is available to purchase.
12366 */
12367 @Override
12368 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12369 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12370 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12371 log("Premium capability "
12372 + TelephonyManager.convertPremiumCapabilityToString(capability)
12373 + " is not available for purchase due to missing permissions.");
12374 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12375 + "permission READ_BASIC_PHONE_STATE.");
12376 }
12377
joonhunshin4ac60942023-11-15 15:23:39 +000012378 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12379 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12380
Sarah Chin2ec39f62022-08-31 17:03:26 -070012381 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012382 if (phone == null) {
12383 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12384 return false;
12385 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012386 final long identity = Binder.clearCallingIdentity();
12387 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012388 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012389 .isPremiumCapabilityAvailableForPurchase(capability);
12390 } finally {
12391 Binder.restoreCallingIdentity(identity);
12392 }
12393 }
12394
12395 /**
12396 * Purchase the given premium capability from the carrier.
12397 *
12398 * @param capability The premium capability to purchase.
12399 * @param callback The result of the purchase request.
12400 * @param subId The subId to purchase the premium capability for.
12401 */
12402 @Override
12403 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12404 log("purchasePremiumCapability: capability="
12405 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12406 + getCurrentPackageName());
12407
12408 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12409 mApp, "purchasePremiumCapability")) {
12410 log("purchasePremiumCapability "
12411 + TelephonyManager.convertPremiumCapabilityToString(capability)
12412 + " failed due to missing permissions.");
12413 throw new SecurityException("purchasePremiumCapability requires permission "
12414 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012415 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12416 mApp, "purchasePremiumCapability")) {
12417 log("purchasePremiumCapability "
12418 + TelephonyManager.convertPremiumCapabilityToString(capability)
12419 + " failed due to missing permissions.");
12420 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012421 }
12422
joonhunshin4ac60942023-11-15 15:23:39 +000012423 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12424 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12425
Sarah Chin2ec39f62022-08-31 17:03:26 -070012426 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012427 if (phone == null) {
12428 try {
12429 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12430 callback.accept(result);
12431 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12432 } catch (RemoteException e) {
12433 String logStr = "Purchase premium capability "
12434 + TelephonyManager.convertPremiumCapabilityToString(capability)
12435 + " failed due to RemoteException handling null phone: " + e;
12436 if (DBG) log(logStr);
12437 AnomalyReporter.reportAnomaly(
12438 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12439 }
12440 return;
12441 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012442
12443 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012444 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012445 callingProcess = mApp.getPackageManager().getApplicationInfo(
12446 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012447 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012448 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012449 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012450
12451 boolean isVisible = false;
12452 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12453 if (am != null) {
12454 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12455 if (processes != null) {
12456 for (ActivityManager.RunningAppProcessInfo process : processes) {
12457 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012458 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012459 if (process.processName.equals(callingProcess) && process.importance
12460 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12461 isVisible = true;
12462 break;
12463 }
12464 }
12465 }
12466 }
12467
12468 if (!isVisible) {
12469 try {
12470 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12471 callback.accept(result);
12472 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12473 } catch (RemoteException e) {
12474 String logStr = "Purchase premium capability "
12475 + TelephonyManager.convertPremiumCapabilityToString(capability)
12476 + " failed due to RemoteException handling background application: " + e;
12477 if (DBG) log(logStr);
12478 AnomalyReporter.reportAnomaly(
12479 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12480 }
12481 return;
12482 }
12483
Sarah Chin71b3a852022-09-28 15:54:19 -070012484 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012485 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012486 }
12487
12488 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012489 * Register an IMS connection state callback
12490 */
12491 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012492 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12493 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012494 if (feature == ImsFeature.FEATURE_MMTEL) {
12495 // ImsMmTelManager
12496 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12497 TelephonyPermissions
12498 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12499 mApp, subId, "registerImsStateCallback");
12500 } else if (feature == ImsFeature.FEATURE_RCS) {
12501 // ImsRcsManager or SipDelegateManager
12502 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12503 Binder.getCallingUid(), "registerImsStateCallback",
12504 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12505 Manifest.permission.READ_PRECISE_PHONE_STATE,
12506 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12507 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12508 }
12509
12510 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12512 "IMS not available on device.");
12513 }
12514
12515 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12516 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12517 }
12518
12519 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12520 if (controller == null) {
12521 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12522 "IMS not available on device.");
12523 }
12524
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012525 if (callingPackage == null) {
12526 callingPackage = getCurrentPackageName();
12527 }
12528
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012529 final long token = Binder.clearCallingIdentity();
12530 try {
12531 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012532 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012533 } catch (ImsException e) {
12534 throw new ServiceSpecificException(e.getCode());
12535 } finally {
12536 Binder.restoreCallingIdentity(token);
12537 }
12538 }
12539
12540 /**
12541 * Unregister an IMS connection state callback
12542 */
12543 @Override
12544 public void unregisterImsStateCallback(IImsStateCallback cb) {
12545 final long token = Binder.clearCallingIdentity();
12546 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12547 if (controller == null) {
12548 return;
12549 }
12550 try {
12551 controller.unregisterImsStateCallback(cb);
12552 } finally {
12553 Binder.restoreCallingIdentity(token);
12554 }
12555 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012556
12557 /**
12558 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12559 *
12560 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12561 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12562 * SecurityException.
12563 * If there is current registered network this value will be same as the registered cell
12564 * identity. If the device goes out of service the previous cell identity is cached and
12565 * will be returned. If the cache age of the Cell identity is more than 24 hours
12566 * it will be cleared and null will be returned.
12567 *
12568 */
12569 @Override
12570 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12571 String callingFeatureId) {
12572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12573 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12574 LocationAccessPolicy.checkLocationPermission(mApp,
12575 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12576 .setCallingPackage(callingPackage)
12577 .setCallingFeatureId(callingFeatureId)
12578 .setCallingPid(Binder.getCallingPid())
12579 .setCallingUid(Binder.getCallingUid())
12580 .setMethod("getLastKnownCellIdentity")
12581 .setLogAsInfo(true)
12582 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12583 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12584 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12585 .build());
12586
12587 boolean hasFinePermission =
12588 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12589 if (!hasFinePermission
12590 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12591 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012592 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012593 }
12594
12595 final long identity = Binder.clearCallingIdentity();
12596 try {
Ling Mac28f0212023-03-24 16:07:15 -070012597 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012598 if (sst == null) return null;
12599 return sst.getLastKnownCellIdentity();
12600 } finally {
12601 Binder.restoreCallingIdentity(identity);
12602 }
12603 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012604
jimsun3b9ccac2021-10-26 15:01:23 +080012605 /**
12606 * Sets the modem service class Name that Telephony will bind to.
12607 *
12608 * @param serviceName The class name of the modem service.
12609 * @return true if the operation is succeed, otherwise false.
12610 */
12611 public boolean setModemService(String serviceName) {
12612 Log.d(LOG_TAG, "setModemService - " + serviceName);
12613 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012615 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12616 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012617 return mPhoneConfigurationManager.setModemService(serviceName);
12618 }
12619
12620 /**
12621 * Return the class name of the currently bounded modem service.
12622 *
12623 * @return the class name of the modem service.
12624 */
12625 public String getModemService() {
12626 String result;
12627 Log.d(LOG_TAG, "getModemService");
12628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12629 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012630 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012631 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12632 "getModemService");
12633 result = mPhoneConfigurationManager.getModemService();
12634 Log.d(LOG_TAG, "result = " + result);
12635 return result;
12636 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012637
12638 @Override
12639 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12640 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12641 mApp.enforceCallingOrSelfPermission(
12642 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12644
12645 final long identity = Binder.clearCallingIdentity();
12646 try {
12647 Phone phone = getPhone(subId);
12648 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012649 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12650 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012651 phone.setVoiceServiceStateOverride(hasService);
12652 } finally {
12653 Binder.restoreCallingIdentity(identity);
12654 }
12655 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012656
12657 /**
12658 * set removable eSIM as default eUICC.
12659 *
12660 * @hide
12661 */
12662 @Override
12663 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12664 enforceModifyPermission();
12665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12666
12667 final long identity = Binder.clearCallingIdentity();
12668 try {
12669 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12670 } finally {
12671 Binder.restoreCallingIdentity(identity);
12672 }
12673 }
12674
12675 /**
12676 * Returns whether the removable eSIM is default eUICC or not.
12677 *
12678 * @hide
12679 */
12680 @Override
12681 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12682 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12684
12685 final long identity = Binder.clearCallingIdentity();
12686 try {
12687 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12688 } finally {
12689 Binder.restoreCallingIdentity(identity);
12690 }
12691 }
12692
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012693 /**
12694 * Get the component name of the default app to direct respond-via-message intent for the
12695 * user associated with this subscription, update the cache if there is no respond-via-message
12696 * application currently configured for this user.
12697 * @return component name of the app and class to direct Respond Via Message intent to, or
12698 * {@code null} if the functionality is not supported.
12699 * @hide
12700 */
12701 @Override
12702 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12703 boolean updateIfNeeded) {
12704 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012705
joonhunshin4ac60942023-11-15 15:23:39 +000012706 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12707 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12708 "getDefaultRespondViaMessageApplication");
12709
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012710 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12711
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012712 UserHandle userHandle = null;
12713 final long identity = Binder.clearCallingIdentity();
12714 try {
12715 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12716 } finally {
12717 Binder.restoreCallingIdentity(identity);
12718 }
12719 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12720 updateIfNeeded, userHandle);
12721 }
Jack Yuf5badd92022-12-08 00:50:53 -080012722
12723 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012724 * Set whether the device is able to connect with null ciphering or integrity
12725 * algorithms. This is a global setting and will apply to all active subscriptions
12726 * and all new subscriptions after this.
12727 *
12728 * @param enabled when true, null cipher and integrity algorithms are allowed.
12729 * @hide
12730 */
12731 @Override
12732 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12733 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12734 enforceModifyPermission();
12735 checkForNullCipherAndIntegritySupport();
12736
12737 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12738 // for listening to these preference changes and applying them immediately.
12739 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12740 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12741 editor.apply();
12742
12743 for (Phone phone: PhoneFactory.getPhones()) {
12744 phone.handleNullCipherEnabledChange();
12745 }
12746 }
12747
12748
12749 /**
12750 * Get whether the device is able to connect with null ciphering or integrity
12751 * algorithms. Note that this retrieves the phone-global preference and not
12752 * the state of the radio.
12753 *
12754 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12755 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12756 * version for this feature.
12757 * @hide
12758 */
12759 @Override
12760 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12761 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12762 enforceReadPermission();
12763 checkForNullCipherAndIntegritySupport();
12764 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12765 }
12766
12767 private void checkForNullCipherAndIntegritySupport() {
12768 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12769 throw new UnsupportedOperationException(
12770 "Null cipher and integrity operations require HAL 2.1 or above");
12771 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012772 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12773 throw new UnsupportedOperationException(
12774 "Null cipher and integrity operations unsupported by modem");
12775 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012776 }
12777
Gil Cukierman06403e12023-11-29 16:33:03 +000012778 private void checkForIdentifierDisclosureNotificationSupport() {
12779 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12780 throw new UnsupportedOperationException(
12781 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12782 + "above");
12783 }
12784 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12785 throw new UnsupportedOperationException(
12786 "Cellular identifier disclosure transparency operations unsupported by modem");
12787 }
12788 }
12789
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012790 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012791 * Get the SIM state for the slot index.
12792 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12793 *
12794 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12795 */
12796 @Override
12797 @SimState
12798 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012799 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12800 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12801
Jack Yuf5badd92022-12-08 00:50:53 -080012802 IccCardConstants.State simState;
12803 if (slotIndex < 0) {
12804 simState = IccCardConstants.State.UNKNOWN;
12805 } else {
12806 Phone phone = null;
12807 try {
12808 phone = PhoneFactory.getPhone(slotIndex);
12809 } catch (IllegalStateException e) {
12810 // ignore
12811 }
12812 if (phone == null) {
12813 simState = IccCardConstants.State.UNKNOWN;
12814 } else {
12815 IccCard icc = phone.getIccCard();
12816 if (icc == null) {
12817 simState = IccCardConstants.State.UNKNOWN;
12818 } else {
12819 simState = icc.getState();
12820 }
12821 }
12822 }
12823 return simState.ordinal();
12824 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012825
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012826 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12827 boolean enableLogcat,
12828 long logcatStartTimestampMillis, boolean enableTelecomDump,
12829 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012830 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12831 TelephonyManager.EmergencyCallDiagnosticParams edp =
12832 new TelephonyManager.EmergencyCallDiagnosticParams();
12833 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12834 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12835 edp.setTelecomDumpSysCollection(enableTelecomDump);
12836 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12837 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12838 Executors.newCachedThreadPool(), db,
12839 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12840 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012841 }
12842
12843 /**
12844 * Request telephony to persist state for debugging emergency call failures.
12845 *
12846 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12847 * @param enableLogcat whether to collect logcat output
12848 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12849 * @param enableTelecomDump whether to collect telecom dumpsys
12850 * @param enableTelephonyDump whether to collect telephony dumpsys
12851 */
12852 @Override
12853 @RequiresPermission(android.Manifest.permission.DUMP)
12854 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12855 long logcatStartTimestampMillis, boolean enableTelecomDump,
12856 boolean enableTelephonyDump) {
12857 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12858 "persistEmergencyCallDiagnosticData");
12859 final long identity = Binder.clearCallingIdentity();
12860 try {
12861 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12862 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12863
12864 } finally {
12865 Binder.restoreCallingIdentity(identity);
12866 }
12867 }
12868
Hui Wang9b5793a2022-12-05 14:38:06 -060012869 /**
12870 * Get current cell broadcast ranges.
12871 */
12872 @Override
12873 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12874 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12875 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12876 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012877
12878 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12879 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12880
Hui Wang9b5793a2022-12-05 14:38:06 -060012881 final long identity = Binder.clearCallingIdentity();
12882 try {
12883 return getPhone(subId).getCellBroadcastIdRanges();
12884 } finally {
12885 Binder.restoreCallingIdentity(identity);
12886 }
12887 }
12888
12889 /**
12890 * Set reception of cell broadcast messages with the list of the given ranges
12891 *
12892 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12893 */
12894 @Override
12895 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12896 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12897 @Nullable IIntegerConsumer callback) {
12898 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12899 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012900
12901 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12902 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12903
Hui Wang9b5793a2022-12-05 14:38:06 -060012904 final long identity = Binder.clearCallingIdentity();
12905 try {
12906 Phone phone = getPhoneFromSubId(subId);
12907 if (DBG) {
12908 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12909 }
12910 phone.setCellBroadcastIdRanges(ranges, result -> {
12911 if (callback != null) {
12912 try {
12913 callback.accept(result);
12914 } catch (RemoteException e) {
12915 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12916 }
12917 }
12918 });
12919 } finally {
12920 Binder.restoreCallingIdentity(identity);
12921 }
12922 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012923
12924 /**
12925 * Returns whether the device supports the domain selection service.
12926 *
12927 * @return {@code true} if the device supports the domain selection service.
12928 */
12929 @Override
12930 public boolean isDomainSelectionSupported() {
12931 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12932 "isDomainSelectionSupported");
12933
12934 final long identity = Binder.clearCallingIdentity();
12935 try {
12936 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12937 } finally {
12938 Binder.restoreCallingIdentity(identity);
12939 }
12940 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012941
12942 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012943 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12944 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12945 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012946 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012947 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012948 * @param enableSatellite {@code true} to enable the satellite modem and
12949 * {@code false} to disable.
12950 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12951 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012952 *
12953 * @throws SecurityException if the caller doesn't have the required permission.
12954 */
12955 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012956 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12957 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012958 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012959 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12960 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012961 }
12962
12963 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012964 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012965 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012966 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012967 * @param result The result receiver that returns whether the satellite modem is enabled
12968 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012969 *
12970 * @throws SecurityException if the caller doesn't have the required permission.
12971 */
12972 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012973 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12974 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012975 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012976 }
12977
12978 /**
Sarah Chin43457982023-02-15 17:50:38 -080012979 * Request to get whether the satellite service demo mode is enabled.
12980 *
12981 * @param subId The subId of the subscription to check whether the satellite demo mode
12982 * is enabled for.
12983 * @param result The result receiver that returns whether the satellite demo mode is enabled
12984 * if the request is successful or an error code if the request failed.
12985 *
12986 * @throws SecurityException if the caller doesn't have the required permission.
12987 */
12988 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012989 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12990 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12991 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012992 }
12993
12994 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012995 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012996 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012997 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012998 * @param result The result receiver that returns whether the satellite service is supported on
12999 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013000 */
13001 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013002 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013003 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013004 }
13005
13006 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013007 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013008 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013009 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013010 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13011 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013012 *
13013 * @throws SecurityException if the caller doesn't have required permission.
13014 */
13015 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013016 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13017 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013018 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013019 }
13020
13021 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013022 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013023 * This can be called by the pointing UI when the user starts pointing to the satellite.
13024 * Modem should continue to report the pointing input as the device or satellite moves.
13025 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013026 * @param subId The subId of the subscription to start satellite transmission updates for.
13027 * @param resultCallback The callback to get the result of the request.
13028 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013029 *
13030 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013031 */
13032 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013033 public void startSatelliteTransmissionUpdates(int subId,
13034 @NonNull IIntegerConsumer resultCallback,
13035 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13036 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13037 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013038 }
13039
13040 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013041 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013042 * This can be called by the pointing UI when the user stops pointing to the satellite.
13043 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013044 * @param subId The subId of the subscription to stop satellite transmission updates for.
13045 * @param resultCallback The callback to get the result of the request.
13046 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13047 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013048 *
13049 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013050 */
13051 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013052 public void stopSatelliteTransmissionUpdates(int subId,
13053 @NonNull IIntegerConsumer resultCallback,
13054 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13055 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13056 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013057 }
13058
13059 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013060 * Register the subscription with a satellite provider.
13061 * This is needed to register the subscription if the provider allows dynamic registration.
13062 *
13063 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013064 * @param token The token to be used as a unique identifier for provisioning with satellite
13065 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013066 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013067 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013068 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013069 * @return The signal transport used by the caller to cancel the provision request,
13070 * or {@code null} if the request failed.
13071 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013072 * @throws SecurityException if the caller doesn't have the required permission.
13073 */
13074 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013075 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013076 @NonNull String token, @NonNull byte[] provisionData,
13077 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013078 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013079 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13080 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013081 }
13082
13083 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013084 * Unregister the device/subscription with the satellite provider.
13085 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013086 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013087 * should report as deprovisioned.
13088 *
13089 * @param subId The subId of the subscription to be deprovisioned.
13090 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013091 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013092 *
13093 * @throws SecurityException if the caller doesn't have the required permission.
13094 */
13095 @Override
13096 public void deprovisionSatelliteService(int subId,
13097 @NonNull String token, @NonNull IIntegerConsumer callback) {
13098 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013099 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013100 }
13101
13102 /**
Sarah Chin43457982023-02-15 17:50:38 -080013103 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013104 *
Sarah Chin43457982023-02-15 17:50:38 -080013105 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013106 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013107 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013108 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013109 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013110 * @throws SecurityException if the caller doesn't have the required permission.
13111 */
13112 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013113 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13114 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013115 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013116 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013117 }
13118
13119 /**
Sarah Chin43457982023-02-15 17:50:38 -080013120 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013121 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013122 *
Sarah Chin43457982023-02-15 17:50:38 -080013123 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013124 * @param callback The callback that was passed to
13125 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013126 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013127 * @throws SecurityException if the caller doesn't have the required permission.
13128 */
13129 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013130 public void unregisterForSatelliteProvisionStateChanged(
13131 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013132 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013133 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013134 }
13135
13136 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013137 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013138 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013139 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013140 * @param result The result receiver that returns whether the device is provisioned with a
13141 * satellite provider if the request is successful or an error code if the
13142 * request failed.
13143 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013144 * @throws SecurityException if the caller doesn't have the required permission.
13145 */
13146 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013147 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13148 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013149 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013150 }
13151
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013152 /**
Sarah Chin43457982023-02-15 17:50:38 -080013153 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013154 *
Sarah Chin43457982023-02-15 17:50:38 -080013155 * @param subId The subId of the subscription to register for satellite modem state changed.
13156 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013157 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013158 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013159 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013160 * @throws SecurityException if the caller doesn't have the required permission.
13161 */
13162 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013163 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013164 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013165 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013166 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013167 }
13168
13169 /**
Sarah Chin43457982023-02-15 17:50:38 -080013170 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013171 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013172 *
Sarah Chin43457982023-02-15 17:50:38 -080013173 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013174 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080013175 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013176 *
13177 * @throws SecurityException if the caller doesn't have the required permission.
13178 */
13179 @Override
Sarah Chin43457982023-02-15 17:50:38 -080013180 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013181 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013182 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013183 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013184 }
13185
13186 /**
13187 * Register to receive incoming datagrams over satellite.
13188 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013189 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013190 * @param callback The callback to handle incoming datagrams over satellite.
13191 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013192 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013193 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013194 * @throws SecurityException if the caller doesn't have the required permission.
13195 */
13196 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013197 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013198 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013199 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080013200 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013201 }
13202
13203 /**
13204 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013205 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013206 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013207 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13208 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080013209 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013210 *
13211 * @throws SecurityException if the caller doesn't have the required permission.
13212 */
13213 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013214 public void unregisterForSatelliteDatagram(int subId,
13215 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013216 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013217 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013218 }
13219
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013220 /**
13221 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013222 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013223 * This method requests modem to check if there are any pending datagrams to be received over
13224 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013225 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013226 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013227 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013228 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013229 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013230 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013231 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013232 @Override
13233 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013234 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013235 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013236 }
13237
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013238 /**
13239 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013240 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013241 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13242 * input to this method. Datagram received here will be passed down to modem without any
13243 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013244 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013245 * @param subId The subId of the subscription to send satellite datagrams for.
13246 * @param datagramType datagram type indicating whether the datagram is of type
13247 * SOS_SMS or LOCATION_SHARING.
13248 * @param datagram encoded gateway datagram which is encrypted by the caller.
13249 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013250 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13251 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013252 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013253 *
13254 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013255 */
13256 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013257 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
13258 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13259 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013260 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013261 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
13262 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013263 }
13264
Sarah Chindf715ec2023-02-13 13:46:24 -080013265 /**
13266 * Request to get whether satellite communication is allowed for the current location.
13267 *
13268 * @param subId The subId of the subscription to check whether satellite communication is
13269 * allowed for the current location for.
13270 * @param result The result receiver that returns whether satellite communication is allowed
13271 * for the current location if the request is successful or an error code
13272 * if the request failed.
13273 *
13274 * @throws SecurityException if the caller doesn't have the required permission.
13275 */
13276 @Override
13277 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
13278 @NonNull ResultReceiver result) {
13279 enforceSatelliteCommunicationPermission(
13280 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013281 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
13282 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013283 }
13284
13285 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013286 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013287 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013288 * @param subId The subId to get the time after which the satellite will be visible for.
13289 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013290 * be visible if the request is successful or an error code if the request failed.
13291 *
13292 * @throws SecurityException if the caller doesn't have the required permission.
13293 */
13294 @Override
13295 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13296 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013297 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013298 }
13299
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013300 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013301 * Inform that Device is aligned to satellite for demo mode.
13302 *
13303 * @param subId The subId to get the time after which the satellite will be visible for.
13304 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13305 * {@code false} Device fails to align with the satellite for demo mode.
13306 *
13307 * @throws SecurityException if the caller doesn't have required permission.
13308 */
13309 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13310
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013311 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013312 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013313 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013314 }
13315
13316 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013317 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13318 * by modem.
13319 *
13320 * @param subId The subId of the subscription to request for.
13321 * @param reason Reason for disallowing satellite communication for carrier.
13322 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13323 * operation.
13324 *
13325 * @throws SecurityException if the caller doesn't have required permission.
13326 */
13327 public void addSatelliteAttachRestrictionForCarrier(int subId,
13328 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13329 @NonNull IIntegerConsumer callback) {
13330 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
13331 final long identity = Binder.clearCallingIdentity();
13332 try {
13333 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
13334 } finally {
13335 Binder.restoreCallingIdentity(identity);
13336 }
13337 }
13338
13339 /**
13340 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13341 * by modem.
13342 *
13343 * @param subId The subId of the subscription to request for.
13344 * @param reason Reason for disallowing satellite communication.
13345 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
13346 * operation.
13347 *
13348 * @throws SecurityException if the caller doesn't have required permission.
13349 */
13350 public void removeSatelliteAttachRestrictionForCarrier(int subId,
13351 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13352 @NonNull IIntegerConsumer callback) {
13353 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
13354 final long identity = Binder.clearCallingIdentity();
13355 try {
13356 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
13357 callback);
13358 } finally {
13359 Binder.restoreCallingIdentity(identity);
13360 }
13361 }
13362
13363 /**
13364 * Get reasons for disallowing satellite communication, as requested by
13365 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
13366 *
13367 * @param subId The subId of the subscription to request for.
13368 *
13369 * @return Integer array of reasons for disallowing satellite communication.
13370 *
13371 * @throws SecurityException if the caller doesn't have the required permission.
13372 */
13373 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
13374 int subId) {
13375 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
13376 final long identity = Binder.clearCallingIdentity();
13377 try {
13378 Set<Integer> reasonSet =
13379 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
13380 return reasonSet.stream().mapToInt(i->i).toArray();
13381 } finally {
13382 Binder.restoreCallingIdentity(identity);
13383 }
13384 }
13385
13386 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013387 * Request to get the signal strength of the satellite connection.
13388 *
13389 * @param subId The subId of the subscription to request for.
13390 * @param result Result receiver to get the error code of the request and the current signal
13391 * strength of the satellite connection.
13392 *
13393 * @throws SecurityException if the caller doesn't have required permission.
13394 */
13395 @Override
13396 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13397 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13398 final long identity = Binder.clearCallingIdentity();
13399 try {
13400 mSatelliteController.requestNtnSignalStrength(subId, result);
13401 } finally {
13402 Binder.restoreCallingIdentity(identity);
13403 }
13404 }
13405
13406 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013407 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13408 * is not successful, a {@link ServiceSpecificException} that contains
13409 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013410 *
13411 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013412 * @param callback The callback to handle the NTN signal strength changed event. If the
13413 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13414 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13415 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13416 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013417 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013418 * @throws SecurityException If the caller doesn't have the required permission.
13419 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013420 */
13421 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013422 public void registerForNtnSignalStrengthChanged(int subId,
13423 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013424 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13425 final long identity = Binder.clearCallingIdentity();
13426 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013427 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013428 } finally {
13429 Binder.restoreCallingIdentity(identity);
13430 }
13431 }
13432
13433 /**
13434 * Unregisters for NTN signal strength changed from satellite modem.
13435 * If callback was not registered before, the request will be ignored.
13436 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013437 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13438 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013439 * @param callback The callback that was passed to
13440 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13441 *
13442 * @throws SecurityException if the caller doesn't have the required permission.
13443 */
13444 @Override
13445 public void unregisterForNtnSignalStrengthChanged(
13446 int subId, @NonNull INtnSignalStrengthCallback callback) {
13447 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13448 final long identity = Binder.clearCallingIdentity();
13449 try {
13450 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13451 } finally {
13452 Binder.restoreCallingIdentity(identity);
13453 }
13454 }
13455
13456 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013457 * Registers for satellite capabilities change event from the satellite service.
13458 *
13459 * @param subId The subId of the subscription to request for.
13460 * @param callback The callback to handle the satellite capabilities changed event.
13461 *
13462 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13463 *
13464 * @throws SecurityException if the caller doesn't have required permission.
13465 */
13466 @Override
13467 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
13468 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
13469 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
13470 final long identity = Binder.clearCallingIdentity();
13471 try {
13472 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
13473 } finally {
13474 Binder.restoreCallingIdentity(identity);
13475 }
13476 }
13477
13478 /**
13479 * Unregisters for satellite capabilities change event from the satellite service.
13480 * If callback was not registered before, the request will be ignored.
13481 *
13482 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13483 * @param callback The callback that was passed to.
13484 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
13485 *
13486 * @throws SecurityException if the caller doesn't have required permission.
13487 */
13488 @Override
13489 public void unregisterForSatelliteCapabilitiesChanged(
13490 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
13491 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
13492 final long identity = Binder.clearCallingIdentity();
13493 try {
13494 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
13495 } finally {
13496 Binder.restoreCallingIdentity(identity);
13497 }
13498 }
13499
13500 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013501 * This API can be used by only CTS to update satellite vendor service package name.
13502 *
13503 * @param servicePackageName The package name of the satellite vendor service.
13504 * @return {@code true} if the satellite vendor service is set successfully,
13505 * {@code false} otherwise.
13506 */
13507 public boolean setSatelliteServicePackageName(String servicePackageName) {
13508 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13509 TelephonyPermissions.enforceShellOnly(
13510 Binder.getCallingUid(), "setSatelliteServicePackageName");
13511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13512 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13513 "setSatelliteServicePackageName");
13514 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13515 }
13516
13517 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013518 * This API can be used by only CTS to update satellite gateway service package name.
13519 *
13520 * @param servicePackageName The package name of the satellite gateway service.
13521 * @return {@code true} if the satellite gateway service is set successfully,
13522 * {@code false} otherwise.
13523 */
13524 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13525 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13526 TelephonyPermissions.enforceShellOnly(
13527 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13529 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13530 "setSatelliteGatewayServicePackageName");
13531 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13532 }
13533
13534 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013535 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13536 *
13537 * @param packageName The package name of the satellite pointing UI app.
13538 * @param className The class name of the satellite pointing UI app.
13539 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13540 * {@code false} otherwise.
13541 */
13542 public boolean setSatellitePointingUiClassName(
13543 @Nullable String packageName, @Nullable String className) {
13544 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13545 + ", className=" + className);
13546 TelephonyPermissions.enforceShellOnly(
13547 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13549 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13550 "setSatelliteGatewayServicePackageName");
13551 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13552 }
13553
13554 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013555 * This API can be used by only CTS to update the timeout duration in milliseconds that
13556 * satellite should stay at listening mode to wait for the next incoming page before disabling
13557 * listening mode.
13558 *
13559 * @param timeoutMillis The timeout duration in millisecond.
13560 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13561 */
13562 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13563 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13564 TelephonyPermissions.enforceShellOnly(
13565 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13567 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13568 "setSatelliteListeningTimeoutDuration");
13569 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13570 }
13571
13572 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013573 * This API can be used by only CTS to update the timeout duration in milliseconds whether
13574 * the device is aligned with the satellite for demo mode
13575 *
13576 * @param timeoutMillis The timeout duration in millisecond.
13577 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13578 */
13579 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
13580 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
13581 TelephonyPermissions.enforceShellOnly(
13582 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
13583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13584 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13585 "setDeviceAlignedTimeoutDuration");
13586 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
13587 }
13588
13589 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013590 * This API can be used in only testing to override connectivity status in monitoring emergency
13591 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13592 *
13593 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13594 * of the following values to enable the override:
13595 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13596 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13597 * To disable the override, use -1 for handoverType.
13598 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13599 * delaySeconds after the emergency call starts.
13600 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13601 */
13602 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13603 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13604 TelephonyPermissions.enforceShellOnly(
13605 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13607 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13608 "setEmergencyCallToSatelliteHandoverType");
13609 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13610 handoverType, delaySeconds);
13611 }
13612
13613 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013614 * This API can be used by only CTS to override the cached value for the device overlay config
13615 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13616 * outgoing satellite datagrams should be sent to modem in demo mode.
13617 *
13618 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13619 * satellite modem or not.
13620 *
13621 * @return {@code true} if the operation is successful, {@code false} otherwise.
13622 */
13623 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13624 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13625 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13626 + "disabled");
13627 return false;
13628 }
13629 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13630 TelephonyPermissions.enforceShellOnly(
13631 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13633 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13634 "setShouldSendDatagramToModemInDemoMode");
13635 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13636 shouldSendToModemInDemoMode);
13637 }
13638
13639 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013640 * Enable or disable notifications sent for cellular identifier disclosure events.
13641 *
13642 * Disclosure events are defined as instances where a device has sent a cellular identifier
13643 * on the Non-access stratum (NAS) before a security context is established. As a result the
13644 * identifier is sent in the clear, which has privacy implications for the user.
13645 *
13646 * @param enable if notifications about disclosure events should be enabled
13647 * @throws SecurityException if the caller does not have the required privileges
13648 * @throws UnsupportedOperationException if the modem does not support this feature.
13649 */
13650 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013651 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013652 enforceModifyPermission();
13653 checkForIdentifierDisclosureNotificationSupport();
13654
13655 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13656 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13657 editor.apply();
13658
13659 // Each phone instance is responsible for updating its respective modem immediately
13660 // after we've made a preference change.
13661 for (Phone phone : PhoneFactory.getPhones()) {
13662 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13663 }
13664 }
13665
13666 /**
13667 * Get whether or not cellular identifier disclosure notifications are enabled.
13668 *
13669 * @throws SecurityException if the caller does not have the required privileges
13670 * @throws UnsupportedOperationException if the modem does not support this feature.
13671 */
13672 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013673 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013674 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13675 checkForIdentifierDisclosureNotificationSupport();
13676 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13677 }
13678
13679 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013680 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13681 *
13682 * <p>This method behaves in one of the following ways:
13683 * <ul>
13684 * <li>return true : if the calling package has the appop permission {@link
13685 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13686 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13687 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13688 * Owner device identifier access check, or the calling package has carrier privileges</>
13689 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13690 * </ul>
13691 */
13692 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13693 String callingPackage, @Nullable String callingFeatureId, String message) {
13694 for (Phone phone : PhoneFactory.getPhones()) {
13695 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13696 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13697 return true;
13698 }
13699 }
13700 return false;
13701 }
arunvoddud7401012022-12-15 16:08:12 +000013702
13703 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013704 * @return The subscription manager service instance.
13705 */
13706 public SubscriptionManagerService getSubscriptionManagerService() {
13707 return SubscriptionManagerService.getInstance();
13708 }
13709
13710 /**
arunvoddud7401012022-12-15 16:08:12 +000013711 * Class binds the consumer[callback] and carrierId.
13712 */
13713 private static class CallerCallbackInfo {
13714 private final Consumer<Integer> mConsumer;
13715 private final int mCarrierId;
13716
13717 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13718 mConsumer = consumer;
13719 mCarrierId = carrierId;
13720 }
13721
13722 public Consumer<Integer> getConsumer() {
13723 return mConsumer;
13724 }
13725
13726 public int getCarrierId() {
13727 return mCarrierId;
13728 }
13729 }
joonhunshin4ac60942023-11-15 15:23:39 +000013730
13731 /*
13732 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
13733 * But the context that is passed in is unused if the phone app is already alive.
13734 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
13735 */
13736 @VisibleForTesting
13737 public void setPackageManager(PackageManager packageManager) {
13738 mPackageManager = packageManager;
13739 }
13740
13741 /*
13742 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
13743 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
13744 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
13745 */
13746 @VisibleForTesting
13747 public void setFeatureFlags(FeatureFlags featureFlags) {
13748 mFeatureFlags = featureFlags;
13749 }
13750
13751 /**
13752 * Make sure the device has required telephony feature
13753 *
13754 * @throws UnsupportedOperationException if the device does not have required telephony feature
13755 */
13756 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
13757 @NonNull String telephonyFeature, @NonNull String methodName) {
13758 if (callingPackage == null || mPackageManager == null) {
13759 return;
13760 }
13761
13762 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
13763 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
13764 Binder.getCallingUserHandle())) {
13765 return;
13766 }
13767
13768 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
13769 throw new UnsupportedOperationException(
13770 methodName + " is unsupported without " + telephonyFeature);
13771 }
13772 }
Jack Yufa8ed012023-02-11 15:42:28 -080013773}