blob: cbf00dd0970b2ca3d59014e3088fb6d47af3f3eb [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
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070020import static android.permission.flags.Flags.opEnableMobileDataByUser;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000021import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080022import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080023
Shuo Qianccbaf742021-02-22 18:32:21 -080024import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
25import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070026import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070027import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000028import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070029
Brad Ebinger34c09a52021-02-17 23:23:21 +000030import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080032import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070033import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000034import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080035import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080037import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070038import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000039import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080040import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.compat.annotation.ChangeId;
42import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000043import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070044import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070045import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.content.Context;
47import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070049import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070050import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.net.Uri;
52import android.os.AsyncResult;
53import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080054import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080056import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070058import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080059import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080060import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.os.Looper;
62import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070063import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080064import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070065import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070066import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080067import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080068import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070069import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070070import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080071import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070073import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070075import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070076import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080077import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070078import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000079import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090080import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080081import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080082import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070083import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080084import android.telephony.AccessNetworkConstants;
85import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070086import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070087import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080088import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070089import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080090import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070091import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080092import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060093import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070094import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080095import android.telephony.CellIdentityCdma;
96import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070098import android.telephony.CellInfoGsm;
99import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700100import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800101import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700102import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700103import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700104import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800105import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700106import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800107import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700108import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800109import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800110import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700111import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800112import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800114import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800115import android.telephony.SignalStrengthUpdateRequest;
116import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800117import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800119import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700120import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700121import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800122import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800123import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800124import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800125import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000127import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000128import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700129import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700130import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800131import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800132import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700133import android.telephony.gba.GbaAuthRequest;
134import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700135import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000137import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000138import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700139import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000140import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700141import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700143import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800144import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700145import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000146import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700147import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800148import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800149import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000150import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000151import android.telephony.satellite.ISatelliteCapabilitiesCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800152import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800153import android.telephony.satellite.ISatelliteProvisionStateCallback;
154import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800155import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800156import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000157import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800158import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800159import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800160import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800162import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700163import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800165import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800166
Andrew Lee312e8172014-10-23 17:01:36 -0700167import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800168import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800169import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800170import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800171import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700172import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700173import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700174import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800175import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800176import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700177import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800179import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700180import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800181import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800182import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800183import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700184import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000185import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700186import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800187import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800189import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800190import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800191import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700192import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700193import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700194import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700196import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800197import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700198import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700199import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700200import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700201import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800202import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800203import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700204import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000205import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700206import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700207import com.android.internal.telephony.SmsPermissions;
Peter Wang59571be2020-01-27 12:35:15 +0800208import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800209import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700210import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000211import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800212import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700213import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700214import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800215import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700216import com.android.internal.telephony.imsphone.ImsPhone;
217import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000218import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800219import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000220import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800221import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
222import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700223import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700224import com.android.internal.telephony.uicc.IccIoResult;
225import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800226import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700227import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800228import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700229import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000230import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800231import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000232import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800233import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000234import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700235import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700236import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800237import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800238import com.android.phone.callcomposer.CallComposerPictureManager;
239import com.android.phone.callcomposer.CallComposerPictureTransfer;
240import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700241import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700242import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000243import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700244import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800245import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700246import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700247import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800248import com.android.services.telephony.TelecomAccountRegistry;
249import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800250import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800251
Hall Liu82694d52020-12-11 18:22:04 -0800252import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700253import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800254import java.io.IOException;
255import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700256import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800258import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000259import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800260import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800261import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800262import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800263import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100264import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800265import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700266import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800267import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800268import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700269import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800270import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800271import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800272import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
274/**
275 * Implementation of the ITelephony interface.
276 */
Santos Cordon117fee72014-05-16 17:56:12 -0700277public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 private static final String LOG_TAG = "PhoneInterfaceManager";
279 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
280 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800281 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282
283 // Message codes used with mMainThreadHandler
284 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700285 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
286 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700287 private static final int CMD_OPEN_CHANNEL = 9;
288 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
289 private static final int CMD_CLOSE_CHANNEL = 11;
290 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800291 private static final int CMD_NV_READ_ITEM = 13;
292 private static final int EVENT_NV_READ_ITEM_DONE = 14;
293 private static final int CMD_NV_WRITE_ITEM = 15;
294 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
295 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
296 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700297 private static final int CMD_RESET_MODEM_CONFIG = 19;
298 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800299 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
300 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800301 private static final int CMD_SEND_ENVELOPE = 25;
302 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700303 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
304 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
305 private static final int CMD_EXCHANGE_SIM_IO = 31;
306 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800307 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
308 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700309 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
310 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700311 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
312 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700313 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
314 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
315 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
316 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700317 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
318 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
319 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
320 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700321 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800322 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
323 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000324 private static final int CMD_SWITCH_SLOTS = 50;
325 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700326 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
327 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
328 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
329 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
330 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
331 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
332 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
333 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700334 private static final int CMD_GET_ALL_CELL_INFO = 60;
335 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
336 private static final int CMD_GET_CELL_LOCATION = 62;
337 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700338 private static final int CMD_MODEM_REBOOT = 64;
339 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700340 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
341 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800342 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
343 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700344 private static final int CMD_GET_MODEM_STATUS = 70;
345 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700346 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
347 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700348 private static final int CMD_ERASE_MODEM_CONFIG = 74;
349 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800350 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
351 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
352 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
353 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800354 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
355 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800356 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800357 private static final int CMD_GET_CALL_FORWARDING = 83;
358 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
359 private static final int CMD_SET_CALL_FORWARDING = 85;
360 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
361 private static final int CMD_GET_CALL_WAITING = 87;
362 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
363 private static final int CMD_SET_CALL_WAITING = 89;
364 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700365 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
366 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
367 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
368 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700369 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
370 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800371 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
372 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800373 private static final int CMD_SET_DATA_THROTTLING = 99;
374 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800375 private static final int CMD_SET_SIM_POWER = 101;
376 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800377 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
378 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
379 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
380 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800381 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
382 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000383 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800384 private static final int CMD_GET_SLICING_CONFIG = 110;
385 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800386 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700387 private static final int CMD_ENABLE_VONR = 113;
388 private static final int EVENT_ENABLE_VONR_DONE = 114;
389 private static final int CMD_IS_VONR_ENABLED = 115;
390 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700391 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
392 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000393
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800394 // Parameters of select command.
395 private static final int SELECT_COMMAND = 0xA4;
396 private static final int SELECT_P1 = 0x04;
397 private static final int SELECT_P2 = 0;
398 private static final int SELECT_P3 = 0x10;
399
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000400 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
401 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
402
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 /** The singleton instance. */
404 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800405 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406
Sarah Chin4beb2b72023-02-14 14:47:54 -0800407 private final PhoneGlobals mApp;
Sarah Chincc5446f2023-10-23 17:57:19 -0700408 private final FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800409 private final CallManager mCM;
410 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000411
412 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800413 private final UserManager mUserManager;
414 private final AppOpsManager mAppOps;
415 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800416 private final SharedPreferences mTelephonySharedPreferences;
417 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800418 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419
Peter Wangdafb9ac2020-01-15 14:13:38 -0800420 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800421 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800422 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
423
Sarah Chin4beb2b72023-02-14 14:47:54 -0800424 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800425
Derek Tan97ebb422014-09-05 16:55:38 -0700426 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
427 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800428 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800429 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700430
Michelecea4cf22018-12-21 15:00:11 -0800431 // String to store multi SIM allowed
432 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
433
Derek Tan740e1672017-06-27 14:56:27 -0700434 // The AID of ISD-R.
435 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
436
yinxub1bed742017-04-17 11:45:04 -0700437 private NetworkScanRequestTracker mNetworkScanRequestTracker;
438
David Kelly5e06a7f2018-03-12 14:10:59 +0000439 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
440 private static final int MANUFACTURER_CODE_LENGTH = 8;
441
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800442 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800443 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800444
Sarah Chin2ec39f62022-08-31 17:03:26 -0700445 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
446 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
447
Derek Tan89e89d42014-07-08 17:00:10 -0700448 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700449 * Experiment flag to enable erase modem config on reset network, default value is false
450 */
451 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
452 "reset_network_erase_modem_config_enabled";
453
Rambo Wang0f050d82021-02-12 11:43:36 -0800454 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800455
Gary Jian76280a42022-12-07 16:18:33 +0800456 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
457
sandeepjsb6c87872021-09-27 15:34:44 +0000458 /**
459 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
460 * one ICCID active at the same time.
461 * Apps should use below API signatures if targeting SDK is T and beyond.
462 *
463 * @hide
464 */
465 @ChangeId
466 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
467 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800468
Naina Nallurid63128d2019-09-17 14:10:30 -0700469 /**
Chen Xu540470b2021-12-14 17:15:47 -0800470 * Apps targeting on Android T and beyond will get exception whenever icc close channel
471 * operation fails.
472 */
473 @ChangeId
474 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
475 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
476
477 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 * A request object to use for transmitting data to an ICC.
479 */
480 private static final class IccAPDUArgument {
481 public int channel, cla, command, p1, p2, p3;
482 public String data;
483
484 public IccAPDUArgument(int channel, int cla, int command,
485 int p1, int p2, int p3, String data) {
486 this.channel = channel;
487 this.cla = cla;
488 this.command = command;
489 this.p1 = p1;
490 this.p2 = p2;
491 this.p3 = p3;
492 this.data = data;
493 }
494 }
495
496 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700497 * A request object to use for transmitting data to an ICC.
498 */
499 private static final class ManualNetworkSelectionArgument {
500 public OperatorInfo operatorInfo;
501 public boolean persistSelection;
502
503 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
504 this.operatorInfo = operatorInfo;
505 this.persistSelection = persistSelection;
506 }
507 }
508
Sarah Chin71b3a852022-09-28 15:54:19 -0700509 private static final class PurchasePremiumCapabilityArgument {
510 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700511 public @NonNull IIntegerConsumer callback;
512
513 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800514 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700515 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700516 this.callback = callback;
517 }
518 }
519
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700520 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
522 * request after sending. The main thread will notify the request when it is complete.
523 */
524 private static final class MainThreadRequest {
525 /** The argument to use for the request */
526 public Object argument;
527 /** The result of the request that is run on the main thread */
528 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800529 // The subscriber id that this request applies to. Defaults to
530 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
531 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532
Nathan Harold92bed182018-10-12 18:16:49 -0700533 // In cases where subId is unavailable, the caller needs to specify the phone.
534 public Phone phone;
535
vagdeviaf9a5b92018-08-15 16:01:53 -0700536 public WorkSource workSource;
537
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 public MainThreadRequest(Object argument) {
539 this.argument = argument;
540 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800541
Nathan Harold92bed182018-10-12 18:16:49 -0700542 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
543 this.argument = argument;
544 if (phone != null) {
545 this.phone = phone;
546 }
547 this.workSource = workSource;
548 }
549
vagdeviaf9a5b92018-08-15 16:01:53 -0700550 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800551 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800552 if (subId != null) {
553 this.subId = subId;
554 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700555 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700557 }
558
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800559 private static final class IncomingThirdPartyCallArgs {
560 public final ComponentName component;
561 public final String callId;
562 public final String callerDisplayName;
563
564 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
565 String callerDisplayName) {
566 this.component = component;
567 this.callId = callId;
568 this.callerDisplayName = callerDisplayName;
569 }
570 }
571
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572 /**
573 * A handler that processes messages on the main thread in the phone process. Since many
574 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
575 * inbound binder threads to the main thread in the phone process. The Binder thread
576 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
577 * on, which will be notified when the operation completes and will contain the result of the
578 * request.
579 *
580 * <p>If a MainThreadRequest object is provided in the msg.obj field,
581 * note that request.result must be set to something non-null for the calling thread to
582 * unblock.
583 */
584 private final class MainThreadHandler extends Handler {
585 @Override
586 public void handleMessage(Message msg) {
587 MainThreadRequest request;
588 Message onCompleted;
589 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000590 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800592 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700593
594 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 case CMD_HANDLE_USSD_REQUEST: {
596 request = (MainThreadRequest) msg.obj;
597 final Phone phone = getPhoneFromRequest(request);
598 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800599 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700601
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 if (!isUssdApiAllowed(request.subId)) {
603 // Carrier does not support use of this API, return failure.
604 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
605 UssdResponse response = new UssdResponse(ussdRequest, null);
606 Bundle returnData = new Bundle();
607 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
608 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700609
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 request.result = true;
611 notifyRequester(request);
612 return;
613 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700614
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 try {
616 request.result = phone != null
617 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
618 } catch (CallStateException cse) {
619 request.result = false;
620 }
621 // Wake up the requesting thread
622 notifyRequester(request);
623 break;
pkanwar32d516d2016-10-14 19:37:38 -0700624 }
625
Yorke Lee716f67e2015-06-17 15:39:16 -0700626 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700628 final Phone phone = getPhoneFromRequest(request);
629 request.result = phone != null ?
630 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
631 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700636
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000640 uiccPort = getUiccPortFromRequest(request);
641 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800643 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700645 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800647 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000648 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800649 iccArgument.channel, iccArgument.cla, iccArgument.command,
650 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
651 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 break;
654
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 ar = (AsyncResult) msg.obj;
657 request = (MainThreadRequest) ar.userObj;
658 if (ar.exception == null && ar.result != null) {
659 request.result = ar.result;
660 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800661 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 if (ar.result == null) {
663 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800664 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800666 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 } else {
668 loge("iccTransmitApduLogicalChannel: Unknown exception");
669 }
670 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 break;
673
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
675 request = (MainThreadRequest) msg.obj;
676 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000677 uiccPort = getUiccPortFromRequest(request);
678 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800680 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800684 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000685 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800686 iccArgument.cla, iccArgument.command, iccArgument.p1,
687 iccArgument.p2,
688 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 }
690 break;
691
692 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result;
697 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800698 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 if (ar.result == null) {
700 loge("iccTransmitApduBasicChannel: Empty response");
701 } else if (ar.exception instanceof CommandException) {
702 loge("iccTransmitApduBasicChannel: CommandException: " +
703 ar.exception);
704 } else {
705 loge("iccTransmitApduBasicChannel: Unknown exception");
706 }
707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 break;
710
711 case CMD_EXCHANGE_SIM_IO:
712 request = (MainThreadRequest) msg.obj;
713 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000714 uiccPort = getUiccPortFromRequest(request);
715 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800717 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
721 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
724 iccArgument.data, onCompleted);
725 }
726 break;
727
728 case EVENT_EXCHANGE_SIM_IO_DONE:
729 ar = (AsyncResult) msg.obj;
730 request = (MainThreadRequest) ar.userObj;
731 if (ar.exception == null && ar.result != null) {
732 request.result = ar.result;
733 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800734 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 break;
738
Derek Tan4d5e5c12014-02-04 11:54:58 -0800739 case CMD_SEND_ENVELOPE:
740 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000741 uiccPort = getUiccPortFromRequest(request);
742 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700743 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800744 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 } else {
747 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800748 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700749 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800750 break;
751
752 case EVENT_SEND_ENVELOPE_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800757 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800758 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700759 if (ar.result == null) {
760 loge("sendEnvelopeWithStatus: Empty response");
761 } else if (ar.exception instanceof CommandException) {
762 loge("sendEnvelopeWithStatus: CommandException: " +
763 ar.exception);
764 } else {
765 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
766 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800767 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700768 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800769 break;
770
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 case CMD_OPEN_CHANNEL:
772 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000773 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800774 IccLogicalChannelRequest openChannelRequest =
775 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000776 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700777 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800778 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800779 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700781 } else {
782 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800783 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
784 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700785 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 break;
787
788 case EVENT_OPEN_CHANNEL_DONE:
789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700791 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700793 int[] result = (int[]) ar.result;
794 int channelId = result[0];
795 byte[] selectResponse = null;
796 if (result.length > 1) {
797 selectResponse = new byte[result.length - 1];
798 for (int i = 1; i < result.length; ++i) {
799 selectResponse[i - 1] = (byte) result[i];
800 }
801 }
802 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800803 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800804
805 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700806 if (uiccPort == null) {
807 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
808 } else {
809 IccLogicalChannelRequest channelRequest =
810 (IccLogicalChannelRequest) request.argument;
811 channelRequest.channel = channelId;
812 uiccPort.onLogicalChannelOpened(channelRequest);
813 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700814 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 if (ar.result == null) {
816 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700818 if (ar.exception != null) {
819 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
820 }
821
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700822 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700823 if (ar.exception instanceof CommandException) {
824 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800825 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700826 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700827 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700828 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700829 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700830 }
831 }
832 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800833 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700835 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700836 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 break;
838
839 case CMD_CLOSE_CHANNEL:
840 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000841 uiccPort = getUiccPortFromRequest(request);
842 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700843 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800844 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800845 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800846 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700847 } else {
848 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000849 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 break;
852
853 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null) {
857 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800858 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700859 if (uiccPort == null) {
860 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
861 } else {
862 final int channelId = (Integer) request.argument;
863 uiccPort.onLogicalChannelClosed(channelId);
864 }
Chen Xu540470b2021-12-14 17:15:47 -0800865 } else {
866 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800867 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800868 if (ar.exception instanceof CommandException) {
869 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
870 CommandException.Error error =
871 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800872 if (error == CommandException.Error.INVALID_ARGUMENTS) {
873 // should only throw exceptions from the binder threads.
874 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800875 "iccCloseLogicalChannel: invalid argument ");
876 }
877 } else {
878 loge("iccCloseLogicalChannel: Unknown exception");
879 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800880 request.result = (exception != null) ? exception :
881 new IllegalStateException(
882 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800883 }
884 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800885 break;
886
887 case CMD_NV_READ_ITEM:
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800890 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
891 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
894 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700899 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800900 request.result = "";
901 if (ar.result == null) {
902 loge("nvReadItem: Empty response");
903 } else if (ar.exception instanceof CommandException) {
904 loge("nvReadItem: CommandException: " +
905 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700906 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800907 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700908 }
909 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700910 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700911 break;
912
Jake Hambye994d462014-02-03 13:10:13 -0800913 case CMD_NV_WRITE_ITEM:
914 request = (MainThreadRequest) msg.obj;
915 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
916 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800917 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700918 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800919 break;
920
921 case EVENT_NV_WRITE_ITEM_DONE:
922 handleNullReturnEvent(msg, "nvWriteItem");
923 break;
924
925 case CMD_NV_WRITE_CDMA_PRL:
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800928 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800929 break;
930
931 case EVENT_NV_WRITE_CDMA_PRL_DONE:
932 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
933 break;
934
chen xu6dac5ab2018-10-26 17:39:23 -0700935 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800936 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700937 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800938 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800939 break;
940
chen xu6dac5ab2018-10-26 17:39:23 -0700941 case EVENT_RESET_MODEM_CONFIG_DONE:
942 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800943 break;
944
Sooraj Sasindran37444802020-08-11 10:40:43 -0700945 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
948 request);
949 Phone phone = getPhoneFromRequest(request);
950 if (phone != null) {
951 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
952 } else {
953 loge("isNRDualConnectivityEnabled: No phone object");
954 request.result = false;
955 notifyRequester(request);
956 }
957 break;
958 }
959
960 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception == null && ar.result != null) {
964 request.result = ar.result;
965 } else {
966 // request.result must be set to something non-null
967 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700968 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700969 request.result = ar.result;
970 } else {
971 request.result = false;
972 }
973 if (ar.result == null) {
974 loge("isNRDualConnectivityEnabled: Empty response");
975 } else if (ar.exception instanceof CommandException) {
976 loge("isNRDualConnectivityEnabled: CommandException: "
977 + ar.exception);
978 } else {
979 loge("isNRDualConnectivityEnabled: Unknown exception");
980 }
981 }
982 notifyRequester(request);
983 break;
984
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700985 case CMD_IS_VONR_ENABLED: {
986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
988 request);
989 Phone phone = getPhoneFromRequest(request);
990 if (phone != null) {
991 phone.isVoNrEnabled(onCompleted, request.workSource);
992 } else {
993 loge("isVoNrEnabled: No phone object");
994 request.result = false;
995 notifyRequester(request);
996 }
997 break;
998 }
999
1000 case EVENT_IS_VONR_ENABLED_DONE:
1001 ar = (AsyncResult) msg.obj;
1002 request = (MainThreadRequest) ar.userObj;
1003 if (ar.exception == null && ar.result != null) {
1004 request.result = ar.result;
1005 } else {
1006 // request.result must be set to something non-null
1007 // for the calling thread to unblock
1008 if (ar.result != null) {
1009 request.result = ar.result;
1010 } else {
1011 request.result = false;
1012 }
1013 if (ar.result == null) {
1014 loge("isVoNrEnabled: Empty response");
1015 } else if (ar.exception instanceof CommandException) {
1016 loge("isVoNrEnabled: CommandException: "
1017 + ar.exception);
1018 } else {
1019 loge("isVoNrEnabled: Unknown exception");
1020 }
1021 }
1022 notifyRequester(request);
1023 break;
1024
Sooraj Sasindran37444802020-08-11 10:40:43 -07001025 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1028 Phone phone = getPhoneFromRequest(request);
1029 if (phone != null) {
1030 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1031 request.workSource);
1032 } else {
1033 loge("enableNrDualConnectivity: No phone object");
1034 request.result =
1035 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1036 notifyRequester(request);
1037 }
1038 break;
1039 }
1040
1041 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 if (ar.exception == null) {
1045 request.result =
1046 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1047 } else {
1048 request.result =
1049 TelephonyManager
1050 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1051 if (ar.exception instanceof CommandException) {
1052 CommandException.Error error =
1053 ((CommandException) (ar.exception)).getCommandError();
1054 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1055 request.result =
1056 TelephonyManager
1057 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001058 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1059 request.result =
1060 TelephonyManager
1061 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001062 }
1063 loge("enableNrDualConnectivity" + ": CommandException: "
1064 + ar.exception);
1065 } else {
1066 loge("enableNrDualConnectivity" + ": Unknown exception");
1067 }
1068 }
1069 notifyRequester(request);
1070 break;
1071 }
1072
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001073 case CMD_ENABLE_VONR: {
1074 request = (MainThreadRequest) msg.obj;
1075 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1076 Phone phone = getPhoneFromRequest(request);
1077 if (phone != null) {
1078 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1079 request.workSource);
1080 } else {
1081 loge("setVoNrEnabled: No phone object");
1082 request.result =
1083 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1084 notifyRequester(request);
1085 }
1086 break;
1087 }
1088
1089 case EVENT_ENABLE_VONR_DONE: {
1090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
1092 if (ar.exception == null) {
1093 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1094 } else {
1095 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1096 if (ar.exception instanceof CommandException) {
1097 CommandException.Error error =
1098 ((CommandException) (ar.exception)).getCommandError();
1099 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1100 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1101 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1102 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1103 } else {
1104 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1105 }
1106 loge("setVoNrEnabled" + ": CommandException: "
1107 + ar.exception);
1108 } else {
1109 loge("setVoNrEnabled" + ": Unknown exception");
1110 }
1111 }
1112 notifyRequester(request);
1113 break;
1114 }
1115
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001117 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001118 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1119 request);
1120 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001121 break;
1122
SongFerngWang3ef3e072020-12-21 16:41:52 +08001123 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 if (ar.exception == null && ar.result != null) {
1127 request.result = ar.result; // Integer
1128 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301129 // request.result must be set to something non-null
1130 // for the calling thread to unblock
1131 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001132 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001133 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001134 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 loge("getAllowedNetworkTypesBitmask: CommandException: "
1136 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001138 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 }
1140 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001141 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 break;
1143
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001145 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001146 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1147 request);
1148 Pair<Integer, Long> reasonWithNetworkTypes =
1149 (Pair<Integer, Long>) request.argument;
1150 getPhoneFromRequest(request).setAllowedNetworkTypes(
1151 reasonWithNetworkTypes.first,
1152 reasonWithNetworkTypes.second,
1153 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 break;
1155
SongFerngWang3ef3e072020-12-21 16:41:52 +08001156 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1157 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 break;
1159
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001160 case CMD_SET_VOICEMAIL_NUMBER:
1161 request = (MainThreadRequest) msg.obj;
1162 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1163 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001164 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1165 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001166 break;
1167
1168 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1169 handleNullReturnEvent(msg, "setVoicemailNumber");
1170 break;
1171
Stuart Scott54788802015-03-30 13:18:01 -07001172 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1175 request);
1176 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1177 break;
1178
1179 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1180 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1181 break;
1182
Shishir Agrawal302c8692015-06-19 13:49:39 -07001183 case CMD_PERFORM_NETWORK_SCAN:
1184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1186 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1187 break;
1188
Hall Liu27d24262020-09-18 19:04:59 -07001189 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001192 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1193 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1194 request.argument;
1195 int callForwardingReason = args.first;
1196 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001197 break;
Hall Liu27d24262020-09-18 19:04:59 -07001198 }
1199 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001202 TelephonyManager.CallForwardingInfoCallback callback =
1203 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1204 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001206 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1208 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1209 // Service Class is a bit mask per 3gpp 27.007. Search for
1210 // any service for voice call.
1211 if ((callForwardInfo.serviceClass
1212 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001213 callForwardingInfo = new CallForwardingInfo(
1214 callForwardInfo.status
1215 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001216 callForwardInfo.reason,
1217 callForwardInfo.number,
1218 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001219 break;
1220 }
1221 }
1222 // Didn't find a call forward info for voice call.
1223 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001224 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1225 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 }
Hall Liu27d24262020-09-18 19:04:59 -07001227 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001228 } else {
1229 if (ar.result == null) {
1230 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1231 }
1232 if (ar.exception != null) {
1233 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1234 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001235 int errorCode = TelephonyManager
1236 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001237 if (ar.exception instanceof CommandException) {
1238 CommandException.Error error =
1239 ((CommandException) (ar.exception)).getCommandError();
1240 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001241 errorCode = TelephonyManager
1242 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001243 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001244 errorCode = TelephonyManager
1245 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001246 }
1247 }
Hall Liu27d24262020-09-18 19:04:59 -07001248 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250 break;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252
Hall Liu27d24262020-09-18 19:04:59 -07001253 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001254 request = (MainThreadRequest) msg.obj;
1255 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001256 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001257 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001258 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1259 request.argument).first;
1260 request.phone.setCallForwardingOption(
1261 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001262 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001263 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001264 callForwardingInfoToSet.getReason(),
1265 callForwardingInfoToSet.getNumber(),
1266 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1267 break;
Hall Liu27d24262020-09-18 19:04:59 -07001268 }
Shuo Qian4a594052020-01-23 11:59:30 -08001269
Hall Liu27d24262020-09-18 19:04:59 -07001270 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001271 ar = (AsyncResult) msg.obj;
1272 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001273 Consumer<Integer> callback =
1274 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1275 request.argument).second;
1276 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001277 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001278 int errorCode = TelephonyManager.CallForwardingInfoCallback
1279 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001280 if (ar.exception instanceof CommandException) {
1281 CommandException.Error error =
1282 ((CommandException) (ar.exception)).getCommandError();
1283 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001284 errorCode = TelephonyManager.CallForwardingInfoCallback
1285 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001286 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001287 errorCode = TelephonyManager.CallForwardingInfoCallback
1288 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001289 }
1290 }
1291 callback.accept(errorCode);
1292 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001293 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001294 }
Shuo Qian4a594052020-01-23 11:59:30 -08001295 break;
Hall Liu27d24262020-09-18 19:04:59 -07001296 }
Shuo Qian4a594052020-01-23 11:59:30 -08001297
Hall Liu27d24262020-09-18 19:04:59 -07001298 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001299 request = (MainThreadRequest) msg.obj;
1300 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1301 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1302 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 EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001306 ar = (AsyncResult) msg.obj;
1307 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001308 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001309 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001310 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001311 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001312 // Service Class is a bit mask per 3gpp 27.007.
1313 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001314 if (callForwardResults.length > 1
1315 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001316 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001317 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001318 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1319 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001320 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001321 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001322 }
1323 } else {
1324 if (ar.result == null) {
1325 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1326 }
1327 if (ar.exception != null) {
1328 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1329 }
1330 if (ar.exception instanceof CommandException) {
1331 CommandException.Error error =
1332 ((CommandException) (ar.exception)).getCommandError();
1333 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001334 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001335 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1337 callWaitingStatus =
1338 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001339 }
1340 }
1341 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001342 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001343 break;
Hall Liu27d24262020-09-18 19:04:59 -07001344 }
Shuo Qian4a594052020-01-23 11:59:30 -08001345
Hall Liu27d24262020-09-18 19:04:59 -07001346 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001347 request = (MainThreadRequest) msg.obj;
1348 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001349 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1350 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001351 break;
Hall Liu27d24262020-09-18 19:04:59 -07001352 }
Shuo Qian4a594052020-01-23 11:59:30 -08001353
Hall Liu27d24262020-09-18 19:04:59 -07001354 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001355 ar = (AsyncResult) msg.obj;
1356 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001357 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1358 Consumer<Integer> callback =
1359 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1360 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001361 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001362 if (ar.exception instanceof CommandException) {
1363 CommandException.Error error =
1364 ((CommandException) (ar.exception)).getCommandError();
1365 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1366 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001367 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1368 callback.accept(
1369 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001370 } else {
1371 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1372 }
1373 } else {
1374 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1375 }
1376 } else {
1377 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1378 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001379 }
Shuo Qian4a594052020-01-23 11:59:30 -08001380 break;
Hall Liu27d24262020-09-18 19:04:59 -07001381 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001382 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1383 ar = (AsyncResult) msg.obj;
1384 request = (MainThreadRequest) ar.userObj;
1385 CellNetworkScanResult cellScanResult;
1386 if (ar.exception == null && ar.result != null) {
1387 cellScanResult = new CellNetworkScanResult(
1388 CellNetworkScanResult.STATUS_SUCCESS,
1389 (List<OperatorInfo>) ar.result);
1390 } else {
1391 if (ar.result == null) {
1392 loge("getCellNetworkScanResults: Empty response");
1393 }
1394 if (ar.exception != null) {
1395 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1396 }
1397 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1398 if (ar.exception instanceof CommandException) {
1399 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001400 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001401 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1402 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1403 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1404 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1405 }
1406 }
1407 cellScanResult = new CellNetworkScanResult(errorCode, null);
1408 }
1409 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001410 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001411 break;
1412
1413 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1414 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001415 ManualNetworkSelectionArgument selArg =
1416 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001417 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1418 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001419 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1420 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001421 break;
1422
1423 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 if (ar.exception == null) {
1427 request.result = true;
1428 } else {
1429 request.result = false;
1430 loge("setNetworkSelectionModeManual " + ar.exception);
1431 }
1432 notifyRequester(request);
1433 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001434 break;
1435
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001436 case CMD_GET_MODEM_ACTIVITY_INFO:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001439 if (defaultPhone != null) {
1440 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001441 } else {
1442 ResultReceiver result = (ResultReceiver) request.argument;
1443 Bundle bundle = new Bundle();
1444 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001445 new ModemActivityInfo(0, 0, 0,
1446 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001447 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001448 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001449 break;
1450
Hall Liud0f208c2020-10-14 16:54:44 -07001451 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001454 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001455 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001456 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001457 if (mLastModemActivityInfo == null) {
1458 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1459 mLastModemActivitySpecificInfo[0] =
1460 new ActivityStatsTechSpecificInfo(
1461 0,
1462 0,
1463 new int[ModemActivityInfo.getNumTxPowerLevels()],
1464 0);
1465 mLastModemActivityInfo =
1466 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1467 }
1468
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001470 // Update the last modem activity info and the result of the request.
1471 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1472 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001473 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001474 } else {
1475 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001476 }
Kai Shi917fdc62022-11-28 14:01:02 -08001477 // This is needed to decouple ret from mLastModemActivityInfo
1478 // We don't want to return mLastModemActivityInfo which is updated
1479 // inside mergeModemActivityInfo()
1480 ret = new ModemActivityInfo(
1481 mLastModemActivityInfo.getTimestampMillis(),
1482 mLastModemActivityInfo.getSleepTimeMillis(),
1483 mLastModemActivityInfo.getIdleTimeMillis(),
1484 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001485
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001486 } else {
1487 if (ar.result == null) {
1488 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001489 error = TelephonyManager.ModemActivityInfoException
1490 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001491 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001492 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001493 error = TelephonyManager.ModemActivityInfoException
1494 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001495 } else {
1496 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001497 error = TelephonyManager.ModemActivityInfoException
1498 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001499 }
1500 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001501 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001502 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001503 bundle.putParcelable(
1504 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001505 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001506 } else {
1507 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1508 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001509 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001510 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001512 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001513
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001514 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001516 CarrierRestrictionRules argument =
1517 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001519 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001520 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001521 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001522
1523 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1524 ar = (AsyncResult) msg.obj;
1525 request = (MainThreadRequest) ar.userObj;
1526 if (ar.exception == null && ar.result != null) {
1527 request.result = ar.result;
1528 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001529 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1530 if (ar.exception instanceof CommandException) {
1531 loge("setAllowedCarriers: CommandException: " + ar.exception);
1532 CommandException.Error error =
1533 ((CommandException) (ar.exception)).getCommandError();
1534 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1535 request.result =
1536 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1537 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001538 } else {
1539 loge("setAllowedCarriers: Unknown exception");
1540 }
1541 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001542 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001543 break;
1544
1545 case CMD_GET_ALLOWED_CARRIERS:
1546 request = (MainThreadRequest) msg.obj;
1547 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001548 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 break;
1550
1551 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1552 ar = (AsyncResult) msg.obj;
1553 request = (MainThreadRequest) ar.userObj;
1554 if (ar.exception == null && ar.result != null) {
1555 request.result = ar.result;
1556 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001557 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001558 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001559 if (ar.result == null) {
1560 loge("getAllowedCarriers: Empty response");
1561 } else if (ar.exception instanceof CommandException) {
1562 loge("getAllowedCarriers: CommandException: " +
1563 ar.exception);
1564 } else {
1565 loge("getAllowedCarriers: Unknown exception");
1566 }
1567 }
arunvoddud7401012022-12-15 16:08:12 +00001568 if (request.argument != null) {
1569 // This is for the implementation of carrierRestrictionStatus.
1570 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1571 Consumer<Integer> callback = callbackInfo.getConsumer();
1572 int callerCarrierId = callbackInfo.getCarrierId();
1573 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1574 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1575 CarrierRestrictionRules carrierRestrictionRules =
1576 (CarrierRestrictionRules) ar.result;
1577 int carrierId = -1;
1578 try {
1579 CarrierIdentifier carrierIdentifier =
1580 carrierRestrictionRules.getAllowedCarriers().get(0);
1581 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1582 carrierIdentifier);
1583 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1584 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1585 }
1586 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1587 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1588 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001589 lockStatus = TelephonyManager
1590 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001591 }
1592 } else {
1593 Rlog.e(LOG_TAG,
1594 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1595 }
1596 callback.accept(lockStatus);
1597 } else {
1598 // This is for the implementation of getAllowedCarriers.
1599 notifyRequester(request);
1600 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001601 break;
1602
Nathan Haroldb3014052017-01-25 15:57:32 -08001603 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1604 ar = (AsyncResult) msg.obj;
1605 request = (MainThreadRequest) ar.userObj;
1606 if (ar.exception == null && ar.result != null) {
1607 request.result = ar.result;
1608 } else {
1609 request.result = new IllegalArgumentException(
1610 "Failed to retrieve Forbidden Plmns");
1611 if (ar.result == null) {
1612 loge("getForbiddenPlmns: Empty response");
1613 } else {
1614 loge("getForbiddenPlmns: Unknown exception");
1615 }
1616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001617 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001618 break;
1619
1620 case CMD_GET_FORBIDDEN_PLMNS:
1621 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001622 uiccPort = getUiccPortFromRequest(request);
1623 if (uiccPort == null) {
1624 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001625 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001626 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001627 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001628 break;
1629 }
1630 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001631 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001632 if (uiccApp == null) {
1633 loge("getForbiddenPlmns() no app with specified type -- "
1634 + appType);
1635 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001636 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001637 break;
1638 } else {
1639 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1640 + " specified type -- " + appType);
1641 }
1642 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1643 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001644 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001645 break;
1646
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001647 case CMD_SWITCH_SLOTS:
1648 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001649 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001650 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001651 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001652 break;
1653
1654 case EVENT_SWITCH_SLOTS_DONE:
1655 ar = (AsyncResult) msg.obj;
1656 request = (MainThreadRequest) ar.userObj;
1657 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001658 notifyRequester(request);
1659 break;
1660 case CMD_GET_NETWORK_SELECTION_MODE:
1661 request = (MainThreadRequest) msg.obj;
1662 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1663 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1664 break;
1665
1666 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1667 ar = (AsyncResult) msg.obj;
1668 request = (MainThreadRequest) ar.userObj;
1669 if (ar.exception != null) {
1670 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1671 } else {
1672 int mode = ((int[]) ar.result)[0];
1673 if (mode == 0) {
1674 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1675 } else {
1676 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1677 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001679 notifyRequester(request);
1680 break;
1681 case CMD_GET_CDMA_ROAMING_MODE:
1682 request = (MainThreadRequest) msg.obj;
1683 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1684 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1685 break;
1686 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1687 ar = (AsyncResult) msg.obj;
1688 request = (MainThreadRequest) ar.userObj;
1689 if (ar.exception != null) {
1690 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1691 } else {
1692 request.result = ((int[]) ar.result)[0];
1693 }
1694 notifyRequester(request);
1695 break;
1696 case CMD_SET_CDMA_ROAMING_MODE:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1699 int mode = (int) request.argument;
1700 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1701 break;
1702 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 request.result = ar.exception == null;
1706 notifyRequester(request);
1707 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001708 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1711 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1712 break;
1713 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception != null) {
1717 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1718 } else {
1719 request.result = ((int[]) ar.result)[0];
1720 }
1721 notifyRequester(request);
1722 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001723 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1726 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001727 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1728 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001729 break;
1730 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 request.result = ar.exception == null;
1734 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001735 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 case CMD_GET_ALL_CELL_INFO:
1737 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001739 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001740 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001741 case EVENT_GET_ALL_CELL_INFO_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001744 // If a timeout occurs, the response will be null
1745 request.result = (ar.exception == null && ar.result != null)
1746 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 synchronized (request) {
1748 request.notifyAll();
1749 }
1750 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001751 case CMD_REQUEST_CELL_INFO_UPDATE:
1752 request = (MainThreadRequest) msg.obj;
1753 request.phone.requestCellInfoUpdate(request.workSource,
1754 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1755 break;
1756 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1760 try {
1761 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001762 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001763 cb.onError(
1764 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1765 ar.exception.getClass().getName(),
1766 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001767 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001768 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001769 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001770 } else {
1771 // use the result as returned
1772 cb.onCellInfo((List<CellInfo>) ar.result);
1773 }
1774 } catch (RemoteException re) {
1775 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1776 }
1777 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001778 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001779 request = (MainThreadRequest) msg.obj;
1780 WorkSource ws = (WorkSource) request.argument;
1781 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001782 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001783 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001784 }
1785 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001786 ar = (AsyncResult) msg.obj;
1787 request = (MainThreadRequest) ar.userObj;
1788 if (ar.exception == null) {
1789 request.result = ar.result;
1790 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001791 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001792 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001793 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001794 }
1795
1796 synchronized (request) {
1797 request.notifyAll();
1798 }
1799 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 }
chen xu6dac5ab2018-10-26 17:39:23 -07001801 case CMD_MODEM_REBOOT:
1802 request = (MainThreadRequest) msg.obj;
1803 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001804 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001805 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001806 case EVENT_CMD_MODEM_REBOOT_DONE:
1807 handleNullReturnEvent(msg, "rebootModem");
1808 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001809 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001810 request = (MainThreadRequest) msg.obj;
1811 boolean enable = (boolean) request.argument;
1812 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001813 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001814 PhoneConfigurationManager.getInstance()
1815 .enablePhone(request.phone, enable, onCompleted);
1816 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001817 }
Michele Berionne5e411512020-11-13 02:36:59 +00001818 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001819 ar = (AsyncResult) msg.obj;
1820 request = (MainThreadRequest) ar.userObj;
1821 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001822 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001823 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001824 if ((boolean) request.result) {
1825 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1826 updateModemStateMetrics();
1827 } else {
1828 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1829 + ar.exception);
1830 }
1831 notifyRequester(request);
1832 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001833 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001834 case CMD_GET_MODEM_STATUS:
1835 request = (MainThreadRequest) msg.obj;
1836 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1837 PhoneConfigurationManager.getInstance()
1838 .getPhoneStatusFromModem(request.phone, onCompleted);
1839 break;
1840 case EVENT_GET_MODEM_STATUS_DONE:
1841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 int id = request.phone.getPhoneId();
1844 if (ar.exception == null && ar.result != null) {
1845 request.result = ar.result;
1846 //update the cache as modem status has changed
1847 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1848 (boolean) request.result);
1849 } else {
1850 // Return true if modem status cannot be retrieved. For most cases,
1851 // modem status is on. And for older version modems, GET_MODEM_STATUS
1852 // and disable modem are not supported. Modem is always on.
1853 // TODO: this should be fixed in R to support a third
1854 // status UNKNOWN b/131631629
1855 request.result = true;
1856 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1857 + ar.exception);
1858 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001859 notifyRequester(request);
1860 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001861 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1862 request = (MainThreadRequest) msg.obj;
1863 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1864 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1865 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1866 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1867 break;
1868 }
1869 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1870 ar = (AsyncResult) msg.obj;
1871 request = (MainThreadRequest) ar.userObj;
1872 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1873 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1874 args.second.accept(ar.exception == null);
1875 notifyRequester(request);
1876 break;
1877 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001878 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1879 request = (MainThreadRequest) msg.obj;
1880 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1881 Phone phone = getPhoneFromRequest(request);
1882 if (phone != null) {
1883 phone.getSystemSelectionChannels(onCompleted);
1884 } else {
1885 loge("getSystemSelectionChannels: No phone object");
1886 request.result = new ArrayList<RadioAccessSpecifier>();
1887 notifyRequester(request);
1888 }
1889 break;
1890 }
1891 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1892 ar = (AsyncResult) msg.obj;
1893 request = (MainThreadRequest) ar.userObj;
1894 if (ar.exception == null && ar.result != null) {
1895 request.result = ar.result;
1896 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001897 request.result = new IllegalStateException(
1898 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001899 if (ar.result == null) {
1900 loge("getSystemSelectionChannels: Empty response");
1901 } else {
1902 loge("getSystemSelectionChannels: Unknown exception");
1903 }
1904 }
1905 notifyRequester(request);
1906 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001907 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1908 ar = (AsyncResult) msg.obj;
1909 request = (MainThreadRequest) ar.userObj;
1910 if (ar.exception == null && ar.result != null) {
1911 request.result = ar.result;
1912 } else {
1913 request.result = -1;
1914 loge("Failed to set Forbidden Plmns");
1915 if (ar.result == null) {
1916 loge("setForbidenPlmns: Empty response");
1917 } else if (ar.exception != null) {
1918 loge("setForbiddenPlmns: Exception: " + ar.exception);
1919 request.result = -1;
1920 } else {
1921 loge("setForbiddenPlmns: Unknown exception");
1922 }
1923 }
1924 notifyRequester(request);
1925 break;
1926 case CMD_SET_FORBIDDEN_PLMNS:
1927 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001928 uiccPort = getUiccPortFromRequest(request);
1929 if (uiccPort == null) {
1930 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001931 request.result = -1;
1932 notifyRequester(request);
1933 break;
1934 }
1935 Pair<Integer, List<String>> setFplmnsArgs =
1936 (Pair<Integer, List<String>>) request.argument;
1937 appType = setFplmnsArgs.first;
1938 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001939 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001940 if (uiccApp == null) {
1941 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1942 request.result = -1;
1943 loge("Failed to get UICC App");
1944 notifyRequester(request);
1945 } else {
1946 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1947 ((SIMRecords) uiccApp.getIccRecords())
1948 .setForbiddenPlmns(onCompleted, fplmns);
1949 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001950 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001951 case CMD_ERASE_MODEM_CONFIG:
1952 request = (MainThreadRequest) msg.obj;
1953 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1954 defaultPhone.eraseModemConfig(onCompleted);
1955 break;
1956 case EVENT_ERASE_MODEM_CONFIG_DONE:
1957 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001958 break;
zoey chene02881a2019-12-30 16:11:23 +08001959
Kai Shif70f46f2021-03-03 13:59:46 -08001960 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1961 request = (MainThreadRequest) msg.obj;
1962 request.result = defaultPhone.eraseDataInSharedPreferences();
1963 notifyRequester(request);
1964 break;
1965
zoey chene02881a2019-12-30 16:11:23 +08001966 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1967 request = (MainThreadRequest) msg.obj;
1968 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1969 Pair<String, String> changed = (Pair<String, String>) request.argument;
1970 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1971 changed.first, changed.second, onCompleted);
1972 break;
1973 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1974 ar = (AsyncResult) msg.obj;
1975 request = (MainThreadRequest) ar.userObj;
1976 if (ar.exception == null) {
1977 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001978 // If the operation is successful, update the PIN storage
1979 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1980 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001981 UiccController.getInstance().getPinStorage()
1982 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001983 } else {
1984 request.result = msg.arg1;
1985 }
1986 notifyRequester(request);
1987 break;
1988
Michele Berionne5e411512020-11-13 02:36:59 +00001989 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001990 request = (MainThreadRequest) msg.obj;
1991 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1992 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1993 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1994 enabled.first, enabled.second, onCompleted);
1995 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001996 }
zoey chene02881a2019-12-30 16:11:23 +08001997 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1998 ar = (AsyncResult) msg.obj;
1999 request = (MainThreadRequest) ar.userObj;
2000 if (ar.exception == null) {
2001 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002002 // If the operation is successful, update the PIN storage
2003 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2004 int phoneId = getPhoneFromRequest(request).getPhoneId();
2005 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002006 UiccController.getInstance().getPinStorage()
2007 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002008 } else {
2009 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2010 }
zoey chene02881a2019-12-30 16:11:23 +08002011 } else {
2012 request.result = msg.arg1;
2013 }
Michele Berionne5e411512020-11-13 02:36:59 +00002014
2015
zoey chene02881a2019-12-30 16:11:23 +08002016 notifyRequester(request);
2017 break;
2018
Peter Wangdafb9ac2020-01-15 14:13:38 -08002019 case MSG_NOTIFY_USER_ACTIVITY:
2020 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002021 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002022 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2023 getDefaultPhone().getContext().sendBroadcastAsUser(
2024 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2025 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002026
2027 case CMD_SET_DATA_THROTTLING: {
2028 request = (MainThreadRequest) msg.obj;
2029 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2030 DataThrottlingRequest dataThrottlingRequest =
2031 (DataThrottlingRequest) request.argument;
2032 Phone phone = getPhoneFromRequest(request);
2033 if (phone != null) {
2034 phone.setDataThrottling(onCompleted,
2035 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2036 dataThrottlingRequest.getCompletionDurationMillis());
2037 } else {
2038 loge("setDataThrottling: No phone object");
2039 request.result =
2040 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2041 notifyRequester(request);
2042 }
2043
2044 break;
2045 }
2046 case EVENT_SET_DATA_THROTTLING_DONE:
2047 ar = (AsyncResult) msg.obj;
2048 request = (MainThreadRequest) ar.userObj;
2049
2050 if (ar.exception == null) {
2051 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2052 } else if (ar.exception instanceof CommandException) {
2053 loge("setDataThrottling: CommandException: " + ar.exception);
2054 CommandException.Error error =
2055 ((CommandException) (ar.exception)).getCommandError();
2056
2057 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2058 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002059 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002060 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2061 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002062 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2063 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002064 } else {
2065 request.result =
2066 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2067 }
2068 } else {
2069 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2070 }
2071 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2072 notifyRequester(request);
2073 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002074
2075 case CMD_SET_SIM_POWER: {
2076 request = (MainThreadRequest) msg.obj;
2077 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2078 request = (MainThreadRequest) msg.obj;
2079 int stateToSet =
2080 ((Pair<Integer, IIntegerConsumer>)
2081 request.argument).first;
2082 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2083 break;
2084 }
2085 case EVENT_SET_SIM_POWER_DONE: {
2086 ar = (AsyncResult) msg.obj;
2087 request = (MainThreadRequest) ar.userObj;
2088 IIntegerConsumer callback =
2089 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2090 if (ar.exception != null) {
2091 loge("setSimPower exception: " + ar.exception);
2092 int errorCode = TelephonyManager.CallForwardingInfoCallback
2093 .RESULT_ERROR_UNKNOWN;
2094 if (ar.exception instanceof CommandException) {
2095 CommandException.Error error =
2096 ((CommandException) (ar.exception)).getCommandError();
2097 if (error == CommandException.Error.SIM_ERR) {
2098 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2099 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2100 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2101 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2102 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2103 } else {
2104 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2105 }
2106 }
2107 try {
2108 callback.accept(errorCode);
2109 } catch (RemoteException e) {
2110 // Ignore if the remote process is no longer available to call back.
2111 Log.w(LOG_TAG, "setSimPower: callback not available.");
2112 }
2113 } else {
2114 try {
2115 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
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 }
2121 break;
2122 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002123 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2124 request = (MainThreadRequest) msg.obj;
2125
2126 final Phone phone = getPhoneFromRequest(request);
2127 if (phone == null || phone.getServiceStateTracker() == null) {
2128 request.result = new IllegalStateException("Phone or SST is null");
2129 notifyRequester(request);
2130 break;
2131 }
2132
2133 Pair<Integer, SignalStrengthUpdateRequest> pair =
2134 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2135 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2136 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002137 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002138 request.subId, pair.first /*callingUid*/,
2139 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002140 break;
2141 }
2142 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2143 ar = (AsyncResult) msg.obj;
2144 request = (MainThreadRequest) ar.userObj;
2145 // request.result will be the exception of ar if present, true otherwise.
2146 // Be cautious not to leave result null which will wait() forever
2147 request.result = ar.exception != null ? ar.exception : true;
2148 notifyRequester(request);
2149 break;
2150 }
2151 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2152 request = (MainThreadRequest) msg.obj;
2153
2154 Phone phone = getPhoneFromRequest(request);
2155 if (phone == null || phone.getServiceStateTracker() == null) {
2156 request.result = new IllegalStateException("Phone or SST is null");
2157 notifyRequester(request);
2158 break;
2159 }
2160
2161 Pair<Integer, SignalStrengthUpdateRequest> pair =
2162 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2163 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2164 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002165 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002166 request.subId, pair.first /*callingUid*/,
2167 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002168 break;
2169 }
2170 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2171 ar = (AsyncResult) msg.obj;
2172 request = (MainThreadRequest) ar.userObj;
2173 request.result = ar.exception != null ? ar.exception : true;
2174 notifyRequester(request);
2175 break;
2176 }
Jordan Liu109698e2020-11-24 14:50:34 -08002177
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002178 case CMD_GET_SLICING_CONFIG: {
2179 request = (MainThreadRequest) msg.obj;
2180 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2181 request.phone.getSlicingConfig(onCompleted);
2182 break;
2183 }
2184 case EVENT_GET_SLICING_CONFIG_DONE: {
2185 ar = (AsyncResult) msg.obj;
2186 request = (MainThreadRequest) ar.userObj;
2187 ResultReceiver result = (ResultReceiver) request.argument;
2188
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002189 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002190 Bundle bundle = new Bundle();
2191 int resultCode = 0;
2192 if (ar.exception != null) {
2193 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2194 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002195 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002196 } else if (ar.result == null) {
2197 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002198 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002199 } else {
2200 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002201 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2202 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002203 }
2204
2205 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002206 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002207 }
2208 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2209 result.send(resultCode, bundle);
2210 notifyRequester(request);
2211 break;
2212 }
2213
Sarah Chin71b3a852022-09-28 15:54:19 -07002214 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002215 request = (MainThreadRequest) msg.obj;
2216 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002217 PurchasePremiumCapabilityArgument arg =
2218 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002219 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2220 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002221 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002222 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002223
Sarah Chin71b3a852022-09-28 15:54:19 -07002224 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002225 ar = (AsyncResult) msg.obj;
2226 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002227 PurchasePremiumCapabilityArgument arg =
2228 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002229 try {
2230 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002231 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002232 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002234 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002235 + TelephonyManager.convertPurchaseResultToString(result));
2236 } catch (RemoteException e) {
2237 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002239 + " failed: " + e;
2240 if (DBG) log(logStr);
2241 AnomalyReporter.reportAnomaly(
2242 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2243 }
2244 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246
Michele Berionne5e411512020-11-13 02:36:59 +00002247 case CMD_PREPARE_UNATTENDED_REBOOT:
2248 request = (MainThreadRequest) msg.obj;
2249 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002250 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002251 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002252 notifyRequester(request);
2253 break;
2254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 default:
2256 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2257 break;
2258 }
2259 }
Jake Hambye994d462014-02-03 13:10:13 -08002260
Pengquan Menga1bb6272018-09-06 09:59:22 -07002261 private void notifyRequester(MainThreadRequest request) {
2262 synchronized (request) {
2263 request.notifyAll();
2264 }
2265 }
2266
Jake Hambye994d462014-02-03 13:10:13 -08002267 private void handleNullReturnEvent(Message msg, String command) {
2268 AsyncResult ar = (AsyncResult) msg.obj;
2269 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2270 if (ar.exception == null) {
2271 request.result = true;
2272 } else {
2273 request.result = false;
2274 if (ar.exception instanceof CommandException) {
2275 loge(command + ": CommandException: " + ar.exception);
2276 } else {
2277 loge(command + ": Unknown exception");
2278 }
2279 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002280 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
2284 /**
2285 * Posts the specified command to be executed on the main thread,
2286 * waits for the request to complete, and returns the result.
2287 * @see #sendRequestAsync
2288 */
2289 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002290 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2291 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002292 }
2293
2294 /**
2295 * Posts the specified command to be executed on the main thread,
2296 * waits for the request to complete, and returns the result.
2297 * @see #sendRequestAsync
2298 */
2299 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2300 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002301 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002302 }
2303
2304 /**
2305 * Posts the specified command to be executed on the main thread,
2306 * waits for the request to complete, and returns the result.
2307 * @see #sendRequestAsync
2308 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002309 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002310 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2311 }
2312
2313 /**
2314 * Posts the specified command to be executed on the main thread,
2315 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2316 * if not timeout or null otherwise.
2317 * @see #sendRequestAsync
2318 */
2319 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2320 long timeoutInMs) {
2321 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002322 }
2323
2324 /**
2325 * Posts the specified command to be executed on the main thread,
2326 * waits for the request to complete, and returns the result.
2327 * @see #sendRequestAsync
2328 */
Nathan Harold92bed182018-10-12 18:16:49 -07002329 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002330 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002331 }
2332
2333 /**
2334 * Posts the specified command to be executed on the main thread,
2335 * waits for the request to complete, and returns the result.
2336 * @see #sendRequestAsync
2337 */
2338 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002339 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2340 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002341 }
2342
2343 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002344 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2345 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2346 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002347 * @see #sendRequestAsync
2348 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002349 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2350 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2352 throw new RuntimeException("This method will deadlock if called from the main thread.");
2353 }
2354
Nathan Harold92bed182018-10-12 18:16:49 -07002355 MainThreadRequest request = null;
2356 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2357 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2358 } else if (phone != null) {
2359 request = new MainThreadRequest(argument, phone, workSource);
2360 } else {
2361 request = new MainThreadRequest(argument, subId, workSource);
2362 }
2363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 Message msg = mMainThreadHandler.obtainMessage(command, request);
2365 msg.sendToTarget();
2366
Rambo Wang0f050d82021-02-12 11:43:36 -08002367
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002369 if (timeoutInMs >= 0) {
2370 // Wait for at least timeoutInMs before returning null request result
2371 long now = SystemClock.elapsedRealtime();
2372 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002373 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002374 try {
2375 request.wait(deadline - now);
2376 } catch (InterruptedException e) {
2377 // Do nothing, go back and check if request is completed or timeout
2378 } finally {
2379 now = SystemClock.elapsedRealtime();
2380 }
2381 }
2382 } else {
2383 // Wait for the request to complete
2384 while (request.result == null) {
2385 try {
2386 request.wait();
2387 } catch (InterruptedException e) {
2388 // Do nothing, go back and wait until the request is complete
2389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
2391 }
2392 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002393 if (request.result == null) {
2394 Log.wtf(LOG_TAG,
2395 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 return request.result;
2398 }
2399
2400 /**
2401 * Asynchronous ("fire and forget") version of sendRequest():
2402 * Posts the specified command to be executed on the main thread, and
2403 * returns immediately.
2404 * @see #sendRequest
2405 */
2406 private void sendRequestAsync(int command) {
2407 mMainThreadHandler.sendEmptyMessage(command);
2408 }
2409
2410 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002411 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002412 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002413 */
2414 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002415 sendRequestAsync(command, argument, null, null);
2416 }
2417
2418 /**
2419 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2420 * @see {@link #sendRequest(int,Object)}
2421 */
2422 private void sendRequestAsync(
2423 int command, Object argument, Phone phone, WorkSource workSource) {
2424 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002425 Message msg = mMainThreadHandler.obtainMessage(command, request);
2426 msg.sendToTarget();
2427 }
2428
2429 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 * Initialize the singleton PhoneInterfaceManager instance.
2431 * This is only done once, at startup, from PhoneApp.onCreate().
2432 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002433 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 synchronized (PhoneInterfaceManager.class) {
2435 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002436 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 } else {
2438 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2439 }
2440 return sInstance;
2441 }
2442 }
2443
2444 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002445 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002447 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002449 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002450 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002451 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2453 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002454 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002455 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002456 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002457 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002458 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002459 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 publish();
arunvoddud7401012022-12-15 16:08:12 +00002461 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002464 @VisibleForTesting
2465 public SharedPreferences getSharedPreferences() {
2466 return mTelephonySharedPreferences;
2467 }
2468
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002469 /**
2470 * Get the default phone for this device.
2471 */
2472 @VisibleForTesting
2473 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002474 Phone thePhone = getPhone(getDefaultSubscription());
2475 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2476 }
2477
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 private void publish() {
2479 if (DBG) log("publish: " + this);
2480
Peter Wangc035ce42020-01-08 21:00:22 -08002481 TelephonyFrameworkInitializer
2482 .getTelephonyServiceManager()
2483 .getTelephonyServiceRegisterer()
2484 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Stuart Scott584921c2015-01-15 17:10:34 -08002487 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002488 if (request.phone != null) {
2489 return request.phone;
2490 } else {
2491 return getPhoneFromSubId(request.subId);
2492 }
2493 }
2494
2495 private Phone getPhoneFromSubId(int subId) {
2496 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2497 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002498 }
2499
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002500 /**
2501 * Get phone object associated with a subscription.
2502 * Return default phone if phone object associated with subscription is null
2503 * @param subId - subscriptionId
2504 * @return phone object associated with a subscription or default phone if null.
2505 */
Ling Mac28f0212023-03-24 16:07:15 -07002506 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002507 Phone phone = getPhoneFromSubId(subId);
2508 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002509 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002510 phone = getDefaultPhone();
2511 }
2512 return phone;
2513 }
2514
Rambo Wange53e07d2022-05-10 13:01:13 -07002515 @Nullable
2516 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002517 Phone phone = getPhoneFromRequest(request);
2518 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002519 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002520 }
2521
Ling Mac28f0212023-03-24 16:07:15 -07002522 /**
2523 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2524 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2525 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2526 * @return The Phone associated the sub Id
2527 */
2528 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002529 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531
Kai Shif70f46f2021-03-03 13:59:46 -08002532 private void sendEraseModemConfig(@NonNull Phone phone) {
2533 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2534 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2535 }
2536
2537 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2538 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2539 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002540 }
2541
Peter Wang44b186e2020-01-13 23:33:09 -08002542 private boolean isImsAvailableOnDevice() {
2543 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2544 if (pm == null) {
2545 // For some reason package manger is not available.. This will fail internally anyway,
2546 // so do not throw error and allow.
2547 return true;
2548 }
2549 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2550 }
2551
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002553 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002554 }
2555
Wink Savilleb564aae2014-10-23 10:18:09 -07002556 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 if (DBG) log("dial: " + number);
2558 // No permission check needed here: This is just a wrapper around the
2559 // ACTION_DIAL intent, which is available to any app since it puts up
2560 // the UI before it does anything.
2561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 String url = createTelUrl(number);
2565 if (url == null) {
2566 return;
2567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569 // PENDING: should we just silently fail if phone is offhook or ringing?
2570 PhoneConstants.State state = mCM.getState(subId);
2571 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2572 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2573 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2574 mApp.startActivity(intent);
2575 }
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579 }
2580
2581 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002582 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
Wink Savilleb564aae2014-10-23 10:18:09 -07002585 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 if (DBG) log("call: " + number);
2587
2588 // This is just a wrapper around the ACTION_CALL intent, but we still
2589 // need to do a permission check since we're calling startActivity()
2590 // from the context of the phone app.
2591 enforceCallPermission();
2592
Jordan Liu1617b712019-07-10 15:06:26 -07002593 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 != AppOpsManager.MODE_ALLOWED) {
2595 return;
2596 }
2597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 String url = createTelUrl(number);
2601 if (url == null) {
2602 return;
2603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 boolean isValid = false;
2606 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2607 if (slist != null) {
2608 for (SubscriptionInfo subInfoRecord : slist) {
2609 if (subInfoRecord.getSubscriptionId() == subId) {
2610 isValid = true;
2611 break;
2612 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002613 }
Wink Saville08874612014-08-31 19:19:58 -07002614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 if (!isValid) {
2616 return;
2617 }
Wink Saville08874612014-08-31 19:19:58 -07002618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2620 intent.putExtra(SUBSCRIPTION_KEY, subId);
2621 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2622 mApp.startActivity(intent);
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 }
2627
Wink Savilleb564aae2014-10-23 10:18:09 -07002628 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002629 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002630 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2631 }
2632
Wink Savilleb564aae2014-10-23 10:18:09 -07002633 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002634 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002635 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2636 }
2637
Wink Savilleb564aae2014-10-23 10:18:09 -07002638 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640
2641 final long identity = Binder.clearCallingIdentity();
2642 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002643 Phone phone = getPhone(subId);
2644 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645 checkSimPin.start();
2646 return checkSimPin.unlockSim(null, pin);
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
2649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
Wink Savilleb564aae2014-10-23 10:18:09 -07002652 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002657 Phone phone = getPhone(subId);
2658 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 checkSimPuk.start();
2660 return checkSimPuk.unlockSim(puk, pin);
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 }
2665
2666 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002667 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 * a synchronous one.
2669 */
2670 private static class UnlockSim extends Thread {
2671
2672 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002673 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674
2675 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002676 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2677 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678
2679 // For replies from SimCard interface
2680 private Handler mHandler;
2681
2682 // For async handler to identify request type
2683 private static final int SUPPLY_PIN_COMPLETE = 100;
2684
Michele Berionne5e411512020-11-13 02:36:59 +00002685 UnlockSim(int phoneId, IccCard simCard) {
2686 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 mSimCard = simCard;
2688 }
2689
2690 @Override
2691 public void run() {
2692 Looper.prepare();
2693 synchronized (UnlockSim.this) {
2694 mHandler = new Handler() {
2695 @Override
2696 public void handleMessage(Message msg) {
2697 AsyncResult ar = (AsyncResult) msg.obj;
2698 switch (msg.what) {
2699 case SUPPLY_PIN_COMPLETE:
2700 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2701 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002702 mRetryCount = msg.arg1;
2703 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002704 CommandException.Error error = null;
2705 if (ar.exception instanceof CommandException) {
2706 error = ((CommandException) (ar.exception))
2707 .getCommandError();
2708 }
2709 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002710 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002711 } else if (error == CommandException.Error.ABORTED) {
2712 /* When UiccCardApp dispose, handle message and return
2713 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002714 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002715 } else {
2716 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2717 }
2718 } else {
2719 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 mDone = true;
2722 UnlockSim.this.notifyAll();
2723 }
2724 break;
2725 }
2726 }
2727 };
2728 UnlockSim.this.notifyAll();
2729 }
2730 Looper.loop();
2731 }
2732
2733 /*
2734 * Use PIN or PUK to unlock SIM card
2735 *
2736 * If PUK is null, unlock SIM card with PIN
2737 *
2738 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302739 *
2740 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2741 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 */
Wink Saville9de0f752013-10-22 19:04:03 -07002743 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744
2745 while (mHandler == null) {
2746 try {
2747 wait();
2748 } catch (InterruptedException e) {
2749 Thread.currentThread().interrupt();
2750 }
2751 }
2752 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2753
2754 if (puk == null) {
2755 mSimCard.supplyPin(pin, callback);
2756 } else {
2757 mSimCard.supplyPuk(puk, pin, callback);
2758 }
2759
2760 while (!mDone) {
2761 try {
2762 Log.d(LOG_TAG, "wait for done");
2763 wait();
2764 } catch (InterruptedException e) {
2765 // Restore the interrupted status
2766 Thread.currentThread().interrupt();
2767 }
2768 }
2769 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002770 int[] resultArray = new int[2];
2771 resultArray[0] = mResult;
2772 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002773
2774 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002775 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002776 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302777 // This instance is no longer reused, so quit its thread's looper.
2778 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002779
Wink Saville9de0f752013-10-22 19:04:03 -07002780 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 }
2782 }
2783
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002784 /**
2785 * This method has been removed due to privacy and stability concerns.
2786 */
2787 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002789 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2790 return;
Wink Saville36469e72014-06-11 15:17:00 -07002791 }
2792
Nathan Harold1f889d82020-06-04 17:05:26 -07002793 @Override
2794 public void updateServiceLocationWithPackageName(String callingPackage) {
2795 mApp.getSystemService(AppOpsManager.class)
2796 .checkPackage(Binder.getCallingUid(), callingPackage);
2797
Nathan Haroldf096d982020-11-18 17:18:06 -08002798 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002799 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2800 // Callers targeting S have no business invoking this method.
2801 return;
2802 }
2803
2804 LocationAccessPolicy.LocationPermissionResult locationResult =
2805 LocationAccessPolicy.checkLocationPermission(mApp,
2806 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2807 .setCallingPackage(callingPackage)
2808 .setCallingFeatureId(null)
2809 .setCallingPid(Binder.getCallingPid())
2810 .setCallingUid(Binder.getCallingUid())
2811 .setMethod("updateServiceLocation")
2812 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2813 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2814 .build());
2815 // Apps that lack location permission have no business calling this method;
2816 // however, because no permission was declared in the public API, denials must
2817 // all be "soft".
2818 switch (locationResult) {
2819 case DENIED_HARD: /* fall through */
2820 case DENIED_SOFT:
2821 return;
2822 }
2823
2824 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 final long identity = Binder.clearCallingIdentity();
2826 try {
Ling Mac28f0212023-03-24 16:07:15 -07002827 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002833 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002834 @Override
2835 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002836 return isRadioOnWithFeature(callingPackage, null);
2837 }
2838
2839
2840 @Override
2841 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2842 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2843 callingFeatureId);
2844 }
2845
2846 @Deprecated
2847 @Override
2848 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2849 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002850 }
2851
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002853 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2854 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002856 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002857 return false;
2858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 return isRadioOnForSubscriber(subId);
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
2865 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002866 }
2867
2868 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 final Phone phone = getPhone(subId);
2872 if (phone != null) {
2873 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2874 } else {
2875 return false;
2876 }
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
2882 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002883 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
Wink Saville36469e72014-06-11 15:17:00 -07002885
Wink Savilleb564aae2014-10-23 10:18:09 -07002886 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888
2889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 final Phone phone = getPhone(subId);
2892 if (phone != null) {
2893 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2894 }
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 }
Wink Saville36469e72014-06-11 15:17:00 -07002898 }
2899
2900 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002901 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002902 }
2903
Wink Savilleb564aae2014-10-23 10:18:09 -07002904 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002905 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 final Phone phone = getPhone(subId);
2910 if (phone == null) {
2911 return false;
2912 }
2913 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2914 toggleRadioOnOffForSubscriber(subId);
2915 }
2916 return true;
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
Wink Saville36469e72014-06-11 15:17:00 -07002921
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002922 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002923 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002924 /*
2925 * If any of the Radios are available, it will need to be
2926 * shutdown. So return true if any Radio is available.
2927 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2931 Phone phone = PhoneFactory.getPhone(i);
2932 if (phone != null && phone.isRadioAvailable()) return true;
2933 }
2934 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2935 return false;
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002938 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002939 }
2940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002942 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 enforceModifyPermission();
2944
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2948 logv("Shutting down Phone " + i);
2949 shutdownRadioUsingPhoneId(i);
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002953 }
2954 }
2955
2956 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002957 Phone phone = PhoneFactory.getPhone(phoneId);
2958 if (phone != null && phone.isRadioAvailable()) {
2959 phone.shutdownRadio();
2960 }
2961 }
2962
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002963 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002964 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965
Ling Ma83dc5ea2023-01-12 15:06:04 -08002966 if (!turnOn) {
2967 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2968 }
2969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2973 if (defaultPhone != null) {
2974 defaultPhone.setRadioPower(turnOn);
2975 return true;
2976 } else {
2977 loge("There's no default phone.");
2978 return false;
2979 }
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002982 }
Wink Saville36469e72014-06-11 15:17:00 -07002983 }
2984
Wink Savilleb564aae2014-10-23 10:18:09 -07002985 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987
Ling Ma83dc5ea2023-01-12 15:06:04 -08002988 if (!turnOn) {
2989 log("setRadioPowerForSubscriber off: subId=" + subId
2990 + ",callingPackage=" + getCurrentPackageName());
2991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 final Phone phone = getPhone(subId);
2995 if (phone != null) {
2996 phone.setRadioPower(turnOn);
2997 return true;
2998 } else {
2999 return false;
3000 }
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003004 }
3005
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003006 /**
3007 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3008 * no reason to power it off. When any of the voters want to power it off, it will be turned
3009 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3010 * powering it off, and these radio off votes will be cleared.
3011 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3012 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3013 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3014 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3015 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3016 * check its vote.
3017 *
3018 * @param subId The subscription ID.
3019 * @param reason The reason for powering off radio.
3020 * @return true on success and false on failure.
3021 */
3022 public boolean requestRadioPowerOffForReason(int subId,
3023 @TelephonyManager.RadioPowerReason int reason) {
3024 enforceModifyPermission();
3025
Ling Ma83dc5ea2023-01-12 15:06:04 -08003026 log("requestRadioPowerOffForReason: subId=" + subId
3027 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003028 final long identity = Binder.clearCallingIdentity();
3029 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003030 boolean result = false;
3031 for (Phone phone : PhoneFactory.getPhones()) {
3032 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003033 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003034 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003035 if (!result) {
3036 loge("requestRadioPowerOffForReason: no phone exists");
3037 }
3038 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
3044 /**
3045 * Remove the vote on powering off the radio for a reason, as requested by
3046 * {@link requestRadioPowerOffForReason}.
3047 *
3048 * @param subId The subscription ID.
3049 * @param reason The reason for powering off radio.
3050 * @return true on success and false on failure.
3051 */
3052 public boolean clearRadioPowerOffForReason(int subId,
3053 @TelephonyManager.RadioPowerReason int reason) {
3054 enforceModifyPermission();
3055
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003058 boolean result = false;
3059 for (Phone phone : PhoneFactory.getPhones()) {
3060 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003061 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003062 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003063 if (!result) {
3064 loge("clearRadioPowerOffForReason: no phone exists");
3065 }
3066 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
3070 }
3071
3072 /**
3073 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3074 *
3075 * @param subId The subscription ID.
3076 * @param callingPackage The package making the call.
3077 * @param callingFeatureId The feature in the package.
3078 * @return List of reasons for powering off radio.
3079 */
3080 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3081 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3082
3083 final long identity = Binder.clearCallingIdentity();
3084 List result = new ArrayList();
3085 try {
3086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3087 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3088 return result;
3089 }
3090
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003091 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003092 if (phone != null) {
3093 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003094 } else {
3095 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003096 }
3097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
3100 return result;
3101 }
3102
Wink Saville36469e72014-06-11 15:17:00 -07003103 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003104 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003105 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003106 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107
3108 final long identity = Binder.clearCallingIdentity();
3109 try {
Jack Yu285100e2022-12-02 22:48:35 -08003110 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111 final Phone phone = getPhone(subId);
3112 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003113 phone.getDataSettingsManager().setDataEnabled(
3114 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 return true;
3116 } else {
3117 return false;
3118 }
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 }
3123
Wink Saville36469e72014-06-11 15:17:00 -07003124 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003125 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003126 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003128
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
Jack Yu285100e2022-12-02 22:48:35 -08003131 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final Phone phone = getPhone(subId);
3133 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003134 phone.getDataSettingsManager().setDataEnabled(
3135 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136 return true;
3137 } else {
3138 return false;
3139 }
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
3144
Sanket Padawe356d7632015-06-22 14:03:32 -07003145 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003146 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 final Phone phone = getPhone(subId);
3150 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003151 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 } else {
3153 return false;
3154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159
3160 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003161 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003162 }
3163
pkanwarae03a6b2016-11-06 20:37:09 -08003164 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 enforceCallPermission();
3166
3167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3170 return;
3171 }
3172 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3173 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
pkanwar32d516d2016-10-14 19:37:38 -07003177 };
3178
Wink Savilleb564aae2014-10-23 10:18:09 -07003179 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003180 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3185 return false;
3186 }
3187 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3188 } finally {
3189 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 }
3192
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003193 /**
3194 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3195 * tag on getCallState Binder call.
3196 */
3197 @Deprecated
3198 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003200 if (CompatChanges.isChangeEnabled(
3201 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3202 Binder.getCallingUid())) {
3203 // Do not allow this API to be called on API version 31+, it should only be
3204 // called on old apps using this Binder call directly.
3205 throw new SecurityException("This method can only be used for applications "
3206 + "targeting API version 30 or less.");
3207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 final long identity = Binder.clearCallingIdentity();
3209 try {
Ling Mac28f0212023-03-24 16:07:15 -07003210 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3211 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
3215 }
3216
3217 @Override
3218 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3219 if (CompatChanges.isChangeEnabled(
3220 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3221 Binder.getCallingUid())) {
3222 // Check READ_PHONE_STATE for API version 31+
3223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3224 featureId, "getCallStateForSubscription")) {
3225 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3226 + "targeting API level 31+.");
3227 }
3228 }
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3233 PhoneConstantConversions.convertCallState(phone.getState());
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 }
3238
Sanket Padawe356d7632015-06-22 14:03:32 -07003239 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003240 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003241 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003242 }
3243
3244 @Override
3245 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246 final long identity = Binder.clearCallingIdentity();
3247 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003248 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003250 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 } else {
3252 return PhoneConstantConversions.convertDataState(
3253 PhoneConstants.DataState.DISCONNECTED);
3254 }
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 }
3259
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003261 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003262 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003263 }
3264
3265 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003266 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 final long identity = Binder.clearCallingIdentity();
3268 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003269 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003271 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 } else {
3273 return TelephonyManager.DATA_ACTIVITY_NONE;
3274 }
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 }
3279
3280 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003281 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003282 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003283 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003284
3285 LocationAccessPolicy.LocationPermissionResult locationResult =
3286 LocationAccessPolicy.checkLocationPermission(mApp,
3287 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3288 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003289 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003290 .setCallingPid(Binder.getCallingPid())
3291 .setCallingUid(Binder.getCallingUid())
3292 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003293 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003294 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3295 .build());
3296 switch (locationResult) {
3297 case DENIED_HARD:
3298 throw new SecurityException("Not allowed to access cell location");
3299 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003300 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3301 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 }
3303
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003304 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003308 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003309 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
Svetoslav64fad262015-04-14 14:35:21 -07003313 }
3314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003316 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003317 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3318 // registered cell info, so return a NULL country instead.
3319 final long identity = Binder.clearCallingIdentity();
3320 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003321 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3322 // Get default phone in this case.
3323 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3324 }
Jack Yu285100e2022-12-02 22:48:35 -08003325 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003327 if (phone == null) return "";
3328 ServiceStateTracker sst = phone.getServiceStateTracker();
3329 if (sst == null) return "";
3330 LocaleTracker lt = sst.getLocaleTracker();
3331 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003332 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003336 }
3337
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003338 /**
3339 * This method was removed due to potential issues caused by performing partial
3340 * updates of service state, and lack of a credible use case.
3341 *
3342 * This has the ability to break the telephony implementation by disabling notification of
3343 * changes in device connectivity. DO NOT USE THIS!
3344 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003345 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003346 public void enableLocationUpdates() {
3347 mApp.enforceCallingOrSelfPermission(
3348 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003349 }
3350
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003351 /**
3352 * This method was removed due to potential issues caused by performing partial
3353 * updates of service state, and lack of a credible use case.
3354 *
3355 * This has the ability to break the telephony implementation by disabling notification of
3356 * changes in device connectivity. DO NOT USE THIS!
3357 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003358 @Override
3359 public void disableLocationUpdates() {
3360 mApp.enforceCallingOrSelfPermission(
3361 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003362 }
3363
3364 @Override
3365 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003366 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3367 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003368 try {
3369 mApp.getSystemService(AppOpsManager.class)
3370 .checkPackage(Binder.getCallingUid(), callingPackage);
3371 } catch (SecurityException e) {
3372 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3373 throw e;
3374 }
3375
Nathan Haroldf096d982020-11-18 17:18:06 -08003376 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003377 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3378 throw new SecurityException(
3379 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3380 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003381
Jordan Liu1617b712019-07-10 15:06:26 -07003382 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3384 return null;
3385 }
Svetoslav64fad262015-04-14 14:35:21 -07003386
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003387 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003389 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003390 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003391
Nathan Haroldf180aac2018-06-01 18:43:55 -07003392 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3393 for (CellInfo ci : info) {
3394 if (ci instanceof CellInfoGsm) {
3395 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3396 } else if (ci instanceof CellInfoWcdma) {
3397 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003400 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 }
3402
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003403 private List<CellInfo> getCachedCellInfo() {
3404 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3405 for (Phone phone : PhoneFactory.getPhones()) {
3406 List<CellInfo> info = phone.getAllCellInfo();
3407 if (info != null) cellInfos.addAll(info);
3408 }
3409 return cellInfos;
3410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003411
3412 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003413 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003414 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003415 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003416
3417 LocationAccessPolicy.LocationPermissionResult locationResult =
3418 LocationAccessPolicy.checkLocationPermission(mApp,
3419 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3420 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003421 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003422 .setCallingPid(Binder.getCallingPid())
3423 .setCallingUid(Binder.getCallingUid())
3424 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003425 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003426 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3427 .build());
3428 switch (locationResult) {
3429 case DENIED_HARD:
3430 throw new SecurityException("Not allowed to access cell info");
3431 case DENIED_SOFT:
3432 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003433 }
3434
Nathan Haroldf096d982020-11-18 17:18:06 -08003435 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003436 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3437 return getCachedCellInfo();
3438 }
3439
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003440 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003441 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003442 final long identity = Binder.clearCallingIdentity();
3443 try {
3444 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3445 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003446 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003447 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 if (info != null) cellInfos.addAll(info);
3449 }
3450 return cellInfos;
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 }
3454 }
3455
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003456 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003457 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3458 String callingFeatureId) {
3459 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3460 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003461 }
3462
3463 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003464 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3465 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003466 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003467 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003468 }
3469
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003470 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3471 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003472 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003473 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003474
3475 LocationAccessPolicy.LocationPermissionResult locationResult =
3476 LocationAccessPolicy.checkLocationPermission(mApp,
3477 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3478 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003479 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003480 .setCallingPid(Binder.getCallingPid())
3481 .setCallingUid(Binder.getCallingUid())
3482 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003483 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3484 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003485 .build());
3486 switch (locationResult) {
3487 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003488 if (TelephonyPermissions
3489 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003490 // Safetynet logging for b/154934934
3491 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3492 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003493 throw new SecurityException("Not allowed to access cell info");
3494 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003495 if (TelephonyPermissions
3496 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003497 // Safetynet logging for b/154934934
3498 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3499 }
Nathan Harold5320c422019-05-09 10:26:08 -07003500 try {
3501 cb.onCellInfo(new ArrayList<CellInfo>());
3502 } catch (RemoteException re) {
3503 // Drop without consequences
3504 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003505 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003506 }
3507
Nathan Harolda939a962019-05-09 10:13:47 -07003508
3509 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003510 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3511
3512 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3513 }
3514
3515 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003516 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003517 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519
3520 final long identity = Binder.clearCallingIdentity();
3521 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003522 Phone phone = getPhone(subId);
3523 if (phone == null) {
3524 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3525 } else {
3526 phone.setCellInfoListRate(rateInMillis, workSource);
3527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528 } finally {
3529 Binder.restoreCallingIdentity(identity);
3530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531 }
3532
Shishir Agrawala9f32182016-04-12 12:00:16 -07003533 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003534 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003535 Phone phone = PhoneFactory.getPhone(slotIndex);
3536 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003537 return null;
3538 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003539 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003540 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003541 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003542 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003543 return null;
3544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 return phone.getImei();
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
3551 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003552 }
3553
3554 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003555 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3556 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3557 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3558 callingFeatureId, "getPrimaryImei")) {
3559 throw new SecurityException("Caller does not have permission");
3560 }
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 for (Phone phone : PhoneFactory.getPhones()) {
3564 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3565 return phone.getImei();
3566 }
3567 }
3568 throw new UnsupportedOperationException("Operation not supported");
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
3571 }
3572 }
3573
3574 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003575 public String getTypeAllocationCodeForSlot(int slotIndex) {
3576 Phone phone = PhoneFactory.getPhone(slotIndex);
3577 String tac = null;
3578 if (phone != null) {
3579 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003580 try {
3581 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3582 } catch (IndexOutOfBoundsException e) {
3583 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3584 return null;
3585 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003586 }
3587 return tac;
3588 }
3589
3590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003592 try {
3593 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3594 } catch (SecurityException se) {
3595 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3596 throw new SecurityException("Package " + callingPackage + " does not belong to "
3597 + Binder.getCallingUid());
3598 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003599 Phone phone = PhoneFactory.getPhone(slotIndex);
3600 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003601 return null;
3602 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003603
Jeff Davidson913390f2018-02-23 17:11:49 -08003604 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003605 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003606 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003607 return null;
3608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 return phone.getMeid();
3613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
Jack Yu2af8d712017-03-15 17:14:14 -07003616 }
3617
3618 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003619 public String getManufacturerCodeForSlot(int slotIndex) {
3620 Phone phone = PhoneFactory.getPhone(slotIndex);
3621 String manufacturerCode = null;
3622 if (phone != null) {
3623 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003624 try {
3625 manufacturerCode =
3626 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3627 } catch (IndexOutOfBoundsException e) {
3628 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3629 return null;
3630 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003631 }
3632 return manufacturerCode;
3633 }
3634
3635 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003636 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3637 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003638 Phone phone = PhoneFactory.getPhone(slotIndex);
3639 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003640 return null;
3641 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003642 int subId = phone.getSubId();
3643 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003644 mApp, subId, callingPackage, callingFeatureId,
3645 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003646 return null;
3647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 return phone.getDeviceSvn();
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003655 }
3656
fionaxu43304da2017-11-27 22:51:16 -08003657 @Override
3658 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 final Phone phone = getPhone(subId);
3662 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
fionaxu43304da2017-11-27 22:51:16 -08003666 }
3667
3668 @Override
3669 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 final Phone phone = getPhone(subId);
3673 return phone == null ? null : phone.getCarrierName();
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
fionaxu43304da2017-11-27 22:51:16 -08003677 }
3678
calvinpanffe225e2018-11-01 19:43:06 +08003679 @Override
chen xu0026ca62019-03-06 15:28:50 -08003680 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 final Phone phone = getPhone(subId);
3684 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003685 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
3689 }
3690
3691 @Override
chen xu0026ca62019-03-06 15:28:50 -08003692 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003696 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
3700 }
3701
chen xu651eec72018-11-11 19:03:44 -08003702 @Override
chen xu864e11c2018-12-06 22:10:03 -08003703 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3704 if (!isSubscriptionMccMnc) {
3705 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3706 }
chen xu651eec72018-11-11 19:03:44 -08003707 final Phone phone = PhoneFactory.getPhone(slotIndex);
3708 if (phone == null) {
3709 return TelephonyManager.UNKNOWN_CARRIER_ID;
3710 }
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
3717 }
3718
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003719 //
3720 // Internal helper methods.
3721 //
3722
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003723 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003724 * Make sure the caller is the calling package itself
3725 *
3726 * @throws SecurityException if the caller is not the calling package
3727 */
3728 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3729 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003730 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3731 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003732 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003733 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003734 } catch (PackageManager.NameNotFoundException e) {
3735 // packageUid is -1
3736 }
3737 if (packageUid != callingUid) {
3738 throw new SecurityException(message + ": Package " + callingPackage
3739 + " does not belong to " + callingUid);
3740 }
3741 }
3742
3743 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003744 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3745 *
3746 * @throws SecurityException if the caller does not have the required permission
3747 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003748 @VisibleForTesting
3749 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003750 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3751 }
3752
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003753 /**
arunvoddud7401012022-12-15 16:08:12 +00003754 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003755 *
3756 * @throws SecurityException if the caller does not have the required permission
3757 */
3758 @VisibleForTesting
3759 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003760 enforceReadPermission(null);
3761 }
3762
3763 /**
3764 * Make sure the caller has the READ_PHONE_STATE permissions.
3765 *
3766 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3767 */
3768 @VisibleForTesting
3769 public void enforceReadPermission(String msg) {
3770 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003771 }
3772
Shuo Qian3b6ee772019-11-13 17:43:31 -08003773 private void enforceActiveEmergencySessionPermission() {
3774 mApp.enforceCallingOrSelfPermission(
3775 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3776 }
3777
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003778 /**
3779 * Make sure the caller has the CALL_PHONE permission.
3780 *
3781 * @throws SecurityException if the caller does not have the required permission
3782 */
3783 private void enforceCallPermission() {
3784 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3785 }
3786
paulhu5a773602019-08-23 19:17:33 +08003787 private void enforceSettingsPermission() {
3788 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003789 }
3790
Michele Berionne5e411512020-11-13 02:36:59 +00003791 private void enforceRebootPermission() {
3792 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3793 }
3794
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003795 /**
3796 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3797 * @param message - log message to print.
3798 * @throws SecurityException if the caller does not have the required permission
3799 */
3800 private void enforceSatelliteCommunicationPermission(String message) {
3801 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3802 }
3803
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003804 private String createTelUrl(String number) {
3805 if (TextUtils.isEmpty(number)) {
3806 return null;
3807 }
3808
Jake Hambye994d462014-02-03 13:10:13 -08003809 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003810 }
3811
Ihab Awadf9e92732013-12-05 18:02:52 -08003812 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003813 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003814 }
3815
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003816 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003817 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003818 }
3819
Ihab Awadf9e92732013-12-05 18:02:52 -08003820 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003821 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003822 }
3823
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003824 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003825 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003826 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003827 }
3828
Sanket Padawe356d7632015-06-22 14:03:32 -07003829 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003830 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 final Phone phone = PhoneFactory.getPhone(slotIndex);
3834 if (phone == null) {
3835 return PhoneConstants.PHONE_TYPE_NONE;
3836 } else {
3837 return phone.getPhoneType();
3838 }
3839 } finally {
3840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003842 }
3843
3844 /**
3845 * Returns the CDMA ERI icon index to display
3846 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003848 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3849 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3850 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003851 }
3852
Sanket Padawe356d7632015-06-22 14:03:32 -07003853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003854 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3855 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003857 mApp, subId, callingPackage, callingFeatureId,
3858 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003859 return -1;
3860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861
3862 final long identity = Binder.clearCallingIdentity();
3863 try {
3864 final Phone phone = getPhone(subId);
3865 if (phone != null) {
3866 return phone.getCdmaEriIconIndex();
3867 } else {
3868 return -1;
3869 }
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003873 }
3874
3875 /**
3876 * Returns the CDMA ERI icon mode,
3877 * 0 - ON
3878 * 1 - FLASHING
3879 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003880 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003881 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3882 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3883 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003884 }
3885
Sanket Padawe356d7632015-06-22 14:03:32 -07003886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003887 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3888 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003890 mApp, subId, callingPackage, callingFeatureId,
3891 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003892 return -1;
3893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894
3895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 final Phone phone = getPhone(subId);
3898 if (phone != null) {
3899 return phone.getCdmaEriIconMode();
3900 } else {
3901 return -1;
3902 }
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003906 }
3907
3908 /**
3909 * Returns the CDMA ERI text,
3910 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003911 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003912 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3913 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3914 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003915 }
3916
Sanket Padawe356d7632015-06-22 14:03:32 -07003917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003918 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3919 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003921 mApp, subId, callingPackage, callingFeatureId,
3922 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003923 return null;
3924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925
3926 final long identity = Binder.clearCallingIdentity();
3927 try {
3928 final Phone phone = getPhone(subId);
3929 if (phone != null) {
3930 return phone.getCdmaEriText();
3931 } else {
3932 return null;
3933 }
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003937 }
3938
3939 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003940 * Returns the CDMA MDN.
3941 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003942 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003943 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3945 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003950 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951 return phone.getLine1Number();
3952 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003953 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954 return null;
3955 }
3956 } finally {
3957 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003958 }
3959 }
3960
3961 /**
3962 * Returns the CDMA MIN.
3963 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003964 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003965 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3967 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968
3969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 final Phone phone = getPhone(subId);
3972 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3973 return phone.getCdmaMin();
3974 } else {
3975 return null;
3976 }
3977 } finally {
3978 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003979 }
3980 }
3981
Hall Liud892bec2018-11-30 14:51:45 -08003982 @Override
3983 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3984 INumberVerificationCallback callback, String callingPackage) {
3985 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3986 != PERMISSION_GRANTED) {
3987 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3988 }
3989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3990
3991 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3992 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003993 throw new SecurityException("Calling package must be configured in the device config: "
3994 + "calling package: " + callingPackage
3995 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003996 }
3997
3998 if (range == null) {
3999 throw new NullPointerException("Range must be non-null");
4000 }
4001
4002 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004003 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004004
4005 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4006 }
4007
Junda Liuca05d5d2014-08-14 22:36:34 -07004008 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004009 * Returns true if CDMA provisioning needs to run.
4010 */
4011 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004012 final long identity = Binder.clearCallingIdentity();
4013 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004014 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 } finally {
4016 Binder.restoreCallingIdentity(identity);
4017 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004018 }
4019
4020 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004021 * Sets the voice mail number of a given subId.
4022 */
4023 @Override
4024 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004025 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4026 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4031 new Pair<String, String>(alphaTag, number), new Integer(subId));
4032 return success;
4033 } finally {
4034 Binder.restoreCallingIdentity(identity);
4035 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004036 }
4037
Ta-wei Yen87c49842016-05-13 21:19:52 -07004038 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004039 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004041 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4042 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004043 if (!TextUtils.equals(callingPackage, systemDialer)) {
4044 throw new SecurityException("caller must be system dialer");
4045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046
4047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4050 if (phoneAccountHandle == null) {
4051 return null;
4052 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004053 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 } finally {
4055 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004056 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004057 }
4058
4059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004060 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4061 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004062 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004064 mApp, subId, callingPackage, callingFeatureId,
4065 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004066 return null;
4067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004069 final long identity = Binder.clearCallingIdentity();
4070 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004071 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004075 }
4076
4077 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004078 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4079 VisualVoicemailSmsFilterSettings settings) {
4080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004085 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004089 }
4090
4091 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004092 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4093 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094
4095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004098 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004102 }
4103
4104 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004105 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4106 String callingPackage, int subId) {
4107 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108
4109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004112 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004116 }
4117
4118 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004119 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121
4122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004125 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004129 }
4130
4131 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004132 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4133 String callingAttributionTag, int subId, String number, int port, String text,
4134 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004136 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004137 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004138 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004139 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4140 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004141 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004142
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004143 /**
fionaxu0152e512016-11-14 13:36:14 -08004144 * Sets the voice activation state of a given subId.
4145 */
4146 @Override
4147 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4149 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004150
4151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 final Phone phone = getPhone(subId);
4154 if (phone != null) {
4155 phone.setVoiceActivationState(activationState);
4156 } else {
4157 loge("setVoiceActivationState fails with invalid subId: " + subId);
4158 }
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004161 }
4162 }
4163
4164 /**
4165 * Sets the data activation state of a given subId.
4166 */
4167 @Override
4168 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4170 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004171
4172 final long identity = Binder.clearCallingIdentity();
4173 try {
4174 final Phone phone = getPhone(subId);
4175 if (phone != null) {
4176 phone.setDataActivationState(activationState);
4177 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004178 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179 }
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004182 }
4183 }
4184
4185 /**
4186 * Returns the voice activation state of a given subId.
4187 */
4188 @Override
4189 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191
fionaxu0152e512016-11-14 13:36:14 -08004192 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 if (phone != null) {
4196 return phone.getVoiceActivationState();
4197 } else {
4198 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4199 }
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004202 }
4203 }
4204
4205 /**
4206 * Returns the data activation state of a given subId.
4207 */
4208 @Override
4209 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211
fionaxu0152e512016-11-14 13:36:14 -08004212 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 if (phone != null) {
4216 return phone.getDataActivationState();
4217 } else {
4218 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4219 }
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004222 }
4223 }
4224
4225 /**
Wink Saville36469e72014-06-11 15:17:00 -07004226 * Returns the unread count of voicemails for a subId
4227 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004228 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004229 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4230 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004232 mApp, subId, callingPackage, callingFeatureId,
4233 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004234 return 0;
4235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236 final long identity = Binder.clearCallingIdentity();
4237 try {
4238 final Phone phone = getPhone(subId);
4239 if (phone != null) {
4240 return phone.getVoiceMessageCount();
4241 } else {
4242 return 0;
4243 }
4244 } finally {
4245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004247 }
4248
4249 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004250 * returns true, if the device is in a state where both voice and data
4251 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004252 */
4253 @Override
4254 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255 final long identity = Binder.clearCallingIdentity();
4256 try {
Ling Mac28f0212023-03-24 16:07:15 -07004257 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004261 }
4262
4263 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004264 * Send the dialer code if called from the current default dialer or the caller has
4265 * carrier privilege.
4266 * @param inputCode The dialer code to send
4267 */
4268 @Override
4269 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004270 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004272 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4273 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004274 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004275 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004276 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004277 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004281 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
fionaxu235cc5e2017-03-06 22:25:57 -08004285 }
4286
Pengquan Menga1bb6272018-09-06 09:59:22 -07004287 @Override
4288 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004289 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004290 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4291 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 if (!isActiveSubscription(subId)) {
4295 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4296 }
4297 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4298 } finally {
4299 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004300 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004301 }
4302
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004304 public boolean isInEmergencySmsMode() {
4305 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 for (Phone phone : PhoneFactory.getPhones()) {
4309 if (phone.isInEmergencySmsMode()) {
4310 return true;
4311 }
4312 }
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 return false;
4317 }
4318
shilu366312e2019-12-17 09:28:10 -08004319 /**
4320 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4321 * @param subId The subscription to use to check the configuration.
4322 * @param c The callback that will be used to send the result.
4323 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004324 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004325 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4326 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004327 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004328 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004329
4330 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4331 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4332 "IMS not available on device.");
4333 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 final long token = Binder.clearCallingIdentity();
4335 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004336 int slotId = getSlotIndexOrException(subId);
4337 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004338
4339 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4340 if (controller != null) {
4341 ImsManager imsManager = controller.getImsManager(subId);
4342 if (imsManager != null) {
4343 imsManager.addRegistrationCallbackForSubscription(c, subId);
4344 } else {
4345 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4346 }
4347 } else {
4348 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4349 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004350 } catch (ImsException e) {
4351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 } finally {
4353 Binder.restoreCallingIdentity(token);
4354 }
4355 }
4356
shilu366312e2019-12-17 09:28:10 -08004357 /**
4358 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4359 * @param subId The subscription to use to check the configuration.
4360 * @param c The callback that will be used to send the result.
4361 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004363 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004364 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004365 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004366 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4367 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4368 }
Meng Wangafbc5852019-09-19 17:37:13 -07004369 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004370
Meng Wangafbc5852019-09-19 17:37:13 -07004371 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004372 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4373 if (controller != null) {
4374 ImsManager imsManager = controller.getImsManager(subId);
4375 if (imsManager != null) {
4376 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4377 } else {
4378 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4379 + "is inactive, ignoring unregister.");
4380 // If the ImsManager is not valid, just return, since the callback
4381 // will already have been removed internally.
4382 }
4383 }
Meng Wangafbc5852019-09-19 17:37:13 -07004384 } finally {
4385 Binder.restoreCallingIdentity(token);
4386 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 }
4388
Brad Ebingera34a6c22019-10-22 17:36:18 -07004389 /**
4390 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4391 */
4392 @Override
4393 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4394 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4395 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4396 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4397 "IMS not available on device.");
4398 }
4399 final long token = Binder.clearCallingIdentity();
4400 try {
4401 Phone phone = getPhone(subId);
4402 if (phone == null) {
4403 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4404 + subId + "'");
4405 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4406 }
4407 phone.getImsRegistrationState(regState -> {
4408 try {
4409 consumer.accept((regState == null)
4410 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4411 } catch (RemoteException e) {
4412 // Ignore if the remote process is no longer available to call back.
4413 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4414 }
4415 });
4416 } finally {
4417 Binder.restoreCallingIdentity(token);
4418 }
4419 }
4420
4421 /**
4422 * Get the transport type for the IMS service registration state.
4423 */
4424 @Override
4425 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004426 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004427 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004428 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4429 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4430 "IMS not available on device.");
4431 }
4432 final long token = Binder.clearCallingIdentity();
4433 try {
4434 Phone phone = getPhone(subId);
4435 if (phone == null) {
4436 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4437 + subId + "'");
4438 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4439 }
4440 phone.getImsRegistrationTech(regTech -> {
4441 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4442 int regTechConverted = (regTech == null)
4443 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4444 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4445 regTechConverted);
4446 try {
4447 consumer.accept(regTechConverted);
4448 } catch (RemoteException e) {
4449 // Ignore if the remote process is no longer available to call back.
4450 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4451 }
4452 });
4453 } finally {
4454 Binder.restoreCallingIdentity(token);
4455 }
4456 }
4457
shilu366312e2019-12-17 09:28:10 -08004458 /**
4459 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4460 * @param subId The subscription to use to check the configuration.
4461 * @param c The callback that will be used to send the result.
4462 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004463 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004464 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4465 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004466 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004467 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004468 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4469 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4470 "IMS not available on device.");
4471 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 final long token = Binder.clearCallingIdentity();
4473 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004474 int slotId = getSlotIndexOrException(subId);
4475 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004476
4477 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4478 if (controller != null) {
4479 ImsManager imsManager = controller.getImsManager(subId);
4480 if (imsManager != null) {
4481 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4482 } else {
4483 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4484 }
4485 } else {
4486 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4487 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004488 } catch (ImsException e) {
4489 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 } finally {
4491 Binder.restoreCallingIdentity(token);
4492 }
4493 }
4494
shilu366312e2019-12-17 09:28:10 -08004495 /**
4496 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4497 * @param subId The subscription to use to check the configuration.
4498 * @param c The callback that will be used to send the result.
4499 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004501 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004502 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004503 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004504 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4505 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4506 }
Meng Wangafbc5852019-09-19 17:37:13 -07004507
4508 final long token = Binder.clearCallingIdentity();
4509 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004510 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4511 if (controller != null) {
4512 ImsManager imsManager = controller.getImsManager(subId);
4513 if (imsManager != null) {
4514 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4515 } else {
4516 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4517 + " is inactive, ignoring unregister.");
4518 // If the ImsManager is not valid, just return, since the callback
4519 // will already have been removed internally.
4520 }
4521 }
Meng Wangafbc5852019-09-19 17:37:13 -07004522 } finally {
4523 Binder.restoreCallingIdentity(token);
4524 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004525 }
4526
4527 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004528 public boolean isCapable(int subId, int capability, int regTech) {
4529 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 final long token = Binder.clearCallingIdentity();
4531 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004532 int slotId = getSlotIndexOrException(subId);
4533 verifyImsMmTelConfiguredOrThrow(slotId);
4534 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4535 } catch (com.android.ims.ImsException e) {
4536 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4537 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004538 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004539 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4540 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004541 } finally {
4542 Binder.restoreCallingIdentity(token);
4543 }
4544 }
4545
4546 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004547 public boolean isAvailable(int subId, int capability, int regTech) {
4548 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 final long token = Binder.clearCallingIdentity();
4550 try {
4551 Phone phone = getPhone(subId);
4552 if (phone == null) return false;
4553 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004554 } catch (com.android.ims.ImsException e) {
4555 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4556 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004557 } finally {
4558 Binder.restoreCallingIdentity(token);
4559 }
4560 }
4561
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004562 /**
4563 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4564 * subscription.
4565 * @param subId The subscription to use to check the configuration.
4566 * @param callback The callback that will be used to send the result.
4567 * @param capability The MmTelFeature capability that will be used to send the result.
4568 * @param transportType The transport type of the MmTelFeature capability.
4569 */
4570 @Override
4571 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4572 int transportType) {
4573 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004574 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4575 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4576 "IMS not available on device.");
4577 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004578 final long token = Binder.clearCallingIdentity();
4579 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004580 int slotId = getSlotIndex(subId);
4581 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4582 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4583 + subId + "'");
4584 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4585 }
4586 verifyImsMmTelConfiguredOrThrow(slotId);
4587 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4588 transportType, aBoolean -> {
4589 try {
4590 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4591 } catch (RemoteException e) {
4592 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4593 + "running. Ignore");
4594 }
4595 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004596 } catch (ImsException e) {
4597 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004598 } finally {
4599 Binder.restoreCallingIdentity(token);
4600 }
4601 }
4602
shilu366312e2019-12-17 09:28:10 -08004603 /**
4604 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4605 * @param subId The subscription to use to check the configuration.
4606 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004607 @Override
4608 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004609 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004610 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004611
Brad Ebinger35c841c2018-10-01 10:40:55 -07004612 final long token = Binder.clearCallingIdentity();
4613 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004614 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004615 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004616 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004617 } catch (ImsException e) {
4618 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004619 } finally {
4620 Binder.restoreCallingIdentity(token);
4621 }
4622 }
4623
4624 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004625 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004627 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 final long identity = Binder.clearCallingIdentity();
4629 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004630 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004631 // This setting doesn't require an active ImsService connection, so do not verify. The
4632 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004633 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004634 } catch (ImsException e) {
4635 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
4639 }
4640
shilu366312e2019-12-17 09:28:10 -08004641 /**
4642 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4643 * @param subId The subscription to use to check the configuration.
4644 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004645 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004646 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004647 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004648 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004649 final long identity = Binder.clearCallingIdentity();
4650 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004651 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004652 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004653 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004654 } catch (ImsException e) {
4655 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
4659 }
4660
4661 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004662 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004664 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004665 final long identity = Binder.clearCallingIdentity();
4666 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004667 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004668 // This setting doesn't require an active ImsService connection, so do not verify. The
4669 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004671 } catch (ImsException e) {
4672 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
4676 }
4677
shilu366312e2019-12-17 09:28:10 -08004678 /**
4679 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4680 * @param subId The subscription to use to check the configuration.
4681 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004682 @Override
4683 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004684 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004685 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004686 final long identity = Binder.clearCallingIdentity();
4687 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004688 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004689 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004691 } catch (ImsException e) {
4692 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
4696 }
4697
4698 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004699 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004701 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004702 final long identity = Binder.clearCallingIdentity();
4703 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004704 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004705 // This setting doesn't require an active ImsService connection, so do not verify. The
4706 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004707 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004708 } catch (ImsException e) {
4709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
4713 }
4714
shilu366312e2019-12-17 09:28:10 -08004715 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004716 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4717 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4718 * @param subId The subscription to use to check the configuration.
4719 */
4720 @Override
4721 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004722 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004723 mApp, subId, "isCrossSimCallingEnabledByUser");
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004726 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004727 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004728 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004729 } catch (ImsException e) {
4730 throw new ServiceSpecificException(e.getCode());
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
4734 }
4735
4736 /**
4737 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4738 * Requires MODIFY_PHONE_STATE permission.
4739 * @param subId The subscription to use to check the configuration.
4740 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4741 * false otherwise
4742 */
4743 @Override
4744 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4746 "setCrossSimCallingEnabled");
4747 final long identity = Binder.clearCallingIdentity();
4748 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004749 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004750 // This setting doesn't require an active ImsService connection, so do not verify. The
4751 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004752 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004753 } catch (ImsException e) {
4754 throw new ServiceSpecificException(e.getCode());
4755 } finally {
4756 Binder.restoreCallingIdentity(identity);
4757 }
4758 }
4759
4760 /**
shilu366312e2019-12-17 09:28:10 -08004761 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4762 * @param subId The subscription to use to check the configuration.
4763 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004764 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004765
Brad Ebinger35c841c2018-10-01 10:40:55 -07004766 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004767 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004768 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 final long identity = Binder.clearCallingIdentity();
4770 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004771 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004772 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004773 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004774 } catch (ImsException e) {
4775 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 } finally {
4777 Binder.restoreCallingIdentity(identity);
4778 }
4779 }
4780
4781 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004782 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004784 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 final long identity = Binder.clearCallingIdentity();
4786 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004787 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004788 // This setting doesn't require an active ImsService connection, so do not verify. The
4789 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004790 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004791 } catch (ImsException e) {
4792 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004793 } finally {
4794 Binder.restoreCallingIdentity(identity);
4795 }
4796 }
4797
4798 @Override
4799 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4801 "setVoWiFiNonPersistent");
4802 final long identity = Binder.clearCallingIdentity();
4803 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004804 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004805 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004806 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004807 } catch (ImsException e) {
4808 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004809 } finally {
4810 Binder.restoreCallingIdentity(identity);
4811 }
4812 }
4813
shilu366312e2019-12-17 09:28:10 -08004814 /**
4815 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4816 * @param subId The subscription to use to check the configuration.
4817 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004818 @Override
4819 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004820 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004821 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004822 final long identity = Binder.clearCallingIdentity();
4823 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004824 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004825 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004826 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004827 } catch (ImsException e) {
4828 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
4832 }
4833
4834 @Override
4835 public void setVoWiFiModeSetting(int subId, int mode) {
4836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4837 "setVoWiFiModeSetting");
4838 final long identity = Binder.clearCallingIdentity();
4839 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004840 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004841 // This setting doesn't require an active ImsService connection, so do not verify. The
4842 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004843 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004844 } catch (ImsException e) {
4845 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004846 } finally {
4847 Binder.restoreCallingIdentity(identity);
4848 }
4849 }
4850
4851 @Override
4852 public int getVoWiFiRoamingModeSetting(int subId) {
4853 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004856 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004857 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004858 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004859 } catch (ImsException e) {
4860 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
4864 }
4865
4866 @Override
4867 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4869 "setVoWiFiRoamingModeSetting");
4870 final long identity = Binder.clearCallingIdentity();
4871 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004872 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004873 // This setting doesn't require an active ImsService connection, so do not verify. The
4874 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004875 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004876 } catch (ImsException e) {
4877 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
4881 }
4882
4883 @Override
4884 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4886 "setRttCapabilityEnabled");
4887 final long identity = Binder.clearCallingIdentity();
4888 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004889 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004890 // This setting doesn't require an active ImsService connection, so do not verify. The
4891 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004892 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004893 } catch (ImsException e) {
4894 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
4898 }
4899
shilu366312e2019-12-17 09:28:10 -08004900 /**
4901 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4902 * @param subId The subscription to use to check the configuration.
4903 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004904 @Override
4905 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004906 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004907 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 final long identity = Binder.clearCallingIdentity();
4909 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004910 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004911 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004912 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004913 } catch (ImsException e) {
4914 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004915 } finally {
4916 Binder.restoreCallingIdentity(identity);
4917 }
4918 }
4919
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 @Override
4921 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4922 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004923
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004924 final long identity = Binder.clearCallingIdentity();
4925 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004926 if (!isImsAvailableOnDevice()) {
4927 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4928 "IMS not available on device.");
4929 }
4930 int slotId = getSlotIndexOrException(subId);
4931 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004932
4933 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4934 if (controller != null) {
4935 ImsManager imsManager = controller.getImsManager(subId);
4936 if (imsManager != null) {
4937 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4938 } else {
4939 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4940 }
4941 } else {
4942 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4943 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004944 } catch (ImsException e) {
4945 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
4951 @Override
4952 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4953 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004954
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004955 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004956 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4957 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4958 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004959 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004960 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4961 if (controller != null) {
4962 ImsManager imsManager = controller.getImsManager(subId);
4963 if (imsManager != null) {
4964 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4965 } else {
4966 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4967 + " is inactive, ignoring unregister.");
4968 // If the ImsManager is not valid, just return, since the callback will already
4969 // have been removed internally.
4970 }
4971 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
4975 }
4976
joonhunshincffb7fc2021-11-28 07:32:01 +00004977 @Override
4978 public void registerFeatureProvisioningChangedCallback(int subId,
4979 IFeatureProvisioningCallback callback) {
4980 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4981 mApp, subId, "registerFeatureProvisioningChangedCallback");
4982
4983 final long identity = Binder.clearCallingIdentity();
4984 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4985 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4986 }
4987
joonhunshin91bc1952022-04-29 08:47:15 +00004988 try {
4989 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4990 if (controller == null) {
4991 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4992 "Device does not support IMS");
4993 }
4994 controller.addFeatureProvisioningChangedCallback(subId, callback);
4995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004998 }
4999
5000 @Override
5001 public void unregisterFeatureProvisioningChangedCallback(int subId,
5002 IFeatureProvisioningCallback callback) {
5003 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5004 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5005
5006 final long identity = Binder.clearCallingIdentity();
5007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5008 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5009 }
5010
joonhunshin91bc1952022-04-29 08:47:15 +00005011 try {
5012 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5013 if (controller == null) {
5014 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5015 return;
5016 }
5017 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005021 }
allenwtsu99c623b2020-01-03 18:24:23 +08005022
5023 private void checkModifyPhoneStatePermission(int subId, String message) {
5024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5025 message);
5026 }
5027
allenwtsu99c623b2020-01-03 18:24:23 +08005028 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005029 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005030 boolean isProvisioned) {
5031 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5032
5033 final long identity = Binder.clearCallingIdentity();
5034 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005035 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5036 if (controller == null) {
5037 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5038 return;
5039 }
5040 controller.setRcsProvisioningStatusForCapability(
5041 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005042 } finally {
5043 Binder.restoreCallingIdentity(identity);
5044 }
allenwtsu99c623b2020-01-03 18:24:23 +08005045 }
5046
5047
5048 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005049 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5050 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5051 mApp, subId, "getRcsProvisioningStatusForCapability");
5052
allenwtsu99c623b2020-01-03 18:24:23 +08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005055 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5056 if (controller == null) {
5057 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5058
5059 // device does not support IMS, this method will return true always.
5060 return true;
5061 }
5062 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005063 } finally {
5064 Binder.restoreCallingIdentity(identity);
5065 }
5066 }
5067
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005068 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005069 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5070 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005071 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005072
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005075 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5076 if (controller == null) {
5077 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5078 return;
5079 }
5080 controller.setImsProvisioningStatusForCapability(
5081 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005082 } finally {
5083 Binder.restoreCallingIdentity(identity);
5084 }
5085 }
5086
5087 @Override
5088 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005089 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5090 mApp, subId, "getProvisioningStatusForCapability");
5091
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005092 final long identity = Binder.clearCallingIdentity();
5093 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005094 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5095 if (controller == null) {
5096 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005097
joonhunshin91bc1952022-04-29 08:47:15 +00005098 // device does not support IMS, this method will return true always.
5099 return true;
5100 }
5101 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
5105 }
5106
5107 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005108 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5109 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5110 mApp, subId, "isProvisioningRequiredForCapability");
5111
5112 final long identity = Binder.clearCallingIdentity();
5113 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005114 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5115 if (controller == null) {
5116 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5117
5118 // device does not support IMS, this method will return false
5119 return false;
5120 }
5121 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005122 } finally {
5123 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005124 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005125 }
5126
5127 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005128 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5129 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5130 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005131
joonhunshincffb7fc2021-11-28 07:32:01 +00005132 final long identity = Binder.clearCallingIdentity();
5133 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005134 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5135 if (controller == null) {
5136 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5137
5138 // device does not support IMS, this method will return false
5139 return false;
5140 }
5141 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005142 } finally {
5143 Binder.restoreCallingIdentity(identity);
5144 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005145 }
5146
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005147 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005148 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005149 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5150 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5151 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005152 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5153 mApp, subId, "getImsProvisioningInt");
5154
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005158 int slotId = getSlotIndex(subId);
5159 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5160 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5161 + subId + "' for key:" + key);
5162 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5163 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005164
joonhunshin91bc1952022-04-29 08:47:15 +00005165 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5166 if (controller == null) {
5167 loge("getImsProvisioningInt: Device does not support IMS");
5168
5169 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5170 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5171 }
5172 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005173 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5174 return retVal;
5175 }
5176
calvinpanb5a34062021-02-08 19:59:36 +08005177 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005178 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005179 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5180 + subId + "' for key:" + key);
5181 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005182 } finally {
5183 Binder.restoreCallingIdentity(identity);
5184 }
5185 }
5186
5187 @Override
5188 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005189 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5190 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5191 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005192 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5193 mApp, subId, "getImsProvisioningString");
5194
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005195 final long identity = Binder.clearCallingIdentity();
5196 try {
5197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005198 int slotId = getSlotIndex(subId);
5199 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5200 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5201 + subId + "' for key:" + key);
5202 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5203 }
calvinpanb5a34062021-02-08 19:59:36 +08005204 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005205 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005206 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5207 + subId + "' for key:" + key);
5208 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
5212 }
5213
5214 @Override
5215 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5217 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5218 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5220 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005221
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005225 int slotId = getSlotIndex(subId);
5226 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5227 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5228 + subId + "' for key:" + key);
5229 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5230 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005231
joonhunshin91bc1952022-04-29 08:47:15 +00005232 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5233 if (controller == null) {
5234 loge("setImsProvisioningInt: Device does not support IMS");
5235
5236 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5237 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5238 }
5239 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005240 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5241 return retVal;
5242 }
5243
calvinpanb5a34062021-02-08 19:59:36 +08005244 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5245 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005246 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005247 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005248 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
5252 }
5253
5254 @Override
5255 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005256 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5257 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5258 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5260 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005264 int slotId = getSlotIndex(subId);
5265 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5266 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5267 + subId + "' for key:" + key);
5268 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5269 }
calvinpanb5a34062021-02-08 19:59:36 +08005270 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5271 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005272 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005273 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005274 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
5278 }
5279
Brad Ebinger919631e2021-06-02 17:46:35 -07005280 /**
5281 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5282 * for the given slot ID or no ImsResolver instance has been created.
5283 * @param slotId The slot ID that the IMS service is created for.
5284 * @throws ImsException If there is no ImsService configured for this slot.
5285 */
5286 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5287 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5288 ImsFeature.FEATURE_MMTEL)) {
5289 throw new ImsException("This subscription does not support MMTEL over IMS",
5290 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5291 }
5292 }
5293
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005294 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005295 int slotId = SubscriptionManager.getSlotIndex(subId);
5296 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005297 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5298 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005299 }
5300 return slotId;
5301 }
5302
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005303 private int getSlotIndex(int subId) {
5304 int slotId = SubscriptionManager.getSlotIndex(subId);
5305 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5306 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5307 }
5308 return slotId;
5309 }
5310
Wink Saville36469e72014-06-11 15:17:00 -07005311 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005312 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005313 */
5314 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005315 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5316 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005317 try {
5318 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5319 } catch (SecurityException se) {
5320 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5321 throw new SecurityException("Package " + callingPackage + " does not belong to "
5322 + Binder.getCallingUid());
5323 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005324 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005325 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005326 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005327 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005328 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005329 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005330 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005331 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5332 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 final Phone phone = getPhone(subId);
5337 if (phone != null) {
5338 return phone.getServiceState().getDataNetworkType();
5339 } else {
5340 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5341 }
5342 } finally {
5343 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005345 }
5346
5347 /**
5348 * Returns the data network type
5349 */
5350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005351 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005352 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005353 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005354 }
5355
5356 /**
5357 * Returns the data network type for a subId
5358 */
5359 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005360 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5361 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005362 String functionName = "getDataNetworkTypeForSubscriber";
5363 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5364 mApp, functionName)) {
5365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5366 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5367 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5368 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005369 }
5370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 final long identity = Binder.clearCallingIdentity();
5372 try {
5373 final Phone phone = getPhone(subId);
5374 if (phone != null) {
5375 return phone.getServiceState().getDataNetworkType();
5376 } else {
5377 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5378 }
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005382 }
5383
5384 /**
Wink Saville36469e72014-06-11 15:17:00 -07005385 * Returns the Voice network type for a subId
5386 */
5387 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005388 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5389 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005390 String functionName = "getVoiceNetworkTypeForSubscriber";
5391 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5392 mApp, functionName)) {
5393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5394 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5395 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5396 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005397 }
5398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 final long identity = Binder.clearCallingIdentity();
5400 try {
5401 final Phone phone = getPhone(subId);
5402 if (phone != null) {
5403 return phone.getServiceState().getVoiceNetworkType();
5404 } else {
5405 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5406 }
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005410 }
5411
5412 /**
5413 * @return true if a ICC card is present
5414 */
5415 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005416 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005417 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005418 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005419 }
5420
5421 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005422 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005423 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005424 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005425 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
5428 final Phone phone = PhoneFactory.getPhone(slotIndex);
5429 if (phone != null) {
5430 return phone.getIccCard().hasIccCard();
5431 } else {
5432 return false;
5433 }
5434 } finally {
5435 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005437 }
5438
5439 /**
5440 * Return if the current radio is LTE on CDMA. This
5441 * is a tri-state return value as for a period of time
5442 * the mode may be unknown.
5443 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005444 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005445 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005446 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005447 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005449 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5450 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5451 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005452 }
5453
Sanket Padawe356d7632015-06-22 14:03:32 -07005454 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005455 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5456 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005457 try {
5458 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5459 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005460 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5461 }
5462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 final Phone phone = getPhone(subId);
5466 if (phone == null) {
5467 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5468 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005469 return TelephonyProperties.lte_on_cdma_device()
5470 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 }
5472 } finally {
5473 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005474 }
Wink Saville36469e72014-06-11 15:17:00 -07005475 }
5476
Wink Saville36469e72014-06-11 15:17:00 -07005477 /**
5478 * {@hide}
5479 * Returns Default subId, 0 in the case of single standby.
5480 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005481 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005482 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005483 }
5484
Shishir Agrawala9f32182016-04-12 12:00:16 -07005485 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005486 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005487 }
5488
Wink Savilleb564aae2014-10-23 10:18:09 -07005489 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005490 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005491 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005492
Pengquan Menge92a50d2018-09-21 15:54:48 -07005493 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005494 return getSubscriptionManagerService().isActiveSubId(subId,
5495 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005496 }
5497
Ihab Awadf2177b72013-11-25 13:33:23 -08005498 /**
5499 * @see android.telephony.TelephonyManager.WifiCallingChoices
5500 */
5501 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 final long identity = Binder.clearCallingIdentity();
5503 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005504 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5506 getWhenToMakeWifiCallsDefaultPreference());
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005510 }
5511
5512 /**
5513 * @see android.telephony.TelephonyManager.WifiCallingChoices
5514 */
5515 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005519 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005524 }
5525
Sailesh Nepald1e68152013-12-12 19:08:02 -08005526 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005527 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005528 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005529 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005530
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005531 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5532 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5533 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005534 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005535 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005536 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005537 }
5538 return PhoneFactory.getPhone(phoneId);
5539 }
5540
Shishir Agrawal566b7612013-10-28 14:41:00 -07005541 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005542 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005543 @NonNull IccLogicalChannelRequest request) {
5544 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5545 /*message=*/ "iccOpenLogicalChannel");
5546
5547 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5548 // Verify that the callingPackage in the request belongs to the calling UID
5549 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5550
5551 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005552 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005553
Rambo Wanga1782702021-11-10 20:15:19 -08005554 private Phone getPhoneFromValidIccLogicalChannelRequest(
5555 @NonNull IccLogicalChannelRequest request, String message) {
5556 Phone phone;
5557 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5559 mApp, request.subId, message);
5560 phone = getPhoneFromSubId(request.subId);
5561 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5562 enforceModifyPermission();
5563 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5564 } else {
5565 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005566 }
Rambo Wanga1782702021-11-10 20:15:19 -08005567 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005568 }
5569
5570 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005571 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 final long identity = Binder.clearCallingIdentity();
5573 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005574 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005576 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5577 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005578 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5579 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 loge("The calling package is not allowed to access ISD-R.");
5581 throw new SecurityException(
5582 "The calling package is not allowed to access ISD-R.");
5583 }
Derek Tan740e1672017-06-27 14:56:27 -07005584 }
Derek Tan740e1672017-06-27 14:56:27 -07005585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005587 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5588 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 return response;
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005593 }
5594
5595 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005596 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5597 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5598 /*message=*/"iccCloseLogicalChannel");
5599
5600 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5601
5602 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005604
Rambo Wanga1782702021-11-10 20:15:19 -08005605 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5606 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005607 // before this feature is enabled, this API should only return false if
5608 // the operation fails instead of throwing runtime exception for
5609 // backward-compatibility.
5610 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5611 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005614 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005615 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 }
Chen Xue9d737e2022-01-01 23:41:31 -08005617 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005618 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005619 Boolean success = false;
5620 if (result instanceof RuntimeException) {
5621 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005622 if (shouldThrowExceptionOnFailure) {
5623 throw (RuntimeException) result;
5624 } else {
5625 return false;
5626 }
Chen Xue9d737e2022-01-01 23:41:31 -08005627 } else if (result instanceof Boolean) {
5628 success = (Boolean) result;
5629 } else {
5630 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5631 }
Rambo Wanga1782702021-11-10 20:15:19 -08005632 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 return success;
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005636 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005637 }
5638
5639 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005640 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005641 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5643 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005644 if (DBG) {
5645 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5646 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5647 + p3 + " data=" + data);
5648 }
5649 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5650 command, p1, p2, p3, data);
5651 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005652
Jordan Liu4c733742019-02-28 12:03:40 -08005653 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005654 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005655 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005656 enforceModifyPermission();
5657 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005658 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005659 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5660 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005661 }
5662 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005663 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5664 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005665 }
5666
5667 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5668 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 final long identity = Binder.clearCallingIdentity();
5670 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005671 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 return "";
5673 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005676 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5677 null /* workSource */);
5678 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 // Append the returned status code to the end of the response payload.
5681 String s = Integer.toHexString(
5682 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5683 if (response.payload != null) {
5684 s = IccUtils.bytesToHexString(response.payload) + s;
5685 }
5686 return s;
5687 } finally {
5688 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005690 }
Jake Hambye994d462014-02-03 13:10:13 -08005691
Evan Charltonc66da362014-05-16 14:06:40 -07005692 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005693 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5694 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5696 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005698 if (DBG) {
5699 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5700 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5701 }
5702 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5703 cla, command, p1, p2, p3, data);
5704 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005705
Jordan Liu4c733742019-02-28 12:03:40 -08005706 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005707 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005708 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005709 enforceModifyPermission();
5710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5711 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005712 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005713 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5714 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005715 }
5716
5717 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005718 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5719 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005720 }
5721
5722 // open APDU basic channel assuming the caller has sufficient permissions
5723 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5724 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5728 && TextUtils.equals(ISDR_AID, data)) {
5729 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005730 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5731 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 if (bestComponent == null
5733 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5734 loge("The calling package is not allowed to select ISD-R.");
5735 throw new SecurityException(
5736 "The calling package is not allowed to select ISD-R.");
5737 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005738 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005741 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5742 null /* workSource */);
5743 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 // Append the returned status code to the end of the response payload.
5746 String s = Integer.toHexString(
5747 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5748 if (response.payload != null) {
5749 s = IccUtils.bytesToHexString(response.payload) + s;
5750 }
5751 return s;
5752 } finally {
5753 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005754 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005755 }
5756
5757 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005758 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005759 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5761 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 if (DBG) {
5766 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5767 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5768 }
5769
5770 IccIoResult response =
5771 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5772 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5773 subId);
5774
5775 if (DBG) {
5776 log("Exchange SIM_IO [R]" + response);
5777 }
5778
5779 byte[] result = null;
5780 int length = 2;
5781 if (response.payload != null) {
5782 length = 2 + response.payload.length;
5783 result = new byte[length];
5784 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5785 } else {
5786 result = new byte[length];
5787 }
5788
5789 result[length - 1] = (byte) response.sw2;
5790 result[length - 2] = (byte) response.sw1;
5791 return result;
5792 } finally {
5793 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005794 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005795 }
5796
Nathan Haroldb3014052017-01-25 15:57:32 -08005797 /**
5798 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5799 * on a particular subscription
5800 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005801 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5802 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005804 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005805 return null;
5806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 if (appType != TelephonyManager.APPTYPE_USIM
5811 && appType != TelephonyManager.APPTYPE_SIM) {
5812 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5813 return null;
5814 }
5815 Object response = sendRequest(
5816 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5817 if (response instanceof String[]) {
5818 return (String[]) response;
5819 }
yincheng zhao2737e882019-09-06 17:06:54 -07005820 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005822 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 } finally {
5824 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005825 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005826 }
5827
yincheng zhao2737e882019-09-06 17:06:54 -07005828 /**
5829 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5830 * subscription.
5831 *
5832 * @param subId the id of the subscription.
5833 * @param appType the uicc app type, must be USIM or SIM.
5834 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5835 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005836 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005837 * @return number of fplmns that is successfully written to the SIM.
5838 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005839 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5840 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5842 mApp, subId, "setForbiddenPlmns");
5843
yincheng zhao2737e882019-09-06 17:06:54 -07005844 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5845 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5846 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5847 }
5848 if (fplmns == null) {
5849 throw new IllegalArgumentException("Fplmn List provided is null");
5850 }
5851 for (String fplmn : fplmns) {
5852 if (!CellIdentity.isValidPlmn(fplmn)) {
5853 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5854 }
5855 }
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 Object response = sendRequest(
5859 CMD_SET_FORBIDDEN_PLMNS,
5860 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5861 subId);
5862 return (int) response;
5863 } finally {
5864 Binder.restoreCallingIdentity(identity);
5865 }
5866 }
5867
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005868 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005869 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5871 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 final long identity = Binder.clearCallingIdentity();
5874 try {
5875 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5876 if (response.payload == null) {
5877 return "";
5878 }
Evan Charltonc66da362014-05-16 14:06:40 -07005879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 // Append the returned status code to the end of the response payload.
5881 String s = Integer.toHexString(
5882 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5883 s = IccUtils.bytesToHexString(response.payload) + s;
5884 return s;
5885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
Evan Charltonc66da362014-05-16 14:06:40 -07005888 }
5889
Jake Hambye994d462014-02-03 13:10:13 -08005890 /**
5891 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5892 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5893 *
5894 * @param itemID the ID of the item to read
5895 * @return the NV item as a String, or null on error.
5896 */
5897 @Override
5898 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5901 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005906 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5908 return value;
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
Jake Hambye994d462014-02-03 13:10:13 -08005912 }
5913
5914 /**
5915 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5916 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5917 *
5918 * @param itemID the ID of the item to read
5919 * @param itemValue the value to write, as a String
5920 * @return true on success; false on any failure
5921 */
5922 @Override
5923 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005924 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5926 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
5930 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5931 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005932 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5934 return success;
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
5937 }
Jake Hambye994d462014-02-03 13:10:13 -08005938 }
5939
5940 /**
5941 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5942 * Used for device configuration by some CDMA operators.
5943 *
5944 * @param preferredRoamingList byte array containing the new PRL
5945 * @return true on success; false on any failure
5946 */
5947 @Override
5948 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5950 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951
5952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5955 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5956 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5957 return success;
5958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
Jake Hambye994d462014-02-03 13:10:13 -08005961 }
5962
5963 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005964 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005965 * Used for device configuration by some CDMA operators.
5966 *
chen xu6dac5ab2018-10-26 17:39:23 -07005967 * @param slotIndex - device slot.
5968 *
Jake Hambye994d462014-02-03 13:10:13 -08005969 * @return true on success; false on any failure
5970 */
5971 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005972 public boolean resetModemConfig(int slotIndex) {
5973 Phone phone = PhoneFactory.getPhone(slotIndex);
5974 if (phone != null) {
5975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5976 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977
chen xu6dac5ab2018-10-26 17:39:23 -07005978 final long identity = Binder.clearCallingIdentity();
5979 try {
5980 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5981 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5982 return success;
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 }
chen xu6dac5ab2018-10-26 17:39:23 -07005987 return false;
5988 }
5989
5990 /**
5991 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5992 *
5993 * @param slotIndex - device slot.
5994 *
5995 * @return true on success; false on any failure
5996 */
5997 @Override
5998 public boolean rebootModem(int slotIndex) {
5999 Phone phone = PhoneFactory.getPhone(slotIndex);
6000 if (phone != null) {
6001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6002 mApp, phone.getSubId(), "rebootModem");
6003
6004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6007 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6008 return success;
6009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
6012 }
6013 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006014 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006015
Brad Ebinger51f743a2017-01-23 13:50:20 -08006016 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006017 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6018 * {@link #disableIms(int)}.
6019 * @param slotIndex device slot.
6020 */
6021 public void resetIms(int slotIndex) {
6022 enforceModifyPermission();
6023
6024 final long identity = Binder.clearCallingIdentity();
6025 try {
6026 if (mImsResolver == null) {
6027 // may happen if the does not support IMS.
6028 return;
6029 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006030 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006031 } finally {
6032 Binder.restoreCallingIdentity(identity);
6033 }
6034 }
6035
6036 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006037 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6038 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006039 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006040 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042
6043 final long identity = Binder.clearCallingIdentity();
6044 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006045 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006046 // may happen if the device does not support IMS.
6047 return;
6048 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006049 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006053 }
6054
6055 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006056 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6057 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006058 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006059 public void disableIms(int slotId) {
6060 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061
6062 final long identity = Binder.clearCallingIdentity();
6063 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006064 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006065 // may happen if the device does not support IMS.
6066 return;
6067 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006068 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 } finally {
6070 Binder.restoreCallingIdentity(identity);
6071 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006072 }
6073
6074 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006075 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6076 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006077 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006078 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006079 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081
6082 final long identity = Binder.clearCallingIdentity();
6083 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006084 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006085 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6086 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006087 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006088 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 } finally {
6090 Binder.restoreCallingIdentity(identity);
6091 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006092 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006093 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006094 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6095 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006096 @Override
6097 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006098 enforceModifyPermission();
6099
6100 final long identity = Binder.clearCallingIdentity();
6101 try {
6102 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006103 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
6107 }
6108
6109 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006110 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006111 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006112 */
6113 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6114 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115
6116 final long identity = Binder.clearCallingIdentity();
6117 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006118 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006119 // may happen if the device does not support IMS.
6120 return null;
6121 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006122 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 } finally {
6124 Binder.restoreCallingIdentity(identity);
6125 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006126 }
6127
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006128 /**
6129 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006130 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006131 */
6132 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134
6135 final long identity = Binder.clearCallingIdentity();
6136 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006137 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006138 // may happen if the device does not support IMS.
6139 return null;
6140 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006141 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 } finally {
6143 Binder.restoreCallingIdentity(identity);
6144 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006145 }
6146
Brad Ebinger884c07b2018-02-15 16:17:40 -08006147 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006148 * Sets the ImsService Package Name that Telephony will bind to.
6149 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006150 * @param slotIndex the slot ID that the ImsService should bind for.
6151 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006152 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006153 * @param featureTypes An integer array of feature types associated with a packageName.
6154 * @param packageName The name of the package that the current configuration will be replaced
6155 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006156 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006157 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006158 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6159 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006162 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 final long identity = Binder.clearCallingIdentity();
6165 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006166 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006167 // may happen if the device does not support IMS.
6168 return false;
6169 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006170 Map<Integer, String> featureConfig = new HashMap<>();
6171 for (int featureType : featureTypes) {
6172 featureConfig.put(featureType, packageName);
6173 }
6174 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6175 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006179 }
6180
6181 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006182 * Clears any carrier ImsService overrides for the slot index specified that were previously
6183 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6184 *
6185 * This should only be used for testing.
6186 *
6187 * @param slotIndex the slot ID that the ImsService should bind for.
6188 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6189 */
6190 @Override
6191 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6193 "clearCarrierImsServiceOverride");
6194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006195 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006196
6197 final long identity = Binder.clearCallingIdentity();
6198 try {
6199 if (mImsResolver == null) {
6200 // may happen if the device does not support IMS.
6201 return false;
6202 }
6203 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6204 } finally {
6205 Binder.restoreCallingIdentity(identity);
6206 }
6207 }
6208
6209 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006210 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006211 *
6212 * @param slotId The slot that the ImsService is associated with.
6213 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6214 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006215 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006216 * @return the package name of the ImsService configuration.
6217 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006218 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6219 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006220 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006221 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6222 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 final long identity = Binder.clearCallingIdentity();
6225 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006226 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006227 // may happen if the device does not support IMS.
6228 return "";
6229 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006230 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006231 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6232 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006236 }
6237
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006238 /**
6239 * Get the MmTelFeature state associated with the requested subscription id.
6240 * @param subId The subscription that the MmTelFeature is associated with.
6241 * @param callback A callback with an integer containing the
6242 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6243 */
6244 @Override
6245 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6246 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006247 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6248 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6249 "IMS not available on device.");
6250 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006251 final long token = Binder.clearCallingIdentity();
6252 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006253 int slotId = getSlotIndex(subId);
6254 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6255 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6256 + subId + "'");
6257 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6258 }
6259 verifyImsMmTelConfiguredOrThrow(slotId);
6260 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6261 try {
6262 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6263 } catch (RemoteException e) {
6264 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6265 + "Ignore");
6266 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006267 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006268 } catch (ImsException e) {
6269 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006270 } finally {
6271 Binder.restoreCallingIdentity(token);
6272 }
6273 }
6274
Daniel Brightbb5840b2021-01-12 15:48:18 -08006275 /**
6276 * Sets the ims registration state on all valid {@link Phone}s.
6277 */
6278 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280
6281 final long identity = Binder.clearCallingIdentity();
6282 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006283 // NOTE: Before S, this method only set the default phone.
6284 for (final Phone phone : PhoneFactory.getPhones()) {
6285 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6286 phone.setImsRegistrationState(registered);
6287 }
6288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
Wink Saville36469e72014-06-11 15:17:00 -07006292 }
6293
6294 /**
Stuart Scott54788802015-03-30 13:18:01 -07006295 * Set the network selection mode to automatic.
6296 *
6297 */
6298 @Override
6299 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6301 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302
6303 final long identity = Binder.clearCallingIdentity();
6304 try {
shilufc958392020-01-20 11:36:01 -08006305 if (!isActiveSubscription(subId)) {
6306 return;
6307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006309 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6310 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
Stuart Scott54788802015-03-30 13:18:01 -07006314 }
6315
Jack Yud10cdd42020-09-28 20:28:01 -07006316 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006317 * Ask the radio to connect to the input network and change selection mode to manual.
6318 *
6319 * @param subId the id of the subscription.
6320 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6321 * the operator to attach to.
6322 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6323 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6324 * normal network selection next time.
6325 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006326 */
6327 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006328 public boolean setNetworkSelectionModeManual(
6329 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6331 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006332
Jack Yu285100e2022-12-02 22:48:35 -08006333 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006334 if (!isActiveSubscription(subId)) {
6335 return false;
6336 }
6337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006339 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006341 if (DBG) {
6342 log("setNetworkSelectionModeManual: subId: " + subId
6343 + " operator: " + operatorInfo);
6344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006349 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006350 /**
shilu84f6e8b2019-12-19 13:58:01 -08006351 * Get the manual network selection
6352 *
6353 * @param subId the id of the subscription.
6354 *
6355 * @return the previously saved user selected PLMN
6356 */
6357 @Override
6358 public String getManualNetworkSelectionPlmn(int subId) {
6359 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006360 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6361 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006362
6363 final long identity = Binder.clearCallingIdentity();
6364 try {
6365 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006366 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006367 }
6368
6369 final Phone phone = getPhone(subId);
6370 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006371 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006372 }
6373 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6374 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006375 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
6379 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006380
6381 /**
6382 * Scans for available networks.
6383 */
6384 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006385 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6386 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6388 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006389 LocationAccessPolicy.LocationPermissionResult locationResult =
6390 LocationAccessPolicy.checkLocationPermission(mApp,
6391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6392 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006393 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006394 .setCallingPid(Binder.getCallingPid())
6395 .setCallingUid(Binder.getCallingUid())
6396 .setMethod("getCellNetworkScanResults")
6397 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006398 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6399 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006400 .build());
6401 switch (locationResult) {
6402 case DENIED_HARD:
6403 throw new SecurityException("Not allowed to access scan results -- location");
6404 case DENIED_SOFT:
6405 return null;
6406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407
Pengquan Menga1bb6272018-09-06 09:59:22 -07006408 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 try {
6410 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006411 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006416 }
6417
6418 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006419 * Get the call forwarding info, given the call forwarding reason.
6420 */
6421 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006422 public void getCallForwarding(int subId, int callForwardingReason,
6423 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006424 enforceReadPrivilegedPermission("getCallForwarding");
6425 long identity = Binder.clearCallingIdentity();
6426 try {
6427 if (DBG) {
6428 log("getCallForwarding: subId " + subId
6429 + " callForwardingReason" + callForwardingReason);
6430 }
Hall Liu27d24262020-09-18 19:04:59 -07006431
6432 Phone phone = getPhone(subId);
6433 if (phone == null) {
6434 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006435 callback.onError(
6436 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006437 } catch (RemoteException e) {
6438 // ignore
6439 }
6440 return;
6441 }
6442
6443 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6444 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6445 @Override
6446 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6447 try {
6448 callback.onCallForwardingInfoAvailable(info);
6449 } catch (RemoteException e) {
6450 // ignore
6451 }
6452 }
6453
6454 @Override
6455 public void onError(int error) {
6456 try {
6457 callback.onError(error);
6458 } catch (RemoteException e) {
6459 // ignore
6460 }
6461 }
6462 });
6463 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006464 } finally {
6465 Binder.restoreCallingIdentity(identity);
6466 }
6467 }
6468
6469 /**
6470 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6471 * reason, the number to forward, and the timeout before the forwarding is attempted.
6472 */
6473 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006474 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6475 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006476 enforceModifyPermission();
6477 long identity = Binder.clearCallingIdentity();
6478 try {
6479 if (DBG) {
6480 log("setCallForwarding: subId " + subId
6481 + " callForwardingInfo" + callForwardingInfo);
6482 }
Hall Liu27d24262020-09-18 19:04:59 -07006483
6484 Phone phone = getPhone(subId);
6485 if (phone == null) {
6486 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006487 callback.accept(
6488 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006489 } catch (RemoteException e) {
6490 // ignore
6491 }
6492 return;
6493 }
6494
6495 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6496 FunctionalUtils.ignoreRemoteException(callback::accept));
6497
6498 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006499 } finally {
6500 Binder.restoreCallingIdentity(identity);
6501 }
6502 }
6503
6504 /**
Hall Liu27d24262020-09-18 19:04:59 -07006505 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006506 */
6507 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006508 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006509 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006510 long identity = Binder.clearCallingIdentity();
6511 try {
Hall Liu27d24262020-09-18 19:04:59 -07006512 Phone phone = getPhone(subId);
6513 if (phone == null) {
6514 try {
6515 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6516 } catch (RemoteException e) {
6517 // ignore
6518 }
6519 return;
6520 }
SongFerngWang0e767992021-03-31 22:08:45 +08006521 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6522 PersistableBundle c = configManager.getConfigForSubId(subId);
6523 boolean requireUssd = c.getBoolean(
6524 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006525
Shuo Qian4a594052020-01-23 11:59:30 -08006526 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006527 if (requireUssd) {
6528 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6529 getSubscriptionCarrierId(subId));
6530 String newUssdCommand = "";
6531 try {
6532 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006533 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006534 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6535 } catch (NullPointerException e) {
6536 loge("Failed to generate USSD number" + e);
6537 }
6538 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6539 mMainThreadHandler, callback, carrierXmlParser,
6540 CarrierXmlParser.SsEntry.SSAction.QUERY);
6541 final String ussdCommand = newUssdCommand;
6542 Executors.newSingleThreadExecutor().execute(() -> {
6543 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6544 });
6545 } else {
6546 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6547 callback::accept);
6548 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6549 }
Shuo Qian4a594052020-01-23 11:59:30 -08006550 } finally {
6551 Binder.restoreCallingIdentity(identity);
6552 }
6553 }
6554
6555 /**
Hall Liu27d24262020-09-18 19:04:59 -07006556 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006557 */
6558 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006559 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006560 enforceModifyPermission();
6561 long identity = Binder.clearCallingIdentity();
6562 try {
Hall Liu27d24262020-09-18 19:04:59 -07006563 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6564
6565 Phone phone = getPhone(subId);
6566 if (phone == null) {
6567 try {
6568 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6569 } catch (RemoteException e) {
6570 // ignore
6571 }
6572 return;
6573 }
6574
SongFerngWang0e767992021-03-31 22:08:45 +08006575 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6576 PersistableBundle c = configManager.getConfigForSubId(subId);
6577 boolean requireUssd = c.getBoolean(
6578 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006579
SongFerngWang0e767992021-03-31 22:08:45 +08006580 if (DBG) log("getCallWaitingStatus: subId " + subId);
6581 if (requireUssd) {
6582 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6583 getSubscriptionCarrierId(subId));
6584 CarrierXmlParser.SsEntry.SSAction ssAction =
6585 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6586 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6587 String newUssdCommand = "";
6588 try {
6589 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006590 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006591 .makeCommand(ssAction, null);
6592 } catch (NullPointerException e) {
6593 loge("Failed to generate USSD number" + e);
6594 }
6595 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6596 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6597 final String ussdCommand = newUssdCommand;
6598 Executors.newSingleThreadExecutor().execute(() -> {
6599 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6600 });
6601 } else {
6602 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6603 FunctionalUtils.ignoreRemoteException(callback::accept));
6604
6605 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6606 }
Shuo Qian4a594052020-01-23 11:59:30 -08006607 } finally {
6608 Binder.restoreCallingIdentity(identity);
6609 }
6610 }
6611
6612 /**
yinxub1bed742017-04-17 11:45:04 -07006613 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006614 *
yinxub1bed742017-04-17 11:45:04 -07006615 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006616 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6617 * location related information which will be sent if the caller already possess
6618 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006619 * @param request contains the radio access networks with bands/channels to scan
6620 * @param messenger callback messenger for scan results or errors
6621 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006622 * @return the id of the requested scan which can be used to stop the scan.
6623 */
6624 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006625 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6626 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006627 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6629 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006630 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006631 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6632 if (!renounceFineLocationAccess) {
6633 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006634 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6635 .setCallingPackage(callingPackage)
6636 .setCallingFeatureId(callingFeatureId)
6637 .setCallingPid(Binder.getCallingPid())
6638 .setCallingUid(Binder.getCallingUid())
6639 .setMethod("requestNetworkScan")
6640 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6641 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6642 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6643 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006644 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006645 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006646 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6647 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006648 if (e != null) {
6649 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6650 throw e;
6651 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006652 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006653 return TelephonyScanManager.INVALID_SCAN_ID;
6654 }
6655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 }
Hall Liu912dfd32019-04-25 14:02:26 -07006657 int callingUid = Binder.getCallingUid();
6658 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006659 final long identity = Binder.clearCallingIdentity();
6660 try {
6661 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006662 renounceFineLocationAccess, request, messenger, binder,
6663 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006664 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006665 } finally {
6666 Binder.restoreCallingIdentity(identity);
6667 }
yinxu504e1392017-04-12 16:03:22 -07006668 }
6669
Hall Liub2ac8ef2019-02-28 15:56:23 -08006670 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006671 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006672 boolean hasCarrierPriv;
6673 final long identity = Binder.clearCallingIdentity();
6674 try {
6675 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6676 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
Hall Liu558027f2019-05-15 19:14:05 -07006680 boolean hasNetworkScanPermission =
6681 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006682 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006683
6684 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6685 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6686 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006687 }
6688
6689 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6690 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006691 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6692 return new SecurityException("Specific channels must not be"
6693 + " scanned without location access.");
6694 }
6695 }
6696 }
6697
Hall Liub2ac8ef2019-02-28 15:56:23 -08006698 return null;
6699 }
6700
yinxu504e1392017-04-12 16:03:22 -07006701 /**
6702 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006703 *
6704 * @param subId id of the subscription
6705 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006706 */
6707 @Override
6708 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6710 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711
Hall Liu912dfd32019-04-25 14:02:26 -07006712 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 final long identity = Binder.clearCallingIdentity();
6714 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006715 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 } finally {
6717 Binder.restoreCallingIdentity(identity);
6718 }
yinxu504e1392017-04-12 16:03:22 -07006719 }
6720
6721 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006722 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006723 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006724 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006725 */
6726 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006727 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006728 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006729 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006730 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731
6732 final long identity = Binder.clearCallingIdentity();
6733 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006734 if (DBG) log("getAllowedNetworkTypesBitmask");
6735 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6736 int networkTypesBitmask = (result != null ? result[0] : -1);
6737 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6738 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 } finally {
6740 Binder.restoreCallingIdentity(identity);
6741 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006742 }
6743
6744 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006745 * Get the allowed network types for certain reason.
6746 *
6747 * @param subId the id of the subscription.
6748 * @param reason the reason the allowed network type change is taking place
6749 * @return the allowed network types.
6750 */
6751 @Override
6752 public long getAllowedNetworkTypesForReason(int subId,
6753 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006754 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006755 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006756 final long identity = Binder.clearCallingIdentity();
6757 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006758 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
6762 }
6763
6764 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006765 * Enable/Disable E-UTRA-NR Dual Connectivity
6766 * @param subId subscription id of the sim card
6767 * @param nrDualConnectivityState expected NR dual connectivity state
6768 * This can be passed following states
6769 * <ol>
6770 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6771 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6772 * <li>Disable NR dual connectivity and force secondary cell to be released
6773 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6774 * </ol>
6775 * @return operation result.
6776 */
6777 @Override
6778 public int setNrDualConnectivityState(int subId,
6779 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6781 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006782 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006783 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6784 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6785 }
6786
Sooraj Sasindran37444802020-08-11 10:40:43 -07006787 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
6790 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6791 nrDualConnectivityState, subId,
6792 workSource);
6793 if (DBG) log("enableNRDualConnectivity result: " + result);
6794 return result;
6795 } finally {
6796 Binder.restoreCallingIdentity(identity);
6797 }
6798 }
6799
6800 /**
6801 * Is E-UTRA-NR Dual Connectivity enabled
6802 * @return true if dual connectivity is enabled else false
6803 */
6804 @Override
6805 public boolean isNrDualConnectivityEnabled(int subId) {
6806 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006807 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006808 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006809 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006810 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6811 return false;
6812 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006813 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6814 final long identity = Binder.clearCallingIdentity();
6815 try {
6816 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6817 null, subId, workSource);
6818 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6819 return isEnabled;
6820 } finally {
6821 Binder.restoreCallingIdentity(identity);
6822 }
6823 }
6824
6825 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006826 * Set the allowed network types of the device and
6827 * provide the reason triggering the allowed network change.
6828 *
6829 * @param subId the id of the subscription.
6830 * @param reason the reason the allowed network type change is taking place
6831 * @param allowedNetworkTypes the allowed network types.
6832 * @return true on success; false on any failure.
6833 */
6834 @Override
6835 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006836 @TelephonyManager.AllowedNetworkTypesReason int reason,
6837 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6839 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006840 // If the caller only has carrier privileges, then they should not be able to override
6841 // any network types which were set for security reasons.
6842 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6843 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006844 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006845 throw new SecurityException(
6846 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006847 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006848 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006849 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006850 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006851 return false;
6852 }
6853 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6854 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006855 return false;
6856 }
6857
Jack Yu5b494332023-01-23 18:18:04 +00006858 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6859 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006860
Jack Yue37dd262022-12-16 11:53:37 -08006861 Phone phone = getPhone(subId);
6862 if (phone == null) {
6863 return false;
6864 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006865
Jack Yue37dd262022-12-16 11:53:37 -08006866 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006867 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006868 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006869 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006870
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006871 final long identity = Binder.clearCallingIdentity();
6872 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006873 Boolean success = (Boolean) sendRequest(
6874 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6875 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6876
6877 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6878 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 }
6883
6884 /**
Miaoa84611c2019-03-15 09:21:10 +08006885 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006886 *
Miaoa84611c2019-03-15 09:21:10 +08006887 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006888 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006889 * @hide
6890 */
6891 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006892 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006893 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006895 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 try {
Miaoa84611c2019-03-15 09:21:10 +08006897 if (phone != null) {
6898 return phone.hasMatchedTetherApnSetting();
6899 } else {
6900 return false;
6901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 } finally {
6903 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006904 }
Junda Liu475951f2014-11-07 16:45:03 -08006905 }
6906
6907 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006908 * Get the user enabled state of Mobile Data.
6909 *
6910 * TODO: remove and use isUserDataEnabled.
6911 * This can't be removed now because some vendor codes
6912 * calls through ITelephony directly while they should
6913 * use TelephonyManager.
6914 *
6915 * @return true on enabled
6916 */
6917 @Override
6918 public boolean getDataEnabled(int subId) {
6919 return isUserDataEnabled(subId);
6920 }
6921
6922 /**
6923 * Get whether mobile data is enabled per user setting.
6924 *
6925 * There are other factors deciding whether mobile data is actually enabled, but they are
6926 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006927 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006928 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6929 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006930 *
6931 * @return {@code true} if data is enabled else {@code false}
6932 */
6933 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006934 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006935 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006936 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006937 try {
6938 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6939 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006940 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006941 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6942 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006943 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006945 mApp, subId, functionName);
6946
Robert Greenwalt646120a2014-05-23 11:54:03 -07006947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948
6949 final long identity = Binder.clearCallingIdentity();
6950 try {
Jack Yu285100e2022-12-02 22:48:35 -08006951 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6953 Phone phone = PhoneFactory.getPhone(phoneId);
6954 if (phone != null) {
6955 boolean retVal = phone.isUserDataEnabled();
6956 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6957 return retVal;
6958 } else {
6959 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6960 return false;
6961 }
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006964 }
6965 }
6966
6967 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006968 * Checks if the device is capable of mobile data by considering whether whether the
6969 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6970 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006971 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006972 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006973 */
6974 @Override
6975 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006976 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006977 try {
6978 try {
6979 mApp.enforceCallingOrSelfPermission(
6980 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006981 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006982 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006983 try {
6984 mApp.enforceCallingOrSelfPermission(
6985 android.Manifest.permission.READ_PHONE_STATE,
6986 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006987 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006988 mApp.enforceCallingOrSelfPermission(
6989 permission.READ_BASIC_PHONE_STATE, functionName);
6990 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006991 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006992 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006993 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995
6996 final long identity = Binder.clearCallingIdentity();
6997 try {
Jack Yu285100e2022-12-02 22:48:35 -08006998 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 Phone phone = PhoneFactory.getPhone(phoneId);
7000 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007001 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007002 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 return retVal;
7004 } else {
7005 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7006 return false;
7007 }
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007010 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007011 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007012
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007013 /**
7014 * Check if data is enabled for a specific reason
7015 * @param subId Subscription index
7016 * @param reason the reason the data enable change is taking place
7017 * @return {@code true} if the overall data is enabled; {@code false} if not.
7018 */
7019 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007020 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007021 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007022 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007023 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007024 try {
7025 mApp.enforceCallingOrSelfPermission(
7026 android.Manifest.permission.ACCESS_NETWORK_STATE,
7027 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007028 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007029 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7030 functionName);
7031 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007032 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007033 try {
7034 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007035 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007036 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007038 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007039 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007040 }
7041
7042
7043 final long identity = Binder.clearCallingIdentity();
7044 try {
Jack Yu285100e2022-12-02 22:48:35 -08007045 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007046 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007047 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007048 + " reason=" + reason);
7049 }
7050 Phone phone = PhoneFactory.getPhone(phoneId);
7051 if (phone != null) {
7052 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007053 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007054 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007055 return retVal;
7056 } else {
7057 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007058 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007059 + subId + " retVal=false");
7060 }
7061 return false;
7062 }
7063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
7066 }
7067
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007068 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007069 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007070 // No permission needed; this only lets the caller inspect their own status.
7071 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007072 }
Junda Liu29340342014-07-10 15:23:27 -07007073
7074 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007075 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007076 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007077 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7078 }
7079
7080 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7081 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007082 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007083 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7085 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007086 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7087 if (cpt == null) {
7088 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7090 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007091 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007092 }
7093
7094 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007095 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007096 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007097 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007098 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007099 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007100 Phone phone = getPhone(subId);
7101 if (phone == null) {
7102 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7103 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7104 }
7105 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7106 if (cpt == null) {
7107 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007108 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7109 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007110 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007111 }
7112
7113 @Override
7114 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007115 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007116 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7117 }
7118
7119 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007120 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007121 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007122 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007123 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007124 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7125 Phone phone = PhoneFactory.getPhone(phoneId);
7126 if (phone == null) {
7127 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007128 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007129 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7130 if (cpt == null) {
7131 continue;
7132 }
7133 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007134 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7135 break;
7136 }
7137 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007138 return result;
Junda Liu29340342014-07-10 15:23:27 -07007139 }
Derek Tan89e89d42014-07-08 17:00:10 -07007140
7141 @Override
Junda Liue64de782015-04-16 17:19:16 -07007142 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007143 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007144 Phone phone = PhoneFactory.getPhone(phoneId);
7145 if (phone == null) {
7146 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007147 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007148 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7149 if (cpt == null) {
7150 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007151 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007152 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007153 }
7154
Amith Yamasani6e118872016-02-19 12:53:51 -08007155 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007156 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007157 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007158 Phone phone = PhoneFactory.getPhone(phoneId);
7159 if (phone == null) {
7160 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007161 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007162 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7163 if (cpt == null) {
7164 return Collections.emptyList();
7165 }
7166 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007167 }
7168
chen xuf7e9fe82019-05-09 19:31:02 -07007169 @Override
7170 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007171 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007172 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007173 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007174 try {
7175 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7176 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7177 }
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007180 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007181 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007182 }
7183
Rambo Wang6812ffb2022-03-15 16:54:17 -07007184 @Override
7185 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7186 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7187
7188 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7189 if (phone == null) {
7190 return null;
7191 }
7192 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7193 if (cpt == null) {
7194 return null;
7195 }
7196 return cpt.getCarrierServicePackageName();
7197 }
7198
Wink Savilleb564aae2014-10-23 10:18:09 -07007199 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007200 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007201 UiccPort port = phone == null ? null : phone.getUiccPort();
7202 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007203 return null;
7204 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007205 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007206 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007207 return null;
7208 }
7209 return iccId;
7210 }
7211
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007212 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007213 public void setCallComposerStatus(int subId, int status) {
7214 enforceModifyPermission();
7215
7216 final long identity = Binder.clearCallingIdentity();
7217 try {
7218 Phone phone = getPhone(subId);
7219 if (phone != null) {
7220 Phone defaultPhone = phone.getImsPhone();
7221 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7222 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7223 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007224 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7225 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007226 }
7227 }
Shuo Qian284ae752020-12-22 19:10:14 -08007228 } catch (ImsException e) {
7229 throw new ServiceSpecificException(e.getCode());
7230 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007231 Binder.restoreCallingIdentity(identity);
7232 }
7233 }
7234
7235 @Override
7236 public int getCallComposerStatus(int subId) {
7237 enforceReadPrivilegedPermission("getCallComposerStatus");
7238
7239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 Phone phone = getPhone(subId);
7242 if (phone != null) {
7243 Phone defaultPhone = phone.getImsPhone();
7244 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7245 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7246 return imsPhone.getCallComposerStatus();
7247 }
7248 }
7249 } finally {
7250 Binder.restoreCallingIdentity(identity);
7251 }
7252 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7253 }
7254
7255 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007256 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7257 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007258 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007259 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 final String iccId = getIccId(subId);
7264 final Phone phone = getPhone(subId);
7265 if (phone == null) {
7266 return false;
7267 }
7268 final String subscriberId = phone.getSubscriberId();
7269
7270 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007271 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 + subscriberId + " to " + number);
7273 }
7274
7275 if (TextUtils.isEmpty(iccId)) {
7276 return false;
7277 }
7278
7279 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7280
7281 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7282 if (alphaTag == null) {
7283 editor.remove(alphaTagPrefKey);
7284 } else {
7285 editor.putString(alphaTagPrefKey, alphaTag);
7286 }
7287
7288 // Record both the line number and IMSI for this ICCID, since we need to
7289 // track all merged IMSIs based on line number
7290 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7291 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7292 if (number == null) {
7293 editor.remove(numberPrefKey);
7294 editor.remove(subscriberPrefKey);
7295 } else {
7296 editor.putString(numberPrefKey, number);
7297 editor.putString(subscriberPrefKey, subscriberId);
7298 }
7299
7300 editor.commit();
7301 return true;
7302 } finally {
7303 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007304 }
Derek Tan7226c842014-07-02 17:42:23 -07007305 }
7306
7307 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007308 public String getLine1NumberForDisplay(int subId, String callingPackage,
7309 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007310 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007312 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007313 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007314 return null;
7315 }
Derek Tan97ebb422014-09-05 16:55:38 -07007316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 String iccId = getIccId(subId);
7320 if (iccId != null) {
7321 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7322 if (DBG_MERGE) {
7323 log("getLine1NumberForDisplay returning "
7324 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7325 }
7326 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7329 return null;
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007332 }
Derek Tan7226c842014-07-02 17:42:23 -07007333 }
7334
7335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007336 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7337 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007339 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007340 return null;
7341 }
Derek Tan97ebb422014-09-05 16:55:38 -07007342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343 final long identity = Binder.clearCallingIdentity();
7344 try {
7345 String iccId = getIccId(subId);
7346 if (iccId != null) {
7347 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7348 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7349 }
7350 return null;
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007353 }
Derek Tan7226c842014-07-02 17:42:23 -07007354 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007355
7356 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007357 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7358 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007359 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7360 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007362 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007363 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007364 return null;
7365 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007366
Jordan Liub49b04b2019-05-06 14:45:15 -07007367 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7368 // the process, where TelephonyManager was instantiated.
7369 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007370 final long identity = Binder.clearCallingIdentity();
7371 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007372 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 final TelephonyManager tele = TelephonyManager.from(context);
7374 final SubscriptionManager sub = SubscriptionManager.from(context);
7375
7376 // Figure out what subscribers are currently active
7377 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378
Jordan Liub49b04b2019-05-06 14:45:15 -07007379 // Only consider subs which match the current subId
7380 // This logic can be simplified. See b/131189269 for progress.
7381 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007382 activeSubscriberIds.add(tele.getSubscriberId(subId));
7383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384
7385 // First pass, find a number override for an active subscriber
7386 String mergeNumber = null;
7387 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7388 for (String key : prefs.keySet()) {
7389 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7390 final String subscriberId = (String) prefs.get(key);
7391 if (activeSubscriberIds.contains(subscriberId)) {
7392 final String iccId = key.substring(
7393 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7394 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7395 mergeNumber = (String) prefs.get(numberKey);
7396 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007397 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 + " for active subscriber " + subscriberId);
7399 }
7400 if (!TextUtils.isEmpty(mergeNumber)) {
7401 break;
7402 }
7403 }
7404 }
7405 }
7406
7407 // Shortcut when no active merged subscribers
7408 if (TextUtils.isEmpty(mergeNumber)) {
7409 return null;
7410 }
7411
7412 // Second pass, find all subscribers under that line override
7413 final ArraySet<String> result = new ArraySet<>();
7414 for (String key : prefs.keySet()) {
7415 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7416 final String number = (String) prefs.get(key);
7417 if (mergeNumber.equals(number)) {
7418 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7419 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7420 final String subscriberId = (String) prefs.get(subscriberKey);
7421 if (!TextUtils.isEmpty(subscriberId)) {
7422 result.add(subscriberId);
7423 }
7424 }
7425 }
7426 }
7427
7428 final String[] resultArray = result.toArray(new String[result.size()]);
7429 Arrays.sort(resultArray);
7430 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007431 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7433 }
7434 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007435 } finally {
7436 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007437 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007438 }
7439
7440 @Override
zoey chen38003472019-12-13 17:16:31 +08007441 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7442 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007443
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
7446 final TelephonyManager telephonyManager = mApp.getSystemService(
7447 TelephonyManager.class);
7448 String subscriberId = telephonyManager.getSubscriberId(subId);
7449 if (subscriberId == null) {
7450 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007451 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007452 + subId);
7453 }
7454 return null;
7455 }
7456
Jack Yu3beaf9d2023-04-14 09:17:27 -07007457 final SubscriptionInfo info = getSubscriptionManagerService()
7458 .getSubscriptionInfo(subId);
7459 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007460 // If it doesn't belong to any group, return just subscriberId of itself.
7461 if (groupUuid == null) {
7462 return new String[]{subscriberId};
7463 }
7464
7465 // Get all subscriberIds from the group.
7466 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007467 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7468 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7469 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007470 for (SubscriptionInfo subInfo : groupInfos) {
7471 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7472 if (subscriberId != null) {
7473 mergedSubscriberIds.add(subscriberId);
7474 }
7475 }
7476
7477 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480
7481 }
7482 }
7483
7484 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007485 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007486 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007487 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488
7489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 final Phone phone = getPhone(subId);
7492 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007496 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007497
7498 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007499 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007500 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7501 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007502 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7503 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 final Phone phone = getPhone(subId);
7508 if (phone == null) {
7509 return false;
7510 }
7511 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7512 cdmaNonRoamingList);
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007515 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007516 }
7517
7518 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007519 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007520 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007521 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007522 if (phone == null) {
7523 return raf;
7524 }
7525
Shuo Qiandee53402020-05-29 14:08:15 -07007526 try {
7527 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007528 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007529 mApp, phone.getSubId(), "getRadioAccessFamily");
7530 } catch (SecurityException e) {
7531 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7532 throw e;
7533 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 final long identity = Binder.clearCallingIdentity();
7536 try {
chen xub97461a2018-10-26 14:17:57 -07007537 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 } finally {
7539 Binder.restoreCallingIdentity(identity);
7540 }
chen xub97461a2018-10-26 14:17:57 -07007541 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007542 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007543
7544 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007545 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007546 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007547 try {
7548 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7549 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007550 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007551 }
7552 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007553 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007554 }
7555 RoleManager rm = mApp.getSystemService(RoleManager.class);
7556 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7557 if (!dialerRoleHolders.contains(callingPackage)) {
7558 throw new SecurityException("App must be the dialer role holder to"
7559 + " upload a call composer pic");
7560 }
7561
7562 Executors.newSingleThreadExecutor().execute(() -> {
7563 ByteArrayOutputStream output = new ByteArrayOutputStream(
7564 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7565 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7566 boolean readUntilEnd = false;
7567 int totalBytesRead = 0;
7568 byte[] buffer = new byte[16 * 1024];
7569 while (true) {
7570 int numRead;
7571 try {
7572 numRead = input.read(buffer);
7573 } catch (IOException e) {
7574 try {
7575 fd.checkError();
7576 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7577 null);
7578 } catch (IOException e1) {
7579 // This means that the other side closed explicitly with an error. If this
7580 // happens, log and ignore.
7581 loge("Remote end of call composer picture pipe closed: " + e1);
7582 }
7583 break;
7584 }
7585 if (numRead == -1) {
7586 readUntilEnd = true;
7587 break;
7588 }
7589 totalBytesRead += numRead;
7590 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7591 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7592 try {
7593 input.close();
7594 } catch (IOException e) {
7595 // ignore
7596 }
7597 break;
7598 }
7599 output.write(buffer, 0, numRead);
7600 }
7601 // Generally, the remote end will close the file descriptors. The only case where we
7602 // close is above, where the picture size is too big.
7603
7604 try {
7605 fd.checkError();
7606 } catch (IOException e) {
7607 loge("Remote end for call composer closed with an error: " + e);
7608 return;
7609 }
7610
Hall Liuaa4211e2021-01-20 15:43:39 -08007611 if (!readUntilEnd) {
7612 loge("Did not finish reading entire image; aborting");
7613 return;
7614 }
Hall Liu82694d52020-12-11 18:22:04 -08007615
Hall Liuaa4211e2021-01-20 15:43:39 -08007616 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7617 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7618 new CallComposerPictureTransfer.Factory() {},
7619 imageData,
7620 (result) -> {
7621 if (result.first != null) {
7622 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7623 Bundle outputResult = new Bundle();
7624 outputResult.putParcelable(
7625 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7626 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7627 outputResult);
7628 } else {
7629 callback.send(result.second, null);
7630 }
7631 }
7632 );
Hall Liu82694d52020-12-11 18:22:04 -08007633 });
7634 }
7635
7636 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007637 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007638 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640
7641 final long identity = Binder.clearCallingIdentity();
7642 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007643 ImsManager.getInstance(defaultPhone.getContext(),
7644 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 } finally {
7646 Binder.restoreCallingIdentity(identity);
7647 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007648 }
7649
7650 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007651 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007652 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7654 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007655 return false;
7656 }
Svet Ganovb320e182015-04-16 12:30:10 -07007657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658 final long identity = Binder.clearCallingIdentity();
7659 try {
7660 // Check the user preference and the system-level IMS setting. Even if the user has
7661 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7662 // In the long run, we may instead need to check if there exists a connection service
7663 // which can support video calling.
7664 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007665 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 return imsManager.isVtEnabledByPlatform()
7667 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7668 && imsManager.isVtEnabledByUser();
7669 } finally {
7670 Binder.restoreCallingIdentity(identity);
7671 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007672 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007673
Andrew Leea1239f22015-03-02 17:44:07 -08007674 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007675 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7676 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007678 mApp, subId, callingPackage, callingFeatureId,
7679 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 return false;
7681 }
7682
7683 final long identity = Binder.clearCallingIdentity();
7684 try {
7685 CarrierConfigManager configManager =
7686 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007687 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
7691 }
Andrew Leea1239f22015-03-02 17:44:07 -08007692 }
7693
7694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007695 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 return false;
7699 }
7700
7701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 CarrierConfigManager configManager =
7704 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007705 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7707 } finally {
7708 Binder.restoreCallingIdentity(identity);
7709 }
Andrew Leea1239f22015-03-02 17:44:07 -08007710 }
7711
Andrew Lee9431b832015-03-09 18:46:45 -07007712 @Override
7713 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007714 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007715 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007716 }
7717
7718 @Override
7719 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007720 final long identity = Binder.clearCallingIdentity();
7721 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007722 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
Andrew Lee9431b832015-03-09 18:46:45 -07007726 }
7727
Hall Liuf6668912018-10-31 17:05:23 -07007728 /**
7729 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7730 * support for the feature and device firmware support.
7731 *
7732 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7733 */
7734 @Override
7735 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007737 final Phone phone = getPhone(subscriptionId);
7738 if (phone == null) {
7739 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7740 return false;
7741 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007743 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7745 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007746 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 return isCarrierSupported && isDeviceSupported;
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
7750 }
Hall Liu98187582018-01-22 19:15:32 -08007751 }
7752
Hall Liuf6668912018-10-31 17:05:23 -07007753 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007754 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7755 * RTT setting, will return true if the device and carrier both support RTT.
7756 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007757 */
7758 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 final long identity = Binder.clearCallingIdentity();
7760 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007761 boolean isRttSupported = isRttSupported(subscriptionId);
7762 boolean isUserRttSettingOn = Settings.Secure.getInt(
7763 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7764 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7765 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7766 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007767 } finally {
7768 Binder.restoreCallingIdentity(identity);
7769 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007770 }
7771
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007772 @Deprecated
7773 @Override
7774 public String getDeviceId(String callingPackage) {
7775 return getDeviceIdWithFeature(callingPackage, null);
7776 }
7777
Sanket Padawe7310cc72015-01-14 09:53:20 -08007778 /**
7779 * Returns the unique device ID of phone, for example, the IMEI for
7780 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7781 *
7782 * <p>Requires Permission:
7783 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7784 */
7785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007786 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007787 try {
7788 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7789 } catch (SecurityException se) {
7790 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7791 throw new SecurityException("Package " + callingPackage + " does not belong to "
7792 + Binder.getCallingUid());
7793 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007794 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007795 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007796 return null;
7797 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007798 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007799 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007800 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007801 return null;
7802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803
7804 final long identity = Binder.clearCallingIdentity();
7805 try {
7806 return phone.getDeviceId();
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007810 }
7811
Ping Sunc67b7c22016-03-02 19:16:45 +08007812 /**
7813 * {@hide}
7814 * Returns the IMS Registration Status on a particular subid
7815 *
7816 * @param subId
7817 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007818 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007819 Phone phone = getPhone(subId);
7820 if (phone != null) {
7821 return phone.isImsRegistered();
7822 } else {
7823 return false;
7824 }
7825 }
7826
Santos Cordon7a1885b2015-02-03 11:15:19 -08007827 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007828 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007829 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007831 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007832 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7833 }
7834 final long identity = Binder.clearCallingIdentity();
7835 try {
7836 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7837 } finally {
7838 Binder.restoreCallingIdentity(identity);
7839 }
7840 }
7841
7842 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007843 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007844 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007845 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007846 mApp,
7847 subscriptionId,
7848 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7849 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007850 final long identity = Binder.clearCallingIdentity();
7851 try {
7852 Phone phone = getPhone(subscriptionId);
7853 if (phone == null) {
7854 return null;
7855 }
7856 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7857 } finally {
7858 Binder.restoreCallingIdentity(identity);
7859 }
7860 }
7861
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007862 /**
7863 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007864 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007865 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 Phone phone = getPhone(subId);
7869 if (phone != null) {
7870 return phone.isWifiCallingEnabled();
7871 } else {
7872 return false;
7873 }
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007876 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007877 }
7878
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007879 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007880 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007881 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007882 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007883 final long identity = Binder.clearCallingIdentity();
7884 try {
7885 Phone phone = getPhone(subId);
7886 if (phone != null) {
7887 return phone.isVideoEnabled();
7888 } else {
7889 return false;
7890 }
7891 } finally {
7892 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007893 }
7894 }
7895
7896 /**
7897 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7898 * defined in {@link ImsRegistrationImplBase}.
7899 */
7900 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 final long identity = Binder.clearCallingIdentity();
7902 try {
7903 Phone phone = getPhone(subId);
7904 if (phone != null) {
7905 return phone.getImsRegistrationTech();
7906 } else {
7907 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7908 }
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007911 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007912 }
7913
Stuart Scott8eef64f2015-04-08 15:13:54 -07007914 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007915 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007916 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007917 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7918 return;
7919 }
Kai Shif70f46f2021-03-03 13:59:46 -08007920 Phone defaultPhone = getDefaultPhone();
7921 if (defaultPhone != null) {
7922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7923 mApp, getDefaultPhone().getSubId(), "factoryReset");
7924 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007925 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007926
Svet Ganovcc087f82015-05-12 20:35:54 -07007927 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007928 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7929 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007930 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007931 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007932 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007933 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007934 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007935 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007936 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007937 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007938 // There has been issues when Sms raw table somehow stores orphan
7939 // fragments. They lead to garbled message when new fragments come
7940 // in and combined with those stale ones. In case this happens again,
7941 // user can reset all network settings which will clean up this table.
7942 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007943 // Clean up IMS settings as well here.
7944 int slotId = getSlotIndex(subId);
7945 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7946 ImsManager.getInstance(mApp, slotId).factoryReset();
7947 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007948
Kai Shif70f46f2021-03-03 13:59:46 -08007949 if (defaultPhone == null) {
7950 return;
7951 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007952 // Erase modem config if erase modem on network setting is enabled.
7953 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7954 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7955 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007956 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007957 }
Kai Shif70f46f2021-03-03 13:59:46 -08007958
7959 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007960 } finally {
7961 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007962 }
7963 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007964
SongFerngWangfd89b102021-05-27 22:44:54 +08007965 @VisibleForTesting
7966 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7967 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7968 return;
7969 }
7970 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7971 RILConstants.PREFERRED_NETWORK_MODE);
7972 SubscriptionManager.setSubscriptionProperty(subId,
7973 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7974 "user=" + defaultNetworkType);
7975 phone.loadAllowedNetworksFromSubscriptionDatabase();
7976 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7977 defaultNetworkType, null);
7978 }
7979
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007980 private void cleanUpSmsRawTable(Context context) {
7981 ContentResolver resolver = context.getContentResolver();
7982 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7983 resolver.delete(uri, null, null);
7984 }
7985
Narayan Kamath1c496c22015-04-16 14:40:19 +01007986 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007987 public String getSimLocaleForSubscriber(int subId) {
7988 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7989 final Phone phone = getPhone(subId);
7990 if (phone == null) {
7991 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007992 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007994 final long identity = Binder.clearCallingIdentity();
7995 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07007996 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
7997 phone.getContext().getOpPackageName(),
7998 phone.getContext().getAttributionTag());
7999 if (info == null) {
8000 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8001 return null;
chen xu6291c472019-02-04 12:55:53 -08008002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 // Try and fetch the locale from the carrier properties or from the SIM language
8004 // preferences (EF-PL and EF-LI)...
8005 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008006 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008007 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8008 if (localeFromDefaultSim != null) {
8009 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8010 if (DBG) log("Using locale from subId: " + subId + " locale: "
8011 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008012 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008013 } else {
8014 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 }
8016 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 // The SIM language preferences only store a language (e.g. fr = French), not an
8019 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8020 // the SIM and carrier preferences does not include a country we add the country
8021 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008022 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008024 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008025 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 }
8027
8028 if (DBG) log("No locale found - returning null");
8029 return null;
8030 } finally {
8031 Binder.restoreCallingIdentity(identity);
8032 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008033 }
8034
tom hsu0b59d292022-09-29 23:49:21 +08008035 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008036 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008037 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008038 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008039 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008040 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8041 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008042 Locale.forLanguageTag(localeTag).getCountry())) {
8043 return localeTag;
8044 }
8045 }
8046 return inputLocale.toLanguageTag();
8047 }
8048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 /**
8050 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8051 */
8052 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008053 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008054 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008055 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008056
Gary Jian3aa9a762022-01-24 16:41:19 +08008057 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8058 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008059
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008060 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008061 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8062 * representing the state of the modem.
8063 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008064 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8065 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008066 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008067 */
8068 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008069 public void requestModemActivityInfo(ResultReceiver result) {
8070 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008071 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072
8073 final long identity = Binder.clearCallingIdentity();
8074 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008075 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 } finally {
8077 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008078 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008079 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008080
Gary Jian76280a42022-12-07 16:18:33 +08008081 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008082 // less than total activity duration.
8083 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8084 if (info == null) {
8085 return false;
8086 }
8087 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008088 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008089 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8090
Hall Liu49656c02020-10-09 19:00:11 -07008091 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8092
Siddharth Rayb8114062018-06-17 15:02:38 -07008093 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008094 && (info.getSleepTimeMillis() <= activityDurationMs)
8095 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008096 }
8097
Gary Jian3aa9a762022-01-24 16:41:19 +08008098 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8099 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8100 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8101 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8102
8103 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8104 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8105 }
8106
8107 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8108 mLastModemActivityInfo.setReceiveTimeMillis(
8109 rat,
8110 freq,
8111 info.getReceiveTimeMillis(rat, freq)
8112 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8113 }
8114
8115 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8116 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8117 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8118 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8119
8120 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8121 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8122 }
8123 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8124 mLastModemActivityInfo.setReceiveTimeMillis(
8125 rat,
8126 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8127 }
8128
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008129 /**
8130 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8131 * @param info recent ModemActivityInfo
8132 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008133 private void mergeModemActivityInfo(ModemActivityInfo info) {
8134 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008135 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008136 boolean matched;
8137 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8138 matched = false;
8139 int rat = info.getSpecificInfoRat(i);
8140 int freq = info.getSpecificInfoFrequencyRange(i);
8141 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8142 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8143 //if it already exists
8144 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8145 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8146 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8147 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8148 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8149 updateLastModemActivityInfo(info, rat, freq);
8150 matched = true;
8151 }
8152 } else {
8153 updateLastModemActivityInfo(info, rat);
8154 matched = true;
8155 }
8156 }
8157 }
8158
8159 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008160 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008161 new ActivityStatsTechSpecificInfo(
8162 rat,
8163 freq,
8164 info.getTransmitTimeMillis(rat, freq),
8165 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008166 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008167 }
8168 }
8169 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8170 mLastModemActivitySpecificInfo =
8171 new ActivityStatsTechSpecificInfo[merged.size()];
8172 merged.toArray(mLastModemActivitySpecificInfo);
8173
8174 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8175 mLastModemActivityInfo.setSleepTimeMillis(
8176 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008177 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008178 mLastModemActivityInfo.setIdleTimeMillis(
8179 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008180 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008181
8182 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008183 new ModemActivityInfo(
8184 mLastModemActivityInfo.getTimestampMillis(),
8185 mLastModemActivityInfo.getSleepTimeMillis(),
8186 mLastModemActivityInfo.getIdleTimeMillis(),
8187 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008188 }
8189
8190 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8191 ActivityStatsTechSpecificInfo[] info) {
8192 int infoSize = info.length;
8193 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8194 for (int i = 0; i < infoSize; i++) {
8195 ret[i] = new ActivityStatsTechSpecificInfo(
8196 info[i].getRat(), info[i].getFrequencyRange(),
8197 info[i].getTransmitTimeMillis(),
8198 (int) info[i].getReceiveTimeMillis());
8199 }
8200 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008201 }
8202
Jack Yu85bd38a2015-11-09 11:34:32 -08008203 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008204 * Returns the service state information on specified subscription.
8205 */
8206 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008207 public ServiceState getServiceStateForSubscriber(int subId,
8208 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8209 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008211 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008212 return null;
8213 }
8214
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008215 boolean hasFinePermission = false;
8216 boolean hasCoarsePermission = false;
8217 if (!renounceFineLocationAccess) {
8218 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8219 LocationAccessPolicy.checkLocationPermission(mApp,
8220 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8221 .setCallingPackage(callingPackage)
8222 .setCallingFeatureId(callingFeatureId)
8223 .setCallingPid(Binder.getCallingPid())
8224 .setCallingUid(Binder.getCallingUid())
8225 .setMethod("getServiceStateForSubscriber")
8226 .setLogAsInfo(true)
8227 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8228 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8229 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8230 .build());
8231 hasFinePermission =
8232 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8233 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008234
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008235 if (!renounceCoarseLocationAccess) {
8236 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8237 LocationAccessPolicy.checkLocationPermission(mApp,
8238 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8239 .setCallingPackage(callingPackage)
8240 .setCallingFeatureId(callingFeatureId)
8241 .setCallingPid(Binder.getCallingPid())
8242 .setCallingUid(Binder.getCallingUid())
8243 .setMethod("getServiceStateForSubscriber")
8244 .setLogAsInfo(true)
8245 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8246 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8247 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8248 .build());
8249 hasCoarsePermission =
8250 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8251 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008252
Jack Yu479f40e2020-10-27 21:29:25 -07008253 final Phone phone = getPhone(subId);
8254 if (phone == null) {
8255 return null;
8256 }
8257
Jordan Liu0f2bc442020-11-18 16:47:37 -08008258 final long identity = Binder.clearCallingIdentity();
8259
Jack Yu479f40e2020-10-27 21:29:25 -07008260 boolean isCallingPackageDataService = phone.getDataServicePackages()
8261 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008263 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008264 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8265 .getSubscriptionInfoInternal(subId);
8266 if (subInfo == null || !subInfo.isActive()) {
8267 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8268 + "subId=" + subId);
8269 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008270 }
8271
Hall Liuf19c44f2018-11-27 14:38:17 -08008272 ServiceState ss = phone.getServiceState();
8273
8274 // Scrub out the location info in ServiceState depending on what level of access
8275 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008276 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008277 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8278 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008282 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008283
8284 /**
8285 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8286 *
8287 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8288 * voicemail ringtone.
8289 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8290 * PhoneAccount.
8291 */
8292 @Override
8293 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8297 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008298 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8302 } finally {
8303 Binder.restoreCallingIdentity(identity);
8304 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008305 }
8306
8307 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008308 * Sets the per-account voicemail ringtone.
8309 *
8310 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8311 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8312 *
8313 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8314 * voicemail ringtone.
8315 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8316 * PhoneAccount.
8317 */
8318 @Override
8319 public void setVoicemailRingtoneUri(String callingPackage,
8320 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008321 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008323 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8324 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8326 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8327 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329
8330 final long identity = Binder.clearCallingIdentity();
8331 try {
8332 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8333 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008334 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 }
8336 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8337 } finally {
8338 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008339 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008340 }
8341
8342 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008343 * Returns whether vibration is set for voicemail notification in Phone settings.
8344 *
8345 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8346 * voicemail vibration setting.
8347 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8348 */
8349 @Override
8350 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008351 final long identity = Binder.clearCallingIdentity();
8352 try {
8353 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8354 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008355 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8359 } finally {
8360 Binder.restoreCallingIdentity(identity);
8361 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008362 }
8363
Youhan Wange64578a2016-05-02 15:32:42 -07008364 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008365 * Sets the per-account voicemail vibration.
8366 *
8367 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8368 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8369 *
8370 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8371 * voicemail vibration setting.
8372 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8373 * specific PhoneAccount.
8374 */
8375 @Override
8376 public void setVoicemailVibrationEnabled(String callingPackage,
8377 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008378 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008380 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8381 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8383 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8384 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008385 }
8386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 final long identity = Binder.clearCallingIdentity();
8388 try {
8389 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8390 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008391 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 }
8393 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008396 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008397 }
8398
8399 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008400 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8401 *
8402 * @throws SecurityException if the caller does not have the required permission
8403 */
arunvoddud7401012022-12-15 16:08:12 +00008404 @VisibleForTesting
8405 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008406 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008407 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008408 }
8409
8410 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008411 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8412 * permission.
8413 *
8414 * @throws SecurityException if the caller does not have the required permission
8415 */
8416 private void enforceSendSmsPermission() {
8417 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8418 }
8419
8420 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008421 * Make sure either called from same process as self (phone) or IPC caller has interact across
8422 * users permission.
8423 *
8424 * @throws SecurityException if the caller does not have the required permission
8425 */
8426 private void enforceInteractAcrossUsersPermission(String message) {
8427 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8428 }
8429
8430 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008431 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008432 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008433 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008434 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008435 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008436 final long identity = Binder.clearCallingIdentity();
8437 try {
8438 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008439 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440 if (componentName == null) {
8441 throw new SecurityException(
8442 "Caller not current active visual voicemail package[null]");
8443 }
8444 String vvmPackage = componentName.getPackageName();
8445 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008446 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 }
8448 } finally {
8449 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008450 }
8451 }
8452
8453 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008454 * Return the application ID for the app type.
8455 *
8456 * @param subId the subscription ID that this request applies to.
8457 * @param appType the uicc app type.
8458 * @return Application ID for specificied app type, or null if no uicc.
8459 */
8460 @Override
8461 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008462 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008463 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464
8465 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008466 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467 if (phone == null) {
8468 return null;
8469 }
8470 String aid = null;
8471 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008472 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008473 .getApplicationByType(appType).getAid();
8474 } catch (Exception e) {
8475 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8476 }
8477 return aid;
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008480 }
Youhan Wange64578a2016-05-02 15:32:42 -07008481 }
8482
Youhan Wang4001d252016-05-11 10:29:41 -07008483 /**
8484 * Return the Electronic Serial Number.
8485 *
8486 * @param subId the subscription ID that this request applies to.
8487 * @return ESN or null if error.
8488 */
8489 @Override
8490 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008491 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008492 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493
8494 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008495 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008496 if (phone == null) {
8497 return null;
8498 }
8499 String esn = null;
8500 try {
8501 esn = phone.getEsn();
8502 } catch (Exception e) {
8503 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8504 }
8505 return esn;
8506 } finally {
8507 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008508 }
Youhan Wang4001d252016-05-11 10:29:41 -07008509 }
8510
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008511 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008512 * Return the Preferred Roaming List Version.
8513 *
8514 * @param subId the subscription ID that this request applies to.
8515 * @return PRLVersion or null if error.
8516 */
8517 @Override
8518 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008519 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008520 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521
8522 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008523 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 if (phone == null) {
8525 return null;
8526 }
8527 String cdmaPrlVersion = null;
8528 try {
8529 cdmaPrlVersion = phone.getCdmaPrlVersion();
8530 } catch (Exception e) {
8531 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8532 }
8533 return cdmaPrlVersion;
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008536 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008537 }
8538
8539 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008540 * Get snapshot of Telephony histograms
8541 * @return List of Telephony histograms
8542 * @hide
8543 */
8544 @Override
8545 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8547 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 return RIL.getTelephonyRILTimingHistograms();
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008555 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008556
8557 /**
8558 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008559 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8560 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008561 * Require system privileges. In the future we may add this to carrier APIs.
8562 *
Michele Berionne482f8202018-11-27 18:57:59 -08008563 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008564 */
8565 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008566 @TelephonyManager.SetCarrierRestrictionResult
8567 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008568 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008569 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008570
Michele Berionne482f8202018-11-27 18:57:59 -08008571 if (carrierRestrictionRules == null) {
8572 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008573 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575 final long identity = Binder.clearCallingIdentity();
8576 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008577 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008578 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008582 }
8583
8584 /**
8585 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008586 * Get the allowed carrier list and the excluded carrier list, including the priority between
8587 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008588 * Require system privileges. In the future we may add this to carrier APIs.
8589 *
Michele Berionne482f8202018-11-27 18:57:59 -08008590 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008591 */
8592 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008593 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008594 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008595 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596
8597 final long identity = Binder.clearCallingIdentity();
8598 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008599 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8600 if (response instanceof CarrierRestrictionRules) {
8601 return (CarrierRestrictionRules) response;
8602 }
8603 // Response is an Exception of some kind,
8604 // which is signalled to the user as a NULL retval
8605 return null;
8606 } catch (Exception e) {
8607 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8608 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008612 }
8613
fionaxu59545b42016-05-25 15:53:37 -07008614 /**
arunvoddud7401012022-12-15 16:08:12 +00008615 * Fetches the carrier restriction status of the device and sends the status to the caller
8616 * through the callback.
8617 *
8618 * @param callback The callback that will be used to send the result.
8619 * @throws SecurityException if the caller does not have the required permission/privileges or
8620 * the caller is not allowlisted.
8621 */
8622 @Override
8623 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8624 enforceReadPermission("getCarrierRestrictionStatus");
8625 int carrierId = validateCallerAndGetCarrierId(packageName);
8626 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8627 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8628 throw new SecurityException("Not an authorized caller");
8629 }
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8633 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8634 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8635 } finally {
8636 Binder.restoreCallingIdentity(identity);
8637 }
8638 }
8639
arunvoddu567f2b42023-04-25 17:22:00 +00008640 @Override
8641 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8642 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8643 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8644 return allowListInfo.getShaIdList(pkgName, carrierId);
8645 }
8646
arunvoddud7401012022-12-15 16:08:12 +00008647 @VisibleForTesting
8648 public int validateCallerAndGetCarrierId(String packageName) {
8649 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8650 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8651 }
8652
8653 /**
fionaxu59545b42016-05-25 15:53:37 -07008654 * Action set from carrier signalling broadcast receivers to enable/disable radio
8655 * @param subId the subscription ID that this action applies to.
8656 * @param enabled control enable or disable radio.
8657 * {@hide}
8658 */
8659 @Override
8660 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8661 enforceModifyPermission();
8662 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008663
8664 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008665 if (phone == null) {
8666 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8667 return;
8668 }
8669 try {
8670 phone.carrierActionSetRadioEnabled(enabled);
8671 } catch (Exception e) {
8672 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008673 } finally {
8674 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008675 }
8676 }
8677
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008678 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008679 * Enable or disable Voice over NR (VoNR)
8680 * @param subId the subscription ID that this action applies to.
8681 * @param enabled enable or disable VoNR.
8682 * @return operation result.
8683 */
8684 @Override
8685 public int setVoNrEnabled(int subId, boolean enabled) {
8686 enforceModifyPermission();
8687 final Phone phone = getPhone(subId);
8688
8689 final long identity = Binder.clearCallingIdentity();
8690 if (phone == null) {
8691 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8692 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8693 }
8694
8695 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8696 try {
8697 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8698 workSource);
8699 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008700
8701 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8702 if (DBG) {
8703 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8704 }
8705 SubscriptionManager.setSubscriptionProperty(
8706 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8707 (enabled ? "1" : "0"));
8708 }
8709
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008710 return result;
8711 } finally {
8712 Binder.restoreCallingIdentity(identity);
8713 }
8714 }
8715
8716 /**
8717 * Is voice over NR enabled
8718 * @return true if VoNR is enabled else false
8719 */
8720 @Override
8721 public boolean isVoNrEnabled(int subId) {
8722 enforceReadPrivilegedPermission("isVoNrEnabled");
8723 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8724 final long identity = Binder.clearCallingIdentity();
8725 try {
8726 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8727 null, subId, workSource);
8728 if (DBG) log("isVoNrEnabled: " + isEnabled);
8729 return isEnabled;
8730 } finally {
8731 Binder.restoreCallingIdentity(identity);
8732 }
8733 }
8734
8735 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008736 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8737 * network status based on which carrier apps could apply actions accordingly,
8738 * enable/disable default url handler for example.
8739 *
8740 * @param subId the subscription ID that this action applies to.
8741 * @param report control start/stop reporting the default network status.
8742 * {@hide}
8743 */
8744 @Override
8745 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8746 enforceModifyPermission();
8747 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008748
8749 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008750 if (phone == null) {
8751 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8752 return;
8753 }
8754 try {
8755 phone.carrierActionReportDefaultNetworkStatus(report);
8756 } catch (Exception e) {
8757 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008758 } finally {
8759 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008760 }
8761 }
8762
8763 /**
fionaxud9622282017-07-17 17:51:30 -07008764 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8765 * @param subId the subscription ID that this action applies to.
8766 * {@hide}
8767 */
8768 @Override
8769 public void carrierActionResetAll(int subId) {
8770 enforceModifyPermission();
8771 final Phone phone = getPhone(subId);
8772 if (phone == null) {
8773 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8774 return;
8775 }
8776 try {
8777 phone.carrierActionResetAll();
8778 } catch (Exception e) {
8779 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8780 }
8781 }
8782
8783 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008784 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8785 * bug report is being generated.
8786 */
8787 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008788 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008789 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8790 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008791 writer.println("Permission Denial: can't dump Phone from pid="
8792 + Binder.getCallingPid()
8793 + ", uid=" + Binder.getCallingUid()
8794 + "without permission "
8795 + android.Manifest.permission.DUMP);
8796 return;
8797 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008798 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008799 }
Jack Yueb89b242016-06-22 13:27:47 -07008800
Brad Ebingerdac2f002018-04-03 15:17:52 -07008801 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008802 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8803 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8804 @NonNull String[] args) {
8805 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8806 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008807 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008808 }
8809
Jack Yueb89b242016-06-22 13:27:47 -07008810 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008811 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008812 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008813 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008814 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008815 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008816 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008817 */
8818 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008819 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008820 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008821 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8822 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8823 try {
8824 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008825 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008826 } catch (SecurityException se) {
8827 enforceModifyPermission();
8828 }
8829 } else {
8830 enforceModifyPermission();
8831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008832
Nate Myrenae97d192023-06-09 15:22:31 -07008833 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
8834 && null != callingPackage && opEnableMobileDataByUser()) {
8835 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
8836 callingPackage, null, null);
8837 }
8838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008839 final long identity = Binder.clearCallingIdentity();
8840 try {
8841 Phone phone = getPhone(subId);
8842 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008843 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8844 phone.carrierActionSetMeteredApnsEnabled(enabled);
8845 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008846 phone.getDataSettingsManager().setDataEnabled(
8847 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008849 }
8850 } finally {
8851 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008852 }
8853 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008854
8855 /**
8856 * Get Client request stats
8857 * @return List of Client Request Stats
8858 * @hide
8859 */
8860 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008861 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8862 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008863 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008864 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008865 return null;
8866 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008867 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008869 final long identity = Binder.clearCallingIdentity();
8870 try {
8871 if (phone != null) {
8872 return phone.getClientRequestStats();
8873 }
8874
8875 return null;
8876 } finally {
8877 Binder.restoreCallingIdentity(identity);
8878 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008879 }
8880
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008881 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008882 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008883 if (uid == Process.ROOT_UID && packageName == null) {
8884 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8885 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8886 // exception. ROOT_UID seems not to have a valid package name returned by
8887 // PackageManager, so just fake it here to avoid issues when running telephony shell
8888 // commands that plumb through the RIL as root, like so:
8889 // $ adb root
8890 // $ adb shell cmd phone ...
8891 packageName = "root";
8892 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008893 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008894 }
Jack Yueb4124c2017-02-16 15:32:43 -08008895
8896 /**
Grace Chen70990072017-03-24 17:21:30 -07008897 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008898 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008899 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008900 * @param state State of SIM (power down, power up, pass through)
8901 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8902 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8903 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008904 *
8905 **/
8906 @Override
Grace Chen70990072017-03-24 17:21:30 -07008907 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008908 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008909 Phone phone = PhoneFactory.getPhone(slotIndex);
8910
vagdeviaf9a5b92018-08-15 16:01:53 -07008911 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008913 final long identity = Binder.clearCallingIdentity();
8914 try {
8915 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008916 phone.setSimPowerState(state, null, workSource);
8917 }
8918 } finally {
8919 Binder.restoreCallingIdentity(identity);
8920 }
8921 }
8922
8923 /**
8924 * Set SIM card power state.
8925 *
8926 * @param slotIndex SIM slot id.
8927 * @param state State of SIM (power down, power up, pass through)
8928 * @param callback callback to trigger after success or failure
8929 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8930 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8931 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8932 *
8933 **/
8934 @Override
8935 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8936 IIntegerConsumer callback) {
8937 enforceModifyPermission();
8938 Phone phone = PhoneFactory.getPhone(slotIndex);
8939
8940 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8941
8942 final long identity = Binder.clearCallingIdentity();
8943 try {
8944 if (phone != null) {
8945 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8946 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 }
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008950 }
8951 }
Shuo Qiandd210312017-04-12 22:11:33 +00008952
Tyler Gunn65d45c22017-06-05 11:22:26 -07008953 private boolean isUssdApiAllowed(int subId) {
8954 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008955 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008956 if (configManager == null) {
8957 return false;
8958 }
8959 PersistableBundle pb = configManager.getConfigForSubId(subId);
8960 if (pb == null) {
8961 return false;
8962 }
8963 return pb.getBoolean(
8964 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8965 }
8966
Shuo Qiandd210312017-04-12 22:11:33 +00008967 /**
Ling Mac28f0212023-03-24 16:07:15 -07008968 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008969 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008970 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008971 */
goneil9c5f4872017-12-05 14:07:56 -08008972 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008973 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008974 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 final long identity = Binder.clearCallingIdentity();
8976 try {
Ling Mac28f0212023-03-24 16:07:15 -07008977 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 } finally {
8979 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008980 }
8981 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008982
8983 /**
8984 * Get the current signal strength information for the given subscription.
8985 * Because this information is not updated when the device is in a low power state
8986 * it should not be relied-upon to be current.
8987 * @param subId Subscription index
8988 * @return the most recent cached signal strength info from the modem
8989 */
8990 @Override
8991 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008992 final long identity = Binder.clearCallingIdentity();
8993 try {
8994 Phone p = getPhone(subId);
8995 if (p == null) {
8996 return null;
8997 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008999 return p.getSignalStrength();
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009004
Pengquan Meng77b7f132018-08-22 14:49:57 -07009005 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009006 * Get the current modem radio state for the given slot.
9007 * @param slotIndex slot index.
9008 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009009 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009010 * @return the current radio power state from the modem
9011 */
9012 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009013 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009014 Phone phone = PhoneFactory.getPhone(slotIndex);
9015 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9017 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009018 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9019 }
9020
9021 final long identity = Binder.clearCallingIdentity();
9022 try {
9023 return phone.getRadioPowerState();
9024 } finally {
9025 Binder.restoreCallingIdentity(identity);
9026 }
9027 }
9028 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9029 }
9030
9031 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009032 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9033 *
9034 * <p>Requires one of the following permissions:
9035 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009036 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009037 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9038 * privileges.
9039 *
9040 * @param subId subscription id
9041 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9042 * {@code false}.
9043 */
9044 @Override
9045 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009046 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009047 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009048 try {
9049 mApp.enforceCallingOrSelfPermission(
9050 android.Manifest.permission.ACCESS_NETWORK_STATE,
9051 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009052 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009053 mApp.enforceCallingOrSelfPermission(
9054 permission.READ_BASIC_PHONE_STATE, functionName);
9055 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009056 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009057 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009058 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009059 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009060
Pengquan Menga1bb6272018-09-06 09:59:22 -07009061 boolean isEnabled = false;
9062 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009063 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009064 Phone phone = getPhone(subId);
9065 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009066 } finally {
9067 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009068 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009069 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009070 }
9071
9072
9073 /**
9074 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9075 *
9076 * <p> Requires permission:
9077 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9078 * privileges.
9079 *
9080 * @param subId subscription id
9081 * @param isEnabled {@code true} means enable, {@code false} means disable.
9082 */
9083 @Override
9084 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9086 mApp, subId, "setDataRoamingEnabled");
9087
Pengquan Menga1bb6272018-09-06 09:59:22 -07009088 final long identity = Binder.clearCallingIdentity();
9089 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009090 Phone phone = getPhone(subId);
9091 if (phone != null) {
9092 phone.setDataRoamingEnabled(isEnabled);
9093 }
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009096 }
9097 }
9098
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009099 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009100 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009101 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009102 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009103 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009104
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009105 boolean isAllowed = true;
9106 final long identity = Binder.clearCallingIdentity();
9107 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009108 Phone phone = getPhone(subId);
9109 if (phone != null) {
9110 isAllowed = phone.isCspPlmnEnabled();
9111 }
9112 } finally {
9113 Binder.restoreCallingIdentity(identity);
9114 }
9115 return isAllowed;
9116 }
9117
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009118 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9119 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009120 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009121 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009122 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009123 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9124 if (phone == null) {
9125 return false;
9126 }
9127 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9128 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9129 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009130 }
9131
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009132 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009133 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009134 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009135 mApp.getSystemService(AppOpsManager.class)
9136 .checkPackage(Binder.getCallingUid(), callingPackage);
9137
Jordan Liu1e142fc2019-04-22 15:10:43 -07009138 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009139 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009140 try {
9141 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009142 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009143 } catch (SecurityException e) {
9144 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9145 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009146 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009147 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009148 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009149 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009150 }
sandeepjsb6c87872021-09-27 15:34:44 +00009151 // checking compatibility, if calling app's target SDK is T and beyond.
9152 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9153 Binder.getCallingUid())) {
9154 isIccIdAccessRestricted = true;
9155 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009156 final long identity = Binder.clearCallingIdentity();
9157 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009158 UiccController uiccController = UiccController.getInstance();
9159 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009160 if (hasReadPermission) {
9161 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009162 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009163
9164 // Remove private info if the caller doesn't have access
9165 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9166 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009167 //setting the value after compatibility check
9168 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009169 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9170 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009171 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009172 if (card == null) {
9173 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009174 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009175 continue;
9176 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009177 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9178 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009179 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009180 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009181 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009182 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9183 for (UiccPortInfo portInfo : portInfos) {
9184 UiccPort port = uiccController.getUiccPortForSlot(
9185 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9186 if (port == null) {
9187 // assume no access if port is null
9188 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9189 continue;
9190 }
9191 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9192 uiccPortInfos.add(portInfo);
9193 } else {
9194 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9195 }
9196 }
9197 filteredInfos.add(new UiccCardInfo(
9198 cardInfo.isEuicc(),
9199 cardInfo.getCardId(),
9200 null,
9201 cardInfo.getPhysicalSlotIndex(),
9202 cardInfo.isRemovable(),
9203 cardInfo.isMultipleEnabledProfilesSupported(),
9204 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009205 }
9206 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009207 } finally {
9208 Binder.restoreCallingIdentity(identity);
9209 }
9210 }
9211
sandeepjsb6c87872021-09-27 15:34:44 +00009212 /**
9213 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9214 * generally private and require carrier privileges to view.
9215 *
9216 * @hide
9217 */
9218 @NonNull
9219 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9220 List<UiccPortInfo> portinfo = new ArrayList<>();
9221 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9222 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9223 }
9224 return new UiccCardInfo(
9225 cardInfo.isEuicc(),
9226 cardInfo.getCardId(),
9227 null,
9228 cardInfo.getPhysicalSlotIndex(),
9229 cardInfo.isRemovable(),
9230 cardInfo.isMultipleEnabledProfilesSupported(),
9231 portinfo
9232 );
9233 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009234
sandeepjsb6c87872021-09-27 15:34:44 +00009235 /**
9236 * @hide
9237 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9238 * These values are generally private and require carrier privileges to view.
9239 */
9240 @NonNull
9241 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9242 return new UiccPortInfo(
9243 UiccPortInfo.ICCID_REDACTED,
9244 portInfo.getPortIndex(),
9245 portInfo.getLogicalSlotIndex(),
9246 portInfo.isActive()
9247 );
9248 }
9249 @Override
9250 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009251 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009252 mApp.getSystemService(AppOpsManager.class)
9253 .checkPackage(Binder.getCallingUid(), callingPackage);
9254
sandeepjsb6c87872021-09-27 15:34:44 +00009255 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009256
Aman Guptaf3c90b32022-03-17 04:54:16 +00009257 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9258 // we are reading iccId which is PII data.
9259 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009260
9261 // checking compatibility, if calling app's target SDK is T and beyond.
9262 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9263 Binder.getCallingUid())) {
9264 isLogicalSlotAccessRestricted = true;
9265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009266 final long identity = Binder.clearCallingIdentity();
9267 try {
9268 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009269 if (slots == null || slots.length == 0) {
9270 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009271 return null;
9272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009273 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9274 for (int i = 0; i < slots.length; i++) {
9275 UiccSlot slot = slots[i];
9276 if (slot == null) {
9277 continue;
9278 }
9279
Jordan Liu7be7e652019-05-06 18:55:02 +00009280 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009281 UiccCard card = slot.getUiccCard();
9282 if (card != null) {
9283 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009284 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009285 cardId = slot.getEid();
9286 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009287 // If cardId is null, use iccId of default port as cardId.
9288 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009290 }
9291
Jordan Liu857451f2019-05-09 16:35:35 -07009292 if (cardId != null) {
9293 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9294 // if cardId is an EID, it's all digits so this is fine
9295 cardId = IccUtils.stripTrailingFs(cardId);
9296 }
9297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009298 int cardState = 0;
9299 switch (slot.getCardState()) {
9300 case CARDSTATE_ABSENT:
9301 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9302 break;
9303 case CARDSTATE_PRESENT:
9304 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9305 break;
9306 case CARDSTATE_ERROR:
9307 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9308 break;
9309 case CARDSTATE_RESTRICTED:
9310 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9311 break;
9312 default:
9313 break;
9314
9315 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009316 List<UiccPortInfo> portInfos = new ArrayList<>();
9317 int[] portIndexes = slot.getPortList();
9318 for (int portIdx : portIndexes) {
9319 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009320 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009321 portInfos.add(new UiccPortInfo(iccId, portIdx,
9322 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009324 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009325 slot.isEuicc(),
9326 cardId,
9327 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009328 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009329 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009330 //setting the value after compatibility check
9331 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009332 }
9333 return infos;
9334 } finally {
9335 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009336 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009337 }
9338
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009339 /* Returns null if doesn't have read permission or carrier privilege access. */
9340 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9341 boolean hasReadPermission) {
9342 String iccId = slot.getIccId(portIndex);
9343 if (hasReadPermission) { // if has read permission
9344 return iccId;
9345 } else {
9346 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9347 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9348 // if no read permission, checking carrier privilege access
9349 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9350 return iccId;
9351 }
9352 }
9353 }
9354 // No read permission or carrier privilege access.
9355 return UiccPortInfo.ICCID_REDACTED;
9356 }
9357
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009358 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009359 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009360 public boolean switchSlots(int[] physicalSlots) {
9361 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009362
9363 final long identity = Binder.clearCallingIdentity();
9364 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009365 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9366 for (int i = 0; i < physicalSlots.length; i++) {
9367 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9368 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9369 physicalSlots[i], i));
9370 }
9371 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009372 } finally {
9373 Binder.restoreCallingIdentity(identity);
9374 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009375 }
Jack Yu4c988042018-02-27 15:30:01 -08009376
9377 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009378 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9379 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9380 enforceModifyPermission();
9381
9382 final long identity = Binder.clearCallingIdentity();
9383 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009384 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009385 } finally {
9386 Binder.restoreCallingIdentity(identity);
9387 }
9388 }
9389
9390 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009391 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009392 final long identity = Binder.clearCallingIdentity();
9393 try {
9394 return UiccController.getInstance().getCardIdForDefaultEuicc();
9395 } finally {
9396 Binder.restoreCallingIdentity(identity);
9397 }
9398 }
9399
Pengquan Meng85728fb2018-03-12 16:31:21 -07009400 /**
goneil47ffb6e2018-04-06 15:40:58 -07009401 * A test API to reload the UICC profile.
9402 *
9403 * <p>Requires that the calling app has permission
9404 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9405 * @hide
9406 */
9407 @Override
9408 public void refreshUiccProfile(int subId) {
9409 enforceModifyPermission();
9410
9411 final long identity = Binder.clearCallingIdentity();
9412 try {
9413 Phone phone = getPhone(subId);
9414 if (phone == null) {
9415 return;
9416 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009417 UiccPort uiccPort = phone.getUiccPort();
9418 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009419 return;
9420 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009421 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009422 if (uiccProfile == null) {
9423 return;
9424 }
9425 uiccProfile.refresh();
9426 } finally {
9427 Binder.restoreCallingIdentity(identity);
9428 }
9429 }
9430
9431 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009432 * Returns false if the mobile data is disabled by default, otherwise return true.
9433 */
9434 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009435 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009436 }
9437
9438 /**
9439 * Returns true if the data roaming is enabled by default, i.e the system property
9440 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9441 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9442 */
9443 private boolean getDefaultDataRoamingEnabled(int subId) {
9444 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009445 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009446 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009447 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9448 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9449 return isDataRoamingEnabled;
9450 }
9451
9452 /**
9453 * Returns the default network type for the given {@code subId}, if the default network type is
9454 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9455 */
9456 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009457 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009458 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009459 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9460 return list.get(phoneId);
9461 }
9462 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009463 }
fionaxua13278b2018-03-21 00:08:13 -07009464
9465 @Override
9466 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009467 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009469
9470 final long identity = Binder.clearCallingIdentity();
9471 try {
9472 final Phone phone = getPhone(subId);
9473 if (phone == null) {
9474 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9475 return;
9476 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009477 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9478 if (cpt != null) {
9479 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9480 }
9481 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009482 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9483 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009484 if (carrierPrivilegeRules == null) {
9485 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9486 } else {
9487 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009489 } finally {
9490 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009491 }
fionaxua13278b2018-03-21 00:08:13 -07009492 }
9493
9494 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009495 public void setCarrierServicePackageOverride(
9496 int subId, String carrierServicePackage, String callingPackage) {
9497 TelephonyPermissions.enforceShellOnly(
9498 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9499
Benedict Wong66477622023-02-03 23:30:57 +00009500 final long identity = Binder.clearCallingIdentity();
9501 try {
9502 final Phone phone = getPhone(subId);
9503 if (phone == null || phone.getSubId() != subId) {
9504 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9505 throw new IllegalArgumentException("No phone for subid");
9506 }
9507 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9508 if (cpt == null) {
9509 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9510 throw new IllegalStateException("No CPT for phone");
9511 }
9512 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9513 } finally {
9514 Binder.restoreCallingIdentity(identity);
9515 }
9516 }
9517
9518 @Override
fionaxua13278b2018-03-21 00:08:13 -07009519 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009520 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009521
9522 final long identity = Binder.clearCallingIdentity();
9523 try {
9524 final Phone phone = getPhone(subId);
9525 if (phone == null) {
9526 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9527 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9528 }
9529 return phone.getCarrierIdListVersion();
9530 } finally {
9531 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009532 }
fionaxua13278b2018-03-21 00:08:13 -07009533 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009534
9535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009536 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9537 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009539 mApp, subId, callingPackage, callingFeatureId,
9540 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009541 return -1;
9542 }
9543
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009551
9552 @Override
9553 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009554 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009555 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009556 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009557
9558 final long identity = Binder.clearCallingIdentity();
9559 try {
9560 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
9565
9566 @Override
9567 public boolean setCdmaRoamingMode(int subId, int mode) {
9568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9569 mApp, subId, "setCdmaRoamingMode");
9570
9571 final long identity = Binder.clearCallingIdentity();
9572 try {
9573 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
9578
9579 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009580 public int getCdmaSubscriptionMode(int subId) {
9581 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009582 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009583 mApp, subId, "getCdmaSubscriptionMode");
9584
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9588 } finally {
9589 Binder.restoreCallingIdentity(identity);
9590 }
9591 }
9592
9593 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009594 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9596 mApp, subId, "setCdmaSubscriptionMode");
9597
9598 final long identity = Binder.clearCallingIdentity();
9599 try {
9600 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9601 } finally {
9602 Binder.restoreCallingIdentity(identity);
9603 }
9604 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009605
sqianc5eccab2018-10-19 18:46:41 -07009606 @Override
sqian8c685422019-02-22 15:55:18 -08009607 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009608 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009610 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9611 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009612 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9613 }
9614 final long identity = Binder.clearCallingIdentity();
9615 try {
sqian854d44b2018-12-12 16:48:18 -08009616 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9617 for (Phone phone: PhoneFactory.getPhones()) {
9618 if (phone.getEmergencyNumberTracker() != null
9619 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9620 emergencyNumberListInternal.put(
9621 phone.getSubId(),
9622 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9623 }
sqian11b7a0e2018-12-05 18:48:28 -08009624 }
sqian854d44b2018-12-12 16:48:18 -08009625 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009626 } finally {
9627 Binder.restoreCallingIdentity(identity);
9628 }
sqianc5eccab2018-10-19 18:46:41 -07009629 }
9630
9631 @Override
sqian8c685422019-02-22 15:55:18 -08009632 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009633 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009634 if (!exactMatch) {
9635 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009636 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009637 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009638 }
9639 final long identity = Binder.clearCallingIdentity();
9640 try {
sqian854d44b2018-12-12 16:48:18 -08009641 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009642 //Note: we ignore passed in param exactMatch. We can remove it once
9643 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009644 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009645 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009646 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009647 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009648 }
sqian11b7a0e2018-12-05 18:48:28 -08009649 }
9650 return false;
9651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
9654 }
9655
sqianf4ca7ed2019-01-15 18:32:07 -08009656 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009657 * Start emergency callback mode for GsmCdmaPhone for testing.
9658 */
9659 @Override
9660 public void startEmergencyCallbackMode() {
9661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9662 "startEmergencyCallbackMode");
9663 enforceModifyPermission();
9664 final long identity = Binder.clearCallingIdentity();
9665 try {
9666 for (Phone phone : PhoneFactory.getPhones()) {
9667 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9668 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9669 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9670 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9671 gsmCdmaPhone.obtainMessage(
9672 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9673 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9674 }
9675 }
9676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
9679 }
9680
9681 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009682 * Update emergency number list for test mode.
9683 */
9684 @Override
9685 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9686 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9687 "updateEmergencyNumberListTestMode");
9688
9689 final long identity = Binder.clearCallingIdentity();
9690 try {
9691 for (Phone phone: PhoneFactory.getPhones()) {
9692 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9693 if (tracker != null) {
9694 tracker.executeEmergencyNumberTestModeCommand(action, num);
9695 }
9696 }
9697 } finally {
9698 Binder.restoreCallingIdentity(identity);
9699 }
9700 }
9701
9702 /**
9703 * Get the full emergency number list for test mode.
9704 */
9705 @Override
9706 public List<String> getEmergencyNumberListTestMode() {
9707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9708 "getEmergencyNumberListTestMode");
9709
9710 final long identity = Binder.clearCallingIdentity();
9711 try {
9712 Set<String> emergencyNumbers = new HashSet<>();
9713 for (Phone phone: PhoneFactory.getPhones()) {
9714 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9715 if (tracker != null) {
9716 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9717 emergencyNumbers.add(num.getNumber());
9718 }
9719 }
9720 }
9721 return new ArrayList<>(emergencyNumbers);
9722 } finally {
9723 Binder.restoreCallingIdentity(identity);
9724 }
9725 }
9726
chen xud6b45bd2018-10-30 22:27:10 -07009727 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009728 public int getEmergencyNumberDbVersion(int subId) {
9729 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9730
9731 final long identity = Binder.clearCallingIdentity();
9732 try {
9733 final Phone phone = getPhone(subId);
9734 if (phone == null) {
9735 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9736 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9737 }
9738 return phone.getEmergencyNumberDbVersion();
9739 } finally {
9740 Binder.restoreCallingIdentity(identity);
9741 }
9742 }
9743
9744 @Override
9745 public void notifyOtaEmergencyNumberDbInstalled() {
9746 enforceModifyPermission();
9747
9748 final long identity = Binder.clearCallingIdentity();
9749 try {
9750 for (Phone phone: PhoneFactory.getPhones()) {
9751 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9752 if (tracker != null) {
9753 tracker.updateOtaEmergencyNumberDatabase();
9754 }
9755 }
9756 } finally {
9757 Binder.restoreCallingIdentity(identity);
9758 }
9759 }
9760
9761 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009762 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009763 enforceActiveEmergencySessionPermission();
9764
9765 final long identity = Binder.clearCallingIdentity();
9766 try {
9767 for (Phone phone: PhoneFactory.getPhones()) {
9768 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9769 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009770 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9771 }
9772 }
9773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
9777
9778 @Override
9779 public void resetOtaEmergencyNumberDbFilePath() {
9780 enforceActiveEmergencySessionPermission();
9781
9782 final long identity = Binder.clearCallingIdentity();
9783 try {
9784 for (Phone phone: PhoneFactory.getPhones()) {
9785 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9786 if (tracker != null) {
9787 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009788 }
9789 }
9790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 }
9794
9795 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009796 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9797 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9798 Phone phone = getPhone(subId);
9799 if (phone == null) {
9800 return null;
9801 }
9802 final long identity = Binder.clearCallingIdentity();
9803 try {
9804 UiccProfile profile = UiccController.getInstance()
9805 .getUiccProfileForPhone(phone.getPhoneId());
9806 if (profile != null) {
9807 return profile.getCertsFromCarrierPrivilegeAccessRules();
9808 }
9809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 return null;
9813 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009814
9815 /**
9816 * Enable or disable a modem stack.
9817 */
9818 @Override
9819 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9820 enforceModifyPermission();
9821
9822 final long identity = Binder.clearCallingIdentity();
9823 try {
9824 Phone phone = PhoneFactory.getPhone(slotIndex);
9825 if (phone == null) {
9826 return false;
9827 } else {
9828 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9829 }
9830 } finally {
9831 Binder.restoreCallingIdentity(identity);
9832 }
9833 }
Michelecea4cf22018-12-21 15:00:11 -08009834
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009835 /**
9836 * Whether a modem stack is enabled or not.
9837 */
9838 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009839 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9840 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009841 Phone phone = PhoneFactory.getPhone(slotIndex);
9842 if (phone == null) return false;
9843
9844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009845 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9846 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009847 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9848 }
9849
9850 final long identity = Binder.clearCallingIdentity();
9851 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009852 try {
9853 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9854 } catch (NoSuchElementException ex) {
9855 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9856 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
9861
Michelecea4cf22018-12-21 15:00:11 -08009862 @Override
Michele0ea7d782019-03-19 14:58:42 -07009863 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009864 enforceModifyPermission();
9865
9866 final long identity = Binder.clearCallingIdentity();
9867 try {
9868 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009869 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009870 .commit();
9871 } finally {
9872 Binder.restoreCallingIdentity(identity);
9873 }
9874 }
9875
9876 @Override
Michele0ea7d782019-03-19 14:58:42 -07009877 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009878 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009880 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9881 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009882 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009883 }
Michelecea4cf22018-12-21 15:00:11 -08009884
9885 final long identity = Binder.clearCallingIdentity();
9886 try {
Michele0ea7d782019-03-19 14:58:42 -07009887 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009888 } finally {
9889 Binder.restoreCallingIdentity(identity);
9890 }
9891 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009892
Michele0ea7d782019-03-19 14:58:42 -07009893 @TelephonyManager.IsMultiSimSupportedResult
9894 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009895 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9896 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9897 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009898 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9899 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009900 }
9901 // Check if the hardware supports multisim functionality. If usage of multisim is not
9902 // supported by the modem, indicate that it is restricted.
9903 PhoneCapability staticCapability =
9904 mPhoneConfigurationManager.getStaticPhoneCapability();
9905 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009906 loge("isMultiSimSupportedInternal: no static configuration available");
9907 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009908 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009909 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009910 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9911 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009912 }
9913 // Check if support of multiple SIMs is restricted by carrier
9914 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009915 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009916 }
9917
Michele0ea7d782019-03-19 14:58:42 -07009918 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009919 }
9920
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009921 /**
9922 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009923 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9924 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9925 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009926 * @param numOfSims number of active sims we want to switch to
9927 */
9928 @Override
9929 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009930 if (numOfSims == 1) {
9931 enforceModifyPermission();
9932 } else {
9933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9934 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9935 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009936 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009937
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009938 try {
Michele30b57b22019-03-01 12:01:14 -08009939 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009940 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009941 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9942 return;
9943 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009944 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
9949
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009950 @Override
9951 public boolean isApplicationOnUicc(int subId, int appType) {
9952 enforceReadPrivilegedPermission("isApplicationOnUicc");
9953 Phone phone = getPhone(subId);
9954 if (phone == null) {
9955 return false;
9956 }
9957 final long identity = Binder.clearCallingIdentity();
9958 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009959 UiccPort uiccPort = phone.getUiccPort();
9960 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009961 return false;
9962 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009963 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009964 if (uiccProfile == null) {
9965 return false;
9966 }
9967 if (TelephonyManager.APPTYPE_SIM <= appType
9968 && appType <= TelephonyManager.APPTYPE_ISIM) {
9969 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9970 }
9971 return false;
9972 } finally {
9973 Binder.restoreCallingIdentity(identity);
9974 }
9975 }
9976
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009977 /**
chen xub4baa772019-04-03 10:23:41 -07009978 * Get whether making changes to modem configurations will trigger reboot.
9979 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009980 */
9981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009982 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9983 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009985 mApp, subId, callingPackage, callingFeatureId,
9986 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009987 return false;
9988 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009989 final long identity = Binder.clearCallingIdentity();
9990 try {
9991 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9992 } finally {
9993 Binder.restoreCallingIdentity(identity);
9994 }
9995 }
9996
Nathan Harold29f5f052019-02-15 13:41:57 -08009997 private void updateModemStateMetrics() {
9998 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9999 // TODO: check the state for each modem if the api is ready.
10000 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10001 }
10002
Pengquan Meng3889a572019-01-23 11:16:29 -080010003 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010004 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010005 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010006 // Verify that the callingPackage belongs to the calling UID
10007 mApp.getSystemService(AppOpsManager.class)
10008 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010009 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010010 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010011 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010012 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10013 if (slotInfos != null) {
10014 for (int i = 0; i < slotInfos.length; i++) {
10015 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10016 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10017 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10018 portInfo.getLogicalSlotIndex()));
10019 }
10020 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010021 }
10022 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010023 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010024 } finally {
10025 Binder.restoreCallingIdentity(identity);
10026 }
10027 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010028
10029 /**
10030 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010031 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010032 */
jimsunf9ec1622022-09-13 21:18:43 +080010033 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010034 @Override
10035 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010036 return getHalVersion(HAL_SERVICE_RADIO);
10037 }
10038
10039 /**
10040 * Get the HAL Version of a specific service
10041 */
10042 @Override
10043 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010044 Phone phone = getDefaultPhone();
10045 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010046 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010047 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10048 return hv.major * 100 + hv.minor;
10049 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010050
10051 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010052 * Get the current calling package name.
10053 * @return the current calling package name
10054 */
10055 @Override
10056 public String getCurrentPackageName() {
10057 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10058 }
10059
10060 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010061 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10062 * corresponding network requests on a subId.
10063 *
10064 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010065 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010066 * 2) APN is un-metered for this subscription, or
10067 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010068 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010069 *
10070 * @return whether data is allowed for a apn type.
10071 *
10072 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010073 */
10074 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010075 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010076 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10077 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010078
10079 // Now that all security checks passes, perform the operation as ourselves.
10080 final long identity = Binder.clearCallingIdentity();
10081 try {
10082 Phone phone = getPhone(subId);
10083 if (phone == null) return false;
10084
Jack Yu27422a52022-03-21 10:38:05 -070010085 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010086 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010087 isMetered = phone.getDataNetworkController().getDataConfigManager()
10088 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10089 phone.getServiceState().getDataRoaming());
10090 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010091 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010092 } finally {
10093 Binder.restoreCallingIdentity(identity);
10094 }
10095 }
10096
10097 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010098 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010099 enforceReadPrivilegedPermission("isApnMetered");
10100
10101 // Now that all security checks passes, perform the operation as ourselves.
10102 final long identity = Binder.clearCallingIdentity();
10103 try {
10104 Phone phone = getPhone(subId);
10105 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010106 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10107 DataUtils.apnTypeToNetworkCapability(apnType),
10108 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010109 } finally {
10110 Binder.restoreCallingIdentity(identity);
10111 }
10112 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010113
10114 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010115 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10116 int subscriptionId, IBooleanConsumer resultCallback) {
10117 enforceModifyPermission();
10118 long token = Binder.clearCallingIdentity();
10119 try {
10120 Phone phone = getPhone(subscriptionId);
10121 if (phone == null) {
10122 try {
10123 if (resultCallback != null) {
10124 resultCallback.accept(false);
10125 }
10126 } catch (RemoteException e) {
10127 // ignore
10128 }
10129 return;
10130 }
10131 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10132 Pair.create(specifiers, (x) -> {
10133 try {
10134 if (resultCallback != null) {
10135 resultCallback.accept(x);
10136 }
10137 } catch (RemoteException e) {
10138 // ignore
10139 }
10140 });
10141 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10142 } finally {
10143 Binder.restoreCallingIdentity(token);
10144 }
10145 }
10146
10147 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010148 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10149 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010150 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010151 mApp, subId, "getSystemSelectionChannels");
10152 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10153 final long identity = Binder.clearCallingIdentity();
10154 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010155 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10156 if (result instanceof IllegalStateException) {
10157 throw (IllegalStateException) result;
10158 }
10159 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010160 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10161 return specifiers;
10162 } finally {
10163 Binder.restoreCallingIdentity(identity);
10164 }
10165 }
10166
10167 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010168 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010169 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010170 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010171 }
10172
10173 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010174 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10175 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010176 if (callingPackage == null) {
10177 callingPackage = getCurrentPackageName();
10178 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010179 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10180 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010181 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10182 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010183 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10184 }
10185 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10186 Intent intent = new Intent();
10187 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10188 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10189 // Bring up choose default SMS subscription dialog right now
10190 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10191 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10192 mApp.startActivity(intent);
10193 }
chen xud5ca2d52019-05-28 15:20:57 -070010194
10195 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010196 public void showSwitchToManagedProfileDialog() {
10197 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010198 try {
10199 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10200 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10201 // for work telephony.
10202 Intent intent = new Intent(Intent.ACTION_SENDTO);
10203 intent.setData(Uri.parse("smsto:"));
10204 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10205 mApp.startActivity(intent);
10206 } catch (ActivityNotFoundException e) {
10207 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10208 Intent intent = new Intent();
10209 intent.setClass(mApp, ErrorDialogActivity.class);
10210 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10211 mApp.startActivity(intent);
10212 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010213 }
10214
10215 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010216 public String getMmsUAProfUrl(int subId) {
10217 //TODO investigate if this API should require proper permission check in R b/133791609
10218 final long identity = Binder.clearCallingIdentity();
10219 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010220 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10221 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10222 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10223 return carrierUAProfUrl;
10224 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010225 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10226 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010227 } finally {
10228 Binder.restoreCallingIdentity(identity);
10229 }
10230 }
10231
10232 @Override
10233 public String getMmsUserAgent(int subId) {
10234 //TODO investigate if this API should require proper permission check in R b/133791609
10235 final long identity = Binder.clearCallingIdentity();
10236 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010237 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10238 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10239 if (!TextUtils.isEmpty(carrierUserAgent)) {
10240 return carrierUserAgent;
10241 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010242 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10243 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010244 } finally {
10245 Binder.restoreCallingIdentity(identity);
10246 }
10247 }
Jack Yub07d4972019-05-28 16:12:25 -070010248
10249 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010250 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10251 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010252
Jack Yub07d4972019-05-28 16:12:25 -070010253 final long identity = Binder.clearCallingIdentity();
10254 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010255 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010256 if (phone == null) return false;
10257
Ling Maf188d502022-09-16 15:22:36 -070010258 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010259 } finally {
10260 Binder.restoreCallingIdentity(identity);
10261 }
10262 }
10263
10264 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010265 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010266 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010267 enforceModifyPermission();
10268
changbettyd5c246e2019-12-24 15:40:37 +080010269 final long identity = Binder.clearCallingIdentity();
10270 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010271 Phone phone = getPhone(subscriptionId);
10272 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010273
Ling Maf188d502022-09-16 15:22:36 -070010274 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010275 } finally {
10276 Binder.restoreCallingIdentity(identity);
10277 }
10278 }
10279
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010280 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010281 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010282 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10283 * otherwise.
10284 */
10285 @Override
10286 public void setCepEnabled(boolean isCepEnabled) {
10287 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10288
10289 final long identity = Binder.clearCallingIdentity();
10290 try {
10291 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10292 for (Phone phone : PhoneFactory.getPhones()) {
10293 Phone defaultPhone = phone.getImsPhone();
10294 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10295 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10296 ImsPhoneCallTracker imsPhoneCallTracker =
10297 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10298 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10299 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10300 + imsPhone.getMsisdn());
10301 }
10302 }
10303 } finally {
10304 Binder.restoreCallingIdentity(identity);
10305 }
10306 }
allenwtsu46dcc572020-01-08 18:24:03 +080010307
10308 /**
10309 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10310 *
10311 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10312 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10313 * before being read.
10314 */
10315 @Override
10316 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10317 isCompressed) {
10318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10319 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010320 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10321 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10322 }
10323 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010324 // ProvisioningManager can not handle ServiceSpecificException.
10325 // Throw the IllegalStateException and annotate ProvisioningManager.
10326 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010327 }
10328
10329 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010330 try {
Hui Wang761a6682020-10-31 05:12:53 +000010331 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010334 }
10335 }
zoey chene02881a2019-12-30 16:11:23 +080010336
10337 @Override
10338 public boolean isIccLockEnabled(int subId) {
10339 enforceReadPrivilegedPermission("isIccLockEnabled");
10340
10341 // Now that all security checks passes, perform the operation as ourselves.
10342 final long identity = Binder.clearCallingIdentity();
10343 try {
10344 Phone phone = getPhone(subId);
10345 if (phone != null && phone.getIccCard() != null) {
10346 return phone.getIccCard().getIccLockEnabled();
10347 } else {
10348 return false;
10349 }
10350 } finally {
10351 Binder.restoreCallingIdentity(identity);
10352 }
10353 }
10354
10355 /**
10356 * Set the ICC pin lock enabled or disabled.
10357 *
10358 * @return an integer representing the status of IccLock enabled or disabled in the following
10359 * three cases:
10360 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10361 * successfully.
10362 * - Positive number and zero for remaining password attempts.
10363 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10364 *
10365 */
10366 @Override
10367 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10368 enforceModifyPermission();
10369
10370 Phone phone = getPhone(subId);
10371 if (phone == null) {
10372 return 0;
10373 }
10374 // Now that all security checks passes, perform the operation as ourselves.
10375 final long identity = Binder.clearCallingIdentity();
10376 try {
10377 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10378 new Pair<Boolean, String>(enabled, password), phone, null);
10379 return attemptsRemaining;
10380
10381 } catch (Exception e) {
10382 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
10386 return 0;
10387 }
10388
10389 /**
10390 * Change the ICC password used in ICC pin lock.
10391 *
10392 * @return an integer representing the status of IccLock changed in the following three cases:
10393 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10394 * - Positive number and zero for remaining password attempts.
10395 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10396 *
10397 */
10398 @Override
10399 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10400 enforceModifyPermission();
10401
10402 Phone phone = getPhone(subId);
10403 if (phone == null) {
10404 return 0;
10405 }
10406 // Now that all security checks passes, perform the operation as ourselves.
10407 final long identity = Binder.clearCallingIdentity();
10408 try {
10409 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10410 new Pair<String, String>(oldPassword, newPassword), phone, null);
10411 return attemptsRemaining;
10412
10413 } catch (Exception e) {
10414 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10415 } finally {
10416 Binder.restoreCallingIdentity(identity);
10417 }
10418 return 0;
10419 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010420
10421 /**
10422 * Request for receiving user activity notification
10423 */
10424 @Override
10425 public void requestUserActivityNotification() {
10426 if (!mNotifyUserActivity.get()
10427 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10428 mNotifyUserActivity.set(true);
10429 }
10430 }
10431
10432 /**
10433 * Called when userActivity is signalled in the power manager.
10434 * This is safe to call from any thread, with any window manager locks held or not.
10435 */
10436 @Override
10437 public void userActivity() {
10438 // ***************************************
10439 // * Inherited from PhoneWindowManager *
10440 // ***************************************
10441 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10442 // WITH ITS LOCKS HELD.
10443 //
10444 // This code must be VERY careful about the locks
10445 // it acquires.
10446 // In fact, the current code acquires way too many,
10447 // and probably has lurking deadlocks.
10448
10449 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10450 throw new SecurityException("Only the OS may call notifyUserActivity()");
10451 }
10452
10453 if (mNotifyUserActivity.getAndSet(false)) {
10454 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10455 USER_ACTIVITY_NOTIFICATION_DELAY);
10456 }
10457 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010458
10459 @Override
10460 public boolean canConnectTo5GInDsdsMode() {
10461 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10462 }
Jack Yud10cdd42020-09-28 20:28:01 -070010463
10464 @Override
10465 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10466 String callingFeatureId) {
10467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10468 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10469 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10470 }
10471
10472 Phone phone = getPhone(subId);
10473 if (phone == null) {
10474 throw new RuntimeException("phone is not available");
10475 }
10476 // Now that all security checks passes, perform the operation as ourselves.
10477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 return phone.getEquivalentHomePlmns();
10480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
Daniel Bright59e67312020-11-13 11:49:37 -080010484
10485 @Override
10486 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010487 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10488 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010489 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010490 if (radioInterfaceCapabilities == null) {
10491 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010492 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010493 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010494 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010495
Hui Wang641e81c2020-10-12 12:14:23 -070010496 @Override
10497 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10498 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010499 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10500 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10501 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10502 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10503 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010504 if (DBG) {
10505 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10506 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10507 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10508 }
10509
10510 if (!SubscriptionManager.isValidSubscriptionId(subId)
10511 || appType < TelephonyManager.APPTYPE_UNKNOWN
10512 || appType > TelephonyManager.APPTYPE_ISIM
10513 || nafUrl == null || securityProtocol == null || callback == null) {
10514 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10515 if (callback != null) {
10516 try {
10517 callback.onAuthenticationFailure(
10518 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10519 } catch (RemoteException exception) {
10520 log("Fail to notify onAuthenticationFailure due to " + exception);
10521 }
10522 return;
10523 }
10524 }
10525
10526 final long token = Binder.clearCallingIdentity();
10527 try {
10528 getGbaManager(subId).bootstrapAuthenticationRequest(
10529 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010530 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010531 } finally {
10532 Binder.restoreCallingIdentity(token);
10533 }
10534 }
10535
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010536 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010537 * Attempts to set the radio power state for all phones for thermal reason.
10538 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010539 * requested radio power state will actually be set. See {@link
10540 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10541 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010542 * @param enable {@code true} if trying to turn radio on.
10543 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10544 * false}.
10545 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010546 private boolean setRadioPowerForThermal(boolean enable) {
10547 boolean isPhoneAvailable = false;
10548 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10549 Phone phone = PhoneFactory.getPhone(i);
10550 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010551 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010552 isPhoneAvailable = true;
10553 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010554 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010555
10556 // return true if successfully informed the phone object about the thermal radio power
10557 // request.
10558 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010559 }
10560
10561 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010562 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010563 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10564 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10565 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10566 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10567 throw new IllegalArgumentException("modem does not support data throttling");
10568 }
10569
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010570 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10571 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010572 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010573 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10574 }
10575
Sarah Chinecc78c42022-03-31 21:16:48 -070010576 setDataEnabledForReason(
10577 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010578
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010579 if (isDataThrottlingSupported) {
10580 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010581 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010582 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10583 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10584 } else if (thermalMitigationResult
10585 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010586 log("Modem likely does not support data throttling on secondary carrier. Data " +
10587 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10588 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010589 }
10590 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010591 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010592
10593 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010594 }
10595
Jack Nudelman644b91a2021-03-12 14:09:48 -080010596 private static List<String> getThermalMitigationAllowlist(Context context) {
10597 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10598 for (String pckg : context.getResources()
10599 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10600 sThermalMitigationAllowlistedPackages.add(pckg);
10601 }
10602 }
10603
10604 return sThermalMitigationAllowlistedPackages;
10605 }
10606
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010607 private boolean isAnyPhoneInEmergencyState() {
10608 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10609 if (tm.isInEmergencyCall()) {
10610 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10611 return true;
10612 }
10613 for (Phone phone : PhoneFactory.getPhones()) {
10614 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10615 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010616 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10617 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010618 return true;
10619 }
10620 }
10621
10622 return false;
10623 }
10624
Jack Nudelman644b91a2021-03-12 14:09:48 -080010625 /**
10626 * Used by shell commands to add an authorized package name for thermal mitigation.
10627 * @param packageName name of package to be allowlisted
10628 * @param context
10629 */
10630 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10631 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10632 sThermalMitigationAllowlistedPackages.add(packageName);
10633 }
10634
10635 /**
10636 * Used by shell commands to remove an authorized package name for thermal mitigation.
10637 * @param packageName name of package to remove from allowlist
10638 * @param context
10639 */
10640 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10641 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10642 sThermalMitigationAllowlistedPackages.remove(packageName);
10643 }
10644
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010645 /**
10646 * Thermal mitigation request to control functionalities at modem.
10647 *
10648 * @param subId the id of the subscription.
10649 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010650 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010651 *
10652 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10653 */
10654 @Override
10655 @ThermalMitigationResult
10656 public int sendThermalMitigationRequest(
10657 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010658 ThermalMitigationRequest thermalMitigationRequest,
10659 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010660 enforceModifyPermission();
10661
Jack Nudelman644b91a2021-03-12 14:09:48 -080010662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10663 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10664 .contains(callingPackage)) {
10665 throw new SecurityException("Calling package must be configured in the device config. "
10666 + "calling package: " + callingPackage);
10667 }
10668
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10670 final long identity = Binder.clearCallingIdentity();
10671
10672 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10673 try {
10674 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10675 switch (thermalMitigationAction) {
10676 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10677 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010678 handleDataThrottlingRequest(subId,
10679 thermalMitigationRequest.getDataThrottlingRequest(),
10680 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010681 break;
10682 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10683 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10684 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10685 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10686 }
10687
10688 // Ensure that radio is on. If not able to power on due to phone being
10689 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010690 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010691 thermalMitigationResult =
10692 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10693 break;
10694 }
10695
10696 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010697 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010698 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10699 break;
10700 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10701 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10702 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10703 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10704 }
10705
10706 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10707 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010708 Phone phone = getPhone(subId);
10709 if (phone == null) {
10710 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010711 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010712 break;
10713 }
10714
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010715 TelephonyConnectionService service =
10716 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010717 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010718 Log.e(LOG_TAG, "An emergency call is pending");
10719 thermalMitigationResult =
10720 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10721 break;
10722 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010723 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010724 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010725 break;
10726 }
10727 } else {
10728 thermalMitigationResult =
10729 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10730 break;
10731 }
10732
10733 // Turn radio off. If not able to power off due to phone being unavailable,
10734 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010735 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010736 thermalMitigationResult =
10737 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10738 break;
10739 }
10740 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010741 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010742 break;
10743 default:
10744 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10745 + "not exist. Requested action: " + thermalMitigationAction);
10746 }
10747 } catch (IllegalArgumentException e) {
10748 throw e;
10749 } catch (Exception e) {
10750 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10751 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10752 } finally {
10753 Binder.restoreCallingIdentity(identity);
10754 }
10755
10756 if (DBG) {
10757 log("thermalMitigationRequest returning with thermalMitigationResult: "
10758 + thermalMitigationResult);
10759 }
10760
10761 return thermalMitigationResult;
10762 }
Hui Wang641e81c2020-10-12 12:14:23 -070010763
10764 /**
10765 * Set the GbaService Package Name that Telephony will bind to.
10766 *
10767 * @param subId The sim that the GbaService is associated with.
10768 * @param packageName The name of the package to be replaced with.
10769 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10770 */
10771 @Override
10772 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10773 enforceModifyPermission();
10774
10775 final long identity = Binder.clearCallingIdentity();
10776 try {
10777 return getGbaManager(subId).overrideServicePackage(packageName);
10778 } finally {
10779 Binder.restoreCallingIdentity(identity);
10780 }
10781 }
10782
10783 /**
10784 * Return the package name of the currently bound GbaService.
10785 *
10786 * @param subId The sim that the GbaService is associated with.
10787 * @return the package name of the GbaService configuration, null if GBA is not supported.
10788 */
10789 @Override
10790 public String getBoundGbaService(int subId) {
10791 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10792
10793 final long identity = Binder.clearCallingIdentity();
10794 try {
10795 return getGbaManager(subId).getServicePackage();
10796 } finally {
10797 Binder.restoreCallingIdentity(identity);
10798 }
10799 }
10800
10801 /**
10802 * Set the release time for telephony to unbind GbaService.
10803 *
10804 * @param subId The sim that the GbaService is associated with.
10805 * @param interval The release time to unbind GbaService by millisecond.
10806 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10807 */
10808 @Override
10809 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10810 enforceModifyPermission();
10811
10812 final long identity = Binder.clearCallingIdentity();
10813 try {
10814 return getGbaManager(subId).overrideReleaseTime(interval);
10815 } finally {
10816 Binder.restoreCallingIdentity(identity);
10817 }
10818 }
10819
10820 /**
10821 * Return the release time for telephony to unbind GbaService.
10822 *
10823 * @param subId The sim that the GbaService is associated with.
10824 * @return The release time to unbind GbaService by millisecond.
10825 */
10826 @Override
10827 public int getGbaReleaseTime(int subId) {
10828 enforceReadPrivilegedPermission("getGbaReleaseTime");
10829
10830 final long identity = Binder.clearCallingIdentity();
10831 try {
10832 return getGbaManager(subId).getReleaseTime();
10833 } finally {
10834 Binder.restoreCallingIdentity(identity);
10835 }
10836 }
10837
10838 private GbaManager getGbaManager(int subId) {
10839 GbaManager instance = GbaManager.getInstance(subId);
10840 if (instance == null) {
10841 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10842 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10843 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10844 }
10845 return instance;
10846 }
Hui Wang761a6682020-10-31 05:12:53 +000010847
10848 /**
10849 * indicate whether the device and the carrier can support
10850 * RCS VoLTE single registration.
10851 */
10852 @Override
10853 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010854 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10855 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10856 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10857 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010858
10859 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10860 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10861 }
10862
10863 final long identity = Binder.clearCallingIdentity();
10864 try {
10865 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10866 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010867 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10868 if (isCapable != null) {
10869 return isCapable;
10870 }
Hui Wang761a6682020-10-31 05:12:53 +000010871 }
Hui Wang67af90e2021-06-04 16:57:15 -070010872 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10873 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010874 } finally {
10875 Binder.restoreCallingIdentity(identity);
10876 }
10877 }
10878
10879 /**
10880 * Register RCS provisioning callback.
10881 */
10882 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010883 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010884 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010885 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010886 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010887 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10888 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010889
10890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10891 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10892 }
10893 if (!isImsAvailableOnDevice()) {
10894 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10895 "IMS not available on device.");
10896 }
10897
10898 final long identity = Binder.clearCallingIdentity();
10899 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010900 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010901 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010902 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10903 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010904 }
Hui Wang761a6682020-10-31 05:12:53 +000010905 } finally {
10906 Binder.restoreCallingIdentity(identity);
10907 }
10908 }
10909
10910 /**
10911 * Unregister RCS provisioning callback.
10912 */
10913 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010914 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010915 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010916 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010917 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010918 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10919 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010920
10921 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10922 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10923 }
10924 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010925 // operation failed silently
10926 Rlog.w(LOG_TAG, "IMS not available on device.");
10927 return;
Hui Wang761a6682020-10-31 05:12:53 +000010928 }
10929
10930 final long identity = Binder.clearCallingIdentity();
10931 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010932 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010933 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010934 } finally {
10935 Binder.restoreCallingIdentity(identity);
10936 }
10937 }
10938
10939 /**
10940 * trigger RCS reconfiguration.
10941 */
10942 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010943 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10944 "triggerRcsReconfiguration",
10945 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010946
10947 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10948 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10949 }
10950 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010951 // ProvisioningManager can not handle ServiceSpecificException.
10952 // Throw the IllegalStateException and annotate ProvisioningManager.
10953 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010954 }
10955
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
10958 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10959 } finally {
10960 Binder.restoreCallingIdentity(identity);
10961 }
10962 }
10963
10964 /**
10965 * Provide the client configuration parameters of the RCS application.
10966 */
10967 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010968 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10969 "setRcsClientConfiguration",
10970 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010971
10972 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10973 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10974 }
10975 if (!isImsAvailableOnDevice()) {
10976 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10977 "IMS not available on device.");
10978 }
10979
10980 final long identity = Binder.clearCallingIdentity();
10981
10982 try {
10983 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10984 if (configBinder == null) {
10985 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010986 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10987 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010988 } else {
10989 configBinder.setRcsClientConfiguration(rcc);
10990 }
joonhunshin3e154242021-09-17 06:33:39 +000010991
10992 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10993 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010994 } catch (RemoteException e) {
10995 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010996 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10997 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010998 } finally {
10999 Binder.restoreCallingIdentity(identity);
11000 }
11001 }
11002
11003 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011004 * Enables or disables the test mode for RCS VoLTE single registration.
11005 */
11006 @Override
11007 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11009 "setRcsSingleRegistrationTestModeEnabled");
11010
11011 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11012 }
11013
11014 /**
11015 * Gets the test mode for RCS VoLTE single registration.
11016 */
11017 @Override
11018 public boolean getRcsSingleRegistrationTestModeEnabled() {
11019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11020 "getRcsSingleRegistrationTestModeEnabled");
11021
11022 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11023 }
11024
11025 /**
Hui Wang761a6682020-10-31 05:12:53 +000011026 * Overrides the config of RCS VoLTE single registration enabled for the device.
11027 */
11028 @Override
11029 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11031 "setDeviceSingleRegistrationEnabledOverride");
11032 enforceModifyPermission();
11033
11034 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11035 : Boolean.parseBoolean(enabledStr);
11036 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011037 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011038 }
11039
11040 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011041 * Sends a device to device communication message. Only usable via shell.
11042 * @param message message to send.
11043 * @param value message value.
11044 */
11045 @Override
11046 public void sendDeviceToDeviceMessage(int message, int value) {
11047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011048 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011049 enforceModifyPermission();
11050
11051 final long identity = Binder.clearCallingIdentity();
11052 try {
11053 TelephonyConnectionService service =
11054 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11055 if (service == null) {
11056 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11057 return;
11058 }
11059 service.sendTestDeviceToDeviceMessage(message, value);
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
11064
Tyler Gunnbabbda02021-02-10 11:05:02 -080011065 /**
11066 * Sets the specified device to device transport active.
11067 * @param transport The transport to set active.
11068 */
11069 @Override
11070 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11072 "setActiveDeviceToDeviceTransport");
11073 enforceModifyPermission();
11074
11075 final long identity = Binder.clearCallingIdentity();
11076 try {
11077 TelephonyConnectionService service =
11078 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11079 if (service == null) {
11080 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11081 return;
11082 }
11083 service.setActiveDeviceToDeviceTransport(transport);
11084 } finally {
11085 Binder.restoreCallingIdentity(identity);
11086 }
11087 }
Tyler Gunn92479152021-01-20 16:30:10 -080011088
Tyler Gunnd4339262021-05-03 14:46:49 -070011089 @Override
11090 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11092 "setDeviceToDeviceForceEnabled");
11093
11094 final long identity = Binder.clearCallingIdentity();
11095 try {
11096 Arrays.stream(PhoneFactory.getPhones()).forEach(
11097 p -> {
11098 Phone thePhone = p.getImsPhone();
11099 if (thePhone != null && thePhone instanceof ImsPhone) {
11100 ImsPhone imsPhone = (ImsPhone) thePhone;
11101 CallTracker tracker = imsPhone.getCallTracker();
11102 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11103 ImsPhoneCallTracker imsPhoneCallTracker =
11104 (ImsPhoneCallTracker) tracker;
11105 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11106 }
11107 }
11108 }
11109 );
11110 } finally {
11111 Binder.restoreCallingIdentity(identity);
11112 }
11113 }
11114
Tyler Gunn92479152021-01-20 16:30:10 -080011115 /**
Hui Wang761a6682020-10-31 05:12:53 +000011116 * Gets the config of RCS VoLTE single registration enabled for the device.
11117 */
11118 @Override
11119 public boolean getDeviceSingleRegistrationEnabled() {
11120 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11121 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11122 }
11123
11124 /**
11125 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11126 */
11127 @Override
11128 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11130 "setCarrierSingleRegistrationEnabledOverride");
11131 enforceModifyPermission();
11132
11133 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11134 : Boolean.parseBoolean(enabledStr);
11135 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11136 subId, enabled);
11137 }
11138
11139 /**
11140 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11141 */
11142 @Override
11143 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11144 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11145 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11146 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011147
11148 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011149 * Overrides the ims feature validation result
11150 */
11151 @Override
11152 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11153 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11154 "setImsFeatureValidationOverride");
11155
11156 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11157 : Boolean.parseBoolean(enabledStr);
11158 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11159 subId, enabled);
11160 }
11161
11162 /**
11163 * Gets the ims feature validation override value
11164 */
11165 @Override
11166 public boolean getImsFeatureValidationOverride(int subId) {
11167 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11168 "getImsFeatureValidationOverride");
11169 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11170 }
11171
11172 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011173 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11174 * their mobile plan.
11175 */
11176 @Override
11177 public String getMobileProvisioningUrl() {
11178 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11179 final long identity = Binder.clearCallingIdentity();
11180 try {
11181 return getDefaultPhone().getMobileProvisioningUrl();
11182 } finally {
11183 Binder.restoreCallingIdentity(identity);
11184 }
11185 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011186
James.cf Linbcdf8b32021-01-14 16:44:13 +080011187 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011188 * Get the EAB contact from the EAB database.
11189 */
11190 @Override
11191 public String getContactFromEab(String contact) {
11192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11193 enforceModifyPermission();
11194 final long identity = Binder.clearCallingIdentity();
11195 try {
11196 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11197 } finally {
11198 Binder.restoreCallingIdentity(identity);
11199 }
11200 }
11201
11202 /**
Calvin Pana1434322021-07-01 19:27:01 +080011203 * Get the EAB capability from the EAB database.
11204 */
11205 @Override
11206 public String getCapabilityFromEab(String contact) {
11207 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11208 enforceModifyPermission();
11209 final long identity = Binder.clearCallingIdentity();
11210 try {
11211 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11212 } finally {
11213 Binder.restoreCallingIdentity(identity);
11214 }
11215 }
11216
11217 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011218 * Remove the EAB contacts from the EAB database.
11219 */
11220 @Override
11221 public int removeContactFromEab(int subId, String contacts) {
11222 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11223 enforceModifyPermission();
11224 final long identity = Binder.clearCallingIdentity();
11225 try {
11226 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11227 } finally {
11228 Binder.restoreCallingIdentity(identity);
11229 }
11230 }
11231
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011232 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011233 public boolean getDeviceUceEnabled() {
11234 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11235 final long identity = Binder.clearCallingIdentity();
11236 try {
11237 return mApp.getDeviceUceEnabled();
11238 } finally {
11239 Binder.restoreCallingIdentity(identity);
11240 }
11241 }
11242
11243 @Override
11244 public void setDeviceUceEnabled(boolean isEnabled) {
11245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11246 final long identity = Binder.clearCallingIdentity();
11247 try {
11248 mApp.setDeviceUceEnabled(isEnabled);
11249 } finally {
11250 Binder.restoreCallingIdentity(identity);
11251 }
11252 }
11253
Brad Ebinger14d467f2021-02-12 06:18:28 +000011254 /**
11255 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11256 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11257 */
11258 // Used for SHELL command only right now.
11259 @Override
11260 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11261 List<String> featureTags) {
11262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11263 "addUceRegistrationOverrideShell");
11264 final long identity = Binder.clearCallingIdentity();
11265 try {
11266 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11267 new ArraySet<>(featureTags));
11268 } catch (ImsException e) {
11269 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11270 } finally {
11271 Binder.restoreCallingIdentity(identity);
11272 }
11273 }
11274
11275 /**
11276 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11277 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11278 */
11279 // Used for SHELL command only right now.
11280 @Override
11281 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11282 List<String> featureTags) {
11283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11284 "removeUceRegistrationOverrideShell");
11285 final long identity = Binder.clearCallingIdentity();
11286 try {
11287 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11288 new ArraySet<>(featureTags));
11289 } catch (ImsException e) {
11290 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11291 } finally {
11292 Binder.restoreCallingIdentity(identity);
11293 }
11294 }
11295
11296 /**
11297 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11298 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11299 */
11300 // Used for SHELL command only right now.
11301 @Override
11302 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11303 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11304 "clearUceRegistrationOverrideShell");
11305 final long identity = Binder.clearCallingIdentity();
11306 try {
11307 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11308 } catch (ImsException e) {
11309 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11310 } finally {
11311 Binder.restoreCallingIdentity(identity);
11312 }
11313 }
11314
11315 /**
11316 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11317 */
11318 // Used for SHELL command only right now.
11319 @Override
11320 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11321 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11322 "getLatestRcsContactUceCapabilityShell");
11323 final long identity = Binder.clearCallingIdentity();
11324 try {
11325 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11326 } catch (ImsException e) {
11327 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11328 } finally {
11329 Binder.restoreCallingIdentity(identity);
11330 }
11331 }
11332
11333 /**
11334 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11335 * device does not have an active PUBLISH.
11336 */
11337 // Used for SHELL command only right now.
11338 @Override
11339 public String getLastUcePidfXmlShell(int subId) {
11340 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11341 final long identity = Binder.clearCallingIdentity();
11342 try {
11343 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11344 } catch (ImsException e) {
11345 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11346 } finally {
11347 Binder.restoreCallingIdentity(identity);
11348 }
11349 }
11350
James.cf Line8713a42021-04-29 16:04:26 +080011351 /**
11352 * Remove UCE requests cannot be sent to the network status.
11353 */
11354 // Used for SHELL command only right now.
11355 @Override
11356 public boolean removeUceRequestDisallowedStatus(int subId) {
11357 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11358 final long identity = Binder.clearCallingIdentity();
11359 try {
11360 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11361 } catch (ImsException e) {
11362 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11363 } finally {
11364 Binder.restoreCallingIdentity(identity);
11365 }
11366 }
11367
James.cf Lin18bb9002021-05-25 01:37:38 +080011368 /**
11369 * Remove UCE requests cannot be sent to the network status.
11370 */
11371 // Used for SHELL command only.
11372 @Override
11373 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11374 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11375 final long identity = Binder.clearCallingIdentity();
11376 try {
11377 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11378 } catch (ImsException e) {
11379 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11380 } finally {
11381 Binder.restoreCallingIdentity(identity);
11382 }
11383 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011384
James.cf Lin4b784aa2021-01-31 03:25:15 +080011385 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011386 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11387 String callingPackage) {
11388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11389 mApp, subId, "setSignalStrengthUpdateRequest");
11390
11391 final int callingUid = Binder.getCallingUid();
11392 // Verify that tha callingPackage belongs to the calling UID
11393 mApp.getSystemService(AppOpsManager.class)
11394 .checkPackage(callingUid, callingPackage);
11395
Rambo Wang3607f502021-02-01 21:51:40 -080011396 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011397
11398 final long identity = Binder.clearCallingIdentity();
11399 try {
11400 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11401 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11402
11403 if (result instanceof IllegalStateException) {
11404 throw (IllegalStateException) result;
11405 }
11406 } finally {
11407 Binder.restoreCallingIdentity(identity);
11408 }
11409 }
11410
11411 @Override
11412 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11413 String callingPackage) {
11414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11415 mApp, subId, "clearSignalStrengthUpdateRequest");
11416
11417 final int callingUid = Binder.getCallingUid();
11418 // Verify that tha callingPackage belongs to the calling UID
11419 mApp.getSystemService(AppOpsManager.class)
11420 .checkPackage(callingUid, callingPackage);
11421
11422 final long identity = Binder.clearCallingIdentity();
11423 try {
11424 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11425 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11426
11427 if (result instanceof IllegalStateException) {
11428 throw (IllegalStateException) result;
11429 }
11430 } finally {
11431 Binder.restoreCallingIdentity(identity);
11432 }
11433 }
11434
Rambo Wang3607f502021-02-01 21:51:40 -080011435 private static void validateSignalStrengthUpdateRequest(Context context,
11436 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011437 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11438 // phone/system process do not have further restriction on request
11439 return;
11440 }
11441
11442 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011443 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011444 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011445 context.enforceCallingOrSelfPermission(
11446 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11447 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011448 }
11449
11450 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011451 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011452 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011453 || info.isEnabled()) {
11454 throw new IllegalArgumentException(
11455 "Only system can set hide fields in SignalThresholdInfo");
11456 }
11457
11458 // Thresholds length for each RAN need in range. This has been validated in
11459 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11460 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11461 final int[] thresholds = info.getThresholds();
11462 Objects.requireNonNull(thresholds);
11463 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11464 || thresholds.length
11465 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11466 throw new IllegalArgumentException(
11467 "thresholds length is out of range: " + thresholds.length);
11468 }
11469 }
11470 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011471
11472 /**
11473 * Gets the current phone capability.
11474 *
11475 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11476 * @return the PhoneCapability which describes the data connection capability of modem.
11477 * It's used to evaluate possible phone config change, for example from single
11478 * SIM device to multi-SIM device.
11479 */
11480 @Override
11481 public PhoneCapability getPhoneCapability() {
11482 enforceReadPrivilegedPermission("getPhoneCapability");
11483 final long identity = Binder.clearCallingIdentity();
11484 try {
11485 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11486 } finally {
11487 Binder.restoreCallingIdentity(identity);
11488 }
11489 }
Michele Berionne5e411512020-11-13 02:36:59 +000011490
11491 /**
11492 * Prepare TelephonyManager for an unattended reboot. The reboot is
11493 * required to be done shortly after the API is invoked.
11494 */
11495 @Override
11496 @TelephonyManager.PrepareUnattendedRebootResult
11497 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011498 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011499 enforceRebootPermission();
11500
11501 final long identity = Binder.clearCallingIdentity();
11502 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011503 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011504 } finally {
11505 Binder.restoreCallingIdentity(identity);
11506 }
11507 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011508
11509 /**
11510 * Request to get the current slicing configuration including URSP rules and
11511 * NSSAIs (configured, allowed and rejected).
11512 *
11513 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11514 */
11515 @Override
11516 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011517 TelephonyPermissions
11518 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11519 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011520
11521 final long identity = Binder.clearCallingIdentity();
11522 try {
11523 Phone phone = getDefaultPhone();
11524 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11525 } finally {
11526 Binder.restoreCallingIdentity(identity);
11527 }
11528 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011529
11530 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011531 * Check whether the given premium capability is available for purchase from the carrier.
11532 *
11533 * @param capability The premium capability to check.
11534 * @param subId The subId to check the premium capability for.
11535 *
11536 * @return Whether the given premium capability is available to purchase.
11537 */
11538 @Override
11539 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11540 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11541 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11542 log("Premium capability "
11543 + TelephonyManager.convertPremiumCapabilityToString(capability)
11544 + " is not available for purchase due to missing permissions.");
11545 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11546 + "permission READ_BASIC_PHONE_STATE.");
11547 }
11548
11549 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011550 if (phone == null) {
11551 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11552 return false;
11553 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011554 final long identity = Binder.clearCallingIdentity();
11555 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070011556 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011557 .isPremiumCapabilityAvailableForPurchase(capability);
11558 } finally {
11559 Binder.restoreCallingIdentity(identity);
11560 }
11561 }
11562
11563 /**
11564 * Purchase the given premium capability from the carrier.
11565 *
11566 * @param capability The premium capability to purchase.
11567 * @param callback The result of the purchase request.
11568 * @param subId The subId to purchase the premium capability for.
11569 */
11570 @Override
11571 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11572 log("purchasePremiumCapability: capability="
11573 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11574 + getCurrentPackageName());
11575
11576 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11577 mApp, "purchasePremiumCapability")) {
11578 log("purchasePremiumCapability "
11579 + TelephonyManager.convertPremiumCapabilityToString(capability)
11580 + " failed due to missing permissions.");
11581 throw new SecurityException("purchasePremiumCapability requires permission "
11582 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011583 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11584 mApp, "purchasePremiumCapability")) {
11585 log("purchasePremiumCapability "
11586 + TelephonyManager.convertPremiumCapabilityToString(capability)
11587 + " failed due to missing permissions.");
11588 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011589 }
11590
11591 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011592 if (phone == null) {
11593 try {
11594 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11595 callback.accept(result);
11596 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11597 } catch (RemoteException e) {
11598 String logStr = "Purchase premium capability "
11599 + TelephonyManager.convertPremiumCapabilityToString(capability)
11600 + " failed due to RemoteException handling null phone: " + e;
11601 if (DBG) log(logStr);
11602 AnomalyReporter.reportAnomaly(
11603 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11604 }
11605 return;
11606 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011607
11608 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011609 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011610 callingProcess = mApp.getPackageManager().getApplicationInfo(
11611 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011612 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011613 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011614 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011615
11616 boolean isVisible = false;
11617 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11618 if (am != null) {
11619 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11620 if (processes != null) {
11621 for (ActivityManager.RunningAppProcessInfo process : processes) {
11622 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011623 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011624 if (process.processName.equals(callingProcess) && process.importance
11625 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11626 isVisible = true;
11627 break;
11628 }
11629 }
11630 }
11631 }
11632
11633 if (!isVisible) {
11634 try {
11635 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11636 callback.accept(result);
11637 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11638 } catch (RemoteException e) {
11639 String logStr = "Purchase premium capability "
11640 + TelephonyManager.convertPremiumCapabilityToString(capability)
11641 + " failed due to RemoteException handling background application: " + e;
11642 if (DBG) log(logStr);
11643 AnomalyReporter.reportAnomaly(
11644 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11645 }
11646 return;
11647 }
11648
Sarah Chin71b3a852022-09-28 15:54:19 -070011649 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011650 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011651 }
11652
11653 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011654 * Register an IMS connection state callback
11655 */
11656 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011657 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11658 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011659 if (feature == ImsFeature.FEATURE_MMTEL) {
11660 // ImsMmTelManager
11661 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11662 TelephonyPermissions
11663 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11664 mApp, subId, "registerImsStateCallback");
11665 } else if (feature == ImsFeature.FEATURE_RCS) {
11666 // ImsRcsManager or SipDelegateManager
11667 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11668 Binder.getCallingUid(), "registerImsStateCallback",
11669 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11670 Manifest.permission.READ_PRECISE_PHONE_STATE,
11671 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11672 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11673 }
11674
11675 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11676 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11677 "IMS not available on device.");
11678 }
11679
11680 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11681 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11682 }
11683
11684 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11685 if (controller == null) {
11686 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11687 "IMS not available on device.");
11688 }
11689
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011690 if (callingPackage == null) {
11691 callingPackage = getCurrentPackageName();
11692 }
11693
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011694 final long token = Binder.clearCallingIdentity();
11695 try {
11696 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011697 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011698 } catch (ImsException e) {
11699 throw new ServiceSpecificException(e.getCode());
11700 } finally {
11701 Binder.restoreCallingIdentity(token);
11702 }
11703 }
11704
11705 /**
11706 * Unregister an IMS connection state callback
11707 */
11708 @Override
11709 public void unregisterImsStateCallback(IImsStateCallback cb) {
11710 final long token = Binder.clearCallingIdentity();
11711 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11712 if (controller == null) {
11713 return;
11714 }
11715 try {
11716 controller.unregisterImsStateCallback(cb);
11717 } finally {
11718 Binder.restoreCallingIdentity(token);
11719 }
11720 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011721
11722 /**
11723 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11724 *
11725 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000011726 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011727 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000011728 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011729 * If there is current registered network this value will be same as the registered cell
11730 * identity. If the device goes out of service the previous cell identity is cached and
11731 * will be returned. If the cache age of the Cell identity is more than 24 hours
11732 * it will be cleared and null will be returned.
11733 *
11734 */
11735 @Override
11736 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11737 String callingFeatureId) {
11738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11739 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11740 LocationAccessPolicy.checkLocationPermission(mApp,
11741 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11742 .setCallingPackage(callingPackage)
11743 .setCallingFeatureId(callingFeatureId)
11744 .setCallingPid(Binder.getCallingPid())
11745 .setCallingUid(Binder.getCallingUid())
11746 .setMethod("getLastKnownCellIdentity")
11747 .setLogAsInfo(true)
11748 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11749 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11750 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11751 .build());
11752
11753 boolean hasFinePermission =
11754 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11755 if (!hasFinePermission
11756 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11757 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011758 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011759 }
11760
11761 final long identity = Binder.clearCallingIdentity();
11762 try {
Ling Mac28f0212023-03-24 16:07:15 -070011763 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011764 if (sst == null) return null;
11765 return sst.getLastKnownCellIdentity();
11766 } finally {
11767 Binder.restoreCallingIdentity(identity);
11768 }
11769 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011770
jimsun3b9ccac2021-10-26 15:01:23 +080011771 /**
11772 * Sets the modem service class Name that Telephony will bind to.
11773 *
11774 * @param serviceName The class name of the modem service.
11775 * @return true if the operation is succeed, otherwise false.
11776 */
11777 public boolean setModemService(String serviceName) {
11778 Log.d(LOG_TAG, "setModemService - " + serviceName);
11779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011781 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11782 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011783 return mPhoneConfigurationManager.setModemService(serviceName);
11784 }
11785
11786 /**
11787 * Return the class name of the currently bounded modem service.
11788 *
11789 * @return the class name of the modem service.
11790 */
11791 public String getModemService() {
11792 String result;
11793 Log.d(LOG_TAG, "getModemService");
11794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11795 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011796 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011797 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11798 "getModemService");
11799 result = mPhoneConfigurationManager.getModemService();
11800 Log.d(LOG_TAG, "result = " + result);
11801 return result;
11802 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011803
11804 @Override
11805 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11806 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11807 mApp.enforceCallingOrSelfPermission(
11808 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11809 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11810
11811 final long identity = Binder.clearCallingIdentity();
11812 try {
11813 Phone phone = getPhone(subId);
11814 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011815 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11816 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011817 phone.setVoiceServiceStateOverride(hasService);
11818 } finally {
11819 Binder.restoreCallingIdentity(identity);
11820 }
11821 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011822
11823 /**
11824 * set removable eSIM as default eUICC.
11825 *
11826 * @hide
11827 */
11828 @Override
11829 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11830 enforceModifyPermission();
11831 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11832
11833 final long identity = Binder.clearCallingIdentity();
11834 try {
11835 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11836 } finally {
11837 Binder.restoreCallingIdentity(identity);
11838 }
11839 }
11840
11841 /**
11842 * Returns whether the removable eSIM is default eUICC or not.
11843 *
11844 * @hide
11845 */
11846 @Override
11847 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11848 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11849 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11850
11851 final long identity = Binder.clearCallingIdentity();
11852 try {
11853 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11854 } finally {
11855 Binder.restoreCallingIdentity(identity);
11856 }
11857 }
11858
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011859 /**
11860 * Get the component name of the default app to direct respond-via-message intent for the
11861 * user associated with this subscription, update the cache if there is no respond-via-message
11862 * application currently configured for this user.
11863 * @return component name of the app and class to direct Respond Via Message intent to, or
11864 * {@code null} if the functionality is not supported.
11865 * @hide
11866 */
11867 @Override
11868 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11869 boolean updateIfNeeded) {
11870 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011871
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011872 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11873
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011874 UserHandle userHandle = null;
11875 final long identity = Binder.clearCallingIdentity();
11876 try {
11877 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11878 } finally {
11879 Binder.restoreCallingIdentity(identity);
11880 }
11881 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11882 updateIfNeeded, userHandle);
11883 }
Jack Yuf5badd92022-12-08 00:50:53 -080011884
11885 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011886 * Set whether the device is able to connect with null ciphering or integrity
11887 * algorithms. This is a global setting and will apply to all active subscriptions
11888 * and all new subscriptions after this.
11889 *
11890 * @param enabled when true, null cipher and integrity algorithms are allowed.
11891 * @hide
11892 */
11893 @Override
11894 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11895 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11896 enforceModifyPermission();
11897 checkForNullCipherAndIntegritySupport();
11898
11899 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11900 // for listening to these preference changes and applying them immediately.
11901 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11902 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11903 editor.apply();
11904
11905 for (Phone phone: PhoneFactory.getPhones()) {
11906 phone.handleNullCipherEnabledChange();
11907 }
11908 }
11909
11910
11911 /**
11912 * Get whether the device is able to connect with null ciphering or integrity
11913 * algorithms. Note that this retrieves the phone-global preference and not
11914 * the state of the radio.
11915 *
11916 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11917 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11918 * version for this feature.
11919 * @hide
11920 */
11921 @Override
11922 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11923 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11924 enforceReadPermission();
11925 checkForNullCipherAndIntegritySupport();
11926 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11927 }
11928
11929 private void checkForNullCipherAndIntegritySupport() {
11930 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11931 throw new UnsupportedOperationException(
11932 "Null cipher and integrity operations require HAL 2.1 or above");
11933 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011934 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11935 throw new UnsupportedOperationException(
11936 "Null cipher and integrity operations unsupported by modem");
11937 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011938 }
11939
11940 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011941 * Get the SIM state for the slot index.
11942 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11943 *
11944 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11945 */
11946 @Override
11947 @SimState
11948 public int getSimStateForSlotIndex(int slotIndex) {
11949 IccCardConstants.State simState;
11950 if (slotIndex < 0) {
11951 simState = IccCardConstants.State.UNKNOWN;
11952 } else {
11953 Phone phone = null;
11954 try {
11955 phone = PhoneFactory.getPhone(slotIndex);
11956 } catch (IllegalStateException e) {
11957 // ignore
11958 }
11959 if (phone == null) {
11960 simState = IccCardConstants.State.UNKNOWN;
11961 } else {
11962 IccCard icc = phone.getIccCard();
11963 if (icc == null) {
11964 simState = IccCardConstants.State.UNKNOWN;
11965 } else {
11966 simState = icc.getState();
11967 }
11968 }
11969 }
11970 return simState.ordinal();
11971 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011972
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011973 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11974 boolean enableLogcat,
11975 long logcatStartTimestampMillis, boolean enableTelecomDump,
11976 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011977 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11978 TelephonyManager.EmergencyCallDiagnosticParams edp =
11979 new TelephonyManager.EmergencyCallDiagnosticParams();
11980 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11981 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11982 edp.setTelecomDumpSysCollection(enableTelecomDump);
11983 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11984 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
11985 Executors.newCachedThreadPool(), db,
11986 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
11987 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011988 }
11989
11990 /**
11991 * Request telephony to persist state for debugging emergency call failures.
11992 *
11993 * @param dropBoxTag Tag to use when persisting data to dropbox service.
11994 * @param enableLogcat whether to collect logcat output
11995 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
11996 * @param enableTelecomDump whether to collect telecom dumpsys
11997 * @param enableTelephonyDump whether to collect telephony dumpsys
11998 */
11999 @Override
12000 @RequiresPermission(android.Manifest.permission.DUMP)
12001 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12002 long logcatStartTimestampMillis, boolean enableTelecomDump,
12003 boolean enableTelephonyDump) {
12004 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12005 "persistEmergencyCallDiagnosticData");
12006 final long identity = Binder.clearCallingIdentity();
12007 try {
12008 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12009 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12010
12011 } finally {
12012 Binder.restoreCallingIdentity(identity);
12013 }
12014 }
12015
Hui Wang9b5793a2022-12-05 14:38:06 -060012016 /**
12017 * Get current cell broadcast ranges.
12018 */
12019 @Override
12020 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12021 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12022 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12023 "getCellBroadcastIdRanges");
12024 final long identity = Binder.clearCallingIdentity();
12025 try {
12026 return getPhone(subId).getCellBroadcastIdRanges();
12027 } finally {
12028 Binder.restoreCallingIdentity(identity);
12029 }
12030 }
12031
12032 /**
12033 * Set reception of cell broadcast messages with the list of the given ranges
12034 *
12035 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12036 */
12037 @Override
12038 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12039 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12040 @Nullable IIntegerConsumer callback) {
12041 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12042 "setCellBroadcastIdRanges");
12043 final long identity = Binder.clearCallingIdentity();
12044 try {
12045 Phone phone = getPhoneFromSubId(subId);
12046 if (DBG) {
12047 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12048 }
12049 phone.setCellBroadcastIdRanges(ranges, result -> {
12050 if (callback != null) {
12051 try {
12052 callback.accept(result);
12053 } catch (RemoteException e) {
12054 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12055 }
12056 }
12057 });
12058 } finally {
12059 Binder.restoreCallingIdentity(identity);
12060 }
12061 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012062
12063 /**
12064 * Returns whether the device supports the domain selection service.
12065 *
12066 * @return {@code true} if the device supports the domain selection service.
12067 */
12068 @Override
12069 public boolean isDomainSelectionSupported() {
12070 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12071 "isDomainSelectionSupported");
12072
12073 final long identity = Binder.clearCallingIdentity();
12074 try {
12075 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12076 } finally {
12077 Binder.restoreCallingIdentity(identity);
12078 }
12079 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012080
12081 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012082 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12083 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12084 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012085 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012086 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012087 * @param enableSatellite {@code true} to enable the satellite modem and
12088 * {@code false} to disable.
12089 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12090 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012091 *
12092 * @throws SecurityException if the caller doesn't have the required permission.
12093 */
12094 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012095 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12096 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012097 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012098 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12099 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012100 }
12101
12102 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012103 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012104 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012105 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012106 * @param result The result receiver that returns whether the satellite modem is enabled
12107 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012108 *
12109 * @throws SecurityException if the caller doesn't have the required permission.
12110 */
12111 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012112 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12113 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012114 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012115 }
12116
12117 /**
Sarah Chin43457982023-02-15 17:50:38 -080012118 * Request to get whether the satellite service demo mode is enabled.
12119 *
12120 * @param subId The subId of the subscription to check whether the satellite demo mode
12121 * is enabled for.
12122 * @param result The result receiver that returns whether the satellite demo mode is enabled
12123 * if the request is successful or an error code if the request failed.
12124 *
12125 * @throws SecurityException if the caller doesn't have the required permission.
12126 */
12127 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012128 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12129 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12130 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012131 }
12132
12133 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012134 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012135 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012136 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012137 * @param result The result receiver that returns whether the satellite service is supported on
12138 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012139 */
12140 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012141 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012142 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012143 }
12144
12145 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012146 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012147 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012148 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012149 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12150 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012151 *
12152 * @throws SecurityException if the caller doesn't have required permission.
12153 */
12154 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012155 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12156 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012157 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012158 }
12159
12160 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012161 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012162 * This can be called by the pointing UI when the user starts pointing to the satellite.
12163 * Modem should continue to report the pointing input as the device or satellite moves.
12164 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012165 * @param subId The subId of the subscription to start satellite transmission updates for.
12166 * @param resultCallback The callback to get the result of the request.
12167 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012168 *
12169 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012170 */
12171 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012172 public void startSatelliteTransmissionUpdates(int subId,
12173 @NonNull IIntegerConsumer resultCallback,
12174 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12175 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12176 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012177 }
12178
12179 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012180 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012181 * This can be called by the pointing UI when the user stops pointing to the satellite.
12182 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012183 * @param subId The subId of the subscription to stop satellite transmission updates for.
12184 * @param resultCallback The callback to get the result of the request.
12185 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12186 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012187 *
12188 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012189 */
12190 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012191 public void stopSatelliteTransmissionUpdates(int subId,
12192 @NonNull IIntegerConsumer resultCallback,
12193 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12194 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12195 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012196 }
12197
12198 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012199 * Register the subscription with a satellite provider.
12200 * This is needed to register the subscription if the provider allows dynamic registration.
12201 *
12202 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012203 * @param token The token to be used as a unique identifier for provisioning with satellite
12204 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012205 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012206 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012207 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012208 * @return The signal transport used by the caller to cancel the provision request,
12209 * or {@code null} if the request failed.
12210 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012211 * @throws SecurityException if the caller doesn't have the required permission.
12212 */
12213 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012214 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012215 @NonNull String token, @NonNull byte[] provisionData,
12216 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012217 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012218 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12219 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012220 }
12221
12222 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012223 * Unregister the device/subscription with the satellite provider.
12224 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012225 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012226 * should report as deprovisioned.
12227 *
12228 * @param subId The subId of the subscription to be deprovisioned.
12229 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012230 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012231 *
12232 * @throws SecurityException if the caller doesn't have the required permission.
12233 */
12234 @Override
12235 public void deprovisionSatelliteService(int subId,
12236 @NonNull String token, @NonNull IIntegerConsumer callback) {
12237 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012238 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012239 }
12240
12241 /**
Sarah Chin43457982023-02-15 17:50:38 -080012242 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012243 *
Sarah Chin43457982023-02-15 17:50:38 -080012244 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012245 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012246 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012247 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012248 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012249 * @throws SecurityException if the caller doesn't have the required permission.
12250 */
12251 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012252 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12253 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012254 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012255 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012256 }
12257
12258 /**
Sarah Chin43457982023-02-15 17:50:38 -080012259 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012260 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012261 *
Sarah Chin43457982023-02-15 17:50:38 -080012262 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012263 * @param callback The callback that was passed to
12264 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012265 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012266 * @throws SecurityException if the caller doesn't have the required permission.
12267 */
12268 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012269 public void unregisterForSatelliteProvisionStateChanged(
12270 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012271 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012272 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012273 }
12274
12275 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012276 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012277 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012278 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012279 * @param result The result receiver that returns whether the device is provisioned with a
12280 * satellite provider if the request is successful or an error code if the
12281 * request failed.
12282 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012283 * @throws SecurityException if the caller doesn't have the required permission.
12284 */
12285 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012286 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12287 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012288 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012289 }
12290
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012291 /**
Sarah Chin43457982023-02-15 17:50:38 -080012292 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012293 *
Sarah Chin43457982023-02-15 17:50:38 -080012294 * @param subId The subId of the subscription to register for satellite modem state changed.
12295 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012296 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012297 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012298 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012299 * @throws SecurityException if the caller doesn't have the required permission.
12300 */
12301 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012302 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012303 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012304 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012305 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012306 }
12307
12308 /**
Sarah Chin43457982023-02-15 17:50:38 -080012309 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012310 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012311 *
Sarah Chin43457982023-02-15 17:50:38 -080012312 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012313 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012314 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012315 *
12316 * @throws SecurityException if the caller doesn't have the required permission.
12317 */
12318 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012319 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012320 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012321 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012322 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012323 }
12324
12325 /**
12326 * Register to receive incoming datagrams over satellite.
12327 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012328 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012329 * @param callback The callback to handle incoming datagrams over satellite.
12330 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012331 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012332 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012333 * @throws SecurityException if the caller doesn't have the required permission.
12334 */
12335 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012336 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012337 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012338 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012339 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012340 }
12341
12342 /**
12343 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012344 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012345 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012346 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12347 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012348 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012349 *
12350 * @throws SecurityException if the caller doesn't have the required permission.
12351 */
12352 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012353 public void unregisterForSatelliteDatagram(int subId,
12354 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012355 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012356 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012357 }
12358
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012359 /**
12360 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012361 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012362 * This method requests modem to check if there are any pending datagrams to be received over
12363 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012364 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012365 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012366 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012367 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012368 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012369 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012370 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012371 @Override
12372 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012373 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012374 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012375 }
12376
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012377 /**
12378 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012379 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012380 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12381 * input to this method. Datagram received here will be passed down to modem without any
12382 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012383 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012384 * @param subId The subId of the subscription to send satellite datagrams for.
12385 * @param datagramType datagram type indicating whether the datagram is of type
12386 * SOS_SMS or LOCATION_SHARING.
12387 * @param datagram encoded gateway datagram which is encrypted by the caller.
12388 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012389 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12390 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012391 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012392 *
12393 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012394 */
12395 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012396 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12397 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12398 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012399 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012400 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12401 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012402 }
12403
Sarah Chindf715ec2023-02-13 13:46:24 -080012404 /**
12405 * Request to get whether satellite communication is allowed for the current location.
12406 *
12407 * @param subId The subId of the subscription to check whether satellite communication is
12408 * allowed for the current location for.
12409 * @param result The result receiver that returns whether satellite communication is allowed
12410 * for the current location if the request is successful or an error code
12411 * if the request failed.
12412 *
12413 * @throws SecurityException if the caller doesn't have the required permission.
12414 */
12415 @Override
12416 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12417 @NonNull ResultReceiver result) {
12418 enforceSatelliteCommunicationPermission(
12419 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012420 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12421 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012422 }
12423
12424 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012425 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012426 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012427 * @param subId The subId to get the time after which the satellite will be visible for.
12428 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012429 * be visible if the request is successful or an error code if the request failed.
12430 *
12431 * @throws SecurityException if the caller doesn't have the required permission.
12432 */
12433 @Override
12434 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12435 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012436 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012437 }
12438
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012439 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012440 * Inform that Device is aligned to satellite for demo mode.
12441 *
12442 * @param subId The subId to get the time after which the satellite will be visible for.
12443 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12444 * {@code false} Device fails to align with the satellite for demo mode.
12445 *
12446 * @throws SecurityException if the caller doesn't have required permission.
12447 */
12448 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12449
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012450 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012451 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012452 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012453 }
12454
12455 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012456 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12457 * by modem.
12458 *
12459 * @param subId The subId of the subscription to request for.
12460 * @param reason Reason for disallowing satellite communication for carrier.
12461 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12462 * operation.
12463 *
12464 * @throws SecurityException if the caller doesn't have required permission.
12465 */
12466 public void addSatelliteAttachRestrictionForCarrier(int subId,
12467 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12468 @NonNull IIntegerConsumer callback) {
12469 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12470 final long identity = Binder.clearCallingIdentity();
12471 try {
12472 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12473 } finally {
12474 Binder.restoreCallingIdentity(identity);
12475 }
12476 }
12477
12478 /**
12479 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12480 * by modem.
12481 *
12482 * @param subId The subId of the subscription to request for.
12483 * @param reason Reason for disallowing satellite communication.
12484 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12485 * operation.
12486 *
12487 * @throws SecurityException if the caller doesn't have required permission.
12488 */
12489 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12490 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12491 @NonNull IIntegerConsumer callback) {
12492 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12493 final long identity = Binder.clearCallingIdentity();
12494 try {
12495 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12496 callback);
12497 } finally {
12498 Binder.restoreCallingIdentity(identity);
12499 }
12500 }
12501
12502 /**
12503 * Get reasons for disallowing satellite communication, as requested by
12504 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12505 *
12506 * @param subId The subId of the subscription to request for.
12507 *
12508 * @return Integer array of reasons for disallowing satellite communication.
12509 *
12510 * @throws SecurityException if the caller doesn't have the required permission.
12511 */
12512 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12513 int subId) {
12514 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12515 final long identity = Binder.clearCallingIdentity();
12516 try {
12517 Set<Integer> reasonSet =
12518 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12519 return reasonSet.stream().mapToInt(i->i).toArray();
12520 } finally {
12521 Binder.restoreCallingIdentity(identity);
12522 }
12523 }
12524
12525 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012526 * Request to get the signal strength of the satellite connection.
12527 *
12528 * @param subId The subId of the subscription to request for.
12529 * @param result Result receiver to get the error code of the request and the current signal
12530 * strength of the satellite connection.
12531 *
12532 * @throws SecurityException if the caller doesn't have required permission.
12533 */
12534 @Override
12535 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12536 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12537 final long identity = Binder.clearCallingIdentity();
12538 try {
12539 mSatelliteController.requestNtnSignalStrength(subId, result);
12540 } finally {
12541 Binder.restoreCallingIdentity(identity);
12542 }
12543 }
12544
12545 /**
12546 * Registers for NTN signal strength changed from satellite modem.
12547 *
12548 * @param subId The subId of the subscription to request for.
12549 * @param callback The callback to handle the NTN signal strength changed event.
12550 *
12551 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12552 *
12553 * @throws SecurityException if the caller doesn't have the required permission.
12554 */
12555 @Override
12556 @SatelliteManager.SatelliteResult public int registerForNtnSignalStrengthChanged(
12557 int subId, @NonNull INtnSignalStrengthCallback callback) {
12558 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12559 final long identity = Binder.clearCallingIdentity();
12560 try {
12561 return mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
12562 } finally {
12563 Binder.restoreCallingIdentity(identity);
12564 }
12565 }
12566
12567 /**
12568 * Unregisters for NTN signal strength changed from satellite modem.
12569 * If callback was not registered before, the request will be ignored.
12570 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000012571 * @param subId The subId of the subscription to unregister for listening NTN signal strength
12572 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012573 * @param callback The callback that was passed to
12574 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12575 *
12576 * @throws SecurityException if the caller doesn't have the required permission.
12577 */
12578 @Override
12579 public void unregisterForNtnSignalStrengthChanged(
12580 int subId, @NonNull INtnSignalStrengthCallback callback) {
12581 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12582 final long identity = Binder.clearCallingIdentity();
12583 try {
12584 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12585 } finally {
12586 Binder.restoreCallingIdentity(identity);
12587 }
12588 }
12589
12590 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000012591 * Registers for satellite capabilities change event from the satellite service.
12592 *
12593 * @param subId The subId of the subscription to request for.
12594 * @param callback The callback to handle the satellite capabilities changed event.
12595 *
12596 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12597 *
12598 * @throws SecurityException if the caller doesn't have required permission.
12599 */
12600 @Override
12601 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
12602 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12603 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
12604 final long identity = Binder.clearCallingIdentity();
12605 try {
12606 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
12607 } finally {
12608 Binder.restoreCallingIdentity(identity);
12609 }
12610 }
12611
12612 /**
12613 * Unregisters for satellite capabilities change event from the satellite service.
12614 * If callback was not registered before, the request will be ignored.
12615 *
12616 * @param subId The subId of the subscription to unregister for satellite capabilities change.
12617 * @param callback The callback that was passed to.
12618 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
12619 *
12620 * @throws SecurityException if the caller doesn't have required permission.
12621 */
12622 @Override
12623 public void unregisterForSatelliteCapabilitiesChanged(
12624 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12625 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
12626 final long identity = Binder.clearCallingIdentity();
12627 try {
12628 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
12629 } finally {
12630 Binder.restoreCallingIdentity(identity);
12631 }
12632 }
12633
12634 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012635 * This API can be used by only CTS to update satellite vendor service package name.
12636 *
12637 * @param servicePackageName The package name of the satellite vendor service.
12638 * @return {@code true} if the satellite vendor service is set successfully,
12639 * {@code false} otherwise.
12640 */
12641 public boolean setSatelliteServicePackageName(String servicePackageName) {
12642 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12643 TelephonyPermissions.enforceShellOnly(
12644 Binder.getCallingUid(), "setSatelliteServicePackageName");
12645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12646 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12647 "setSatelliteServicePackageName");
12648 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12649 }
12650
12651 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012652 * This API can be used by only CTS to update satellite gateway service package name.
12653 *
12654 * @param servicePackageName The package name of the satellite gateway service.
12655 * @return {@code true} if the satellite gateway service is set successfully,
12656 * {@code false} otherwise.
12657 */
12658 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12659 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12660 TelephonyPermissions.enforceShellOnly(
12661 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12663 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12664 "setSatelliteGatewayServicePackageName");
12665 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12666 }
12667
12668 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012669 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12670 *
12671 * @param packageName The package name of the satellite pointing UI app.
12672 * @param className The class name of the satellite pointing UI app.
12673 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12674 * {@code false} otherwise.
12675 */
12676 public boolean setSatellitePointingUiClassName(
12677 @Nullable String packageName, @Nullable String className) {
12678 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12679 + ", className=" + className);
12680 TelephonyPermissions.enforceShellOnly(
12681 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12683 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12684 "setSatelliteGatewayServicePackageName");
12685 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12686 }
12687
12688 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012689 * This API can be used by only CTS to update the timeout duration in milliseconds that
12690 * satellite should stay at listening mode to wait for the next incoming page before disabling
12691 * listening mode.
12692 *
12693 * @param timeoutMillis The timeout duration in millisecond.
12694 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12695 */
12696 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12697 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12698 TelephonyPermissions.enforceShellOnly(
12699 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12701 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12702 "setSatelliteListeningTimeoutDuration");
12703 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12704 }
12705
12706 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012707 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12708 * the device is aligned with the satellite for demo mode
12709 *
12710 * @param timeoutMillis The timeout duration in millisecond.
12711 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12712 */
12713 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12714 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12715 TelephonyPermissions.enforceShellOnly(
12716 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12718 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12719 "setDeviceAlignedTimeoutDuration");
12720 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12721 }
12722
12723 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070012724 * This API can be used in only testing to override connectivity status in monitoring emergency
12725 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
12726 *
12727 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
12728 * of the following values to enable the override:
12729 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
12730 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
12731 * To disable the override, use -1 for handoverType.
12732 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
12733 * delaySeconds after the emergency call starts.
12734 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
12735 */
12736 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
12737 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
12738 TelephonyPermissions.enforceShellOnly(
12739 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
12740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12741 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12742 "setEmergencyCallToSatelliteHandoverType");
12743 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
12744 handoverType, delaySeconds);
12745 }
12746
12747 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000012748 * This API can be used by only CTS to override the cached value for the device overlay config
12749 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
12750 * outgoing satellite datagrams should be sent to modem in demo mode.
12751 *
12752 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
12753 * satellite modem or not.
12754 *
12755 * @return {@code true} if the operation is successful, {@code false} otherwise.
12756 */
12757 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
12758 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
12759 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
12760 + "disabled");
12761 return false;
12762 }
12763 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
12764 TelephonyPermissions.enforceShellOnly(
12765 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
12766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12767 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12768 "setShouldSendDatagramToModemInDemoMode");
12769 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
12770 shouldSendToModemInDemoMode);
12771 }
12772
12773 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012774 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12775 *
12776 * <p>This method behaves in one of the following ways:
12777 * <ul>
12778 * <li>return true : if the calling package has the appop permission {@link
12779 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12780 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12781 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12782 * Owner device identifier access check, or the calling package has carrier privileges</>
12783 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12784 * </ul>
12785 */
12786 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12787 String callingPackage, @Nullable String callingFeatureId, String message) {
12788 for (Phone phone : PhoneFactory.getPhones()) {
12789 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12790 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12791 return true;
12792 }
12793 }
12794 return false;
12795 }
arunvoddud7401012022-12-15 16:08:12 +000012796
12797 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012798 * @return The subscription manager service instance.
12799 */
12800 public SubscriptionManagerService getSubscriptionManagerService() {
12801 return SubscriptionManagerService.getInstance();
12802 }
12803
12804 /**
arunvoddud7401012022-12-15 16:08:12 +000012805 * Class binds the consumer[callback] and carrierId.
12806 */
12807 private static class CallerCallbackInfo {
12808 private final Consumer<Integer> mConsumer;
12809 private final int mCarrierId;
12810
12811 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12812 mConsumer = consumer;
12813 mCarrierId = carrierId;
12814 }
12815
12816 public Consumer<Integer> getConsumer() {
12817 return mConsumer;
12818 }
12819
12820 public int getCarrierId() {
12821 return mCarrierId;
12822 }
12823 }
Jack Yufa8ed012023-02-11 15:42:28 -080012824}