blob: 596fc61fe76b52fe001bfce5af7b1eb609e5c7af [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;
Gil Cukierman06403e12023-11-29 16:33:03 +0000402 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
403 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000404
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 /** The singleton instance. */
406 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800407 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408
Sarah Chin4beb2b72023-02-14 14:47:54 -0800409 private final PhoneGlobals mApp;
Sarah Chincc5446f2023-10-23 17:57:19 -0700410 private final FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800411 private final CallManager mCM;
412 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000413
414 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800415 private final UserManager mUserManager;
416 private final AppOpsManager mAppOps;
417 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800418 private final SharedPreferences mTelephonySharedPreferences;
419 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800420 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Peter Wangdafb9ac2020-01-15 14:13:38 -0800422 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800423 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800424 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
425
Sarah Chin4beb2b72023-02-14 14:47:54 -0800426 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800427
Derek Tan97ebb422014-09-05 16:55:38 -0700428 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
429 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800430 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800431 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700432
Michelecea4cf22018-12-21 15:00:11 -0800433 // String to store multi SIM allowed
434 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
435
Derek Tan740e1672017-06-27 14:56:27 -0700436 // The AID of ISD-R.
437 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
438
yinxub1bed742017-04-17 11:45:04 -0700439 private NetworkScanRequestTracker mNetworkScanRequestTracker;
440
David Kelly5e06a7f2018-03-12 14:10:59 +0000441 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
442 private static final int MANUFACTURER_CODE_LENGTH = 8;
443
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800444 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800445 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800446
Sarah Chin2ec39f62022-08-31 17:03:26 -0700447 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
448 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
449
Derek Tan89e89d42014-07-08 17:00:10 -0700450 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700451 * Experiment flag to enable erase modem config on reset network, default value is false
452 */
453 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
454 "reset_network_erase_modem_config_enabled";
455
Rambo Wang0f050d82021-02-12 11:43:36 -0800456 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800457
Gary Jian76280a42022-12-07 16:18:33 +0800458 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
459
sandeepjsb6c87872021-09-27 15:34:44 +0000460 /**
461 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
462 * one ICCID active at the same time.
463 * Apps should use below API signatures if targeting SDK is T and beyond.
464 *
465 * @hide
466 */
467 @ChangeId
468 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
469 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800470
Naina Nallurid63128d2019-09-17 14:10:30 -0700471 /**
Chen Xu540470b2021-12-14 17:15:47 -0800472 * Apps targeting on Android T and beyond will get exception whenever icc close channel
473 * operation fails.
474 */
475 @ChangeId
476 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
477 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
478
479 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 * A request object to use for transmitting data to an ICC.
481 */
482 private static final class IccAPDUArgument {
483 public int channel, cla, command, p1, p2, p3;
484 public String data;
485
486 public IccAPDUArgument(int channel, int cla, int command,
487 int p1, int p2, int p3, String data) {
488 this.channel = channel;
489 this.cla = cla;
490 this.command = command;
491 this.p1 = p1;
492 this.p2 = p2;
493 this.p3 = p3;
494 this.data = data;
495 }
496 }
497
498 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700499 * A request object to use for transmitting data to an ICC.
500 */
501 private static final class ManualNetworkSelectionArgument {
502 public OperatorInfo operatorInfo;
503 public boolean persistSelection;
504
505 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
506 this.operatorInfo = operatorInfo;
507 this.persistSelection = persistSelection;
508 }
509 }
510
Sarah Chin71b3a852022-09-28 15:54:19 -0700511 private static final class PurchasePremiumCapabilityArgument {
512 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 public @NonNull IIntegerConsumer callback;
514
515 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800516 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700517 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700518 this.callback = callback;
519 }
520 }
521
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700522 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
524 * request after sending. The main thread will notify the request when it is complete.
525 */
526 private static final class MainThreadRequest {
527 /** The argument to use for the request */
528 public Object argument;
529 /** The result of the request that is run on the main thread */
530 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800531 // The subscriber id that this request applies to. Defaults to
532 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
533 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534
Nathan Harold92bed182018-10-12 18:16:49 -0700535 // In cases where subId is unavailable, the caller needs to specify the phone.
536 public Phone phone;
537
vagdeviaf9a5b92018-08-15 16:01:53 -0700538 public WorkSource workSource;
539
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 public MainThreadRequest(Object argument) {
541 this.argument = argument;
542 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800543
Nathan Harold92bed182018-10-12 18:16:49 -0700544 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
545 this.argument = argument;
546 if (phone != null) {
547 this.phone = phone;
548 }
549 this.workSource = workSource;
550 }
551
vagdeviaf9a5b92018-08-15 16:01:53 -0700552 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800553 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800554 if (subId != null) {
555 this.subId = subId;
556 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700557 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700559 }
560
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800561 private static final class IncomingThirdPartyCallArgs {
562 public final ComponentName component;
563 public final String callId;
564 public final String callerDisplayName;
565
566 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
567 String callerDisplayName) {
568 this.component = component;
569 this.callId = callId;
570 this.callerDisplayName = callerDisplayName;
571 }
572 }
573
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574 /**
575 * A handler that processes messages on the main thread in the phone process. Since many
576 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
577 * inbound binder threads to the main thread in the phone process. The Binder thread
578 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
579 * on, which will be notified when the operation completes and will contain the result of the
580 * request.
581 *
582 * <p>If a MainThreadRequest object is provided in the msg.obj field,
583 * note that request.result must be set to something non-null for the calling thread to
584 * unblock.
585 */
586 private final class MainThreadHandler extends Handler {
587 @Override
588 public void handleMessage(Message msg) {
589 MainThreadRequest request;
590 Message onCompleted;
591 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000592 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800594 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700595
596 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 case CMD_HANDLE_USSD_REQUEST: {
598 request = (MainThreadRequest) msg.obj;
599 final Phone phone = getPhoneFromRequest(request);
600 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800601 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700603
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 if (!isUssdApiAllowed(request.subId)) {
605 // Carrier does not support use of this API, return failure.
606 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
607 UssdResponse response = new UssdResponse(ussdRequest, null);
608 Bundle returnData = new Bundle();
609 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
610 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700611
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 request.result = true;
613 notifyRequester(request);
614 return;
615 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700616
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 try {
618 request.result = phone != null
619 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
620 } catch (CallStateException cse) {
621 request.result = false;
622 }
623 // Wake up the requesting thread
624 notifyRequester(request);
625 break;
pkanwar32d516d2016-10-14 19:37:38 -0700626 }
627
Yorke Lee716f67e2015-06-17 15:39:16 -0700628 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700630 final Phone phone = getPhoneFromRequest(request);
631 request.result = phone != null ?
632 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
633 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700636 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700638
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000642 uiccPort = getUiccPortFromRequest(request);
643 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800651 iccArgument.channel, iccArgument.cla, iccArgument.command,
652 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
653 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 break;
656
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 ar = (AsyncResult) msg.obj;
659 request = (MainThreadRequest) ar.userObj;
660 if (ar.exception == null && ar.result != null) {
661 request.result = ar.result;
662 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800663 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 if (ar.result == null) {
665 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800666 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800668 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 } else {
670 loge("iccTransmitApduLogicalChannel: Unknown exception");
671 }
672 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
677 request = (MainThreadRequest) msg.obj;
678 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000679 uiccPort = getUiccPortFromRequest(request);
680 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000687 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800688 iccArgument.cla, iccArgument.command, iccArgument.p1,
689 iccArgument.p2,
690 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 }
692 break;
693
694 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
697 if (ar.exception == null && ar.result != null) {
698 request.result = ar.result;
699 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800700 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 if (ar.result == null) {
702 loge("iccTransmitApduBasicChannel: Empty response");
703 } else if (ar.exception instanceof CommandException) {
704 loge("iccTransmitApduBasicChannel: CommandException: " +
705 ar.exception);
706 } else {
707 loge("iccTransmitApduBasicChannel: Unknown exception");
708 }
709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 break;
712
713 case CMD_EXCHANGE_SIM_IO:
714 request = (MainThreadRequest) msg.obj;
715 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000716 uiccPort = getUiccPortFromRequest(request);
717 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800719 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 } else {
722 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
723 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
726 iccArgument.data, onCompleted);
727 }
728 break;
729
730 case EVENT_EXCHANGE_SIM_IO_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result;
735 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800736 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 break;
740
Derek Tan4d5e5c12014-02-04 11:54:58 -0800741 case CMD_SEND_ENVELOPE:
742 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000743 uiccPort = getUiccPortFromRequest(request);
744 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800746 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 } else {
749 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800750 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800752 break;
753
754 case EVENT_SEND_ENVELOPE_DONE:
755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700757 if (ar.exception == null && ar.result != null) {
758 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800759 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800760 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700761 if (ar.result == null) {
762 loge("sendEnvelopeWithStatus: Empty response");
763 } else if (ar.exception instanceof CommandException) {
764 loge("sendEnvelopeWithStatus: CommandException: " +
765 ar.exception);
766 } else {
767 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
768 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800771 break;
772
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 case CMD_OPEN_CHANNEL:
774 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000775 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800776 IccLogicalChannelRequest openChannelRequest =
777 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000778 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800780 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800781 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700782 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 } else {
784 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800785 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
786 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 break;
789
790 case EVENT_OPEN_CHANNEL_DONE:
791 ar = (AsyncResult) msg.obj;
792 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700793 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700794 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700795 int[] result = (int[]) ar.result;
796 int channelId = result[0];
797 byte[] selectResponse = null;
798 if (result.length > 1) {
799 selectResponse = new byte[result.length - 1];
800 for (int i = 1; i < result.length; ++i) {
801 selectResponse[i - 1] = (byte) result[i];
802 }
803 }
804 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800805 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800806
807 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700808 if (uiccPort == null) {
809 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
810 } else {
811 IccLogicalChannelRequest channelRequest =
812 (IccLogicalChannelRequest) request.argument;
813 channelRequest.channel = channelId;
814 uiccPort.onLogicalChannelOpened(channelRequest);
815 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 if (ar.result == null) {
818 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700819 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700820 if (ar.exception != null) {
821 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
822 }
823
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700824 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700825 if (ar.exception instanceof CommandException) {
826 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800827 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700828 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700829 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700830 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700831 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700832 }
833 }
834 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800835 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700837 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700838 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 break;
840
841 case CMD_CLOSE_CHANNEL:
842 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000843 uiccPort = getUiccPortFromRequest(request);
844 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700845 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800846 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800847 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800848 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700849 } else {
850 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000851 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700852 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 break;
854
855 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null) {
859 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800860 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700861 if (uiccPort == null) {
862 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
863 } else {
864 final int channelId = (Integer) request.argument;
865 uiccPort.onLogicalChannelClosed(channelId);
866 }
Chen Xu540470b2021-12-14 17:15:47 -0800867 } else {
868 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800869 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800870 if (ar.exception instanceof CommandException) {
871 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
872 CommandException.Error error =
873 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800874 if (error == CommandException.Error.INVALID_ARGUMENTS) {
875 // should only throw exceptions from the binder threads.
876 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800877 "iccCloseLogicalChannel: invalid argument ");
878 }
879 } else {
880 loge("iccCloseLogicalChannel: Unknown exception");
881 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800882 request.result = (exception != null) ? exception :
883 new IllegalStateException(
884 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800885 }
886 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
889 case CMD_NV_READ_ITEM:
890 request = (MainThreadRequest) msg.obj;
891 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800892 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
893 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800894 break;
895
896 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700901 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800902 request.result = "";
903 if (ar.result == null) {
904 loge("nvReadItem: Empty response");
905 } else if (ar.exception instanceof CommandException) {
906 loge("nvReadItem: CommandException: " +
907 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700908 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800909 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700913 break;
914
Jake Hambye994d462014-02-03 13:10:13 -0800915 case CMD_NV_WRITE_ITEM:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
918 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700920 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800921 break;
922
923 case EVENT_NV_WRITE_ITEM_DONE:
924 handleNullReturnEvent(msg, "nvWriteItem");
925 break;
926
927 case CMD_NV_WRITE_CDMA_PRL:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800930 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800931 break;
932
933 case EVENT_NV_WRITE_CDMA_PRL_DONE:
934 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
935 break;
936
chen xu6dac5ab2018-10-26 17:39:23 -0700937 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800938 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700939 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800940 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800941 break;
942
chen xu6dac5ab2018-10-26 17:39:23 -0700943 case EVENT_RESET_MODEM_CONFIG_DONE:
944 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800945 break;
946
Sooraj Sasindran37444802020-08-11 10:40:43 -0700947 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
950 request);
951 Phone phone = getPhoneFromRequest(request);
952 if (phone != null) {
953 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
954 } else {
955 loge("isNRDualConnectivityEnabled: No phone object");
956 request.result = false;
957 notifyRequester(request);
958 }
959 break;
960 }
961
962 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null && ar.result != null) {
966 request.result = ar.result;
967 } else {
968 // request.result must be set to something non-null
969 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700970 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700971 request.result = ar.result;
972 } else {
973 request.result = false;
974 }
975 if (ar.result == null) {
976 loge("isNRDualConnectivityEnabled: Empty response");
977 } else if (ar.exception instanceof CommandException) {
978 loge("isNRDualConnectivityEnabled: CommandException: "
979 + ar.exception);
980 } else {
981 loge("isNRDualConnectivityEnabled: Unknown exception");
982 }
983 }
984 notifyRequester(request);
985 break;
986
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700987 case CMD_IS_VONR_ENABLED: {
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
990 request);
991 Phone phone = getPhoneFromRequest(request);
992 if (phone != null) {
993 phone.isVoNrEnabled(onCompleted, request.workSource);
994 } else {
995 loge("isVoNrEnabled: No phone object");
996 request.result = false;
997 notifyRequester(request);
998 }
999 break;
1000 }
1001
1002 case EVENT_IS_VONR_ENABLED_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 if (ar.exception == null && ar.result != null) {
1006 request.result = ar.result;
1007 } else {
1008 // request.result must be set to something non-null
1009 // for the calling thread to unblock
1010 if (ar.result != null) {
1011 request.result = ar.result;
1012 } else {
1013 request.result = false;
1014 }
1015 if (ar.result == null) {
1016 loge("isVoNrEnabled: Empty response");
1017 } else if (ar.exception instanceof CommandException) {
1018 loge("isVoNrEnabled: CommandException: "
1019 + ar.exception);
1020 } else {
1021 loge("isVoNrEnabled: Unknown exception");
1022 }
1023 }
1024 notifyRequester(request);
1025 break;
1026
Sooraj Sasindran37444802020-08-11 10:40:43 -07001027 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1030 Phone phone = getPhoneFromRequest(request);
1031 if (phone != null) {
1032 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1033 request.workSource);
1034 } else {
1035 loge("enableNrDualConnectivity: No phone object");
1036 request.result =
1037 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1038 notifyRequester(request);
1039 }
1040 break;
1041 }
1042
1043 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 if (ar.exception == null) {
1047 request.result =
1048 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1049 } else {
1050 request.result =
1051 TelephonyManager
1052 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1053 if (ar.exception instanceof CommandException) {
1054 CommandException.Error error =
1055 ((CommandException) (ar.exception)).getCommandError();
1056 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1057 request.result =
1058 TelephonyManager
1059 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001060 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1061 request.result =
1062 TelephonyManager
1063 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001064 }
1065 loge("enableNrDualConnectivity" + ": CommandException: "
1066 + ar.exception);
1067 } else {
1068 loge("enableNrDualConnectivity" + ": Unknown exception");
1069 }
1070 }
1071 notifyRequester(request);
1072 break;
1073 }
1074
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001075 case CMD_ENABLE_VONR: {
1076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1078 Phone phone = getPhoneFromRequest(request);
1079 if (phone != null) {
1080 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1081 request.workSource);
1082 } else {
1083 loge("setVoNrEnabled: No phone object");
1084 request.result =
1085 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1086 notifyRequester(request);
1087 }
1088 break;
1089 }
1090
1091 case EVENT_ENABLE_VONR_DONE: {
1092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null) {
1095 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1096 } else {
1097 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1098 if (ar.exception instanceof CommandException) {
1099 CommandException.Error error =
1100 ((CommandException) (ar.exception)).getCommandError();
1101 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1102 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1103 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1104 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1105 } else {
1106 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1107 }
1108 loge("setVoNrEnabled" + ": CommandException: "
1109 + ar.exception);
1110 } else {
1111 loge("setVoNrEnabled" + ": Unknown exception");
1112 }
1113 }
1114 notifyRequester(request);
1115 break;
1116 }
1117
SongFerngWang3ef3e072020-12-21 16:41:52 +08001118 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001120 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1121 request);
1122 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 break;
1124
SongFerngWang3ef3e072020-12-21 16:41:52 +08001125 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
1128 if (ar.exception == null && ar.result != null) {
1129 request.result = ar.result; // Integer
1130 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301131 // request.result must be set to something non-null
1132 // for the calling thread to unblock
1133 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001134 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 loge("getAllowedNetworkTypesBitmask: CommandException: "
1138 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 }
1142 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001143 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 break;
1145
SongFerngWang3ef3e072020-12-21 16:41:52 +08001146 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001147 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1149 request);
1150 Pair<Integer, Long> reasonWithNetworkTypes =
1151 (Pair<Integer, Long>) request.argument;
1152 getPhoneFromRequest(request).setAllowedNetworkTypes(
1153 reasonWithNetworkTypes.first,
1154 reasonWithNetworkTypes.second,
1155 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1159 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 break;
1161
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001162 case CMD_SET_VOICEMAIL_NUMBER:
1163 request = (MainThreadRequest) msg.obj;
1164 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1165 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001166 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1167 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001168 break;
1169
1170 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1171 handleNullReturnEvent(msg, "setVoicemailNumber");
1172 break;
1173
Stuart Scott54788802015-03-30 13:18:01 -07001174 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1175 request = (MainThreadRequest) msg.obj;
1176 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1177 request);
1178 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1179 break;
1180
1181 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1182 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1183 break;
1184
Shishir Agrawal302c8692015-06-19 13:49:39 -07001185 case CMD_PERFORM_NETWORK_SCAN:
1186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1188 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1189 break;
1190
Hall Liu27d24262020-09-18 19:04:59 -07001191 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001194 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1195 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1196 request.argument;
1197 int callForwardingReason = args.first;
1198 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001199 break;
Hall Liu27d24262020-09-18 19:04:59 -07001200 }
1201 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001202 ar = (AsyncResult) msg.obj;
1203 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001204 TelephonyManager.CallForwardingInfoCallback callback =
1205 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1206 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001208 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001209 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1210 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1211 // Service Class is a bit mask per 3gpp 27.007. Search for
1212 // any service for voice call.
1213 if ((callForwardInfo.serviceClass
1214 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001215 callForwardingInfo = new CallForwardingInfo(
1216 callForwardInfo.status
1217 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001218 callForwardInfo.reason,
1219 callForwardInfo.number,
1220 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001221 break;
1222 }
1223 }
1224 // Didn't find a call forward info for voice call.
1225 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001226 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1227 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001228 }
Hall Liu27d24262020-09-18 19:04:59 -07001229 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001230 } else {
1231 if (ar.result == null) {
1232 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1233 }
1234 if (ar.exception != null) {
1235 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1236 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 int errorCode = TelephonyManager
1238 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001239 if (ar.exception instanceof CommandException) {
1240 CommandException.Error error =
1241 ((CommandException) (ar.exception)).getCommandError();
1242 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001243 errorCode = TelephonyManager
1244 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001245 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 errorCode = TelephonyManager
1247 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001248 }
1249 }
Hall Liu27d24262020-09-18 19:04:59 -07001250 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252 break;
Hall Liu27d24262020-09-18 19:04:59 -07001253 }
Shuo Qian4a594052020-01-23 11:59:30 -08001254
Hall Liu27d24262020-09-18 19:04:59 -07001255 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001256 request = (MainThreadRequest) msg.obj;
1257 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001258 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001259 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001260 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1261 request.argument).first;
1262 request.phone.setCallForwardingOption(
1263 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001264 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001265 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001266 callForwardingInfoToSet.getReason(),
1267 callForwardingInfoToSet.getNumber(),
1268 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1269 break;
Hall Liu27d24262020-09-18 19:04:59 -07001270 }
Shuo Qian4a594052020-01-23 11:59:30 -08001271
Hall Liu27d24262020-09-18 19:04:59 -07001272 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001273 ar = (AsyncResult) msg.obj;
1274 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001275 Consumer<Integer> callback =
1276 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1277 request.argument).second;
1278 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001279 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001280 int errorCode = TelephonyManager.CallForwardingInfoCallback
1281 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001282 if (ar.exception instanceof CommandException) {
1283 CommandException.Error error =
1284 ((CommandException) (ar.exception)).getCommandError();
1285 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001286 errorCode = TelephonyManager.CallForwardingInfoCallback
1287 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001288 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001289 errorCode = TelephonyManager.CallForwardingInfoCallback
1290 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001291 }
1292 }
1293 callback.accept(errorCode);
1294 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001295 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001296 }
Shuo Qian4a594052020-01-23 11:59:30 -08001297 break;
Hall Liu27d24262020-09-18 19:04:59 -07001298 }
Shuo Qian4a594052020-01-23 11:59:30 -08001299
Hall Liu27d24262020-09-18 19:04:59 -07001300 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 request = (MainThreadRequest) msg.obj;
1302 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1303 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001310 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001311 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001312 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001313 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001314 // Service Class is a bit mask per 3gpp 27.007.
1315 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001316 if (callForwardResults.length > 1
1317 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001318 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001319 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001320 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1321 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001322 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001323 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001324 }
1325 } else {
1326 if (ar.result == null) {
1327 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1328 }
1329 if (ar.exception != null) {
1330 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1331 }
1332 if (ar.exception instanceof CommandException) {
1333 CommandException.Error error =
1334 ((CommandException) (ar.exception)).getCommandError();
1335 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001337 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1339 callWaitingStatus =
1340 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001341 }
1342 }
1343 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001344 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001345 break;
Hall Liu27d24262020-09-18 19:04:59 -07001346 }
Shuo Qian4a594052020-01-23 11:59:30 -08001347
Hall Liu27d24262020-09-18 19:04:59 -07001348 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001349 request = (MainThreadRequest) msg.obj;
1350 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001351 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1352 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001353 break;
Hall Liu27d24262020-09-18 19:04:59 -07001354 }
Shuo Qian4a594052020-01-23 11:59:30 -08001355
Hall Liu27d24262020-09-18 19:04:59 -07001356 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001357 ar = (AsyncResult) msg.obj;
1358 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001359 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1360 Consumer<Integer> callback =
1361 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1362 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001363 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001364 if (ar.exception instanceof CommandException) {
1365 CommandException.Error error =
1366 ((CommandException) (ar.exception)).getCommandError();
1367 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1368 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001369 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1370 callback.accept(
1371 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001372 } else {
1373 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1374 }
1375 } else {
1376 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1377 }
1378 } else {
1379 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1380 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001381 }
Shuo Qian4a594052020-01-23 11:59:30 -08001382 break;
Hall Liu27d24262020-09-18 19:04:59 -07001383 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001384 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 CellNetworkScanResult cellScanResult;
1388 if (ar.exception == null && ar.result != null) {
1389 cellScanResult = new CellNetworkScanResult(
1390 CellNetworkScanResult.STATUS_SUCCESS,
1391 (List<OperatorInfo>) ar.result);
1392 } else {
1393 if (ar.result == null) {
1394 loge("getCellNetworkScanResults: Empty response");
1395 }
1396 if (ar.exception != null) {
1397 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1398 }
1399 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1400 if (ar.exception instanceof CommandException) {
1401 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001402 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1404 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1405 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1406 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1407 }
1408 }
1409 cellScanResult = new CellNetworkScanResult(errorCode, null);
1410 }
1411 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001412 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001413 break;
1414
1415 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1416 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001417 ManualNetworkSelectionArgument selArg =
1418 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001419 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1420 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001421 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1422 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001423 break;
1424
1425 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 if (ar.exception == null) {
1429 request.result = true;
1430 } else {
1431 request.result = false;
1432 loge("setNetworkSelectionModeManual " + ar.exception);
1433 }
1434 notifyRequester(request);
1435 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 break;
1437
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001438 case CMD_GET_MODEM_ACTIVITY_INFO:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001441 if (defaultPhone != null) {
1442 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001443 } else {
1444 ResultReceiver result = (ResultReceiver) request.argument;
1445 Bundle bundle = new Bundle();
1446 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001447 new ModemActivityInfo(0, 0, 0,
1448 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001449 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001450 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 break;
1452
Hall Liud0f208c2020-10-14 16:54:44 -07001453 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001456 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001457 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001458 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001459 if (mLastModemActivityInfo == null) {
1460 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1461 mLastModemActivitySpecificInfo[0] =
1462 new ActivityStatsTechSpecificInfo(
1463 0,
1464 0,
1465 new int[ModemActivityInfo.getNumTxPowerLevels()],
1466 0);
1467 mLastModemActivityInfo =
1468 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1469 }
1470
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001472 // Update the last modem activity info and the result of the request.
1473 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1474 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001475 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001476 } else {
1477 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 }
Kai Shi917fdc62022-11-28 14:01:02 -08001479 // This is needed to decouple ret from mLastModemActivityInfo
1480 // We don't want to return mLastModemActivityInfo which is updated
1481 // inside mergeModemActivityInfo()
1482 ret = new ModemActivityInfo(
1483 mLastModemActivityInfo.getTimestampMillis(),
1484 mLastModemActivityInfo.getSleepTimeMillis(),
1485 mLastModemActivityInfo.getIdleTimeMillis(),
1486 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001487
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 } else {
1489 if (ar.result == null) {
1490 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001491 error = TelephonyManager.ModemActivityInfoException
1492 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001494 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001495 error = TelephonyManager.ModemActivityInfoException
1496 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 } else {
1498 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001499 error = TelephonyManager.ModemActivityInfoException
1500 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001501 }
1502 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001503 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001504 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001505 bundle.putParcelable(
1506 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001507 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001508 } else {
1509 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1510 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001511 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001512 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001513 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001514 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001516 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001517 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001518 CarrierRestrictionRules argument =
1519 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001520 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001521 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001522 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001523 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524
1525 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 if (ar.exception == null && ar.result != null) {
1529 request.result = ar.result;
1530 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001531 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1532 if (ar.exception instanceof CommandException) {
1533 loge("setAllowedCarriers: CommandException: " + ar.exception);
1534 CommandException.Error error =
1535 ((CommandException) (ar.exception)).getCommandError();
1536 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1537 request.result =
1538 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1539 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 } else {
1541 loge("setAllowedCarriers: Unknown exception");
1542 }
1543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
1546
1547 case CMD_GET_ALLOWED_CARRIERS:
1548 request = (MainThreadRequest) msg.obj;
1549 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001550 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001551 break;
1552
1553 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1554 ar = (AsyncResult) msg.obj;
1555 request = (MainThreadRequest) ar.userObj;
1556 if (ar.exception == null && ar.result != null) {
1557 request.result = ar.result;
1558 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001559 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001560 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001561 if (ar.result == null) {
1562 loge("getAllowedCarriers: Empty response");
1563 } else if (ar.exception instanceof CommandException) {
1564 loge("getAllowedCarriers: CommandException: " +
1565 ar.exception);
1566 } else {
1567 loge("getAllowedCarriers: Unknown exception");
1568 }
1569 }
arunvoddud7401012022-12-15 16:08:12 +00001570 if (request.argument != null) {
1571 // This is for the implementation of carrierRestrictionStatus.
1572 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1573 Consumer<Integer> callback = callbackInfo.getConsumer();
1574 int callerCarrierId = callbackInfo.getCarrierId();
1575 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1576 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1577 CarrierRestrictionRules carrierRestrictionRules =
1578 (CarrierRestrictionRules) ar.result;
1579 int carrierId = -1;
1580 try {
1581 CarrierIdentifier carrierIdentifier =
1582 carrierRestrictionRules.getAllowedCarriers().get(0);
1583 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1584 carrierIdentifier);
1585 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1586 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1587 }
1588 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1589 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1590 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001591 lockStatus = TelephonyManager
1592 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001593 }
1594 } else {
1595 Rlog.e(LOG_TAG,
1596 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1597 }
1598 callback.accept(lockStatus);
1599 } else {
1600 // This is for the implementation of getAllowedCarriers.
1601 notifyRequester(request);
1602 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001603 break;
1604
Nathan Haroldb3014052017-01-25 15:57:32 -08001605 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1606 ar = (AsyncResult) msg.obj;
1607 request = (MainThreadRequest) ar.userObj;
1608 if (ar.exception == null && ar.result != null) {
1609 request.result = ar.result;
1610 } else {
1611 request.result = new IllegalArgumentException(
1612 "Failed to retrieve Forbidden Plmns");
1613 if (ar.result == null) {
1614 loge("getForbiddenPlmns: Empty response");
1615 } else {
1616 loge("getForbiddenPlmns: Unknown exception");
1617 }
1618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001619 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001620 break;
1621
1622 case CMD_GET_FORBIDDEN_PLMNS:
1623 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001624 uiccPort = getUiccPortFromRequest(request);
1625 if (uiccPort == null) {
1626 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001627 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001628 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001629 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001630 break;
1631 }
1632 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001633 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001634 if (uiccApp == null) {
1635 loge("getForbiddenPlmns() no app with specified type -- "
1636 + appType);
1637 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 break;
1640 } else {
1641 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1642 + " specified type -- " + appType);
1643 }
1644 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1645 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001646 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 break;
1648
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001649 case CMD_SWITCH_SLOTS:
1650 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001651 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001652 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001653 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001654 break;
1655
1656 case EVENT_SWITCH_SLOTS_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
1659 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001660 notifyRequester(request);
1661 break;
1662 case CMD_GET_NETWORK_SELECTION_MODE:
1663 request = (MainThreadRequest) msg.obj;
1664 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1665 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1666 break;
1667
1668 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1669 ar = (AsyncResult) msg.obj;
1670 request = (MainThreadRequest) ar.userObj;
1671 if (ar.exception != null) {
1672 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1673 } else {
1674 int mode = ((int[]) ar.result)[0];
1675 if (mode == 0) {
1676 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1677 } else {
1678 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1679 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001680 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001681 notifyRequester(request);
1682 break;
1683 case CMD_GET_CDMA_ROAMING_MODE:
1684 request = (MainThreadRequest) msg.obj;
1685 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1686 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1687 break;
1688 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1689 ar = (AsyncResult) msg.obj;
1690 request = (MainThreadRequest) ar.userObj;
1691 if (ar.exception != null) {
1692 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1693 } else {
1694 request.result = ((int[]) ar.result)[0];
1695 }
1696 notifyRequester(request);
1697 break;
1698 case CMD_SET_CDMA_ROAMING_MODE:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1701 int mode = (int) request.argument;
1702 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1703 break;
1704 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 request.result = ar.exception == null;
1708 notifyRequester(request);
1709 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001710 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1711 request = (MainThreadRequest) msg.obj;
1712 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1713 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1714 break;
1715 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1716 ar = (AsyncResult) msg.obj;
1717 request = (MainThreadRequest) ar.userObj;
1718 if (ar.exception != null) {
1719 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1720 } else {
1721 request.result = ((int[]) ar.result)[0];
1722 }
1723 notifyRequester(request);
1724 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001725 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1728 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001729 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1730 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001731 break;
1732 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 request.result = ar.exception == null;
1736 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001737 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 case CMD_GET_ALL_CELL_INFO:
1739 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001740 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001741 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001742 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001743 case EVENT_GET_ALL_CELL_INFO_DONE:
1744 ar = (AsyncResult) msg.obj;
1745 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001746 // If a timeout occurs, the response will be null
1747 request.result = (ar.exception == null && ar.result != null)
1748 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001749 synchronized (request) {
1750 request.notifyAll();
1751 }
1752 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001753 case CMD_REQUEST_CELL_INFO_UPDATE:
1754 request = (MainThreadRequest) msg.obj;
1755 request.phone.requestCellInfoUpdate(request.workSource,
1756 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1757 break;
1758 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1759 ar = (AsyncResult) msg.obj;
1760 request = (MainThreadRequest) ar.userObj;
1761 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1762 try {
1763 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001764 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001765 cb.onError(
1766 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1767 ar.exception.getClass().getName(),
1768 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001769 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001770 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001771 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001772 } else {
1773 // use the result as returned
1774 cb.onCellInfo((List<CellInfo>) ar.result);
1775 }
1776 } catch (RemoteException re) {
1777 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1778 }
1779 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001780 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001781 request = (MainThreadRequest) msg.obj;
1782 WorkSource ws = (WorkSource) request.argument;
1783 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001784 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001785 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001786 }
1787 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
1790 if (ar.exception == null) {
1791 request.result = ar.result;
1792 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001793 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001794 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001795 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001796 }
1797
1798 synchronized (request) {
1799 request.notifyAll();
1800 }
1801 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001802 }
chen xu6dac5ab2018-10-26 17:39:23 -07001803 case CMD_MODEM_REBOOT:
1804 request = (MainThreadRequest) msg.obj;
1805 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001806 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001807 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001808 case EVENT_CMD_MODEM_REBOOT_DONE:
1809 handleNullReturnEvent(msg, "rebootModem");
1810 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001811 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001812 request = (MainThreadRequest) msg.obj;
1813 boolean enable = (boolean) request.argument;
1814 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001815 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001816 PhoneConfigurationManager.getInstance()
1817 .enablePhone(request.phone, enable, onCompleted);
1818 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001819 }
Michele Berionne5e411512020-11-13 02:36:59 +00001820 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001821 ar = (AsyncResult) msg.obj;
1822 request = (MainThreadRequest) ar.userObj;
1823 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001824 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001825 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001826 if ((boolean) request.result) {
1827 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1828 updateModemStateMetrics();
1829 } else {
1830 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1831 + ar.exception);
1832 }
1833 notifyRequester(request);
1834 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001835 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001836 case CMD_GET_MODEM_STATUS:
1837 request = (MainThreadRequest) msg.obj;
1838 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1839 PhoneConfigurationManager.getInstance()
1840 .getPhoneStatusFromModem(request.phone, onCompleted);
1841 break;
1842 case EVENT_GET_MODEM_STATUS_DONE:
1843 ar = (AsyncResult) msg.obj;
1844 request = (MainThreadRequest) ar.userObj;
1845 int id = request.phone.getPhoneId();
1846 if (ar.exception == null && ar.result != null) {
1847 request.result = ar.result;
1848 //update the cache as modem status has changed
1849 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1850 (boolean) request.result);
1851 } else {
1852 // Return true if modem status cannot be retrieved. For most cases,
1853 // modem status is on. And for older version modems, GET_MODEM_STATUS
1854 // and disable modem are not supported. Modem is always on.
1855 // TODO: this should be fixed in R to support a third
1856 // status UNKNOWN b/131631629
1857 request.result = true;
1858 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1859 + ar.exception);
1860 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001861 notifyRequester(request);
1862 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001863 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1864 request = (MainThreadRequest) msg.obj;
1865 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1866 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1867 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1868 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1869 break;
1870 }
1871 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1872 ar = (AsyncResult) msg.obj;
1873 request = (MainThreadRequest) ar.userObj;
1874 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1875 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1876 args.second.accept(ar.exception == null);
1877 notifyRequester(request);
1878 break;
1879 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001880 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1883 Phone phone = getPhoneFromRequest(request);
1884 if (phone != null) {
1885 phone.getSystemSelectionChannels(onCompleted);
1886 } else {
1887 loge("getSystemSelectionChannels: No phone object");
1888 request.result = new ArrayList<RadioAccessSpecifier>();
1889 notifyRequester(request);
1890 }
1891 break;
1892 }
1893 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1894 ar = (AsyncResult) msg.obj;
1895 request = (MainThreadRequest) ar.userObj;
1896 if (ar.exception == null && ar.result != null) {
1897 request.result = ar.result;
1898 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001899 request.result = new IllegalStateException(
1900 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001901 if (ar.result == null) {
1902 loge("getSystemSelectionChannels: Empty response");
1903 } else {
1904 loge("getSystemSelectionChannels: Unknown exception");
1905 }
1906 }
1907 notifyRequester(request);
1908 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001909 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912 if (ar.exception == null && ar.result != null) {
1913 request.result = ar.result;
1914 } else {
1915 request.result = -1;
1916 loge("Failed to set Forbidden Plmns");
1917 if (ar.result == null) {
1918 loge("setForbidenPlmns: Empty response");
1919 } else if (ar.exception != null) {
1920 loge("setForbiddenPlmns: Exception: " + ar.exception);
1921 request.result = -1;
1922 } else {
1923 loge("setForbiddenPlmns: Unknown exception");
1924 }
1925 }
1926 notifyRequester(request);
1927 break;
1928 case CMD_SET_FORBIDDEN_PLMNS:
1929 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001930 uiccPort = getUiccPortFromRequest(request);
1931 if (uiccPort == null) {
1932 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001933 request.result = -1;
1934 notifyRequester(request);
1935 break;
1936 }
1937 Pair<Integer, List<String>> setFplmnsArgs =
1938 (Pair<Integer, List<String>>) request.argument;
1939 appType = setFplmnsArgs.first;
1940 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001941 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001942 if (uiccApp == null) {
1943 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1944 request.result = -1;
1945 loge("Failed to get UICC App");
1946 notifyRequester(request);
1947 } else {
1948 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1949 ((SIMRecords) uiccApp.getIccRecords())
1950 .setForbiddenPlmns(onCompleted, fplmns);
1951 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001952 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001953 case CMD_ERASE_MODEM_CONFIG:
1954 request = (MainThreadRequest) msg.obj;
1955 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1956 defaultPhone.eraseModemConfig(onCompleted);
1957 break;
1958 case EVENT_ERASE_MODEM_CONFIG_DONE:
1959 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001960 break;
zoey chene02881a2019-12-30 16:11:23 +08001961
Kai Shif70f46f2021-03-03 13:59:46 -08001962 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1963 request = (MainThreadRequest) msg.obj;
1964 request.result = defaultPhone.eraseDataInSharedPreferences();
1965 notifyRequester(request);
1966 break;
1967
zoey chene02881a2019-12-30 16:11:23 +08001968 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1969 request = (MainThreadRequest) msg.obj;
1970 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1971 Pair<String, String> changed = (Pair<String, String>) request.argument;
1972 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1973 changed.first, changed.second, onCompleted);
1974 break;
1975 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1976 ar = (AsyncResult) msg.obj;
1977 request = (MainThreadRequest) ar.userObj;
1978 if (ar.exception == null) {
1979 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001980 // If the operation is successful, update the PIN storage
1981 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1982 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001983 UiccController.getInstance().getPinStorage()
1984 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001985 } else {
1986 request.result = msg.arg1;
1987 }
1988 notifyRequester(request);
1989 break;
1990
Michele Berionne5e411512020-11-13 02:36:59 +00001991 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001992 request = (MainThreadRequest) msg.obj;
1993 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1994 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1995 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1996 enabled.first, enabled.second, onCompleted);
1997 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001998 }
zoey chene02881a2019-12-30 16:11:23 +08001999 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 if (ar.exception == null) {
2003 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002004 // If the operation is successful, update the PIN storage
2005 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2006 int phoneId = getPhoneFromRequest(request).getPhoneId();
2007 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002008 UiccController.getInstance().getPinStorage()
2009 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002010 } else {
2011 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2012 }
zoey chene02881a2019-12-30 16:11:23 +08002013 } else {
2014 request.result = msg.arg1;
2015 }
Michele Berionne5e411512020-11-13 02:36:59 +00002016
2017
zoey chene02881a2019-12-30 16:11:23 +08002018 notifyRequester(request);
2019 break;
2020
Peter Wangdafb9ac2020-01-15 14:13:38 -08002021 case MSG_NOTIFY_USER_ACTIVITY:
2022 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002023 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002024 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2025 getDefaultPhone().getContext().sendBroadcastAsUser(
2026 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2027 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002028
2029 case CMD_SET_DATA_THROTTLING: {
2030 request = (MainThreadRequest) msg.obj;
2031 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2032 DataThrottlingRequest dataThrottlingRequest =
2033 (DataThrottlingRequest) request.argument;
2034 Phone phone = getPhoneFromRequest(request);
2035 if (phone != null) {
2036 phone.setDataThrottling(onCompleted,
2037 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2038 dataThrottlingRequest.getCompletionDurationMillis());
2039 } else {
2040 loge("setDataThrottling: No phone object");
2041 request.result =
2042 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2043 notifyRequester(request);
2044 }
2045
2046 break;
2047 }
2048 case EVENT_SET_DATA_THROTTLING_DONE:
2049 ar = (AsyncResult) msg.obj;
2050 request = (MainThreadRequest) ar.userObj;
2051
2052 if (ar.exception == null) {
2053 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2054 } else if (ar.exception instanceof CommandException) {
2055 loge("setDataThrottling: CommandException: " + ar.exception);
2056 CommandException.Error error =
2057 ((CommandException) (ar.exception)).getCommandError();
2058
2059 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2060 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002061 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002062 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2063 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002064 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2065 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002066 } else {
2067 request.result =
2068 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2069 }
2070 } else {
2071 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2072 }
2073 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2074 notifyRequester(request);
2075 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002076
2077 case CMD_SET_SIM_POWER: {
2078 request = (MainThreadRequest) msg.obj;
2079 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2080 request = (MainThreadRequest) msg.obj;
2081 int stateToSet =
2082 ((Pair<Integer, IIntegerConsumer>)
2083 request.argument).first;
2084 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2085 break;
2086 }
2087 case EVENT_SET_SIM_POWER_DONE: {
2088 ar = (AsyncResult) msg.obj;
2089 request = (MainThreadRequest) ar.userObj;
2090 IIntegerConsumer callback =
2091 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2092 if (ar.exception != null) {
2093 loge("setSimPower exception: " + ar.exception);
2094 int errorCode = TelephonyManager.CallForwardingInfoCallback
2095 .RESULT_ERROR_UNKNOWN;
2096 if (ar.exception instanceof CommandException) {
2097 CommandException.Error error =
2098 ((CommandException) (ar.exception)).getCommandError();
2099 if (error == CommandException.Error.SIM_ERR) {
2100 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2101 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2102 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2103 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2104 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2105 } else {
2106 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2107 }
2108 }
2109 try {
2110 callback.accept(errorCode);
2111 } catch (RemoteException e) {
2112 // Ignore if the remote process is no longer available to call back.
2113 Log.w(LOG_TAG, "setSimPower: callback not available.");
2114 }
2115 } else {
2116 try {
2117 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2118 } catch (RemoteException e) {
2119 // Ignore if the remote process is no longer available to call back.
2120 Log.w(LOG_TAG, "setSimPower: callback not available.");
2121 }
2122 }
2123 break;
2124 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002125 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2126 request = (MainThreadRequest) msg.obj;
2127
2128 final Phone phone = getPhoneFromRequest(request);
2129 if (phone == null || phone.getServiceStateTracker() == null) {
2130 request.result = new IllegalStateException("Phone or SST is null");
2131 notifyRequester(request);
2132 break;
2133 }
2134
2135 Pair<Integer, SignalStrengthUpdateRequest> pair =
2136 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2137 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2138 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002139 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002140 request.subId, pair.first /*callingUid*/,
2141 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002142 break;
2143 }
2144 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2145 ar = (AsyncResult) msg.obj;
2146 request = (MainThreadRequest) ar.userObj;
2147 // request.result will be the exception of ar if present, true otherwise.
2148 // Be cautious not to leave result null which will wait() forever
2149 request.result = ar.exception != null ? ar.exception : true;
2150 notifyRequester(request);
2151 break;
2152 }
2153 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2154 request = (MainThreadRequest) msg.obj;
2155
2156 Phone phone = getPhoneFromRequest(request);
2157 if (phone == null || phone.getServiceStateTracker() == null) {
2158 request.result = new IllegalStateException("Phone or SST is null");
2159 notifyRequester(request);
2160 break;
2161 }
2162
2163 Pair<Integer, SignalStrengthUpdateRequest> pair =
2164 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2165 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2166 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002167 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002168 request.subId, pair.first /*callingUid*/,
2169 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002170 break;
2171 }
2172 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2173 ar = (AsyncResult) msg.obj;
2174 request = (MainThreadRequest) ar.userObj;
2175 request.result = ar.exception != null ? ar.exception : true;
2176 notifyRequester(request);
2177 break;
2178 }
Jordan Liu109698e2020-11-24 14:50:34 -08002179
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002180 case CMD_GET_SLICING_CONFIG: {
2181 request = (MainThreadRequest) msg.obj;
2182 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2183 request.phone.getSlicingConfig(onCompleted);
2184 break;
2185 }
2186 case EVENT_GET_SLICING_CONFIG_DONE: {
2187 ar = (AsyncResult) msg.obj;
2188 request = (MainThreadRequest) ar.userObj;
2189 ResultReceiver result = (ResultReceiver) request.argument;
2190
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002191 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002192 Bundle bundle = new Bundle();
2193 int resultCode = 0;
2194 if (ar.exception != null) {
2195 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2196 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002197 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002198 } else if (ar.result == null) {
2199 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002200 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002201 } else {
2202 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002203 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2204 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 }
2206
2207 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002208 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 }
2210 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2211 result.send(resultCode, bundle);
2212 notifyRequester(request);
2213 break;
2214 }
2215
Sarah Chin71b3a852022-09-28 15:54:19 -07002216 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002217 request = (MainThreadRequest) msg.obj;
2218 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002219 PurchasePremiumCapabilityArgument arg =
2220 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002221 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2222 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002223 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002224 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002225
Sarah Chin71b3a852022-09-28 15:54:19 -07002226 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002227 ar = (AsyncResult) msg.obj;
2228 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002229 PurchasePremiumCapabilityArgument arg =
2230 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002231 try {
2232 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002236 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002237 + TelephonyManager.convertPurchaseResultToString(result));
2238 } catch (RemoteException e) {
2239 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 + " failed: " + e;
2242 if (DBG) log(logStr);
2243 AnomalyReporter.reportAnomaly(
2244 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2245 }
2246 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002247 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248
Michele Berionne5e411512020-11-13 02:36:59 +00002249 case CMD_PREPARE_UNATTENDED_REBOOT:
2250 request = (MainThreadRequest) msg.obj;
2251 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002252 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002253 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002254 notifyRequester(request);
2255 break;
2256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 default:
2258 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2259 break;
2260 }
2261 }
Jake Hambye994d462014-02-03 13:10:13 -08002262
Pengquan Menga1bb6272018-09-06 09:59:22 -07002263 private void notifyRequester(MainThreadRequest request) {
2264 synchronized (request) {
2265 request.notifyAll();
2266 }
2267 }
2268
Jake Hambye994d462014-02-03 13:10:13 -08002269 private void handleNullReturnEvent(Message msg, String command) {
2270 AsyncResult ar = (AsyncResult) msg.obj;
2271 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2272 if (ar.exception == null) {
2273 request.result = true;
2274 } else {
2275 request.result = false;
2276 if (ar.exception instanceof CommandException) {
2277 loge(command + ": CommandException: " + ar.exception);
2278 } else {
2279 loge(command + ": Unknown exception");
2280 }
2281 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002282 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285
2286 /**
2287 * Posts the specified command to be executed on the main thread,
2288 * waits for the request to complete, and returns the result.
2289 * @see #sendRequestAsync
2290 */
2291 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002292 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2293 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002294 }
2295
2296 /**
2297 * Posts the specified command to be executed on the main thread,
2298 * waits for the request to complete, and returns the result.
2299 * @see #sendRequestAsync
2300 */
2301 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2302 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002303 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
2306 /**
2307 * Posts the specified command to be executed on the main thread,
2308 * waits for the request to complete, and returns the result.
2309 * @see #sendRequestAsync
2310 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002311 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2313 }
2314
2315 /**
2316 * Posts the specified command to be executed on the main thread,
2317 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2318 * if not timeout or null otherwise.
2319 * @see #sendRequestAsync
2320 */
2321 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2322 long timeoutInMs) {
2323 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002324 }
2325
2326 /**
2327 * Posts the specified command to be executed on the main thread,
2328 * waits for the request to complete, and returns the result.
2329 * @see #sendRequestAsync
2330 */
Nathan Harold92bed182018-10-12 18:16:49 -07002331 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002332 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete, and returns the result.
2338 * @see #sendRequestAsync
2339 */
2340 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002341 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2342 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002343 }
2344
2345 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002346 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2347 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2348 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002349 * @see #sendRequestAsync
2350 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002351 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2352 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2354 throw new RuntimeException("This method will deadlock if called from the main thread.");
2355 }
2356
Nathan Harold92bed182018-10-12 18:16:49 -07002357 MainThreadRequest request = null;
2358 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2359 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2360 } else if (phone != null) {
2361 request = new MainThreadRequest(argument, phone, workSource);
2362 } else {
2363 request = new MainThreadRequest(argument, subId, workSource);
2364 }
2365
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 Message msg = mMainThreadHandler.obtainMessage(command, request);
2367 msg.sendToTarget();
2368
Rambo Wang0f050d82021-02-12 11:43:36 -08002369
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 if (timeoutInMs >= 0) {
2372 // Wait for at least timeoutInMs before returning null request result
2373 long now = SystemClock.elapsedRealtime();
2374 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002375 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002376 try {
2377 request.wait(deadline - now);
2378 } catch (InterruptedException e) {
2379 // Do nothing, go back and check if request is completed or timeout
2380 } finally {
2381 now = SystemClock.elapsedRealtime();
2382 }
2383 }
2384 } else {
2385 // Wait for the request to complete
2386 while (request.result == null) {
2387 try {
2388 request.wait();
2389 } catch (InterruptedException e) {
2390 // Do nothing, go back and wait until the request is complete
2391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 }
2393 }
2394 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002395 if (request.result == null) {
2396 Log.wtf(LOG_TAG,
2397 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 return request.result;
2400 }
2401
2402 /**
2403 * Asynchronous ("fire and forget") version of sendRequest():
2404 * Posts the specified command to be executed on the main thread, and
2405 * returns immediately.
2406 * @see #sendRequest
2407 */
2408 private void sendRequestAsync(int command) {
2409 mMainThreadHandler.sendEmptyMessage(command);
2410 }
2411
2412 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002413 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002414 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002415 */
2416 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002417 sendRequestAsync(command, argument, null, null);
2418 }
2419
2420 /**
2421 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2422 * @see {@link #sendRequest(int,Object)}
2423 */
2424 private void sendRequestAsync(
2425 int command, Object argument, Phone phone, WorkSource workSource) {
2426 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002427 Message msg = mMainThreadHandler.obtainMessage(command, request);
2428 msg.sendToTarget();
2429 }
2430
2431 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 * Initialize the singleton PhoneInterfaceManager instance.
2433 * This is only done once, at startup, from PhoneApp.onCreate().
2434 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002435 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 synchronized (PhoneInterfaceManager.class) {
2437 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002438 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 } else {
2440 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2441 }
2442 return sInstance;
2443 }
2444 }
2445
2446 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002447 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002449 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002451 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002452 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002453 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2455 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002456 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002457 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002458 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002459 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002460 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002461 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 publish();
arunvoddud7401012022-12-15 16:08:12 +00002463 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002466 @VisibleForTesting
2467 public SharedPreferences getSharedPreferences() {
2468 return mTelephonySharedPreferences;
2469 }
2470
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002471 /**
2472 * Get the default phone for this device.
2473 */
2474 @VisibleForTesting
2475 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002476 Phone thePhone = getPhone(getDefaultSubscription());
2477 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2478 }
2479
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 private void publish() {
2481 if (DBG) log("publish: " + this);
2482
Peter Wangc035ce42020-01-08 21:00:22 -08002483 TelephonyFrameworkInitializer
2484 .getTelephonyServiceManager()
2485 .getTelephonyServiceRegisterer()
2486 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
Stuart Scott584921c2015-01-15 17:10:34 -08002489 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002490 if (request.phone != null) {
2491 return request.phone;
2492 } else {
2493 return getPhoneFromSubId(request.subId);
2494 }
2495 }
2496
2497 private Phone getPhoneFromSubId(int subId) {
2498 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2499 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002500 }
2501
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002502 /**
2503 * Get phone object associated with a subscription.
2504 * Return default phone if phone object associated with subscription is null
2505 * @param subId - subscriptionId
2506 * @return phone object associated with a subscription or default phone if null.
2507 */
Ling Mac28f0212023-03-24 16:07:15 -07002508 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002509 Phone phone = getPhoneFromSubId(subId);
2510 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002511 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002512 phone = getDefaultPhone();
2513 }
2514 return phone;
2515 }
2516
Rambo Wange53e07d2022-05-10 13:01:13 -07002517 @Nullable
2518 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 Phone phone = getPhoneFromRequest(request);
2520 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002521 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002522 }
2523
Ling Mac28f0212023-03-24 16:07:15 -07002524 /**
2525 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2526 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2527 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2528 * @return The Phone associated the sub Id
2529 */
2530 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002531 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533
Kai Shif70f46f2021-03-03 13:59:46 -08002534 private void sendEraseModemConfig(@NonNull Phone phone) {
2535 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2536 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2537 }
2538
2539 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2540 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2541 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002542 }
2543
Peter Wang44b186e2020-01-13 23:33:09 -08002544 private boolean isImsAvailableOnDevice() {
2545 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2546 if (pm == null) {
2547 // For some reason package manger is not available.. This will fail internally anyway,
2548 // so do not throw error and allow.
2549 return true;
2550 }
2551 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2552 }
2553
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002555 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002556 }
2557
Wink Savilleb564aae2014-10-23 10:18:09 -07002558 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 if (DBG) log("dial: " + number);
2560 // No permission check needed here: This is just a wrapper around the
2561 // ACTION_DIAL intent, which is available to any app since it puts up
2562 // the UI before it does anything.
2563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 String url = createTelUrl(number);
2567 if (url == null) {
2568 return;
2569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571 // PENDING: should we just silently fail if phone is offhook or ringing?
2572 PhoneConstants.State state = mCM.getState(subId);
2573 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2574 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2575 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2576 mApp.startActivity(intent);
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 }
2581 }
2582
2583 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002584 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002585 }
2586
Wink Savilleb564aae2014-10-23 10:18:09 -07002587 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 if (DBG) log("call: " + number);
2589
2590 // This is just a wrapper around the ACTION_CALL intent, but we still
2591 // need to do a permission check since we're calling startActivity()
2592 // from the context of the phone app.
2593 enforceCallPermission();
2594
Jordan Liu1617b712019-07-10 15:06:26 -07002595 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 != AppOpsManager.MODE_ALLOWED) {
2597 return;
2598 }
2599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 String url = createTelUrl(number);
2603 if (url == null) {
2604 return;
2605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 boolean isValid = false;
2608 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2609 if (slist != null) {
2610 for (SubscriptionInfo subInfoRecord : slist) {
2611 if (subInfoRecord.getSubscriptionId() == subId) {
2612 isValid = true;
2613 break;
2614 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002615 }
Wink Saville08874612014-08-31 19:19:58 -07002616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 if (!isValid) {
2618 return;
2619 }
Wink Saville08874612014-08-31 19:19:58 -07002620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2622 intent.putExtra(SUBSCRIPTION_KEY, subId);
2623 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2624 mApp.startActivity(intent);
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629
Wink Savilleb564aae2014-10-23 10:18:09 -07002630 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002631 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002632 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2633 }
2634
Wink Savilleb564aae2014-10-23 10:18:09 -07002635 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002636 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002637 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2638 }
2639
Wink Savilleb564aae2014-10-23 10:18:09 -07002640 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002645 Phone phone = getPhone(subId);
2646 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 checkSimPin.start();
2648 return checkSimPin.unlockSim(null, pin);
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
2651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653
Wink Savilleb564aae2014-10-23 10:18:09 -07002654 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002659 Phone phone = getPhone(subId);
2660 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 checkSimPuk.start();
2662 return checkSimPuk.unlockSim(puk, pin);
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
2668 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002669 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 * a synchronous one.
2671 */
2672 private static class UnlockSim extends Thread {
2673
2674 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002675 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676
2677 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002678 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2679 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680
2681 // For replies from SimCard interface
2682 private Handler mHandler;
2683
2684 // For async handler to identify request type
2685 private static final int SUPPLY_PIN_COMPLETE = 100;
2686
Michele Berionne5e411512020-11-13 02:36:59 +00002687 UnlockSim(int phoneId, IccCard simCard) {
2688 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 mSimCard = simCard;
2690 }
2691
2692 @Override
2693 public void run() {
2694 Looper.prepare();
2695 synchronized (UnlockSim.this) {
2696 mHandler = new Handler() {
2697 @Override
2698 public void handleMessage(Message msg) {
2699 AsyncResult ar = (AsyncResult) msg.obj;
2700 switch (msg.what) {
2701 case SUPPLY_PIN_COMPLETE:
2702 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2703 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002704 mRetryCount = msg.arg1;
2705 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002706 CommandException.Error error = null;
2707 if (ar.exception instanceof CommandException) {
2708 error = ((CommandException) (ar.exception))
2709 .getCommandError();
2710 }
2711 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002712 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002713 } else if (error == CommandException.Error.ABORTED) {
2714 /* When UiccCardApp dispose, handle message and return
2715 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002716 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002717 } else {
2718 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2719 }
2720 } else {
2721 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 mDone = true;
2724 UnlockSim.this.notifyAll();
2725 }
2726 break;
2727 }
2728 }
2729 };
2730 UnlockSim.this.notifyAll();
2731 }
2732 Looper.loop();
2733 }
2734
2735 /*
2736 * Use PIN or PUK to unlock SIM card
2737 *
2738 * If PUK is null, unlock SIM card with PIN
2739 *
2740 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302741 *
2742 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2743 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 */
Wink Saville9de0f752013-10-22 19:04:03 -07002745 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746
2747 while (mHandler == null) {
2748 try {
2749 wait();
2750 } catch (InterruptedException e) {
2751 Thread.currentThread().interrupt();
2752 }
2753 }
2754 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2755
2756 if (puk == null) {
2757 mSimCard.supplyPin(pin, callback);
2758 } else {
2759 mSimCard.supplyPuk(puk, pin, callback);
2760 }
2761
2762 while (!mDone) {
2763 try {
2764 Log.d(LOG_TAG, "wait for done");
2765 wait();
2766 } catch (InterruptedException e) {
2767 // Restore the interrupted status
2768 Thread.currentThread().interrupt();
2769 }
2770 }
2771 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002772 int[] resultArray = new int[2];
2773 resultArray[0] = mResult;
2774 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002775
2776 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002777 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002778 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302779 // This instance is no longer reused, so quit its thread's looper.
2780 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002781
Wink Saville9de0f752013-10-22 19:04:03 -07002782 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784 }
2785
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002786 /**
2787 * This method has been removed due to privacy and stability concerns.
2788 */
2789 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002791 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2792 return;
Wink Saville36469e72014-06-11 15:17:00 -07002793 }
2794
Nathan Harold1f889d82020-06-04 17:05:26 -07002795 @Override
2796 public void updateServiceLocationWithPackageName(String callingPackage) {
2797 mApp.getSystemService(AppOpsManager.class)
2798 .checkPackage(Binder.getCallingUid(), callingPackage);
2799
Nathan Haroldf096d982020-11-18 17:18:06 -08002800 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002801 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2802 // Callers targeting S have no business invoking this method.
2803 return;
2804 }
2805
2806 LocationAccessPolicy.LocationPermissionResult locationResult =
2807 LocationAccessPolicy.checkLocationPermission(mApp,
2808 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2809 .setCallingPackage(callingPackage)
2810 .setCallingFeatureId(null)
2811 .setCallingPid(Binder.getCallingPid())
2812 .setCallingUid(Binder.getCallingUid())
2813 .setMethod("updateServiceLocation")
2814 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2815 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2816 .build());
2817 // Apps that lack location permission have no business calling this method;
2818 // however, because no permission was declared in the public API, denials must
2819 // all be "soft".
2820 switch (locationResult) {
2821 case DENIED_HARD: /* fall through */
2822 case DENIED_SOFT:
2823 return;
2824 }
2825
2826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
Ling Mac28f0212023-03-24 16:07:15 -07002829 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 }
2834
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002835 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002836 @Override
2837 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002838 return isRadioOnWithFeature(callingPackage, null);
2839 }
2840
2841
2842 @Override
2843 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2844 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2845 callingFeatureId);
2846 }
2847
2848 @Deprecated
2849 @Override
2850 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2851 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002852 }
2853
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002854 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002855 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2856 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002858 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002859 return false;
2860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 return isRadioOnForSubscriber(subId);
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002868 }
2869
2870 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 final Phone phone = getPhone(subId);
2874 if (phone != null) {
2875 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2876 } else {
2877 return false;
2878 }
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
2884 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002885 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 }
Wink Saville36469e72014-06-11 15:17:00 -07002887
Wink Savilleb564aae2014-10-23 10:18:09 -07002888 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
2895 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2896 }
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 }
Wink Saville36469e72014-06-11 15:17:00 -07002900 }
2901
2902 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002903 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002904 }
2905
Wink Savilleb564aae2014-10-23 10:18:09 -07002906 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002907 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908
2909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 if (phone == null) {
2913 return false;
2914 }
2915 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2916 toggleRadioOnOffForSubscriber(subId);
2917 }
2918 return true;
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
Wink Saville36469e72014-06-11 15:17:00 -07002923
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002924 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002925 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002926 /*
2927 * If any of the Radios are available, it will need to be
2928 * shutdown. So return true if any Radio is available.
2929 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2933 Phone phone = PhoneFactory.getPhone(i);
2934 if (phone != null && phone.isRadioAvailable()) return true;
2935 }
2936 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2937 return false;
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002940 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002941 }
2942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002944 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 enforceModifyPermission();
2946
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2950 logv("Shutting down Phone " + i);
2951 shutdownRadioUsingPhoneId(i);
2952 }
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002955 }
2956 }
2957
2958 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002959 Phone phone = PhoneFactory.getPhone(phoneId);
2960 if (phone != null && phone.isRadioAvailable()) {
2961 phone.shutdownRadio();
2962 }
2963 }
2964
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002966 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967
Ling Ma83dc5ea2023-01-12 15:06:04 -08002968 if (!turnOn) {
2969 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2970 }
2971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2975 if (defaultPhone != null) {
2976 defaultPhone.setRadioPower(turnOn);
2977 return true;
2978 } else {
2979 loge("There's no default phone.");
2980 return false;
2981 }
2982 } finally {
2983 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002984 }
Wink Saville36469e72014-06-11 15:17:00 -07002985 }
2986
Wink Savilleb564aae2014-10-23 10:18:09 -07002987 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002988 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989
Ling Ma83dc5ea2023-01-12 15:06:04 -08002990 if (!turnOn) {
2991 log("setRadioPowerForSubscriber off: subId=" + subId
2992 + ",callingPackage=" + getCurrentPackageName());
2993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 final Phone phone = getPhone(subId);
2997 if (phone != null) {
2998 phone.setRadioPower(turnOn);
2999 return true;
3000 } else {
3001 return false;
3002 }
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 }
3007
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003008 /**
3009 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3010 * no reason to power it off. When any of the voters want to power it off, it will be turned
3011 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3012 * powering it off, and these radio off votes will be cleared.
3013 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3014 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3015 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3016 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3017 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3018 * check its vote.
3019 *
3020 * @param subId The subscription ID.
3021 * @param reason The reason for powering off radio.
3022 * @return true on success and false on failure.
3023 */
3024 public boolean requestRadioPowerOffForReason(int subId,
3025 @TelephonyManager.RadioPowerReason int reason) {
3026 enforceModifyPermission();
3027
Ling Ma83dc5ea2023-01-12 15:06:04 -08003028 log("requestRadioPowerOffForReason: subId=" + subId
3029 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003030 final long identity = Binder.clearCallingIdentity();
3031 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003032 boolean result = false;
3033 for (Phone phone : PhoneFactory.getPhones()) {
3034 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003035 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003036 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003037 if (!result) {
3038 loge("requestRadioPowerOffForReason: no phone exists");
3039 }
3040 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
3046 /**
3047 * Remove the vote on powering off the radio for a reason, as requested by
3048 * {@link requestRadioPowerOffForReason}.
3049 *
3050 * @param subId The subscription ID.
3051 * @param reason The reason for powering off radio.
3052 * @return true on success and false on failure.
3053 */
3054 public boolean clearRadioPowerOffForReason(int subId,
3055 @TelephonyManager.RadioPowerReason int reason) {
3056 enforceModifyPermission();
3057
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003060 boolean result = false;
3061 for (Phone phone : PhoneFactory.getPhones()) {
3062 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003063 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003064 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003065 if (!result) {
3066 loge("clearRadioPowerOffForReason: no phone exists");
3067 }
3068 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 /**
3075 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3076 *
3077 * @param subId The subscription ID.
3078 * @param callingPackage The package making the call.
3079 * @param callingFeatureId The feature in the package.
3080 * @return List of reasons for powering off radio.
3081 */
3082 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3083 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3084
3085 final long identity = Binder.clearCallingIdentity();
3086 List result = new ArrayList();
3087 try {
3088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3089 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3090 return result;
3091 }
3092
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003093 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 if (phone != null) {
3095 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003096 } else {
3097 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003098 }
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
3102 return result;
3103 }
3104
Wink Saville36469e72014-06-11 15:17:00 -07003105 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003106 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003107 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
Jack Yu285100e2022-12-02 22:48:35 -08003112 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final Phone phone = getPhone(subId);
3114 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003115 phone.getDataSettingsManager().setDataEnabled(
3116 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 return true;
3118 } else {
3119 return false;
3120 }
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124 }
3125
Wink Saville36469e72014-06-11 15:17:00 -07003126 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003127 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003128 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
Jack Yu285100e2022-12-02 22:48:35 -08003133 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 final Phone phone = getPhone(subId);
3135 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003136 phone.getDataSettingsManager().setDataEnabled(
3137 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 return true;
3139 } else {
3140 return false;
3141 }
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 }
3146
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003148 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 final Phone phone = getPhone(subId);
3152 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003153 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003154 } else {
3155 return false;
3156 }
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
3162 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003163 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003164 }
3165
pkanwarae03a6b2016-11-06 20:37:09 -08003166 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 enforceCallPermission();
3168
3169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3172 return;
3173 }
3174 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3175 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3176 } finally {
3177 Binder.restoreCallingIdentity(identity);
3178 }
pkanwar32d516d2016-10-14 19:37:38 -07003179 };
3180
Wink Savilleb564aae2014-10-23 10:18:09 -07003181 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3187 return false;
3188 }
3189 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3190 } finally {
3191 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 }
3194
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003195 /**
3196 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3197 * tag on getCallState Binder call.
3198 */
3199 @Deprecated
3200 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003202 if (CompatChanges.isChangeEnabled(
3203 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3204 Binder.getCallingUid())) {
3205 // Do not allow this API to be called on API version 31+, it should only be
3206 // called on old apps using this Binder call directly.
3207 throw new SecurityException("This method can only be used for applications "
3208 + "targeting API version 30 or less.");
3209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
Ling Mac28f0212023-03-24 16:07:15 -07003212 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3213 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
3220 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3221 if (CompatChanges.isChangeEnabled(
3222 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3223 Binder.getCallingUid())) {
3224 // Check READ_PHONE_STATE for API version 31+
3225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3226 featureId, "getCallStateForSubscription")) {
3227 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3228 + "targeting API level 31+.");
3229 }
3230 }
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3235 PhoneConstantConversions.convertCallState(phone.getState());
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 }
3240
Sanket Padawe356d7632015-06-22 14:03:32 -07003241 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003242 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003243 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003244 }
3245
3246 @Override
3247 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003252 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 } else {
3254 return PhoneConstantConversions.convertDataState(
3255 PhoneConstants.DataState.DISCONNECTED);
3256 }
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003260 }
3261
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003263 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003264 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003265 }
3266
3267 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003268 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003271 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003273 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 } else {
3275 return TelephonyManager.DATA_ACTIVITY_NONE;
3276 }
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
3282 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003283 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003284 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003285 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003286
3287 LocationAccessPolicy.LocationPermissionResult locationResult =
3288 LocationAccessPolicy.checkLocationPermission(mApp,
3289 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3290 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003291 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003292 .setCallingPid(Binder.getCallingPid())
3293 .setCallingUid(Binder.getCallingUid())
3294 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003295 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003296 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3297 .build());
3298 switch (locationResult) {
3299 case DENIED_HARD:
3300 throw new SecurityException("Not allowed to access cell location");
3301 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003302 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3303 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 }
3305
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003306 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003310 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003311 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
Svetoslav64fad262015-04-14 14:35:21 -07003315 }
3316
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003318 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003319 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3320 // registered cell info, so return a NULL country instead.
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003323 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3324 // Get default phone in this case.
3325 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3326 }
Jack Yu285100e2022-12-02 22:48:35 -08003327 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003329 if (phone == null) return "";
3330 ServiceStateTracker sst = phone.getServiceStateTracker();
3331 if (sst == null) return "";
3332 LocaleTracker lt = sst.getLocaleTracker();
3333 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003334 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003338 }
3339
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003340 /**
3341 * This method was removed due to potential issues caused by performing partial
3342 * updates of service state, and lack of a credible use case.
3343 *
3344 * This has the ability to break the telephony implementation by disabling notification of
3345 * changes in device connectivity. DO NOT USE THIS!
3346 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003347 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 public void enableLocationUpdates() {
3349 mApp.enforceCallingOrSelfPermission(
3350 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003351 }
3352
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003353 /**
3354 * This method was removed due to potential issues caused by performing partial
3355 * updates of service state, and lack of a credible use case.
3356 *
3357 * This has the ability to break the telephony implementation by disabling notification of
3358 * changes in device connectivity. DO NOT USE THIS!
3359 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003360 @Override
3361 public void disableLocationUpdates() {
3362 mApp.enforceCallingOrSelfPermission(
3363 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 }
3365
3366 @Override
3367 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003368 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3369 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003370 try {
3371 mApp.getSystemService(AppOpsManager.class)
3372 .checkPackage(Binder.getCallingUid(), callingPackage);
3373 } catch (SecurityException e) {
3374 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3375 throw e;
3376 }
3377
Nathan Haroldf096d982020-11-18 17:18:06 -08003378 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003379 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3380 throw new SecurityException(
3381 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3382 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003383
Jordan Liu1617b712019-07-10 15:06:26 -07003384 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003385 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3386 return null;
3387 }
Svetoslav64fad262015-04-14 14:35:21 -07003388
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003389 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003391 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003392 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393
Nathan Haroldf180aac2018-06-01 18:43:55 -07003394 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3395 for (CellInfo ci : info) {
3396 if (ci instanceof CellInfoGsm) {
3397 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3398 } else if (ci instanceof CellInfoWcdma) {
3399 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003402 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 }
3404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 private List<CellInfo> getCachedCellInfo() {
3406 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3407 for (Phone phone : PhoneFactory.getPhones()) {
3408 List<CellInfo> info = phone.getAllCellInfo();
3409 if (info != null) cellInfos.addAll(info);
3410 }
3411 return cellInfos;
3412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413
3414 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003415 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003416 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003417 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003418
3419 LocationAccessPolicy.LocationPermissionResult locationResult =
3420 LocationAccessPolicy.checkLocationPermission(mApp,
3421 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3422 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003423 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003424 .setCallingPid(Binder.getCallingPid())
3425 .setCallingUid(Binder.getCallingUid())
3426 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003427 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003428 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3429 .build());
3430 switch (locationResult) {
3431 case DENIED_HARD:
3432 throw new SecurityException("Not allowed to access cell info");
3433 case DENIED_SOFT:
3434 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 }
3436
Nathan Haroldf096d982020-11-18 17:18:06 -08003437 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003438 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3439 return getCachedCellInfo();
3440 }
3441
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003442 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3447 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003448 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003449 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 if (info != null) cellInfos.addAll(info);
3451 }
3452 return cellInfos;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456 }
3457
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003459 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3460 String callingFeatureId) {
3461 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3462 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003463 }
3464
3465 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003466 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3467 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003468 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003469 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003470 }
3471
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003472 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3473 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003475 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003476
3477 LocationAccessPolicy.LocationPermissionResult locationResult =
3478 LocationAccessPolicy.checkLocationPermission(mApp,
3479 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3480 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003481 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003482 .setCallingPid(Binder.getCallingPid())
3483 .setCallingUid(Binder.getCallingUid())
3484 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003485 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3486 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003487 .build());
3488 switch (locationResult) {
3489 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003490 if (TelephonyPermissions
3491 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003492 // Safetynet logging for b/154934934
3493 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3494 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003495 throw new SecurityException("Not allowed to access cell info");
3496 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003497 if (TelephonyPermissions
3498 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003499 // Safetynet logging for b/154934934
3500 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3501 }
Nathan Harold5320c422019-05-09 10:26:08 -07003502 try {
3503 cb.onCellInfo(new ArrayList<CellInfo>());
3504 } catch (RemoteException re) {
3505 // Drop without consequences
3506 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003507 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003508 }
3509
Nathan Harolda939a962019-05-09 10:13:47 -07003510
3511 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003512 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3513
3514 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3515 }
3516
3517 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003518 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003519 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003524 Phone phone = getPhone(subId);
3525 if (phone == null) {
3526 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3527 } else {
3528 phone.setCellInfoListRate(rateInMillis, workSource);
3529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
Shishir Agrawala9f32182016-04-12 12:00:16 -07003535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003536 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 return null;
3540 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003542 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003543 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003544 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003545 return null;
3546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 return phone.getImei();
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003554 }
3555
3556 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003557 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3558 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3559 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3560 callingFeatureId, "getPrimaryImei")) {
3561 throw new SecurityException("Caller does not have permission");
3562 }
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 for (Phone phone : PhoneFactory.getPhones()) {
3566 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3567 return phone.getImei();
3568 }
3569 }
3570 throw new UnsupportedOperationException("Operation not supported");
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 }
3575
3576 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003577 public String getTypeAllocationCodeForSlot(int slotIndex) {
3578 Phone phone = PhoneFactory.getPhone(slotIndex);
3579 String tac = null;
3580 if (phone != null) {
3581 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003582 try {
3583 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3584 } catch (IndexOutOfBoundsException e) {
3585 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3586 return null;
3587 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003588 }
3589 return tac;
3590 }
3591
3592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003593 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003594 try {
3595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3596 } catch (SecurityException se) {
3597 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3598 throw new SecurityException("Package " + callingPackage + " does not belong to "
3599 + Binder.getCallingUid());
3600 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003601 Phone phone = PhoneFactory.getPhone(slotIndex);
3602 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003603 return null;
3604 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605
Jeff Davidson913390f2018-02-23 17:11:49 -08003606 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003607 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003608 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003609 return null;
3610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611
3612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 return phone.getMeid();
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
Jack Yu2af8d712017-03-15 17:14:14 -07003618 }
3619
3620 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003621 public String getManufacturerCodeForSlot(int slotIndex) {
3622 Phone phone = PhoneFactory.getPhone(slotIndex);
3623 String manufacturerCode = null;
3624 if (phone != null) {
3625 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003626 try {
3627 manufacturerCode =
3628 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3629 } catch (IndexOutOfBoundsException e) {
3630 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3631 return null;
3632 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003633 }
3634 return manufacturerCode;
3635 }
3636
3637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3639 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 Phone phone = PhoneFactory.getPhone(slotIndex);
3641 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 return null;
3643 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 int subId = phone.getSubId();
3645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003646 mApp, subId, callingPackage, callingFeatureId,
3647 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003648 return null;
3649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 return phone.getDeviceSvn();
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003657 }
3658
fionaxu43304da2017-11-27 22:51:16 -08003659 @Override
3660 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = getPhone(subId);
3664 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
fionaxu43304da2017-11-27 22:51:16 -08003668 }
3669
3670 @Override
3671 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 final Phone phone = getPhone(subId);
3675 return phone == null ? null : phone.getCarrierName();
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
fionaxu43304da2017-11-27 22:51:16 -08003679 }
3680
calvinpanffe225e2018-11-01 19:43:06 +08003681 @Override
chen xu0026ca62019-03-06 15:28:50 -08003682 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003687 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
chen xu0026ca62019-03-06 15:28:50 -08003694 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003698 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
3702 }
3703
chen xu651eec72018-11-11 19:03:44 -08003704 @Override
chen xu864e11c2018-12-06 22:10:03 -08003705 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3706 if (!isSubscriptionMccMnc) {
3707 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3708 }
chen xu651eec72018-11-11 19:03:44 -08003709 final Phone phone = PhoneFactory.getPhone(slotIndex);
3710 if (phone == null) {
3711 return TelephonyManager.UNKNOWN_CARRIER_ID;
3712 }
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
3719 }
3720
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 //
3722 // Internal helper methods.
3723 //
3724
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003725 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003726 * Make sure the caller is the calling package itself
3727 *
3728 * @throws SecurityException if the caller is not the calling package
3729 */
3730 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3731 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003732 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3733 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003734 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003735 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003736 } catch (PackageManager.NameNotFoundException e) {
3737 // packageUid is -1
3738 }
3739 if (packageUid != callingUid) {
3740 throw new SecurityException(message + ": Package " + callingPackage
3741 + " does not belong to " + callingUid);
3742 }
3743 }
3744
3745 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003746 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3747 *
3748 * @throws SecurityException if the caller does not have the required permission
3749 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003750 @VisibleForTesting
3751 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003752 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3753 }
3754
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003755 /**
arunvoddud7401012022-12-15 16:08:12 +00003756 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003757 *
3758 * @throws SecurityException if the caller does not have the required permission
3759 */
3760 @VisibleForTesting
3761 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003762 enforceReadPermission(null);
3763 }
3764
3765 /**
3766 * Make sure the caller has the READ_PHONE_STATE permissions.
3767 *
3768 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3769 */
3770 @VisibleForTesting
3771 public void enforceReadPermission(String msg) {
3772 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003773 }
3774
Shuo Qian3b6ee772019-11-13 17:43:31 -08003775 private void enforceActiveEmergencySessionPermission() {
3776 mApp.enforceCallingOrSelfPermission(
3777 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3778 }
3779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003780 /**
3781 * Make sure the caller has the CALL_PHONE permission.
3782 *
3783 * @throws SecurityException if the caller does not have the required permission
3784 */
3785 private void enforceCallPermission() {
3786 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3787 }
3788
paulhu5a773602019-08-23 19:17:33 +08003789 private void enforceSettingsPermission() {
3790 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003791 }
3792
Michele Berionne5e411512020-11-13 02:36:59 +00003793 private void enforceRebootPermission() {
3794 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3795 }
3796
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003797 /**
3798 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3799 * @param message - log message to print.
3800 * @throws SecurityException if the caller does not have the required permission
3801 */
3802 private void enforceSatelliteCommunicationPermission(String message) {
3803 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3804 }
3805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003806 private String createTelUrl(String number) {
3807 if (TextUtils.isEmpty(number)) {
3808 return null;
3809 }
3810
Jake Hambye994d462014-02-03 13:10:13 -08003811 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 }
3813
Ihab Awadf9e92732013-12-05 18:02:52 -08003814 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003815 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003818 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003819 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003820 }
3821
Ihab Awadf9e92732013-12-05 18:02:52 -08003822 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003823 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003824 }
3825
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003827 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003828 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003829 }
3830
Sanket Padawe356d7632015-06-22 14:03:32 -07003831 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003832 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 final Phone phone = PhoneFactory.getPhone(slotIndex);
3836 if (phone == null) {
3837 return PhoneConstants.PHONE_TYPE_NONE;
3838 } else {
3839 return phone.getPhoneType();
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003844 }
3845
3846 /**
3847 * Returns the CDMA ERI icon index to display
3848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003850 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3851 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3852 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003853 }
3854
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 mApp, subId, callingPackage, callingFeatureId,
3860 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003861 return -1;
3862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863
3864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 final Phone phone = getPhone(subId);
3867 if (phone != null) {
3868 return phone.getCdmaEriIconIndex();
3869 } else {
3870 return -1;
3871 }
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 }
3876
3877 /**
3878 * Returns the CDMA ERI icon mode,
3879 * 0 - ON
3880 * 1 - FLASHING
3881 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003883 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3884 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3885 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003886 }
3887
Sanket Padawe356d7632015-06-22 14:03:32 -07003888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003889 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3890 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003892 mApp, subId, callingPackage, callingFeatureId,
3893 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003894 return -1;
3895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896
3897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 final Phone phone = getPhone(subId);
3900 if (phone != null) {
3901 return phone.getCdmaEriIconMode();
3902 } else {
3903 return -1;
3904 }
3905 } finally {
3906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003908 }
3909
3910 /**
3911 * Returns the CDMA ERI text,
3912 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003913 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003914 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3915 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3916 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003917 }
3918
Sanket Padawe356d7632015-06-22 14:03:32 -07003919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003920 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3921 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003923 mApp, subId, callingPackage, callingFeatureId,
3924 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003925 return null;
3926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 final Phone phone = getPhone(subId);
3931 if (phone != null) {
3932 return phone.getCdmaEriText();
3933 } else {
3934 return null;
3935 }
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 }
3940
3941 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003942 * Returns the CDMA MDN.
3943 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003944 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003945 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3947 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 return phone.getLine1Number();
3954 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 return null;
3957 }
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003960 }
3961 }
3962
3963 /**
3964 * Returns the CDMA MIN.
3965 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003966 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003967 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3969 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 final Phone phone = getPhone(subId);
3974 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3975 return phone.getCdmaMin();
3976 } else {
3977 return null;
3978 }
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003981 }
3982 }
3983
Hall Liud892bec2018-11-30 14:51:45 -08003984 @Override
3985 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3986 INumberVerificationCallback callback, String callingPackage) {
3987 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3988 != PERMISSION_GRANTED) {
3989 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3990 }
3991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3992
3993 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3994 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003995 throw new SecurityException("Calling package must be configured in the device config: "
3996 + "calling package: " + callingPackage
3997 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003998 }
3999
4000 if (range == null) {
4001 throw new NullPointerException("Range must be non-null");
4002 }
4003
4004 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004005 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004006
4007 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4008 }
4009
Junda Liuca05d5d2014-08-14 22:36:34 -07004010 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004011 * Returns true if CDMA provisioning needs to run.
4012 */
4013 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004016 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 }
4021
4022 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004023 * Sets the voice mail number of a given subId.
4024 */
4025 @Override
4026 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4028 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029
4030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4033 new Pair<String, String>(alphaTag, number), new Integer(subId));
4034 return success;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004038 }
4039
Ta-wei Yen87c49842016-05-13 21:19:52 -07004040 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004041 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004043 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4044 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004045 if (!TextUtils.equals(callingPackage, systemDialer)) {
4046 throw new SecurityException("caller must be system dialer");
4047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4052 if (phoneAccountHandle == null) {
4053 return null;
4054 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 } finally {
4057 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004058 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004059 }
4060
4061 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004062 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4063 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 mApp, subId, callingPackage, callingFeatureId,
4067 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004068 return null;
4069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004071 final long identity = Binder.clearCallingIdentity();
4072 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004073 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004077 }
4078
4079 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004080 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4081 VisualVoicemailSmsFilterSettings settings) {
4082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004091 }
4092
4093 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004094 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4095 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004100 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004104 }
4105
4106 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004107 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4108 String callingPackage, int subId) {
4109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 } finally {
4116 Binder.restoreCallingIdentity(identity);
4117 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004118 }
4119
4120 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004121 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004127 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004131 }
4132
4133 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004134 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4135 String callingAttributionTag, int subId, String number, int port, String text,
4136 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004138 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004139 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004140 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004141 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4142 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004143 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004144
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004145 /**
fionaxu0152e512016-11-14 13:36:14 -08004146 * Sets the voice activation state of a given subId.
4147 */
4148 @Override
4149 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4151 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 final Phone phone = getPhone(subId);
4156 if (phone != null) {
4157 phone.setVoiceActivationState(activationState);
4158 } else {
4159 loge("setVoiceActivationState fails with invalid subId: " + subId);
4160 }
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004163 }
4164 }
4165
4166 /**
4167 * Sets the data activation state of a given subId.
4168 */
4169 @Override
4170 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4172 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 final Phone phone = getPhone(subId);
4177 if (phone != null) {
4178 phone.setDataActivationState(activationState);
4179 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004180 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 }
4182 } finally {
4183 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004184 }
4185 }
4186
4187 /**
4188 * Returns the voice activation state of a given subId.
4189 */
4190 @Override
4191 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193
fionaxu0152e512016-11-14 13:36:14 -08004194 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 if (phone != null) {
4198 return phone.getVoiceActivationState();
4199 } else {
4200 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4201 }
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004204 }
4205 }
4206
4207 /**
4208 * Returns the data activation state of a given subId.
4209 */
4210 @Override
4211 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
fionaxu0152e512016-11-14 13:36:14 -08004214 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 if (phone != null) {
4218 return phone.getDataActivationState();
4219 } else {
4220 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4221 }
4222 } finally {
4223 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004224 }
4225 }
4226
4227 /**
Wink Saville36469e72014-06-11 15:17:00 -07004228 * Returns the unread count of voicemails for a subId
4229 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004231 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4232 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 mApp, subId, callingPackage, callingFeatureId,
4235 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004236 return 0;
4237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 final long identity = Binder.clearCallingIdentity();
4239 try {
4240 final Phone phone = getPhone(subId);
4241 if (phone != null) {
4242 return phone.getVoiceMessageCount();
4243 } else {
4244 return 0;
4245 }
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004249 }
4250
4251 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004252 * returns true, if the device is in a state where both voice and data
4253 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004254 */
4255 @Override
4256 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
Ling Mac28f0212023-03-24 16:07:15 -07004259 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004263 }
4264
4265 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004266 * Send the dialer code if called from the current default dialer or the caller has
4267 * carrier privilege.
4268 * @param inputCode The dialer code to send
4269 */
4270 @Override
4271 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004274 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4275 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004276 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004277 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004283 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
fionaxu235cc5e2017-03-06 22:25:57 -08004287 }
4288
Pengquan Menga1bb6272018-09-06 09:59:22 -07004289 @Override
4290 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004291 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004292 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4293 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 if (!isActiveSubscription(subId)) {
4297 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4298 }
4299 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004303 }
4304
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004306 public boolean isInEmergencySmsMode() {
4307 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 for (Phone phone : PhoneFactory.getPhones()) {
4311 if (phone.isInEmergencySmsMode()) {
4312 return true;
4313 }
4314 }
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
4318 return false;
4319 }
4320
shilu366312e2019-12-17 09:28:10 -08004321 /**
4322 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4323 * @param subId The subscription to use to check the configuration.
4324 * @param c The callback that will be used to send the result.
4325 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004326 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004327 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4328 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004329 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004330 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004331
4332 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4334 "IMS not available on device.");
4335 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 final long token = Binder.clearCallingIdentity();
4337 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004338 int slotId = getSlotIndexOrException(subId);
4339 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004340
4341 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4342 if (controller != null) {
4343 ImsManager imsManager = controller.getImsManager(subId);
4344 if (imsManager != null) {
4345 imsManager.addRegistrationCallbackForSubscription(c, subId);
4346 } else {
4347 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4348 }
4349 } else {
4350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4351 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004352 } catch (ImsException e) {
4353 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 } finally {
4355 Binder.restoreCallingIdentity(token);
4356 }
4357 }
4358
shilu366312e2019-12-17 09:28:10 -08004359 /**
4360 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4361 * @param subId The subscription to use to check the configuration.
4362 * @param c The callback that will be used to send the result.
4363 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004365 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004366 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004367 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004368 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4369 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4370 }
Meng Wangafbc5852019-09-19 17:37:13 -07004371 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004372
Meng Wangafbc5852019-09-19 17:37:13 -07004373 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004374 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4375 if (controller != null) {
4376 ImsManager imsManager = controller.getImsManager(subId);
4377 if (imsManager != null) {
4378 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4379 } else {
4380 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4381 + "is inactive, ignoring unregister.");
4382 // If the ImsManager is not valid, just return, since the callback
4383 // will already have been removed internally.
4384 }
4385 }
Meng Wangafbc5852019-09-19 17:37:13 -07004386 } finally {
4387 Binder.restoreCallingIdentity(token);
4388 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 }
4390
Brad Ebingera34a6c22019-10-22 17:36:18 -07004391 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004392 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4393 * @param subId The subscription to use to check the configuration.
4394 * @param c The callback that will be used to send the result.
4395 */
4396 @Override
4397 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4398 throws RemoteException {
4399 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4400 mApp, subId, "registerImsEmergencyRegistrationCallback");
4401
4402 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4403 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4404 "IMS not available on device.");
4405 }
4406 final long token = Binder.clearCallingIdentity();
4407 try {
4408 int slotId = getSlotIndexOrException(subId);
4409 verifyImsMmTelConfiguredOrThrow(slotId);
4410
4411 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4412 if (controller != null) {
4413 ImsManager imsManager = controller.getImsManager(subId);
4414 if (imsManager != null) {
4415 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4416 } else {
4417 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4418 }
4419 } else {
4420 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4421 }
4422 } catch (ImsException e) {
4423 throw new ServiceSpecificException(e.getCode());
4424 } finally {
4425 Binder.restoreCallingIdentity(token);
4426 }
4427 }
4428
4429 /**
4430 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4431 * @param subId The subscription to use to check the configuration.
4432 * @param c The callback that will be used to send the result.
4433 */
4434 @Override
4435 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4436 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4437 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4438 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4439 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4440 }
4441 final long token = Binder.clearCallingIdentity();
4442
4443 try {
4444 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4445 if (controller != null) {
4446 ImsManager imsManager = controller.getImsManager(subId);
4447 if (imsManager != null) {
4448 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4449 } else {
4450 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4451 + "is inactive, ignoring unregister.");
4452 // If the ImsManager is not valid, just return, since the callback
4453 // will already have been removed internally.
4454 }
4455 }
4456 } finally {
4457 Binder.restoreCallingIdentity(token);
4458 }
4459 }
4460
4461 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004462 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4463 */
4464 @Override
4465 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4466 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4467 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4468 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4469 "IMS not available on device.");
4470 }
4471 final long token = Binder.clearCallingIdentity();
4472 try {
4473 Phone phone = getPhone(subId);
4474 if (phone == null) {
4475 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4476 + subId + "'");
4477 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4478 }
4479 phone.getImsRegistrationState(regState -> {
4480 try {
4481 consumer.accept((regState == null)
4482 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4483 } catch (RemoteException e) {
4484 // Ignore if the remote process is no longer available to call back.
4485 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4486 }
4487 });
4488 } finally {
4489 Binder.restoreCallingIdentity(token);
4490 }
4491 }
4492
4493 /**
4494 * Get the transport type for the IMS service registration state.
4495 */
4496 @Override
4497 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004498 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004499 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004500 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4501 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4502 "IMS not available on device.");
4503 }
4504 final long token = Binder.clearCallingIdentity();
4505 try {
4506 Phone phone = getPhone(subId);
4507 if (phone == null) {
4508 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4509 + subId + "'");
4510 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4511 }
4512 phone.getImsRegistrationTech(regTech -> {
4513 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4514 int regTechConverted = (regTech == null)
4515 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4516 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4517 regTechConverted);
4518 try {
4519 consumer.accept(regTechConverted);
4520 } catch (RemoteException e) {
4521 // Ignore if the remote process is no longer available to call back.
4522 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4523 }
4524 });
4525 } finally {
4526 Binder.restoreCallingIdentity(token);
4527 }
4528 }
4529
shilu366312e2019-12-17 09:28:10 -08004530 /**
4531 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4532 * @param subId The subscription to use to check the configuration.
4533 * @param c The callback that will be used to send the result.
4534 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004536 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4537 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004538 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004539 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004540 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4541 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4542 "IMS not available on device.");
4543 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 final long token = Binder.clearCallingIdentity();
4545 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004546 int slotId = getSlotIndexOrException(subId);
4547 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004548
4549 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4550 if (controller != null) {
4551 ImsManager imsManager = controller.getImsManager(subId);
4552 if (imsManager != null) {
4553 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4554 } else {
4555 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4556 }
4557 } else {
4558 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4559 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004560 } catch (ImsException e) {
4561 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004562 } finally {
4563 Binder.restoreCallingIdentity(token);
4564 }
4565 }
4566
shilu366312e2019-12-17 09:28:10 -08004567 /**
4568 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4569 * @param subId The subscription to use to check the configuration.
4570 * @param c The callback that will be used to send the result.
4571 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004573 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004574 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004575 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004576 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4577 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4578 }
Meng Wangafbc5852019-09-19 17:37:13 -07004579
4580 final long token = Binder.clearCallingIdentity();
4581 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004582 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4583 if (controller != null) {
4584 ImsManager imsManager = controller.getImsManager(subId);
4585 if (imsManager != null) {
4586 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4587 } else {
4588 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4589 + " is inactive, ignoring unregister.");
4590 // If the ImsManager is not valid, just return, since the callback
4591 // will already have been removed internally.
4592 }
4593 }
Meng Wangafbc5852019-09-19 17:37:13 -07004594 } finally {
4595 Binder.restoreCallingIdentity(token);
4596 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004597 }
4598
4599 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004600 public boolean isCapable(int subId, int capability, int regTech) {
4601 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004602 final long token = Binder.clearCallingIdentity();
4603 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004604 int slotId = getSlotIndexOrException(subId);
4605 verifyImsMmTelConfiguredOrThrow(slotId);
4606 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4607 } catch (com.android.ims.ImsException e) {
4608 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4609 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004610 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004611 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4612 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 } finally {
4614 Binder.restoreCallingIdentity(token);
4615 }
4616 }
4617
4618 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004619 public boolean isAvailable(int subId, int capability, int regTech) {
4620 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 final long token = Binder.clearCallingIdentity();
4622 try {
4623 Phone phone = getPhone(subId);
4624 if (phone == null) return false;
4625 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004626 } catch (com.android.ims.ImsException e) {
4627 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4628 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004629 } finally {
4630 Binder.restoreCallingIdentity(token);
4631 }
4632 }
4633
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004634 /**
4635 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4636 * subscription.
4637 * @param subId The subscription to use to check the configuration.
4638 * @param callback The callback that will be used to send the result.
4639 * @param capability The MmTelFeature capability that will be used to send the result.
4640 * @param transportType The transport type of the MmTelFeature capability.
4641 */
4642 @Override
4643 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4644 int transportType) {
4645 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004646 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4647 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4648 "IMS not available on device.");
4649 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004650 final long token = Binder.clearCallingIdentity();
4651 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004652 int slotId = getSlotIndex(subId);
4653 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4654 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4655 + subId + "'");
4656 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4657 }
4658 verifyImsMmTelConfiguredOrThrow(slotId);
4659 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4660 transportType, aBoolean -> {
4661 try {
4662 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4663 } catch (RemoteException e) {
4664 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4665 + "running. Ignore");
4666 }
4667 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004668 } catch (ImsException e) {
4669 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004670 } finally {
4671 Binder.restoreCallingIdentity(token);
4672 }
4673 }
4674
shilu366312e2019-12-17 09:28:10 -08004675 /**
4676 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4677 * @param subId The subscription to use to check the configuration.
4678 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004679 @Override
4680 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004681 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004682 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004683
Brad Ebinger35c841c2018-10-01 10:40:55 -07004684 final long token = Binder.clearCallingIdentity();
4685 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004686 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004687 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004688 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004689 } catch (ImsException e) {
4690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004691 } finally {
4692 Binder.restoreCallingIdentity(token);
4693 }
4694 }
4695
4696 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004697 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004699 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004700 final long identity = Binder.clearCallingIdentity();
4701 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004702 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004703 // This setting doesn't require an active ImsService connection, so do not verify. The
4704 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004705 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004706 } catch (ImsException e) {
4707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
4711 }
4712
shilu366312e2019-12-17 09:28:10 -08004713 /**
4714 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4715 * @param subId The subscription to use to check the configuration.
4716 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004717 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004718 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004719 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004720 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004721 final long identity = Binder.clearCallingIdentity();
4722 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004723 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004724 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004725 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004726 } catch (ImsException e) {
4727 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
4731 }
4732
4733 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004734 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004736 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004737 final long identity = Binder.clearCallingIdentity();
4738 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004739 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004740 // This setting doesn't require an active ImsService connection, so do not verify. The
4741 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004742 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004743 } catch (ImsException e) {
4744 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
4748 }
4749
shilu366312e2019-12-17 09:28:10 -08004750 /**
4751 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4752 * @param subId The subscription to use to check the configuration.
4753 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004754 @Override
4755 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004756 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004757 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004758 final long identity = Binder.clearCallingIdentity();
4759 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004760 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004761 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004762 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004763 } catch (ImsException e) {
4764 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004765 } finally {
4766 Binder.restoreCallingIdentity(identity);
4767 }
4768 }
4769
4770 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004771 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004773 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004774 final long identity = Binder.clearCallingIdentity();
4775 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004776 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004777 // This setting doesn't require an active ImsService connection, so do not verify. The
4778 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004779 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004780 } catch (ImsException e) {
4781 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
4785 }
4786
shilu366312e2019-12-17 09:28:10 -08004787 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004788 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4789 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4790 * @param subId The subscription to use to check the configuration.
4791 */
4792 @Override
4793 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004794 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004795 mApp, subId, "isCrossSimCallingEnabledByUser");
4796 final long identity = Binder.clearCallingIdentity();
4797 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004798 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004799 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004800 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004801 } catch (ImsException e) {
4802 throw new ServiceSpecificException(e.getCode());
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
4806 }
4807
4808 /**
4809 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4810 * Requires MODIFY_PHONE_STATE permission.
4811 * @param subId The subscription to use to check the configuration.
4812 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4813 * false otherwise
4814 */
4815 @Override
4816 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4818 "setCrossSimCallingEnabled");
4819 final long identity = Binder.clearCallingIdentity();
4820 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004821 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004822 // This setting doesn't require an active ImsService connection, so do not verify. The
4823 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004824 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004825 } catch (ImsException e) {
4826 throw new ServiceSpecificException(e.getCode());
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
4830 }
4831
4832 /**
shilu366312e2019-12-17 09:28:10 -08004833 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4834 * @param subId The subscription to use to check the configuration.
4835 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004836 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004837
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004839 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004840 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004841 final long identity = Binder.clearCallingIdentity();
4842 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004843 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004844 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004845 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004846 } catch (ImsException e) {
4847 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
4851 }
4852
4853 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004854 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004856 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004857 final long identity = Binder.clearCallingIdentity();
4858 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004859 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004860 // This setting doesn't require an active ImsService connection, so do not verify. The
4861 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004862 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004863 } catch (ImsException e) {
4864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
4868 }
4869
4870 @Override
4871 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4873 "setVoWiFiNonPersistent");
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004876 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004877 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004878 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004879 } catch (ImsException e) {
4880 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
4884 }
4885
shilu366312e2019-12-17 09:28:10 -08004886 /**
4887 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4888 * @param subId The subscription to use to check the configuration.
4889 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004890 @Override
4891 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004892 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004893 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004894 final long identity = Binder.clearCallingIdentity();
4895 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004896 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004897 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004898 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004899 } catch (ImsException e) {
4900 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
4904 }
4905
4906 @Override
4907 public void setVoWiFiModeSetting(int subId, int mode) {
4908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4909 "setVoWiFiModeSetting");
4910 final long identity = Binder.clearCallingIdentity();
4911 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004912 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004913 // This setting doesn't require an active ImsService connection, so do not verify. The
4914 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004915 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004916 } catch (ImsException e) {
4917 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
4921 }
4922
4923 @Override
4924 public int getVoWiFiRoamingModeSetting(int subId) {
4925 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004928 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004929 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004930 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004931 } catch (ImsException e) {
4932 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
4936 }
4937
4938 @Override
4939 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4941 "setVoWiFiRoamingModeSetting");
4942 final long identity = Binder.clearCallingIdentity();
4943 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004944 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004945 // This setting doesn't require an active ImsService connection, so do not verify. The
4946 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004947 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004948 } catch (ImsException e) {
4949 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
4953 }
4954
4955 @Override
4956 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4958 "setRttCapabilityEnabled");
4959 final long identity = Binder.clearCallingIdentity();
4960 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004961 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004962 // This setting doesn't require an active ImsService connection, so do not verify. The
4963 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004964 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004965 } catch (ImsException e) {
4966 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
4970 }
4971
shilu366312e2019-12-17 09:28:10 -08004972 /**
4973 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4974 * @param subId The subscription to use to check the configuration.
4975 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004976 @Override
4977 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004978 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004979 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 final long identity = Binder.clearCallingIdentity();
4981 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004982 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004983 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004984 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004985 } catch (ImsException e) {
4986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
4990 }
4991
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004992 @Override
4993 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4994 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004995
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004996 final long identity = Binder.clearCallingIdentity();
4997 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004998 if (!isImsAvailableOnDevice()) {
4999 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5000 "IMS not available on device.");
5001 }
5002 int slotId = getSlotIndexOrException(subId);
5003 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005004
5005 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5006 if (controller != null) {
5007 ImsManager imsManager = controller.getImsManager(subId);
5008 if (imsManager != null) {
5009 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5010 } else {
5011 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5012 }
5013 } else {
5014 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5015 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005016 } catch (ImsException e) {
5017 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
5021 }
5022
5023 @Override
5024 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5025 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005026
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005027 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005028 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5029 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5030 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005031 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005032 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5033 if (controller != null) {
5034 ImsManager imsManager = controller.getImsManager(subId);
5035 if (imsManager != null) {
5036 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5037 } else {
5038 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5039 + " is inactive, ignoring unregister.");
5040 // If the ImsManager is not valid, just return, since the callback will already
5041 // have been removed internally.
5042 }
5043 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
5047 }
5048
joonhunshincffb7fc2021-11-28 07:32:01 +00005049 @Override
5050 public void registerFeatureProvisioningChangedCallback(int subId,
5051 IFeatureProvisioningCallback callback) {
5052 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5053 mApp, subId, "registerFeatureProvisioningChangedCallback");
5054
5055 final long identity = Binder.clearCallingIdentity();
5056 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5057 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5058 }
5059
joonhunshin91bc1952022-04-29 08:47:15 +00005060 try {
5061 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5062 if (controller == null) {
5063 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5064 "Device does not support IMS");
5065 }
5066 controller.addFeatureProvisioningChangedCallback(subId, callback);
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
5069 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005070 }
5071
5072 @Override
5073 public void unregisterFeatureProvisioningChangedCallback(int subId,
5074 IFeatureProvisioningCallback callback) {
5075 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5076 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5077
5078 final long identity = Binder.clearCallingIdentity();
5079 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5080 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5081 }
5082
joonhunshin91bc1952022-04-29 08:47:15 +00005083 try {
5084 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5085 if (controller == null) {
5086 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5087 return;
5088 }
5089 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005093 }
allenwtsu99c623b2020-01-03 18:24:23 +08005094
5095 private void checkModifyPhoneStatePermission(int subId, String message) {
5096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5097 message);
5098 }
5099
allenwtsu99c623b2020-01-03 18:24:23 +08005100 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005101 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005102 boolean isProvisioned) {
5103 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5104
5105 final long identity = Binder.clearCallingIdentity();
5106 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005107 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5108 if (controller == null) {
5109 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5110 return;
5111 }
5112 controller.setRcsProvisioningStatusForCapability(
5113 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
allenwtsu99c623b2020-01-03 18:24:23 +08005117 }
5118
5119
5120 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005121 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5122 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5123 mApp, subId, "getRcsProvisioningStatusForCapability");
5124
allenwtsu99c623b2020-01-03 18:24:23 +08005125 final long identity = Binder.clearCallingIdentity();
5126 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005127 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5128 if (controller == null) {
5129 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5130
5131 // device does not support IMS, this method will return true always.
5132 return true;
5133 }
5134 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
5138 }
5139
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005140 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005141 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5142 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005143 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005144
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005147 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5148 if (controller == null) {
5149 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5150 return;
5151 }
5152 controller.setImsProvisioningStatusForCapability(
5153 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
5157 }
5158
5159 @Override
5160 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005161 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5162 mApp, subId, "getProvisioningStatusForCapability");
5163
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005164 final long identity = Binder.clearCallingIdentity();
5165 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005166 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5167 if (controller == null) {
5168 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005169
joonhunshin91bc1952022-04-29 08:47:15 +00005170 // device does not support IMS, this method will return true always.
5171 return true;
5172 }
5173 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
5177 }
5178
5179 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005180 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5181 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5182 mApp, subId, "isProvisioningRequiredForCapability");
5183
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005186 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5187 if (controller == null) {
5188 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5189
5190 // device does not support IMS, this method will return false
5191 return false;
5192 }
5193 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005196 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005197 }
5198
5199 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005200 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5201 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5202 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005203
joonhunshincffb7fc2021-11-28 07:32:01 +00005204 final long identity = Binder.clearCallingIdentity();
5205 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005206 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5207 if (controller == null) {
5208 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5209
5210 // device does not support IMS, this method will return false
5211 return false;
5212 }
5213 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005217 }
5218
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005219 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005220 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005221 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5222 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5223 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005224 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5225 mApp, subId, "getImsProvisioningInt");
5226
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005227 final long identity = Binder.clearCallingIdentity();
5228 try {
5229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005230 int slotId = getSlotIndex(subId);
5231 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5232 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5233 + subId + "' for key:" + key);
5234 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5235 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005236
joonhunshin91bc1952022-04-29 08:47:15 +00005237 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5238 if (controller == null) {
5239 loge("getImsProvisioningInt: Device does not support IMS");
5240
5241 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5242 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5243 }
5244 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005245 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5246 return retVal;
5247 }
5248
calvinpanb5a34062021-02-08 19:59:36 +08005249 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005250 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005251 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5252 + subId + "' for key:" + key);
5253 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
5257 }
5258
5259 @Override
5260 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005261 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5262 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5263 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005264 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5265 mApp, subId, "getImsProvisioningString");
5266
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005267 final long identity = Binder.clearCallingIdentity();
5268 try {
5269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005270 int slotId = getSlotIndex(subId);
5271 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5272 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5273 + subId + "' for key:" + key);
5274 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5275 }
calvinpanb5a34062021-02-08 19:59:36 +08005276 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005277 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005278 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5279 + subId + "' for key:" + key);
5280 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
5284 }
5285
5286 @Override
5287 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005288 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5289 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5290 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5292 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005293
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005294 final long identity = Binder.clearCallingIdentity();
5295 try {
5296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005297 int slotId = getSlotIndex(subId);
5298 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5299 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5300 + subId + "' for key:" + key);
5301 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5302 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005303
joonhunshin91bc1952022-04-29 08:47:15 +00005304 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5305 if (controller == null) {
5306 loge("setImsProvisioningInt: Device does not support IMS");
5307
5308 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5309 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5310 }
5311 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005312 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5313 return retVal;
5314 }
5315
calvinpanb5a34062021-02-08 19:59:36 +08005316 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5317 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005318 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005319 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005320 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
5324 }
5325
5326 @Override
5327 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005328 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5329 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5330 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5332 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005336 int slotId = getSlotIndex(subId);
5337 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5338 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5339 + subId + "' for key:" + key);
5340 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5341 }
calvinpanb5a34062021-02-08 19:59:36 +08005342 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5343 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005344 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005345 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005346 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005347 } finally {
5348 Binder.restoreCallingIdentity(identity);
5349 }
5350 }
5351
Brad Ebinger919631e2021-06-02 17:46:35 -07005352 /**
5353 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5354 * for the given slot ID or no ImsResolver instance has been created.
5355 * @param slotId The slot ID that the IMS service is created for.
5356 * @throws ImsException If there is no ImsService configured for this slot.
5357 */
5358 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5359 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5360 ImsFeature.FEATURE_MMTEL)) {
5361 throw new ImsException("This subscription does not support MMTEL over IMS",
5362 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5363 }
5364 }
5365
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005366 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005367 int slotId = SubscriptionManager.getSlotIndex(subId);
5368 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005369 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5370 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005371 }
5372 return slotId;
5373 }
5374
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005375 private int getSlotIndex(int subId) {
5376 int slotId = SubscriptionManager.getSlotIndex(subId);
5377 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5378 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5379 }
5380 return slotId;
5381 }
5382
Wink Saville36469e72014-06-11 15:17:00 -07005383 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005384 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005385 */
5386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005387 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5388 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005389 try {
5390 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5391 } catch (SecurityException se) {
5392 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5393 throw new SecurityException("Package " + callingPackage + " does not belong to "
5394 + Binder.getCallingUid());
5395 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005396 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005397 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005398 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005399 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005400 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005401 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005402 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005403 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5404 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 final long identity = Binder.clearCallingIdentity();
5407 try {
5408 final Phone phone = getPhone(subId);
5409 if (phone != null) {
5410 return phone.getServiceState().getDataNetworkType();
5411 } else {
5412 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5413 }
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005417 }
5418
5419 /**
5420 * Returns the data network type
5421 */
5422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005423 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005424 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005425 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005426 }
5427
5428 /**
5429 * Returns the data network type for a subId
5430 */
5431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005432 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5433 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005434 String functionName = "getDataNetworkTypeForSubscriber";
5435 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5436 mApp, functionName)) {
5437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5438 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5439 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5440 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005441 }
5442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
5445 final Phone phone = getPhone(subId);
5446 if (phone != null) {
5447 return phone.getServiceState().getDataNetworkType();
5448 } else {
5449 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5450 }
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005454 }
5455
5456 /**
Wink Saville36469e72014-06-11 15:17:00 -07005457 * Returns the Voice network type for a subId
5458 */
5459 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005460 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5461 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005462 String functionName = "getVoiceNetworkTypeForSubscriber";
5463 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5464 mApp, functionName)) {
5465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5466 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5467 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5468 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005469 }
5470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 final Phone phone = getPhone(subId);
5474 if (phone != null) {
5475 return phone.getServiceState().getVoiceNetworkType();
5476 } else {
5477 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5478 }
5479 } finally {
5480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005482 }
5483
5484 /**
5485 * @return true if a ICC card is present
5486 */
5487 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005488 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005489 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005490 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005491 }
5492
5493 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005494 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005495 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005496 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005497 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498 final long identity = Binder.clearCallingIdentity();
5499 try {
5500 final Phone phone = PhoneFactory.getPhone(slotIndex);
5501 if (phone != null) {
5502 return phone.getIccCard().hasIccCard();
5503 } else {
5504 return false;
5505 }
5506 } finally {
5507 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005509 }
5510
5511 /**
5512 * Return if the current radio is LTE on CDMA. This
5513 * is a tri-state return value as for a period of time
5514 * the mode may be unknown.
5515 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005516 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005517 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005518 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005519 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005521 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5522 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5523 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005524 }
5525
Sanket Padawe356d7632015-06-22 14:03:32 -07005526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005527 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5528 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005529 try {
5530 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5531 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005532 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5533 }
5534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 final Phone phone = getPhone(subId);
5538 if (phone == null) {
5539 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5540 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005541 return TelephonyProperties.lte_on_cdma_device()
5542 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 }
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005546 }
Wink Saville36469e72014-06-11 15:17:00 -07005547 }
5548
Wink Saville36469e72014-06-11 15:17:00 -07005549 /**
5550 * {@hide}
5551 * Returns Default subId, 0 in the case of single standby.
5552 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005553 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005554 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005555 }
5556
Shishir Agrawala9f32182016-04-12 12:00:16 -07005557 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005558 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005559 }
5560
Wink Savilleb564aae2014-10-23 10:18:09 -07005561 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005562 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005563 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005564
Pengquan Menge92a50d2018-09-21 15:54:48 -07005565 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005566 return getSubscriptionManagerService().isActiveSubId(subId,
5567 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005568 }
5569
Ihab Awadf2177b72013-11-25 13:33:23 -08005570 /**
5571 * @see android.telephony.TelephonyManager.WifiCallingChoices
5572 */
5573 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
5575 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005576 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5578 getWhenToMakeWifiCallsDefaultPreference());
5579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005582 }
5583
5584 /**
5585 * @see android.telephony.TelephonyManager.WifiCallingChoices
5586 */
5587 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005591 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005596 }
5597
Sailesh Nepald1e68152013-12-12 19:08:02 -08005598 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005599 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005600 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005601 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005602
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005603 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5604 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5605 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005606 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005607 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005608 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005609 }
5610 return PhoneFactory.getPhone(phoneId);
5611 }
5612
Shishir Agrawal566b7612013-10-28 14:41:00 -07005613 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005614 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005615 @NonNull IccLogicalChannelRequest request) {
5616 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5617 /*message=*/ "iccOpenLogicalChannel");
5618
5619 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5620 // Verify that the callingPackage in the request belongs to the calling UID
5621 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5622
5623 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005624 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005625
Rambo Wanga1782702021-11-10 20:15:19 -08005626 private Phone getPhoneFromValidIccLogicalChannelRequest(
5627 @NonNull IccLogicalChannelRequest request, String message) {
5628 Phone phone;
5629 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, request.subId, message);
5632 phone = getPhoneFromSubId(request.subId);
5633 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5634 enforceModifyPermission();
5635 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5636 } else {
5637 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005638 }
Rambo Wanga1782702021-11-10 20:15:19 -08005639 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005640 }
5641
5642 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005643 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 final long identity = Binder.clearCallingIdentity();
5645 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005646 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005648 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5649 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005650 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5651 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 loge("The calling package is not allowed to access ISD-R.");
5653 throw new SecurityException(
5654 "The calling package is not allowed to access ISD-R.");
5655 }
Derek Tan740e1672017-06-27 14:56:27 -07005656 }
Derek Tan740e1672017-06-27 14:56:27 -07005657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005659 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5660 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 return response;
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005665 }
5666
5667 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005668 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5669 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5670 /*message=*/"iccCloseLogicalChannel");
5671
5672 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5673
5674 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005676
Rambo Wanga1782702021-11-10 20:15:19 -08005677 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5678 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005679 // before this feature is enabled, this API should only return false if
5680 // the operation fails instead of throwing runtime exception for
5681 // backward-compatibility.
5682 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5683 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 final long identity = Binder.clearCallingIdentity();
5685 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005686 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005687 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 }
Chen Xue9d737e2022-01-01 23:41:31 -08005689 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005690 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005691 Boolean success = false;
5692 if (result instanceof RuntimeException) {
5693 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005694 if (shouldThrowExceptionOnFailure) {
5695 throw (RuntimeException) result;
5696 } else {
5697 return false;
5698 }
Chen Xue9d737e2022-01-01 23:41:31 -08005699 } else if (result instanceof Boolean) {
5700 success = (Boolean) result;
5701 } else {
5702 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5703 }
Rambo Wanga1782702021-11-10 20:15:19 -08005704 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 return success;
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005708 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005709 }
5710
5711 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005712 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005713 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5715 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005716 if (DBG) {
5717 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5718 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5719 + p3 + " data=" + data);
5720 }
5721 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5722 command, p1, p2, p3, data);
5723 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005724
Jordan Liu4c733742019-02-28 12:03:40 -08005725 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005726 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005727 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005728 enforceModifyPermission();
5729 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005730 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005731 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5732 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005733 }
5734 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005735 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5736 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005737 }
5738
5739 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5740 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 final long identity = Binder.clearCallingIdentity();
5742 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005743 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 return "";
5745 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005748 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5749 null /* workSource */);
5750 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 // Append the returned status code to the end of the response payload.
5753 String s = Integer.toHexString(
5754 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5755 if (response.payload != null) {
5756 s = IccUtils.bytesToHexString(response.payload) + s;
5757 }
5758 return s;
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005761 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005762 }
Jake Hambye994d462014-02-03 13:10:13 -08005763
Evan Charltonc66da362014-05-16 14:06:40 -07005764 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005765 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5766 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5768 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005770 if (DBG) {
5771 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5772 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5773 }
5774 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5775 cla, command, p1, p2, p3, data);
5776 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005777
Jordan Liu4c733742019-02-28 12:03:40 -08005778 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005779 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005780 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005781 enforceModifyPermission();
5782 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5783 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005784 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005785 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5786 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005787 }
5788
5789 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005790 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5791 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005792 }
5793
5794 // open APDU basic channel assuming the caller has sufficient permissions
5795 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5796 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5800 && TextUtils.equals(ISDR_AID, data)) {
5801 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005802 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5803 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 if (bestComponent == null
5805 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5806 loge("The calling package is not allowed to select ISD-R.");
5807 throw new SecurityException(
5808 "The calling package is not allowed to select ISD-R.");
5809 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005810 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005813 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5814 null /* workSource */);
5815 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 // Append the returned status code to the end of the response payload.
5818 String s = Integer.toHexString(
5819 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5820 if (response.payload != null) {
5821 s = IccUtils.bytesToHexString(response.payload) + s;
5822 }
5823 return s;
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005826 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005827 }
5828
5829 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005830 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005831 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5833 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 final long identity = Binder.clearCallingIdentity();
5836 try {
5837 if (DBG) {
5838 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5839 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5840 }
5841
5842 IccIoResult response =
5843 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5844 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5845 subId);
5846
5847 if (DBG) {
5848 log("Exchange SIM_IO [R]" + response);
5849 }
5850
5851 byte[] result = null;
5852 int length = 2;
5853 if (response.payload != null) {
5854 length = 2 + response.payload.length;
5855 result = new byte[length];
5856 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5857 } else {
5858 result = new byte[length];
5859 }
5860
5861 result[length - 1] = (byte) response.sw2;
5862 result[length - 2] = (byte) response.sw1;
5863 return result;
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005866 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005867 }
5868
Nathan Haroldb3014052017-01-25 15:57:32 -08005869 /**
5870 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5871 * on a particular subscription
5872 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005873 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5874 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005876 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005877 return null;
5878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 if (appType != TelephonyManager.APPTYPE_USIM
5883 && appType != TelephonyManager.APPTYPE_SIM) {
5884 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5885 return null;
5886 }
5887 Object response = sendRequest(
5888 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5889 if (response instanceof String[]) {
5890 return (String[]) response;
5891 }
yincheng zhao2737e882019-09-06 17:06:54 -07005892 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005894 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005897 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005898 }
5899
yincheng zhao2737e882019-09-06 17:06:54 -07005900 /**
5901 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5902 * subscription.
5903 *
5904 * @param subId the id of the subscription.
5905 * @param appType the uicc app type, must be USIM or SIM.
5906 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5907 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005908 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005909 * @return number of fplmns that is successfully written to the SIM.
5910 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005911 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5912 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5914 mApp, subId, "setForbiddenPlmns");
5915
yincheng zhao2737e882019-09-06 17:06:54 -07005916 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5917 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5918 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5919 }
5920 if (fplmns == null) {
5921 throw new IllegalArgumentException("Fplmn List provided is null");
5922 }
5923 for (String fplmn : fplmns) {
5924 if (!CellIdentity.isValidPlmn(fplmn)) {
5925 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5926 }
5927 }
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
5930 Object response = sendRequest(
5931 CMD_SET_FORBIDDEN_PLMNS,
5932 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5933 subId);
5934 return (int) response;
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
5937 }
5938 }
5939
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005940 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005941 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5943 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 final long identity = Binder.clearCallingIdentity();
5946 try {
5947 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5948 if (response.payload == null) {
5949 return "";
5950 }
Evan Charltonc66da362014-05-16 14:06:40 -07005951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 // Append the returned status code to the end of the response payload.
5953 String s = Integer.toHexString(
5954 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5955 s = IccUtils.bytesToHexString(response.payload) + s;
5956 return s;
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
Evan Charltonc66da362014-05-16 14:06:40 -07005960 }
5961
Jake Hambye994d462014-02-03 13:10:13 -08005962 /**
5963 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5964 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5965 *
5966 * @param itemID the ID of the item to read
5967 * @return the NV item as a String, or null on error.
5968 */
5969 @Override
5970 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005971 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5973 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974
5975 final long identity = Binder.clearCallingIdentity();
5976 try {
5977 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005978 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5980 return value;
5981 } finally {
5982 Binder.restoreCallingIdentity(identity);
5983 }
Jake Hambye994d462014-02-03 13:10:13 -08005984 }
5985
5986 /**
5987 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5988 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5989 *
5990 * @param itemID the ID of the item to read
5991 * @param itemValue the value to write, as a String
5992 * @return true on success; false on any failure
5993 */
5994 @Override
5995 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005996 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5998 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999
6000 final long identity = Binder.clearCallingIdentity();
6001 try {
6002 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6003 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006004 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6006 return success;
6007 } finally {
6008 Binder.restoreCallingIdentity(identity);
6009 }
Jake Hambye994d462014-02-03 13:10:13 -08006010 }
6011
6012 /**
6013 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6014 * Used for device configuration by some CDMA operators.
6015 *
6016 * @param preferredRoamingList byte array containing the new PRL
6017 * @return true on success; false on any failure
6018 */
6019 @Override
6020 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6022 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023
6024 final long identity = Binder.clearCallingIdentity();
6025 try {
6026 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6027 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6028 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6029 return success;
6030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
Jake Hambye994d462014-02-03 13:10:13 -08006033 }
6034
6035 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006036 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006037 * Used for device configuration by some CDMA operators.
6038 *
chen xu6dac5ab2018-10-26 17:39:23 -07006039 * @param slotIndex - device slot.
6040 *
Jake Hambye994d462014-02-03 13:10:13 -08006041 * @return true on success; false on any failure
6042 */
6043 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006044 public boolean resetModemConfig(int slotIndex) {
6045 Phone phone = PhoneFactory.getPhone(slotIndex);
6046 if (phone != null) {
6047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6048 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049
chen xu6dac5ab2018-10-26 17:39:23 -07006050 final long identity = Binder.clearCallingIdentity();
6051 try {
6052 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6053 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6054 return success;
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 }
chen xu6dac5ab2018-10-26 17:39:23 -07006059 return false;
6060 }
6061
6062 /**
6063 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6064 *
6065 * @param slotIndex - device slot.
6066 *
6067 * @return true on success; false on any failure
6068 */
6069 @Override
6070 public boolean rebootModem(int slotIndex) {
6071 Phone phone = PhoneFactory.getPhone(slotIndex);
6072 if (phone != null) {
6073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6074 mApp, phone.getSubId(), "rebootModem");
6075
6076 final long identity = Binder.clearCallingIdentity();
6077 try {
6078 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6079 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6080 return success;
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
6084 }
6085 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006086 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006087
Brad Ebinger51f743a2017-01-23 13:50:20 -08006088 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006089 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6090 * {@link #disableIms(int)}.
6091 * @param slotIndex device slot.
6092 */
6093 public void resetIms(int slotIndex) {
6094 enforceModifyPermission();
6095
6096 final long identity = Binder.clearCallingIdentity();
6097 try {
6098 if (mImsResolver == null) {
6099 // may happen if the does not support IMS.
6100 return;
6101 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006102 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006103 } finally {
6104 Binder.restoreCallingIdentity(identity);
6105 }
6106 }
6107
6108 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006109 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6110 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006111 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006112 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114
6115 final long identity = Binder.clearCallingIdentity();
6116 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006117 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006118 // may happen if the device does not support IMS.
6119 return;
6120 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006121 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006125 }
6126
6127 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006128 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6129 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006130 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006131 public void disableIms(int slotId) {
6132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133
6134 final long identity = Binder.clearCallingIdentity();
6135 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006136 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006137 // may happen if the device does not support IMS.
6138 return;
6139 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006140 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006144 }
6145
6146 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006147 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6148 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006149 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006150 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006151 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153
6154 final long identity = Binder.clearCallingIdentity();
6155 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006156 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6158 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006159 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006160 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006164 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006165 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006166 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6167 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006168 @Override
6169 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006170 enforceModifyPermission();
6171
6172 final long identity = Binder.clearCallingIdentity();
6173 try {
6174 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006175 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
6179 }
6180
6181 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006182 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006183 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006184 */
6185 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006190 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006191 // may happen if the device does not support IMS.
6192 return null;
6193 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006194 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 } finally {
6196 Binder.restoreCallingIdentity(identity);
6197 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006198 }
6199
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006200 /**
6201 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006202 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006203 */
6204 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206
6207 final long identity = Binder.clearCallingIdentity();
6208 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006209 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006210 // may happen if the device does not support IMS.
6211 return null;
6212 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006213 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 } finally {
6215 Binder.restoreCallingIdentity(identity);
6216 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006217 }
6218
Brad Ebinger884c07b2018-02-15 16:17:40 -08006219 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006220 * Sets the ImsService Package Name that Telephony will bind to.
6221 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006222 * @param slotIndex the slot ID that the ImsService should bind for.
6223 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006224 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006225 * @param featureTypes An integer array of feature types associated with a packageName.
6226 * @param packageName The name of the package that the current configuration will be replaced
6227 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006228 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006229 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006230 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6231 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006232 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006234 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 final long identity = Binder.clearCallingIdentity();
6237 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006238 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006239 // may happen if the device does not support IMS.
6240 return false;
6241 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006242 Map<Integer, String> featureConfig = new HashMap<>();
6243 for (int featureType : featureTypes) {
6244 featureConfig.put(featureType, packageName);
6245 }
6246 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6247 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006251 }
6252
6253 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006254 * Clears any carrier ImsService overrides for the slot index specified that were previously
6255 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6256 *
6257 * This should only be used for testing.
6258 *
6259 * @param slotIndex the slot ID that the ImsService should bind for.
6260 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6261 */
6262 @Override
6263 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006264 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6265 "clearCarrierImsServiceOverride");
6266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006267 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006268
6269 final long identity = Binder.clearCallingIdentity();
6270 try {
6271 if (mImsResolver == null) {
6272 // may happen if the device does not support IMS.
6273 return false;
6274 }
6275 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6276 } finally {
6277 Binder.restoreCallingIdentity(identity);
6278 }
6279 }
6280
6281 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006282 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006283 *
6284 * @param slotId The slot that the ImsService is associated with.
6285 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6286 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006287 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006288 * @return the package name of the ImsService configuration.
6289 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006290 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6291 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006292 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006293 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6294 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 final long identity = Binder.clearCallingIdentity();
6297 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006298 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006299 // may happen if the device does not support IMS.
6300 return "";
6301 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006302 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006303 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6304 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 } finally {
6306 Binder.restoreCallingIdentity(identity);
6307 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006308 }
6309
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006310 /**
6311 * Get the MmTelFeature state associated with the requested subscription id.
6312 * @param subId The subscription that the MmTelFeature is associated with.
6313 * @param callback A callback with an integer containing the
6314 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6315 */
6316 @Override
6317 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6318 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006319 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6320 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6321 "IMS not available on device.");
6322 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006323 final long token = Binder.clearCallingIdentity();
6324 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006325 int slotId = getSlotIndex(subId);
6326 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6327 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6328 + subId + "'");
6329 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6330 }
6331 verifyImsMmTelConfiguredOrThrow(slotId);
6332 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6333 try {
6334 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6335 } catch (RemoteException e) {
6336 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6337 + "Ignore");
6338 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006339 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006340 } catch (ImsException e) {
6341 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006342 } finally {
6343 Binder.restoreCallingIdentity(token);
6344 }
6345 }
6346
Daniel Brightbb5840b2021-01-12 15:48:18 -08006347 /**
6348 * Sets the ims registration state on all valid {@link Phone}s.
6349 */
6350 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006351 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006355 // NOTE: Before S, this method only set the default phone.
6356 for (final Phone phone : PhoneFactory.getPhones()) {
6357 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6358 phone.setImsRegistrationState(registered);
6359 }
6360 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
Wink Saville36469e72014-06-11 15:17:00 -07006364 }
6365
6366 /**
Stuart Scott54788802015-03-30 13:18:01 -07006367 * Set the network selection mode to automatic.
6368 *
6369 */
6370 @Override
6371 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6373 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374
6375 final long identity = Binder.clearCallingIdentity();
6376 try {
shilufc958392020-01-20 11:36:01 -08006377 if (!isActiveSubscription(subId)) {
6378 return;
6379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006381 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6382 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
Stuart Scott54788802015-03-30 13:18:01 -07006386 }
6387
Jack Yud10cdd42020-09-28 20:28:01 -07006388 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006389 * Ask the radio to connect to the input network and change selection mode to manual.
6390 *
6391 * @param subId the id of the subscription.
6392 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6393 * the operator to attach to.
6394 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6395 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6396 * normal network selection next time.
6397 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006398 */
6399 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006400 public boolean setNetworkSelectionModeManual(
6401 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6403 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006404
Jack Yu285100e2022-12-02 22:48:35 -08006405 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006406 if (!isActiveSubscription(subId)) {
6407 return false;
6408 }
6409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006411 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006413 if (DBG) {
6414 log("setNetworkSelectionModeManual: subId: " + subId
6415 + " operator: " + operatorInfo);
6416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006421 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006422 /**
shilu84f6e8b2019-12-19 13:58:01 -08006423 * Get the manual network selection
6424 *
6425 * @param subId the id of the subscription.
6426 *
6427 * @return the previously saved user selected PLMN
6428 */
6429 @Override
6430 public String getManualNetworkSelectionPlmn(int subId) {
6431 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006432 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6433 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006434
6435 final long identity = Binder.clearCallingIdentity();
6436 try {
6437 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006438 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006439 }
6440
6441 final Phone phone = getPhone(subId);
6442 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006443 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006444 }
6445 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6446 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006447 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
6451 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006452
6453 /**
6454 * Scans for available networks.
6455 */
6456 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006457 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6458 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6460 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006461 LocationAccessPolicy.LocationPermissionResult locationResult =
6462 LocationAccessPolicy.checkLocationPermission(mApp,
6463 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6464 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006465 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006466 .setCallingPid(Binder.getCallingPid())
6467 .setCallingUid(Binder.getCallingUid())
6468 .setMethod("getCellNetworkScanResults")
6469 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006470 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6471 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006472 .build());
6473 switch (locationResult) {
6474 case DENIED_HARD:
6475 throw new SecurityException("Not allowed to access scan results -- location");
6476 case DENIED_SOFT:
6477 return null;
6478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479
Pengquan Menga1bb6272018-09-06 09:59:22 -07006480 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 try {
6482 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006483 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006484 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006488 }
6489
6490 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006491 * Get the call forwarding info, given the call forwarding reason.
6492 */
6493 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006494 public void getCallForwarding(int subId, int callForwardingReason,
6495 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006496 enforceReadPrivilegedPermission("getCallForwarding");
6497 long identity = Binder.clearCallingIdentity();
6498 try {
6499 if (DBG) {
6500 log("getCallForwarding: subId " + subId
6501 + " callForwardingReason" + callForwardingReason);
6502 }
Hall Liu27d24262020-09-18 19:04:59 -07006503
6504 Phone phone = getPhone(subId);
6505 if (phone == null) {
6506 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006507 callback.onError(
6508 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006509 } catch (RemoteException e) {
6510 // ignore
6511 }
6512 return;
6513 }
6514
6515 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6516 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6517 @Override
6518 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6519 try {
6520 callback.onCallForwardingInfoAvailable(info);
6521 } catch (RemoteException e) {
6522 // ignore
6523 }
6524 }
6525
6526 @Override
6527 public void onError(int error) {
6528 try {
6529 callback.onError(error);
6530 } catch (RemoteException e) {
6531 // ignore
6532 }
6533 }
6534 });
6535 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006536 } finally {
6537 Binder.restoreCallingIdentity(identity);
6538 }
6539 }
6540
6541 /**
6542 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6543 * reason, the number to forward, and the timeout before the forwarding is attempted.
6544 */
6545 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006546 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6547 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006548 enforceModifyPermission();
6549 long identity = Binder.clearCallingIdentity();
6550 try {
6551 if (DBG) {
6552 log("setCallForwarding: subId " + subId
6553 + " callForwardingInfo" + callForwardingInfo);
6554 }
Hall Liu27d24262020-09-18 19:04:59 -07006555
6556 Phone phone = getPhone(subId);
6557 if (phone == null) {
6558 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006559 callback.accept(
6560 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006561 } catch (RemoteException e) {
6562 // ignore
6563 }
6564 return;
6565 }
6566
6567 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6568 FunctionalUtils.ignoreRemoteException(callback::accept));
6569
6570 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
6574 }
6575
6576 /**
Hall Liu27d24262020-09-18 19:04:59 -07006577 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006578 */
6579 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006580 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006581 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006582 long identity = Binder.clearCallingIdentity();
6583 try {
Hall Liu27d24262020-09-18 19:04:59 -07006584 Phone phone = getPhone(subId);
6585 if (phone == null) {
6586 try {
6587 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6588 } catch (RemoteException e) {
6589 // ignore
6590 }
6591 return;
6592 }
SongFerngWang0e767992021-03-31 22:08:45 +08006593 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6594 PersistableBundle c = configManager.getConfigForSubId(subId);
6595 boolean requireUssd = c.getBoolean(
6596 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006597
Shuo Qian4a594052020-01-23 11:59:30 -08006598 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006599 if (requireUssd) {
6600 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6601 getSubscriptionCarrierId(subId));
6602 String newUssdCommand = "";
6603 try {
6604 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006605 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006606 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6607 } catch (NullPointerException e) {
6608 loge("Failed to generate USSD number" + e);
6609 }
6610 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6611 mMainThreadHandler, callback, carrierXmlParser,
6612 CarrierXmlParser.SsEntry.SSAction.QUERY);
6613 final String ussdCommand = newUssdCommand;
6614 Executors.newSingleThreadExecutor().execute(() -> {
6615 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6616 });
6617 } else {
6618 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6619 callback::accept);
6620 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6621 }
Shuo Qian4a594052020-01-23 11:59:30 -08006622 } finally {
6623 Binder.restoreCallingIdentity(identity);
6624 }
6625 }
6626
6627 /**
Hall Liu27d24262020-09-18 19:04:59 -07006628 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006629 */
6630 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006631 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006632 enforceModifyPermission();
6633 long identity = Binder.clearCallingIdentity();
6634 try {
Hall Liu27d24262020-09-18 19:04:59 -07006635 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6636
6637 Phone phone = getPhone(subId);
6638 if (phone == null) {
6639 try {
6640 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6641 } catch (RemoteException e) {
6642 // ignore
6643 }
6644 return;
6645 }
6646
SongFerngWang0e767992021-03-31 22:08:45 +08006647 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6648 PersistableBundle c = configManager.getConfigForSubId(subId);
6649 boolean requireUssd = c.getBoolean(
6650 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006651
SongFerngWang0e767992021-03-31 22:08:45 +08006652 if (DBG) log("getCallWaitingStatus: subId " + subId);
6653 if (requireUssd) {
6654 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6655 getSubscriptionCarrierId(subId));
6656 CarrierXmlParser.SsEntry.SSAction ssAction =
6657 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6658 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6659 String newUssdCommand = "";
6660 try {
6661 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006662 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006663 .makeCommand(ssAction, null);
6664 } catch (NullPointerException e) {
6665 loge("Failed to generate USSD number" + e);
6666 }
6667 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6668 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6669 final String ussdCommand = newUssdCommand;
6670 Executors.newSingleThreadExecutor().execute(() -> {
6671 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6672 });
6673 } else {
6674 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6675 FunctionalUtils.ignoreRemoteException(callback::accept));
6676
6677 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6678 }
Shuo Qian4a594052020-01-23 11:59:30 -08006679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
6682 }
6683
6684 /**
yinxub1bed742017-04-17 11:45:04 -07006685 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006686 *
yinxub1bed742017-04-17 11:45:04 -07006687 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006688 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6689 * location related information which will be sent if the caller already possess
6690 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006691 * @param request contains the radio access networks with bands/channels to scan
6692 * @param messenger callback messenger for scan results or errors
6693 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006694 * @return the id of the requested scan which can be used to stop the scan.
6695 */
6696 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006697 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6698 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006699 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6701 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006702 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006703 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6704 if (!renounceFineLocationAccess) {
6705 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006706 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6707 .setCallingPackage(callingPackage)
6708 .setCallingFeatureId(callingFeatureId)
6709 .setCallingPid(Binder.getCallingPid())
6710 .setCallingUid(Binder.getCallingUid())
6711 .setMethod("requestNetworkScan")
6712 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6713 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6714 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6715 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006716 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006717 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006718 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6719 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006720 if (e != null) {
6721 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6722 throw e;
6723 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006724 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006725 return TelephonyScanManager.INVALID_SCAN_ID;
6726 }
6727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 }
Hall Liu912dfd32019-04-25 14:02:26 -07006729 int callingUid = Binder.getCallingUid();
6730 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006734 renounceFineLocationAccess, request, messenger, binder,
6735 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006736 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006737 } finally {
6738 Binder.restoreCallingIdentity(identity);
6739 }
yinxu504e1392017-04-12 16:03:22 -07006740 }
6741
Hall Liub2ac8ef2019-02-28 15:56:23 -08006742 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006743 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006744 boolean hasCarrierPriv;
6745 final long identity = Binder.clearCallingIdentity();
6746 try {
6747 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6748 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6749 } finally {
6750 Binder.restoreCallingIdentity(identity);
6751 }
Hall Liu558027f2019-05-15 19:14:05 -07006752 boolean hasNetworkScanPermission =
6753 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006754 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006755
6756 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6757 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6758 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006759 }
6760
6761 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6762 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006763 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6764 return new SecurityException("Specific channels must not be"
6765 + " scanned without location access.");
6766 }
6767 }
6768 }
6769
Hall Liub2ac8ef2019-02-28 15:56:23 -08006770 return null;
6771 }
6772
yinxu504e1392017-04-12 16:03:22 -07006773 /**
6774 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006775 *
6776 * @param subId id of the subscription
6777 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006778 */
6779 @Override
6780 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6782 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783
Hall Liu912dfd32019-04-25 14:02:26 -07006784 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 final long identity = Binder.clearCallingIdentity();
6786 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006787 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 } finally {
6789 Binder.restoreCallingIdentity(identity);
6790 }
yinxu504e1392017-04-12 16:03:22 -07006791 }
6792
6793 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006794 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006795 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006796 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006797 */
6798 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006799 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006800 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006801 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006802 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803
6804 final long identity = Binder.clearCallingIdentity();
6805 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006806 if (DBG) log("getAllowedNetworkTypesBitmask");
6807 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6808 int networkTypesBitmask = (result != null ? result[0] : -1);
6809 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6810 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 } finally {
6812 Binder.restoreCallingIdentity(identity);
6813 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006814 }
6815
6816 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006817 * Get the allowed network types for certain reason.
6818 *
6819 * @param subId the id of the subscription.
6820 * @param reason the reason the allowed network type change is taking place
6821 * @return the allowed network types.
6822 */
6823 @Override
6824 public long getAllowedNetworkTypesForReason(int subId,
6825 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006826 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006827 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006828 final long identity = Binder.clearCallingIdentity();
6829 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006830 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
6834 }
6835
6836 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006837 * Enable/Disable E-UTRA-NR Dual Connectivity
6838 * @param subId subscription id of the sim card
6839 * @param nrDualConnectivityState expected NR dual connectivity state
6840 * This can be passed following states
6841 * <ol>
6842 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6843 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6844 * <li>Disable NR dual connectivity and force secondary cell to be released
6845 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6846 * </ol>
6847 * @return operation result.
6848 */
6849 @Override
6850 public int setNrDualConnectivityState(int subId,
6851 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6853 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006854 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006855 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6856 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6857 }
6858
Sooraj Sasindran37444802020-08-11 10:40:43 -07006859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6860 final long identity = Binder.clearCallingIdentity();
6861 try {
6862 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6863 nrDualConnectivityState, subId,
6864 workSource);
6865 if (DBG) log("enableNRDualConnectivity result: " + result);
6866 return result;
6867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
6870 }
6871
6872 /**
6873 * Is E-UTRA-NR Dual Connectivity enabled
6874 * @return true if dual connectivity is enabled else false
6875 */
6876 @Override
6877 public boolean isNrDualConnectivityEnabled(int subId) {
6878 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006879 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006880 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006881 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006882 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6883 return false;
6884 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6886 final long identity = Binder.clearCallingIdentity();
6887 try {
6888 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6889 null, subId, workSource);
6890 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6891 return isEnabled;
6892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
6895 }
6896
6897 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006898 * Set the allowed network types of the device and
6899 * provide the reason triggering the allowed network change.
6900 *
6901 * @param subId the id of the subscription.
6902 * @param reason the reason the allowed network type change is taking place
6903 * @param allowedNetworkTypes the allowed network types.
6904 * @return true on success; false on any failure.
6905 */
6906 @Override
6907 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006908 @TelephonyManager.AllowedNetworkTypesReason int reason,
6909 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6911 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006912 // If the caller only has carrier privileges, then they should not be able to override
6913 // any network types which were set for security reasons.
6914 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6915 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006916 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006917 throw new SecurityException(
6918 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006919 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006920 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006921 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006922 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006923 return false;
6924 }
6925 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6926 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006927 return false;
6928 }
6929
Jack Yu5b494332023-01-23 18:18:04 +00006930 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6931 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006932
Jack Yue37dd262022-12-16 11:53:37 -08006933 Phone phone = getPhone(subId);
6934 if (phone == null) {
6935 return false;
6936 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006937
Jack Yue37dd262022-12-16 11:53:37 -08006938 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006939 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006940 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006941 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006942
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006943 final long identity = Binder.clearCallingIdentity();
6944 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006945 Boolean success = (Boolean) sendRequest(
6946 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6947 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6948
6949 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6950 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
6954 }
6955
6956 /**
Miaoa84611c2019-03-15 09:21:10 +08006957 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006958 *
Miaoa84611c2019-03-15 09:21:10 +08006959 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006960 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006961 * @hide
6962 */
6963 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006964 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006965 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006967 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 try {
Miaoa84611c2019-03-15 09:21:10 +08006969 if (phone != null) {
6970 return phone.hasMatchedTetherApnSetting();
6971 } else {
6972 return false;
6973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006974 } finally {
6975 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006976 }
Junda Liu475951f2014-11-07 16:45:03 -08006977 }
6978
6979 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006980 * Get the user enabled state of Mobile Data.
6981 *
6982 * TODO: remove and use isUserDataEnabled.
6983 * This can't be removed now because some vendor codes
6984 * calls through ITelephony directly while they should
6985 * use TelephonyManager.
6986 *
6987 * @return true on enabled
6988 */
6989 @Override
6990 public boolean getDataEnabled(int subId) {
6991 return isUserDataEnabled(subId);
6992 }
6993
6994 /**
6995 * Get whether mobile data is enabled per user setting.
6996 *
6997 * There are other factors deciding whether mobile data is actually enabled, but they are
6998 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006999 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007000 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7001 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007002 *
7003 * @return {@code true} if data is enabled else {@code false}
7004 */
7005 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007006 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007007 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007008 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007009 try {
7010 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7011 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007012 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007013 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7014 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007015 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007017 mApp, subId, functionName);
7018
Robert Greenwalt646120a2014-05-23 11:54:03 -07007019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020
7021 final long identity = Binder.clearCallingIdentity();
7022 try {
Jack Yu285100e2022-12-02 22:48:35 -08007023 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7025 Phone phone = PhoneFactory.getPhone(phoneId);
7026 if (phone != null) {
7027 boolean retVal = phone.isUserDataEnabled();
7028 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7029 return retVal;
7030 } else {
7031 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7032 return false;
7033 }
7034 } finally {
7035 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007036 }
7037 }
7038
7039 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007040 * Checks if the device is capable of mobile data by considering whether whether the
7041 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7042 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007043 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007044 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007045 */
7046 @Override
7047 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007048 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007049 try {
7050 try {
7051 mApp.enforceCallingOrSelfPermission(
7052 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007053 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007054 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007055 try {
7056 mApp.enforceCallingOrSelfPermission(
7057 android.Manifest.permission.READ_PHONE_STATE,
7058 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007059 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007060 mApp.enforceCallingOrSelfPermission(
7061 permission.READ_BASIC_PHONE_STATE, functionName);
7062 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007063 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007064 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007065 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
Jack Yu285100e2022-12-02 22:48:35 -08007070 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 Phone phone = PhoneFactory.getPhone(phoneId);
7072 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007073 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007074 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 return retVal;
7076 } else {
7077 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7078 return false;
7079 }
7080 } finally {
7081 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007082 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007083 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007084
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007085 /**
7086 * Check if data is enabled for a specific reason
7087 * @param subId Subscription index
7088 * @param reason the reason the data enable change is taking place
7089 * @return {@code true} if the overall data is enabled; {@code false} if not.
7090 */
7091 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007092 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007093 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007094 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007095 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007096 try {
7097 mApp.enforceCallingOrSelfPermission(
7098 android.Manifest.permission.ACCESS_NETWORK_STATE,
7099 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007100 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007101 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7102 functionName);
7103 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007104 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007105 try {
7106 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007107 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007108 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007110 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007111 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007112 }
7113
7114
7115 final long identity = Binder.clearCallingIdentity();
7116 try {
Jack Yu285100e2022-12-02 22:48:35 -08007117 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007118 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007119 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007120 + " reason=" + reason);
7121 }
7122 Phone phone = PhoneFactory.getPhone(phoneId);
7123 if (phone != null) {
7124 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007125 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007126 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007127 return retVal;
7128 } else {
7129 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007130 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007131 + subId + " retVal=false");
7132 }
7133 return false;
7134 }
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
7137 }
7138 }
7139
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007140 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007141 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007142 // No permission needed; this only lets the caller inspect their own status.
7143 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007144 }
Junda Liu29340342014-07-10 15:23:27 -07007145
7146 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007147 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007148 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007149 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7150 }
7151
7152 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7153 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007154 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007155 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007156 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7157 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007158 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7159 if (cpt == null) {
7160 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007161 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7162 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007163 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007164 }
7165
7166 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007167 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007168 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007169 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007170 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007171 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007172 Phone phone = getPhone(subId);
7173 if (phone == null) {
7174 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7175 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7176 }
7177 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7178 if (cpt == null) {
7179 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007180 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7181 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007182 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007183 }
7184
7185 @Override
7186 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007187 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007188 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7189 }
7190
7191 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007192 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007193 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007194 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007195 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007196 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7197 Phone phone = PhoneFactory.getPhone(phoneId);
7198 if (phone == null) {
7199 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007200 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007201 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7202 if (cpt == null) {
7203 continue;
7204 }
7205 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007206 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7207 break;
7208 }
7209 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007210 return result;
Junda Liu29340342014-07-10 15:23:27 -07007211 }
Derek Tan89e89d42014-07-08 17:00:10 -07007212
7213 @Override
Junda Liue64de782015-04-16 17:19:16 -07007214 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007215 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007216 Phone phone = PhoneFactory.getPhone(phoneId);
7217 if (phone == null) {
7218 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007219 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007220 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7221 if (cpt == null) {
7222 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007223 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007224 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007225 }
7226
Amith Yamasani6e118872016-02-19 12:53:51 -08007227 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007228 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007229 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007230 Phone phone = PhoneFactory.getPhone(phoneId);
7231 if (phone == null) {
7232 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007233 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007234 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7235 if (cpt == null) {
7236 return Collections.emptyList();
7237 }
7238 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007239 }
7240
chen xuf7e9fe82019-05-09 19:31:02 -07007241 @Override
7242 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007243 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007244 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007245 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007246 try {
7247 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7248 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7249 }
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007252 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007253 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007254 }
7255
Rambo Wang6812ffb2022-03-15 16:54:17 -07007256 @Override
7257 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7258 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7259
7260 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7261 if (phone == null) {
7262 return null;
7263 }
7264 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7265 if (cpt == null) {
7266 return null;
7267 }
7268 return cpt.getCarrierServicePackageName();
7269 }
7270
Wink Savilleb564aae2014-10-23 10:18:09 -07007271 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007272 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007273 UiccPort port = phone == null ? null : phone.getUiccPort();
7274 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007275 return null;
7276 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007277 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007278 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007279 return null;
7280 }
7281 return iccId;
7282 }
7283
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007284 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007285 public void setCallComposerStatus(int subId, int status) {
7286 enforceModifyPermission();
7287
7288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 Phone phone = getPhone(subId);
7291 if (phone != null) {
7292 Phone defaultPhone = phone.getImsPhone();
7293 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7294 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7295 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007296 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7297 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007298 }
7299 }
Shuo Qian284ae752020-12-22 19:10:14 -08007300 } catch (ImsException e) {
7301 throw new ServiceSpecificException(e.getCode());
7302 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007303 Binder.restoreCallingIdentity(identity);
7304 }
7305 }
7306
7307 @Override
7308 public int getCallComposerStatus(int subId) {
7309 enforceReadPrivilegedPermission("getCallComposerStatus");
7310
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 Phone phone = getPhone(subId);
7314 if (phone != null) {
7315 Phone defaultPhone = phone.getImsPhone();
7316 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7317 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7318 return imsPhone.getCallComposerStatus();
7319 }
7320 }
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7325 }
7326
7327 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007328 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7329 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007330 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007331 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 final String iccId = getIccId(subId);
7336 final Phone phone = getPhone(subId);
7337 if (phone == null) {
7338 return false;
7339 }
7340 final String subscriberId = phone.getSubscriberId();
7341
7342 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007343 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 + subscriberId + " to " + number);
7345 }
7346
7347 if (TextUtils.isEmpty(iccId)) {
7348 return false;
7349 }
7350
7351 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7352
7353 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7354 if (alphaTag == null) {
7355 editor.remove(alphaTagPrefKey);
7356 } else {
7357 editor.putString(alphaTagPrefKey, alphaTag);
7358 }
7359
7360 // Record both the line number and IMSI for this ICCID, since we need to
7361 // track all merged IMSIs based on line number
7362 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7363 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7364 if (number == null) {
7365 editor.remove(numberPrefKey);
7366 editor.remove(subscriberPrefKey);
7367 } else {
7368 editor.putString(numberPrefKey, number);
7369 editor.putString(subscriberPrefKey, subscriberId);
7370 }
7371
7372 editor.commit();
7373 return true;
7374 } finally {
7375 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007376 }
Derek Tan7226c842014-07-02 17:42:23 -07007377 }
7378
7379 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007380 public String getLine1NumberForDisplay(int subId, String callingPackage,
7381 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007382 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007384 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007385 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007386 return null;
7387 }
Derek Tan97ebb422014-09-05 16:55:38 -07007388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 final long identity = Binder.clearCallingIdentity();
7390 try {
7391 String iccId = getIccId(subId);
7392 if (iccId != null) {
7393 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7394 if (DBG_MERGE) {
7395 log("getLine1NumberForDisplay returning "
7396 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7397 }
7398 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7401 return null;
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007404 }
Derek Tan7226c842014-07-02 17:42:23 -07007405 }
7406
7407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007408 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7409 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007411 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007412 return null;
7413 }
Derek Tan97ebb422014-09-05 16:55:38 -07007414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 final long identity = Binder.clearCallingIdentity();
7416 try {
7417 String iccId = getIccId(subId);
7418 if (iccId != null) {
7419 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7420 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7421 }
7422 return null;
7423 } finally {
7424 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007425 }
Derek Tan7226c842014-07-02 17:42:23 -07007426 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007427
7428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007429 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7430 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007431 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7432 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007434 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007435 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007436 return null;
7437 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007438
Jordan Liub49b04b2019-05-06 14:45:15 -07007439 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7440 // the process, where TelephonyManager was instantiated.
7441 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007442 final long identity = Binder.clearCallingIdentity();
7443 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 final TelephonyManager tele = TelephonyManager.from(context);
7446 final SubscriptionManager sub = SubscriptionManager.from(context);
7447
7448 // Figure out what subscribers are currently active
7449 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450
Jordan Liub49b04b2019-05-06 14:45:15 -07007451 // Only consider subs which match the current subId
7452 // This logic can be simplified. See b/131189269 for progress.
7453 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007454 activeSubscriberIds.add(tele.getSubscriberId(subId));
7455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456
7457 // First pass, find a number override for an active subscriber
7458 String mergeNumber = null;
7459 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7460 for (String key : prefs.keySet()) {
7461 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7462 final String subscriberId = (String) prefs.get(key);
7463 if (activeSubscriberIds.contains(subscriberId)) {
7464 final String iccId = key.substring(
7465 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7466 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7467 mergeNumber = (String) prefs.get(numberKey);
7468 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007469 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 + " for active subscriber " + subscriberId);
7471 }
7472 if (!TextUtils.isEmpty(mergeNumber)) {
7473 break;
7474 }
7475 }
7476 }
7477 }
7478
7479 // Shortcut when no active merged subscribers
7480 if (TextUtils.isEmpty(mergeNumber)) {
7481 return null;
7482 }
7483
7484 // Second pass, find all subscribers under that line override
7485 final ArraySet<String> result = new ArraySet<>();
7486 for (String key : prefs.keySet()) {
7487 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7488 final String number = (String) prefs.get(key);
7489 if (mergeNumber.equals(number)) {
7490 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7491 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7492 final String subscriberId = (String) prefs.get(subscriberKey);
7493 if (!TextUtils.isEmpty(subscriberId)) {
7494 result.add(subscriberId);
7495 }
7496 }
7497 }
7498 }
7499
7500 final String[] resultArray = result.toArray(new String[result.size()]);
7501 Arrays.sort(resultArray);
7502 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007503 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7505 }
7506 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007507 } finally {
7508 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007509 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007510 }
7511
7512 @Override
zoey chen38003472019-12-13 17:16:31 +08007513 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7514 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007515
7516 final long identity = Binder.clearCallingIdentity();
7517 try {
7518 final TelephonyManager telephonyManager = mApp.getSystemService(
7519 TelephonyManager.class);
7520 String subscriberId = telephonyManager.getSubscriberId(subId);
7521 if (subscriberId == null) {
7522 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007523 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007524 + subId);
7525 }
7526 return null;
7527 }
7528
Jack Yu3beaf9d2023-04-14 09:17:27 -07007529 final SubscriptionInfo info = getSubscriptionManagerService()
7530 .getSubscriptionInfo(subId);
7531 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007532 // If it doesn't belong to any group, return just subscriberId of itself.
7533 if (groupUuid == null) {
7534 return new String[]{subscriberId};
7535 }
7536
7537 // Get all subscriberIds from the group.
7538 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007539 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7540 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7541 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007542 for (SubscriptionInfo subInfo : groupInfos) {
7543 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7544 if (subscriberId != null) {
7545 mergedSubscriberIds.add(subscriberId);
7546 }
7547 }
7548
7549 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7550 } finally {
7551 Binder.restoreCallingIdentity(identity);
7552
7553 }
7554 }
7555
7556 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007557 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007558 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007559 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560
7561 final long identity = Binder.clearCallingIdentity();
7562 try {
7563 final Phone phone = getPhone(subId);
7564 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7565 } finally {
7566 Binder.restoreCallingIdentity(identity);
7567 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007568 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007569
7570 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007571 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007572 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7573 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007574 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7575 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576
7577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 final Phone phone = getPhone(subId);
7580 if (phone == null) {
7581 return false;
7582 }
7583 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7584 cdmaNonRoamingList);
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007587 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007588 }
7589
7590 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007591 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007592 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007593 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007594 if (phone == null) {
7595 return raf;
7596 }
7597
Shuo Qiandee53402020-05-29 14:08:15 -07007598 try {
7599 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007600 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007601 mApp, phone.getSubId(), "getRadioAccessFamily");
7602 } catch (SecurityException e) {
7603 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7604 throw e;
7605 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607 final long identity = Binder.clearCallingIdentity();
7608 try {
chen xub97461a2018-10-26 14:17:57 -07007609 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
chen xub97461a2018-10-26 14:17:57 -07007613 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007614 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007615
7616 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007617 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007618 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007619 try {
7620 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7621 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007622 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007623 }
7624 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007625 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007626 }
7627 RoleManager rm = mApp.getSystemService(RoleManager.class);
7628 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7629 if (!dialerRoleHolders.contains(callingPackage)) {
7630 throw new SecurityException("App must be the dialer role holder to"
7631 + " upload a call composer pic");
7632 }
7633
7634 Executors.newSingleThreadExecutor().execute(() -> {
7635 ByteArrayOutputStream output = new ByteArrayOutputStream(
7636 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7637 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7638 boolean readUntilEnd = false;
7639 int totalBytesRead = 0;
7640 byte[] buffer = new byte[16 * 1024];
7641 while (true) {
7642 int numRead;
7643 try {
7644 numRead = input.read(buffer);
7645 } catch (IOException e) {
7646 try {
7647 fd.checkError();
7648 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7649 null);
7650 } catch (IOException e1) {
7651 // This means that the other side closed explicitly with an error. If this
7652 // happens, log and ignore.
7653 loge("Remote end of call composer picture pipe closed: " + e1);
7654 }
7655 break;
7656 }
7657 if (numRead == -1) {
7658 readUntilEnd = true;
7659 break;
7660 }
7661 totalBytesRead += numRead;
7662 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7663 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7664 try {
7665 input.close();
7666 } catch (IOException e) {
7667 // ignore
7668 }
7669 break;
7670 }
7671 output.write(buffer, 0, numRead);
7672 }
7673 // Generally, the remote end will close the file descriptors. The only case where we
7674 // close is above, where the picture size is too big.
7675
7676 try {
7677 fd.checkError();
7678 } catch (IOException e) {
7679 loge("Remote end for call composer closed with an error: " + e);
7680 return;
7681 }
7682
Hall Liuaa4211e2021-01-20 15:43:39 -08007683 if (!readUntilEnd) {
7684 loge("Did not finish reading entire image; aborting");
7685 return;
7686 }
Hall Liu82694d52020-12-11 18:22:04 -08007687
Hall Liuaa4211e2021-01-20 15:43:39 -08007688 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7689 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7690 new CallComposerPictureTransfer.Factory() {},
7691 imageData,
7692 (result) -> {
7693 if (result.first != null) {
7694 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7695 Bundle outputResult = new Bundle();
7696 outputResult.putParcelable(
7697 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7698 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7699 outputResult);
7700 } else {
7701 callback.send(result.second, null);
7702 }
7703 }
7704 );
Hall Liu82694d52020-12-11 18:22:04 -08007705 });
7706 }
7707
7708 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007709 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007710 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712
7713 final long identity = Binder.clearCallingIdentity();
7714 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007715 ImsManager.getInstance(defaultPhone.getContext(),
7716 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 } finally {
7718 Binder.restoreCallingIdentity(identity);
7719 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007720 }
7721
7722 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007723 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007724 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7726 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007727 return false;
7728 }
Svet Ganovb320e182015-04-16 12:30:10 -07007729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 final long identity = Binder.clearCallingIdentity();
7731 try {
7732 // Check the user preference and the system-level IMS setting. Even if the user has
7733 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7734 // In the long run, we may instead need to check if there exists a connection service
7735 // which can support video calling.
7736 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007737 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 return imsManager.isVtEnabledByPlatform()
7739 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7740 && imsManager.isVtEnabledByUser();
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
7743 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007744 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007745
Andrew Leea1239f22015-03-02 17:44:07 -08007746 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007747 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7748 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007750 mApp, subId, callingPackage, callingFeatureId,
7751 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 return false;
7753 }
7754
7755 final long identity = Binder.clearCallingIdentity();
7756 try {
7757 CarrierConfigManager configManager =
7758 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007759 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
Andrew Leea1239f22015-03-02 17:44:07 -08007764 }
7765
7766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007767 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007769 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 return false;
7771 }
7772
7773 final long identity = Binder.clearCallingIdentity();
7774 try {
7775 CarrierConfigManager configManager =
7776 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007777 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7779 } finally {
7780 Binder.restoreCallingIdentity(identity);
7781 }
Andrew Leea1239f22015-03-02 17:44:07 -08007782 }
7783
Andrew Lee9431b832015-03-09 18:46:45 -07007784 @Override
7785 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007786 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007787 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007788 }
7789
7790 @Override
7791 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 final long identity = Binder.clearCallingIdentity();
7793 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007794 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 } finally {
7796 Binder.restoreCallingIdentity(identity);
7797 }
Andrew Lee9431b832015-03-09 18:46:45 -07007798 }
7799
Hall Liuf6668912018-10-31 17:05:23 -07007800 /**
7801 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7802 * support for the feature and device firmware support.
7803 *
7804 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7805 */
7806 @Override
7807 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007809 final Phone phone = getPhone(subscriptionId);
7810 if (phone == null) {
7811 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7812 return false;
7813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007815 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7817 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007818 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 return isCarrierSupported && isDeviceSupported;
7820 } finally {
7821 Binder.restoreCallingIdentity(identity);
7822 }
Hall Liu98187582018-01-22 19:15:32 -08007823 }
7824
Hall Liuf6668912018-10-31 17:05:23 -07007825 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007826 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7827 * RTT setting, will return true if the device and carrier both support RTT.
7828 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007829 */
7830 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007831 final long identity = Binder.clearCallingIdentity();
7832 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007833 boolean isRttSupported = isRttSupported(subscriptionId);
7834 boolean isUserRttSettingOn = Settings.Secure.getInt(
7835 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7836 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7837 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7838 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839 } finally {
7840 Binder.restoreCallingIdentity(identity);
7841 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007842 }
7843
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007844 @Deprecated
7845 @Override
7846 public String getDeviceId(String callingPackage) {
7847 return getDeviceIdWithFeature(callingPackage, null);
7848 }
7849
Sanket Padawe7310cc72015-01-14 09:53:20 -08007850 /**
7851 * Returns the unique device ID of phone, for example, the IMEI for
7852 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7853 *
7854 * <p>Requires Permission:
7855 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7856 */
7857 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007858 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007859 try {
7860 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7861 } catch (SecurityException se) {
7862 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7863 throw new SecurityException("Package " + callingPackage + " does not belong to "
7864 + Binder.getCallingUid());
7865 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007866 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007867 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007868 return null;
7869 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007870 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007871 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007872 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007873 return null;
7874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875
7876 final long identity = Binder.clearCallingIdentity();
7877 try {
7878 return phone.getDeviceId();
7879 } finally {
7880 Binder.restoreCallingIdentity(identity);
7881 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007882 }
7883
Ping Sunc67b7c22016-03-02 19:16:45 +08007884 /**
7885 * {@hide}
7886 * Returns the IMS Registration Status on a particular subid
7887 *
7888 * @param subId
7889 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007890 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007891 Phone phone = getPhone(subId);
7892 if (phone != null) {
7893 return phone.isImsRegistered();
7894 } else {
7895 return false;
7896 }
7897 }
7898
Santos Cordon7a1885b2015-02-03 11:15:19 -08007899 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007900 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007901 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007903 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007904 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7905 }
7906 final long identity = Binder.clearCallingIdentity();
7907 try {
7908 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
7911 }
7912 }
7913
7914 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007915 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007916 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007917 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007918 mApp,
7919 subscriptionId,
7920 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7921 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007922 final long identity = Binder.clearCallingIdentity();
7923 try {
7924 Phone phone = getPhone(subscriptionId);
7925 if (phone == null) {
7926 return null;
7927 }
7928 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7929 } finally {
7930 Binder.restoreCallingIdentity(identity);
7931 }
7932 }
7933
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007934 /**
7935 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007936 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007937 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007938 final long identity = Binder.clearCallingIdentity();
7939 try {
7940 Phone phone = getPhone(subId);
7941 if (phone != null) {
7942 return phone.isWifiCallingEnabled();
7943 } else {
7944 return false;
7945 }
7946 } finally {
7947 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007948 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007949 }
7950
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007951 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007952 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007953 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007954 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 final long identity = Binder.clearCallingIdentity();
7956 try {
7957 Phone phone = getPhone(subId);
7958 if (phone != null) {
7959 return phone.isVideoEnabled();
7960 } else {
7961 return false;
7962 }
7963 } finally {
7964 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007965 }
7966 }
7967
7968 /**
7969 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7970 * defined in {@link ImsRegistrationImplBase}.
7971 */
7972 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 Phone phone = getPhone(subId);
7976 if (phone != null) {
7977 return phone.getImsRegistrationTech();
7978 } else {
7979 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7980 }
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007983 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007984 }
7985
Stuart Scott8eef64f2015-04-08 15:13:54 -07007986 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007987 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007988 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007989 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7990 return;
7991 }
Kai Shif70f46f2021-03-03 13:59:46 -08007992 Phone defaultPhone = getDefaultPhone();
7993 if (defaultPhone != null) {
7994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7995 mApp, getDefaultPhone().getSubId(), "factoryReset");
7996 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007997 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007998
Svet Ganovcc087f82015-05-12 20:35:54 -07007999 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008000 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8001 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008002 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008003 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008004 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008005 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008006 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008007 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008008 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008009 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008010 // There has been issues when Sms raw table somehow stores orphan
8011 // fragments. They lead to garbled message when new fragments come
8012 // in and combined with those stale ones. In case this happens again,
8013 // user can reset all network settings which will clean up this table.
8014 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008015 // Clean up IMS settings as well here.
8016 int slotId = getSlotIndex(subId);
8017 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8018 ImsManager.getInstance(mApp, slotId).factoryReset();
8019 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008020
Kai Shif70f46f2021-03-03 13:59:46 -08008021 if (defaultPhone == null) {
8022 return;
8023 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008024 // Erase modem config if erase modem on network setting is enabled.
8025 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8026 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8027 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008028 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008029 }
Kai Shif70f46f2021-03-03 13:59:46 -08008030
8031 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008032 } finally {
8033 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008034 }
8035 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008036
SongFerngWangfd89b102021-05-27 22:44:54 +08008037 @VisibleForTesting
8038 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8039 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8040 return;
8041 }
8042 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8043 RILConstants.PREFERRED_NETWORK_MODE);
8044 SubscriptionManager.setSubscriptionProperty(subId,
8045 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8046 "user=" + defaultNetworkType);
8047 phone.loadAllowedNetworksFromSubscriptionDatabase();
8048 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8049 defaultNetworkType, null);
8050 }
8051
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008052 private void cleanUpSmsRawTable(Context context) {
8053 ContentResolver resolver = context.getContentResolver();
8054 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8055 resolver.delete(uri, null, null);
8056 }
8057
Narayan Kamath1c496c22015-04-16 14:40:19 +01008058 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008059 public String getSimLocaleForSubscriber(int subId) {
8060 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8061 final Phone phone = getPhone(subId);
8062 if (phone == null) {
8063 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008064 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 final long identity = Binder.clearCallingIdentity();
8067 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008068 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8069 phone.getContext().getOpPackageName(),
8070 phone.getContext().getAttributionTag());
8071 if (info == null) {
8072 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8073 return null;
chen xu6291c472019-02-04 12:55:53 -08008074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 // Try and fetch the locale from the carrier properties or from the SIM language
8076 // preferences (EF-PL and EF-LI)...
8077 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008079 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8080 if (localeFromDefaultSim != null) {
8081 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8082 if (DBG) log("Using locale from subId: " + subId + " locale: "
8083 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008084 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008085 } else {
8086 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 }
8088 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 // The SIM language preferences only store a language (e.g. fr = French), not an
8091 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8092 // the SIM and carrier preferences does not include a country we add the country
8093 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008094 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008096 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008097 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 }
8099
8100 if (DBG) log("No locale found - returning null");
8101 return null;
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008105 }
8106
tom hsu0b59d292022-09-29 23:49:21 +08008107 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008108 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008109 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008110 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008111 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008112 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8113 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008114 Locale.forLanguageTag(localeTag).getCountry())) {
8115 return localeTag;
8116 }
8117 }
8118 return inputLocale.toLanguageTag();
8119 }
8120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 /**
8122 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8123 */
8124 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008125 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008126 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008127 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008128
Gary Jian3aa9a762022-01-24 16:41:19 +08008129 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8130 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008131
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008132 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008133 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8134 * representing the state of the modem.
8135 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008136 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8137 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008138 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008139 */
8140 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008141 public void requestModemActivityInfo(ResultReceiver result) {
8142 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008143 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008144
8145 final long identity = Binder.clearCallingIdentity();
8146 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008147 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148 } finally {
8149 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008150 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008151 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008152
Gary Jian76280a42022-12-07 16:18:33 +08008153 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008154 // less than total activity duration.
8155 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8156 if (info == null) {
8157 return false;
8158 }
8159 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008160 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008161 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8162
Hall Liu49656c02020-10-09 19:00:11 -07008163 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8164
Siddharth Rayb8114062018-06-17 15:02:38 -07008165 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008166 && (info.getSleepTimeMillis() <= activityDurationMs)
8167 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008168 }
8169
Gary Jian3aa9a762022-01-24 16:41:19 +08008170 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8171 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8172 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8173 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8174
8175 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8176 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8177 }
8178
8179 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8180 mLastModemActivityInfo.setReceiveTimeMillis(
8181 rat,
8182 freq,
8183 info.getReceiveTimeMillis(rat, freq)
8184 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8185 }
8186
8187 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8188 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8189 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8190 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8191
8192 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8193 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8194 }
8195 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8196 mLastModemActivityInfo.setReceiveTimeMillis(
8197 rat,
8198 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8199 }
8200
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008201 /**
8202 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8203 * @param info recent ModemActivityInfo
8204 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008205 private void mergeModemActivityInfo(ModemActivityInfo info) {
8206 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008207 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008208 boolean matched;
8209 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8210 matched = false;
8211 int rat = info.getSpecificInfoRat(i);
8212 int freq = info.getSpecificInfoFrequencyRange(i);
8213 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8214 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8215 //if it already exists
8216 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8217 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8218 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8219 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8220 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8221 updateLastModemActivityInfo(info, rat, freq);
8222 matched = true;
8223 }
8224 } else {
8225 updateLastModemActivityInfo(info, rat);
8226 matched = true;
8227 }
8228 }
8229 }
8230
8231 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008232 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008233 new ActivityStatsTechSpecificInfo(
8234 rat,
8235 freq,
8236 info.getTransmitTimeMillis(rat, freq),
8237 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008238 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008239 }
8240 }
8241 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8242 mLastModemActivitySpecificInfo =
8243 new ActivityStatsTechSpecificInfo[merged.size()];
8244 merged.toArray(mLastModemActivitySpecificInfo);
8245
8246 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8247 mLastModemActivityInfo.setSleepTimeMillis(
8248 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008249 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008250 mLastModemActivityInfo.setIdleTimeMillis(
8251 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008252 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008253
8254 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008255 new ModemActivityInfo(
8256 mLastModemActivityInfo.getTimestampMillis(),
8257 mLastModemActivityInfo.getSleepTimeMillis(),
8258 mLastModemActivityInfo.getIdleTimeMillis(),
8259 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008260 }
8261
8262 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8263 ActivityStatsTechSpecificInfo[] info) {
8264 int infoSize = info.length;
8265 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8266 for (int i = 0; i < infoSize; i++) {
8267 ret[i] = new ActivityStatsTechSpecificInfo(
8268 info[i].getRat(), info[i].getFrequencyRange(),
8269 info[i].getTransmitTimeMillis(),
8270 (int) info[i].getReceiveTimeMillis());
8271 }
8272 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008273 }
8274
Jack Yu85bd38a2015-11-09 11:34:32 -08008275 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008276 * Returns the service state information on specified subscription.
8277 */
8278 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008279 public ServiceState getServiceStateForSubscriber(int subId,
8280 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8281 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008283 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008284 return null;
8285 }
8286
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008287 boolean hasFinePermission = false;
8288 boolean hasCoarsePermission = false;
8289 if (!renounceFineLocationAccess) {
8290 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8291 LocationAccessPolicy.checkLocationPermission(mApp,
8292 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8293 .setCallingPackage(callingPackage)
8294 .setCallingFeatureId(callingFeatureId)
8295 .setCallingPid(Binder.getCallingPid())
8296 .setCallingUid(Binder.getCallingUid())
8297 .setMethod("getServiceStateForSubscriber")
8298 .setLogAsInfo(true)
8299 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8300 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8301 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8302 .build());
8303 hasFinePermission =
8304 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8305 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008306
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008307 if (!renounceCoarseLocationAccess) {
8308 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8309 LocationAccessPolicy.checkLocationPermission(mApp,
8310 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8311 .setCallingPackage(callingPackage)
8312 .setCallingFeatureId(callingFeatureId)
8313 .setCallingPid(Binder.getCallingPid())
8314 .setCallingUid(Binder.getCallingUid())
8315 .setMethod("getServiceStateForSubscriber")
8316 .setLogAsInfo(true)
8317 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8318 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8319 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8320 .build());
8321 hasCoarsePermission =
8322 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8323 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008324
Jack Yu479f40e2020-10-27 21:29:25 -07008325 final Phone phone = getPhone(subId);
8326 if (phone == null) {
8327 return null;
8328 }
8329
Jordan Liu0f2bc442020-11-18 16:47:37 -08008330 final long identity = Binder.clearCallingIdentity();
8331
Jack Yu479f40e2020-10-27 21:29:25 -07008332 boolean isCallingPackageDataService = phone.getDataServicePackages()
8333 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008335 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008336 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8337 .getSubscriptionInfoInternal(subId);
8338 if (subInfo == null || !subInfo.isActive()) {
8339 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8340 + "subId=" + subId);
8341 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008342 }
8343
Hall Liuf19c44f2018-11-27 14:38:17 -08008344 ServiceState ss = phone.getServiceState();
8345
8346 // Scrub out the location info in ServiceState depending on what level of access
8347 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008348 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008349 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8350 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008351 } finally {
8352 Binder.restoreCallingIdentity(identity);
8353 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008354 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008355
8356 /**
8357 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8358 *
8359 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8360 * voicemail ringtone.
8361 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8362 * PhoneAccount.
8363 */
8364 @Override
8365 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 final long identity = Binder.clearCallingIdentity();
8367 try {
8368 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8369 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008370 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8374 } finally {
8375 Binder.restoreCallingIdentity(identity);
8376 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008377 }
8378
8379 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008380 * Sets the per-account voicemail ringtone.
8381 *
8382 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8383 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8384 *
8385 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8386 * voicemail ringtone.
8387 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8388 * PhoneAccount.
8389 */
8390 @Override
8391 public void setVoicemailRingtoneUri(String callingPackage,
8392 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008393 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008395 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8396 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8398 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8399 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401
8402 final long identity = Binder.clearCallingIdentity();
8403 try {
8404 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8405 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008406 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 }
8408 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8409 } finally {
8410 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008411 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008412 }
8413
8414 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008415 * Returns whether vibration is set for voicemail notification in Phone settings.
8416 *
8417 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8418 * voicemail vibration setting.
8419 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8420 */
8421 @Override
8422 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 final long identity = Binder.clearCallingIdentity();
8424 try {
8425 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8426 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008427 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008428 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008434 }
8435
Youhan Wange64578a2016-05-02 15:32:42 -07008436 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008437 * Sets the per-account voicemail vibration.
8438 *
8439 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8440 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8441 *
8442 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8443 * voicemail vibration setting.
8444 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8445 * specific PhoneAccount.
8446 */
8447 @Override
8448 public void setVoicemailVibrationEnabled(String callingPackage,
8449 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008450 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008452 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8453 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8455 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8456 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008457 }
8458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459 final long identity = Binder.clearCallingIdentity();
8460 try {
8461 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8462 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008463 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 }
8465 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008468 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008469 }
8470
8471 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008472 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8473 *
8474 * @throws SecurityException if the caller does not have the required permission
8475 */
arunvoddud7401012022-12-15 16:08:12 +00008476 @VisibleForTesting
8477 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008478 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008479 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008480 }
8481
8482 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008483 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8484 * permission.
8485 *
8486 * @throws SecurityException if the caller does not have the required permission
8487 */
8488 private void enforceSendSmsPermission() {
8489 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8490 }
8491
8492 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008493 * Make sure either called from same process as self (phone) or IPC caller has interact across
8494 * users permission.
8495 *
8496 * @throws SecurityException if the caller does not have the required permission
8497 */
8498 private void enforceInteractAcrossUsersPermission(String message) {
8499 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8500 }
8501
8502 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008503 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008504 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008505 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008506 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008507 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 final long identity = Binder.clearCallingIdentity();
8509 try {
8510 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008511 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 if (componentName == null) {
8513 throw new SecurityException(
8514 "Caller not current active visual voicemail package[null]");
8515 }
8516 String vvmPackage = componentName.getPackageName();
8517 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008518 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008519 }
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008522 }
8523 }
8524
8525 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008526 * Return the application ID for the app type.
8527 *
8528 * @param subId the subscription ID that this request applies to.
8529 * @param appType the uicc app type.
8530 * @return Application ID for specificied app type, or null if no uicc.
8531 */
8532 @Override
8533 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008534 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008535 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008536
8537 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008538 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008539 if (phone == null) {
8540 return null;
8541 }
8542 String aid = null;
8543 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008544 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545 .getApplicationByType(appType).getAid();
8546 } catch (Exception e) {
8547 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8548 }
8549 return aid;
8550 } finally {
8551 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008552 }
Youhan Wange64578a2016-05-02 15:32:42 -07008553 }
8554
Youhan Wang4001d252016-05-11 10:29:41 -07008555 /**
8556 * Return the Electronic Serial Number.
8557 *
8558 * @param subId the subscription ID that this request applies to.
8559 * @return ESN or null if error.
8560 */
8561 @Override
8562 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008563 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008564 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008565
8566 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008567 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008568 if (phone == null) {
8569 return null;
8570 }
8571 String esn = null;
8572 try {
8573 esn = phone.getEsn();
8574 } catch (Exception e) {
8575 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8576 }
8577 return esn;
8578 } finally {
8579 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008580 }
Youhan Wang4001d252016-05-11 10:29:41 -07008581 }
8582
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008583 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008584 * Return the Preferred Roaming List Version.
8585 *
8586 * @param subId the subscription ID that this request applies to.
8587 * @return PRLVersion or null if error.
8588 */
8589 @Override
8590 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008591 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008592 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593
8594 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008595 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 if (phone == null) {
8597 return null;
8598 }
8599 String cdmaPrlVersion = null;
8600 try {
8601 cdmaPrlVersion = phone.getCdmaPrlVersion();
8602 } catch (Exception e) {
8603 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8604 }
8605 return cdmaPrlVersion;
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008608 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008609 }
8610
8611 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008612 * Get snapshot of Telephony histograms
8613 * @return List of Telephony histograms
8614 * @hide
8615 */
8616 @Override
8617 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8619 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008620
8621 final long identity = Binder.clearCallingIdentity();
8622 try {
8623 return RIL.getTelephonyRILTimingHistograms();
8624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008627 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008628
8629 /**
8630 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008631 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8632 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008633 * Require system privileges. In the future we may add this to carrier APIs.
8634 *
Michele Berionne482f8202018-11-27 18:57:59 -08008635 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008636 */
8637 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008638 @TelephonyManager.SetCarrierRestrictionResult
8639 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008640 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008641 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008642
Michele Berionne482f8202018-11-27 18:57:59 -08008643 if (carrierRestrictionRules == null) {
8644 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008645 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008647 final long identity = Binder.clearCallingIdentity();
8648 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008649 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008650 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008651 } finally {
8652 Binder.restoreCallingIdentity(identity);
8653 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008654 }
8655
8656 /**
8657 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008658 * Get the allowed carrier list and the excluded carrier list, including the priority between
8659 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008660 * Require system privileges. In the future we may add this to carrier APIs.
8661 *
Michele Berionne482f8202018-11-27 18:57:59 -08008662 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008663 */
8664 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008665 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008666 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008667 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668
8669 final long identity = Binder.clearCallingIdentity();
8670 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008671 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8672 if (response instanceof CarrierRestrictionRules) {
8673 return (CarrierRestrictionRules) response;
8674 }
8675 // Response is an Exception of some kind,
8676 // which is signalled to the user as a NULL retval
8677 return null;
8678 } catch (Exception e) {
8679 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8680 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008681 } finally {
8682 Binder.restoreCallingIdentity(identity);
8683 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008684 }
8685
fionaxu59545b42016-05-25 15:53:37 -07008686 /**
arunvoddud7401012022-12-15 16:08:12 +00008687 * Fetches the carrier restriction status of the device and sends the status to the caller
8688 * through the callback.
8689 *
8690 * @param callback The callback that will be used to send the result.
8691 * @throws SecurityException if the caller does not have the required permission/privileges or
8692 * the caller is not allowlisted.
8693 */
8694 @Override
8695 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8696 enforceReadPermission("getCarrierRestrictionStatus");
8697 int carrierId = validateCallerAndGetCarrierId(packageName);
8698 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8699 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8700 throw new SecurityException("Not an authorized caller");
8701 }
8702 final long identity = Binder.clearCallingIdentity();
8703 try {
8704 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8705 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8706 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8707 } finally {
8708 Binder.restoreCallingIdentity(identity);
8709 }
8710 }
8711
arunvoddu567f2b42023-04-25 17:22:00 +00008712 @Override
8713 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8714 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8715 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8716 return allowListInfo.getShaIdList(pkgName, carrierId);
8717 }
8718
arunvoddud7401012022-12-15 16:08:12 +00008719 @VisibleForTesting
8720 public int validateCallerAndGetCarrierId(String packageName) {
8721 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8722 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8723 }
8724
8725 /**
fionaxu59545b42016-05-25 15:53:37 -07008726 * Action set from carrier signalling broadcast receivers to enable/disable radio
8727 * @param subId the subscription ID that this action applies to.
8728 * @param enabled control enable or disable radio.
8729 * {@hide}
8730 */
8731 @Override
8732 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8733 enforceModifyPermission();
8734 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008735
8736 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008737 if (phone == null) {
8738 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8739 return;
8740 }
8741 try {
8742 phone.carrierActionSetRadioEnabled(enabled);
8743 } catch (Exception e) {
8744 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008745 } finally {
8746 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008747 }
8748 }
8749
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008750 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008751 * Enable or disable Voice over NR (VoNR)
8752 * @param subId the subscription ID that this action applies to.
8753 * @param enabled enable or disable VoNR.
8754 * @return operation result.
8755 */
8756 @Override
8757 public int setVoNrEnabled(int subId, boolean enabled) {
8758 enforceModifyPermission();
8759 final Phone phone = getPhone(subId);
8760
8761 final long identity = Binder.clearCallingIdentity();
8762 if (phone == null) {
8763 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8764 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8765 }
8766
8767 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8768 try {
8769 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8770 workSource);
8771 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008772
8773 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8774 if (DBG) {
8775 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8776 }
8777 SubscriptionManager.setSubscriptionProperty(
8778 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8779 (enabled ? "1" : "0"));
8780 }
8781
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008782 return result;
8783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
8786 }
8787
8788 /**
8789 * Is voice over NR enabled
8790 * @return true if VoNR is enabled else false
8791 */
8792 @Override
8793 public boolean isVoNrEnabled(int subId) {
8794 enforceReadPrivilegedPermission("isVoNrEnabled");
8795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8799 null, subId, workSource);
8800 if (DBG) log("isVoNrEnabled: " + isEnabled);
8801 return isEnabled;
8802 } finally {
8803 Binder.restoreCallingIdentity(identity);
8804 }
8805 }
8806
8807 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008808 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8809 * network status based on which carrier apps could apply actions accordingly,
8810 * enable/disable default url handler for example.
8811 *
8812 * @param subId the subscription ID that this action applies to.
8813 * @param report control start/stop reporting the default network status.
8814 * {@hide}
8815 */
8816 @Override
8817 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8818 enforceModifyPermission();
8819 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008820
8821 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008822 if (phone == null) {
8823 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8824 return;
8825 }
8826 try {
8827 phone.carrierActionReportDefaultNetworkStatus(report);
8828 } catch (Exception e) {
8829 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008830 } finally {
8831 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008832 }
8833 }
8834
8835 /**
fionaxud9622282017-07-17 17:51:30 -07008836 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8837 * @param subId the subscription ID that this action applies to.
8838 * {@hide}
8839 */
8840 @Override
8841 public void carrierActionResetAll(int subId) {
8842 enforceModifyPermission();
8843 final Phone phone = getPhone(subId);
8844 if (phone == null) {
8845 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8846 return;
8847 }
8848 try {
8849 phone.carrierActionResetAll();
8850 } catch (Exception e) {
8851 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8852 }
8853 }
8854
8855 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008856 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8857 * bug report is being generated.
8858 */
8859 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008860 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008861 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8862 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008863 writer.println("Permission Denial: can't dump Phone from pid="
8864 + Binder.getCallingPid()
8865 + ", uid=" + Binder.getCallingUid()
8866 + "without permission "
8867 + android.Manifest.permission.DUMP);
8868 return;
8869 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008870 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008871 }
Jack Yueb89b242016-06-22 13:27:47 -07008872
Brad Ebingerdac2f002018-04-03 15:17:52 -07008873 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008874 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8875 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8876 @NonNull String[] args) {
8877 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8878 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008879 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008880 }
8881
Jack Yueb89b242016-06-22 13:27:47 -07008882 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008883 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008884 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008885 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008886 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008887 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008888 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008889 */
8890 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008891 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008892 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008893 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8894 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8895 try {
8896 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008897 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008898 } catch (SecurityException se) {
8899 enforceModifyPermission();
8900 }
8901 } else {
8902 enforceModifyPermission();
8903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008904
Nate Myrenae97d192023-06-09 15:22:31 -07008905 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
8906 && null != callingPackage && opEnableMobileDataByUser()) {
8907 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
8908 callingPackage, null, null);
8909 }
8910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008911 final long identity = Binder.clearCallingIdentity();
8912 try {
8913 Phone phone = getPhone(subId);
8914 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008915 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8916 phone.carrierActionSetMeteredApnsEnabled(enabled);
8917 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008918 phone.getDataSettingsManager().setDataEnabled(
8919 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008921 }
8922 } finally {
8923 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008924 }
8925 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008926
8927 /**
8928 * Get Client request stats
8929 * @return List of Client Request Stats
8930 * @hide
8931 */
8932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008933 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8934 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008936 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008937 return null;
8938 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008939 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008941 final long identity = Binder.clearCallingIdentity();
8942 try {
8943 if (phone != null) {
8944 return phone.getClientRequestStats();
8945 }
8946
8947 return null;
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008951 }
8952
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008953 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008954 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008955 if (uid == Process.ROOT_UID && packageName == null) {
8956 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8957 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8958 // exception. ROOT_UID seems not to have a valid package name returned by
8959 // PackageManager, so just fake it here to avoid issues when running telephony shell
8960 // commands that plumb through the RIL as root, like so:
8961 // $ adb root
8962 // $ adb shell cmd phone ...
8963 packageName = "root";
8964 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008965 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008966 }
Jack Yueb4124c2017-02-16 15:32:43 -08008967
8968 /**
Grace Chen70990072017-03-24 17:21:30 -07008969 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008970 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008971 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008972 * @param state State of SIM (power down, power up, pass through)
8973 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8974 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8975 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008976 *
8977 **/
8978 @Override
Grace Chen70990072017-03-24 17:21:30 -07008979 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008980 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008981 Phone phone = PhoneFactory.getPhone(slotIndex);
8982
vagdeviaf9a5b92018-08-15 16:01:53 -07008983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 final long identity = Binder.clearCallingIdentity();
8986 try {
8987 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008988 phone.setSimPowerState(state, null, workSource);
8989 }
8990 } finally {
8991 Binder.restoreCallingIdentity(identity);
8992 }
8993 }
8994
8995 /**
8996 * Set SIM card power state.
8997 *
8998 * @param slotIndex SIM slot id.
8999 * @param state State of SIM (power down, power up, pass through)
9000 * @param callback callback to trigger after success or failure
9001 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9002 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9003 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9004 *
9005 **/
9006 @Override
9007 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9008 IIntegerConsumer callback) {
9009 enforceModifyPermission();
9010 Phone phone = PhoneFactory.getPhone(slotIndex);
9011
9012 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9013
9014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 if (phone != null) {
9017 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9018 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009019 }
9020 } finally {
9021 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009022 }
9023 }
Shuo Qiandd210312017-04-12 22:11:33 +00009024
Tyler Gunn65d45c22017-06-05 11:22:26 -07009025 private boolean isUssdApiAllowed(int subId) {
9026 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009027 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009028 if (configManager == null) {
9029 return false;
9030 }
9031 PersistableBundle pb = configManager.getConfigForSubId(subId);
9032 if (pb == null) {
9033 return false;
9034 }
9035 return pb.getBoolean(
9036 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9037 }
9038
Shuo Qiandd210312017-04-12 22:11:33 +00009039 /**
Ling Mac28f0212023-03-24 16:07:15 -07009040 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009041 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009042 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009043 */
goneil9c5f4872017-12-05 14:07:56 -08009044 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009045 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009046 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 final long identity = Binder.clearCallingIdentity();
9048 try {
Ling Mac28f0212023-03-24 16:07:15 -07009049 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009050 } finally {
9051 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009052 }
9053 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009054
9055 /**
9056 * Get the current signal strength information for the given subscription.
9057 * Because this information is not updated when the device is in a low power state
9058 * it should not be relied-upon to be current.
9059 * @param subId Subscription index
9060 * @return the most recent cached signal strength info from the modem
9061 */
9062 @Override
9063 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009064 final long identity = Binder.clearCallingIdentity();
9065 try {
9066 Phone p = getPhone(subId);
9067 if (p == null) {
9068 return null;
9069 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009071 return p.getSignalStrength();
9072 } finally {
9073 Binder.restoreCallingIdentity(identity);
9074 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009075 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009076
Pengquan Meng77b7f132018-08-22 14:49:57 -07009077 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009078 * Get the current modem radio state for the given slot.
9079 * @param slotIndex slot index.
9080 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009081 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009082 * @return the current radio power state from the modem
9083 */
9084 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009085 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009086 Phone phone = PhoneFactory.getPhone(slotIndex);
9087 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9089 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009090 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9091 }
9092
9093 final long identity = Binder.clearCallingIdentity();
9094 try {
9095 return phone.getRadioPowerState();
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9101 }
9102
9103 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009104 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9105 *
9106 * <p>Requires one of the following permissions:
9107 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009108 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009109 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9110 * privileges.
9111 *
9112 * @param subId subscription id
9113 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9114 * {@code false}.
9115 */
9116 @Override
9117 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009118 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009119 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009120 try {
9121 mApp.enforceCallingOrSelfPermission(
9122 android.Manifest.permission.ACCESS_NETWORK_STATE,
9123 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009124 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009125 mApp.enforceCallingOrSelfPermission(
9126 permission.READ_BASIC_PHONE_STATE, functionName);
9127 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009128 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009129 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009130 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009131 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009132
Pengquan Menga1bb6272018-09-06 09:59:22 -07009133 boolean isEnabled = false;
9134 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009135 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009136 Phone phone = getPhone(subId);
9137 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009138 } finally {
9139 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009140 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009141 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009142 }
9143
9144
9145 /**
9146 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9147 *
9148 * <p> Requires permission:
9149 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9150 * privileges.
9151 *
9152 * @param subId subscription id
9153 * @param isEnabled {@code true} means enable, {@code false} means disable.
9154 */
9155 @Override
9156 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9158 mApp, subId, "setDataRoamingEnabled");
9159
Pengquan Menga1bb6272018-09-06 09:59:22 -07009160 final long identity = Binder.clearCallingIdentity();
9161 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009162 Phone phone = getPhone(subId);
9163 if (phone != null) {
9164 phone.setDataRoamingEnabled(isEnabled);
9165 }
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009168 }
9169 }
9170
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009171 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009172 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009173 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009174 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009175 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009176
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009177 boolean isAllowed = true;
9178 final long identity = Binder.clearCallingIdentity();
9179 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009180 Phone phone = getPhone(subId);
9181 if (phone != null) {
9182 isAllowed = phone.isCspPlmnEnabled();
9183 }
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 return isAllowed;
9188 }
9189
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009190 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9191 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009192 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009193 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009194 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009195 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9196 if (phone == null) {
9197 return false;
9198 }
9199 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9200 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9201 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009202 }
9203
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009204 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009205 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009206 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009207 mApp.getSystemService(AppOpsManager.class)
9208 .checkPackage(Binder.getCallingUid(), callingPackage);
9209
Jordan Liu1e142fc2019-04-22 15:10:43 -07009210 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009211 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009212 try {
9213 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009214 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009215 } catch (SecurityException e) {
9216 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9217 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009218 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009219 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009220 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009221 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009222 }
sandeepjsb6c87872021-09-27 15:34:44 +00009223 // checking compatibility, if calling app's target SDK is T and beyond.
9224 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9225 Binder.getCallingUid())) {
9226 isIccIdAccessRestricted = true;
9227 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009228 final long identity = Binder.clearCallingIdentity();
9229 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009230 UiccController uiccController = UiccController.getInstance();
9231 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009232 if (hasReadPermission) {
9233 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009234 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009235
9236 // Remove private info if the caller doesn't have access
9237 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9238 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009239 //setting the value after compatibility check
9240 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009241 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9242 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009243 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009244 if (card == null) {
9245 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009246 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009247 continue;
9248 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009249 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9250 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009251 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009252 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009253 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009254 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9255 for (UiccPortInfo portInfo : portInfos) {
9256 UiccPort port = uiccController.getUiccPortForSlot(
9257 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9258 if (port == null) {
9259 // assume no access if port is null
9260 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9261 continue;
9262 }
9263 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9264 uiccPortInfos.add(portInfo);
9265 } else {
9266 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9267 }
9268 }
9269 filteredInfos.add(new UiccCardInfo(
9270 cardInfo.isEuicc(),
9271 cardInfo.getCardId(),
9272 null,
9273 cardInfo.getPhysicalSlotIndex(),
9274 cardInfo.isRemovable(),
9275 cardInfo.isMultipleEnabledProfilesSupported(),
9276 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009277 }
9278 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
9283
sandeepjsb6c87872021-09-27 15:34:44 +00009284 /**
9285 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9286 * generally private and require carrier privileges to view.
9287 *
9288 * @hide
9289 */
9290 @NonNull
9291 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9292 List<UiccPortInfo> portinfo = new ArrayList<>();
9293 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9294 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9295 }
9296 return new UiccCardInfo(
9297 cardInfo.isEuicc(),
9298 cardInfo.getCardId(),
9299 null,
9300 cardInfo.getPhysicalSlotIndex(),
9301 cardInfo.isRemovable(),
9302 cardInfo.isMultipleEnabledProfilesSupported(),
9303 portinfo
9304 );
9305 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009306
sandeepjsb6c87872021-09-27 15:34:44 +00009307 /**
9308 * @hide
9309 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9310 * These values are generally private and require carrier privileges to view.
9311 */
9312 @NonNull
9313 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9314 return new UiccPortInfo(
9315 UiccPortInfo.ICCID_REDACTED,
9316 portInfo.getPortIndex(),
9317 portInfo.getLogicalSlotIndex(),
9318 portInfo.isActive()
9319 );
9320 }
9321 @Override
9322 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009323 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009324 mApp.getSystemService(AppOpsManager.class)
9325 .checkPackage(Binder.getCallingUid(), callingPackage);
9326
sandeepjsb6c87872021-09-27 15:34:44 +00009327 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009328
Aman Guptaf3c90b32022-03-17 04:54:16 +00009329 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9330 // we are reading iccId which is PII data.
9331 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009332
9333 // checking compatibility, if calling app's target SDK is T and beyond.
9334 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9335 Binder.getCallingUid())) {
9336 isLogicalSlotAccessRestricted = true;
9337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009338 final long identity = Binder.clearCallingIdentity();
9339 try {
9340 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009341 if (slots == null || slots.length == 0) {
9342 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009343 return null;
9344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009345 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9346 for (int i = 0; i < slots.length; i++) {
9347 UiccSlot slot = slots[i];
9348 if (slot == null) {
9349 continue;
9350 }
9351
Jordan Liu7be7e652019-05-06 18:55:02 +00009352 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009353 UiccCard card = slot.getUiccCard();
9354 if (card != null) {
9355 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009356 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009357 cardId = slot.getEid();
9358 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009359 // If cardId is null, use iccId of default port as cardId.
9360 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009362 }
9363
Jordan Liu857451f2019-05-09 16:35:35 -07009364 if (cardId != null) {
9365 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9366 // if cardId is an EID, it's all digits so this is fine
9367 cardId = IccUtils.stripTrailingFs(cardId);
9368 }
9369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009370 int cardState = 0;
9371 switch (slot.getCardState()) {
9372 case CARDSTATE_ABSENT:
9373 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9374 break;
9375 case CARDSTATE_PRESENT:
9376 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9377 break;
9378 case CARDSTATE_ERROR:
9379 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9380 break;
9381 case CARDSTATE_RESTRICTED:
9382 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9383 break;
9384 default:
9385 break;
9386
9387 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009388 List<UiccPortInfo> portInfos = new ArrayList<>();
9389 int[] portIndexes = slot.getPortList();
9390 for (int portIdx : portIndexes) {
9391 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009392 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009393 portInfos.add(new UiccPortInfo(iccId, portIdx,
9394 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009396 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009397 slot.isEuicc(),
9398 cardId,
9399 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009400 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009401 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009402 //setting the value after compatibility check
9403 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009404 }
9405 return infos;
9406 } finally {
9407 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009408 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009409 }
9410
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009411 /* Returns null if doesn't have read permission or carrier privilege access. */
9412 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9413 boolean hasReadPermission) {
9414 String iccId = slot.getIccId(portIndex);
9415 if (hasReadPermission) { // if has read permission
9416 return iccId;
9417 } else {
9418 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9419 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9420 // if no read permission, checking carrier privilege access
9421 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9422 return iccId;
9423 }
9424 }
9425 }
9426 // No read permission or carrier privilege access.
9427 return UiccPortInfo.ICCID_REDACTED;
9428 }
9429
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009430 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009431 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009432 public boolean switchSlots(int[] physicalSlots) {
9433 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009434
9435 final long identity = Binder.clearCallingIdentity();
9436 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009437 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9438 for (int i = 0; i < physicalSlots.length; i++) {
9439 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9440 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9441 physicalSlots[i], i));
9442 }
9443 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009444 } finally {
9445 Binder.restoreCallingIdentity(identity);
9446 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009447 }
Jack Yu4c988042018-02-27 15:30:01 -08009448
9449 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009450 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9451 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9452 enforceModifyPermission();
9453
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009456 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009457 } finally {
9458 Binder.restoreCallingIdentity(identity);
9459 }
9460 }
9461
9462 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009463 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009464 final long identity = Binder.clearCallingIdentity();
9465 try {
9466 return UiccController.getInstance().getCardIdForDefaultEuicc();
9467 } finally {
9468 Binder.restoreCallingIdentity(identity);
9469 }
9470 }
9471
Pengquan Meng85728fb2018-03-12 16:31:21 -07009472 /**
goneil47ffb6e2018-04-06 15:40:58 -07009473 * A test API to reload the UICC profile.
9474 *
9475 * <p>Requires that the calling app has permission
9476 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9477 * @hide
9478 */
9479 @Override
9480 public void refreshUiccProfile(int subId) {
9481 enforceModifyPermission();
9482
9483 final long identity = Binder.clearCallingIdentity();
9484 try {
9485 Phone phone = getPhone(subId);
9486 if (phone == null) {
9487 return;
9488 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009489 UiccPort uiccPort = phone.getUiccPort();
9490 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009491 return;
9492 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009493 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009494 if (uiccProfile == null) {
9495 return;
9496 }
9497 uiccProfile.refresh();
9498 } finally {
9499 Binder.restoreCallingIdentity(identity);
9500 }
9501 }
9502
9503 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009504 * Returns false if the mobile data is disabled by default, otherwise return true.
9505 */
9506 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009507 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009508 }
9509
9510 /**
9511 * Returns true if the data roaming is enabled by default, i.e the system property
9512 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9513 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9514 */
9515 private boolean getDefaultDataRoamingEnabled(int subId) {
9516 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009517 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009518 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009519 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9520 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9521 return isDataRoamingEnabled;
9522 }
9523
9524 /**
9525 * Returns the default network type for the given {@code subId}, if the default network type is
9526 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9527 */
9528 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009529 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009530 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009531 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9532 return list.get(phoneId);
9533 }
9534 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009535 }
fionaxua13278b2018-03-21 00:08:13 -07009536
9537 @Override
9538 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009539 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009541
9542 final long identity = Binder.clearCallingIdentity();
9543 try {
9544 final Phone phone = getPhone(subId);
9545 if (phone == null) {
9546 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9547 return;
9548 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009549 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9550 if (cpt != null) {
9551 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9552 }
9553 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009554 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9555 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009556 if (carrierPrivilegeRules == null) {
9557 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9558 } else {
9559 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009561 } finally {
9562 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009563 }
fionaxua13278b2018-03-21 00:08:13 -07009564 }
9565
9566 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009567 public void setCarrierServicePackageOverride(
9568 int subId, String carrierServicePackage, String callingPackage) {
9569 TelephonyPermissions.enforceShellOnly(
9570 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9571
Benedict Wong66477622023-02-03 23:30:57 +00009572 final long identity = Binder.clearCallingIdentity();
9573 try {
9574 final Phone phone = getPhone(subId);
9575 if (phone == null || phone.getSubId() != subId) {
9576 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9577 throw new IllegalArgumentException("No phone for subid");
9578 }
9579 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9580 if (cpt == null) {
9581 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9582 throw new IllegalStateException("No CPT for phone");
9583 }
9584 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
9589
9590 @Override
fionaxua13278b2018-03-21 00:08:13 -07009591 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009592 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009593
9594 final long identity = Binder.clearCallingIdentity();
9595 try {
9596 final Phone phone = getPhone(subId);
9597 if (phone == null) {
9598 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9599 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9600 }
9601 return phone.getCarrierIdListVersion();
9602 } finally {
9603 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009604 }
fionaxua13278b2018-03-21 00:08:13 -07009605 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009606
9607 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009608 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9609 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009611 mApp, subId, callingPackage, callingFeatureId,
9612 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009613 return -1;
9614 }
9615
9616 final long identity = Binder.clearCallingIdentity();
9617 try {
9618 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9619 } finally {
9620 Binder.restoreCallingIdentity(identity);
9621 }
9622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009623
9624 @Override
9625 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009626 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009627 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009628 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009629
9630 final long identity = Binder.clearCallingIdentity();
9631 try {
9632 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636 }
9637
9638 @Override
9639 public boolean setCdmaRoamingMode(int subId, int mode) {
9640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9641 mApp, subId, "setCdmaRoamingMode");
9642
9643 final long identity = Binder.clearCallingIdentity();
9644 try {
9645 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9646 } finally {
9647 Binder.restoreCallingIdentity(identity);
9648 }
9649 }
9650
9651 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009652 public int getCdmaSubscriptionMode(int subId) {
9653 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009654 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009655 mApp, subId, "getCdmaSubscriptionMode");
9656
9657 final long identity = Binder.clearCallingIdentity();
9658 try {
9659 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9660 } finally {
9661 Binder.restoreCallingIdentity(identity);
9662 }
9663 }
9664
9665 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009666 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9668 mApp, subId, "setCdmaSubscriptionMode");
9669
9670 final long identity = Binder.clearCallingIdentity();
9671 try {
9672 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9673 } finally {
9674 Binder.restoreCallingIdentity(identity);
9675 }
9676 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009677
sqianc5eccab2018-10-19 18:46:41 -07009678 @Override
sqian8c685422019-02-22 15:55:18 -08009679 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009680 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009682 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9683 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009684 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9685 }
9686 final long identity = Binder.clearCallingIdentity();
9687 try {
sqian854d44b2018-12-12 16:48:18 -08009688 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9689 for (Phone phone: PhoneFactory.getPhones()) {
9690 if (phone.getEmergencyNumberTracker() != null
9691 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9692 emergencyNumberListInternal.put(
9693 phone.getSubId(),
9694 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9695 }
sqian11b7a0e2018-12-05 18:48:28 -08009696 }
sqian854d44b2018-12-12 16:48:18 -08009697 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009698 } finally {
9699 Binder.restoreCallingIdentity(identity);
9700 }
sqianc5eccab2018-10-19 18:46:41 -07009701 }
9702
9703 @Override
sqian8c685422019-02-22 15:55:18 -08009704 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009705 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009706 if (!exactMatch) {
9707 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009708 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009709 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009710 }
9711 final long identity = Binder.clearCallingIdentity();
9712 try {
sqian854d44b2018-12-12 16:48:18 -08009713 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009714 //Note: we ignore passed in param exactMatch. We can remove it once
9715 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009716 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009717 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009718 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009719 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009720 }
sqian11b7a0e2018-12-05 18:48:28 -08009721 }
9722 return false;
9723 } finally {
9724 Binder.restoreCallingIdentity(identity);
9725 }
9726 }
9727
sqianf4ca7ed2019-01-15 18:32:07 -08009728 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009729 * Start emergency callback mode for GsmCdmaPhone for testing.
9730 */
9731 @Override
9732 public void startEmergencyCallbackMode() {
9733 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9734 "startEmergencyCallbackMode");
9735 enforceModifyPermission();
9736 final long identity = Binder.clearCallingIdentity();
9737 try {
9738 for (Phone phone : PhoneFactory.getPhones()) {
9739 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9740 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9741 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9742 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9743 gsmCdmaPhone.obtainMessage(
9744 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9745 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9746 }
9747 }
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009754 * Update emergency number list for test mode.
9755 */
9756 @Override
9757 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9759 "updateEmergencyNumberListTestMode");
9760
9761 final long identity = Binder.clearCallingIdentity();
9762 try {
9763 for (Phone phone: PhoneFactory.getPhones()) {
9764 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9765 if (tracker != null) {
9766 tracker.executeEmergencyNumberTestModeCommand(action, num);
9767 }
9768 }
9769 } finally {
9770 Binder.restoreCallingIdentity(identity);
9771 }
9772 }
9773
9774 /**
9775 * Get the full emergency number list for test mode.
9776 */
9777 @Override
9778 public List<String> getEmergencyNumberListTestMode() {
9779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9780 "getEmergencyNumberListTestMode");
9781
9782 final long identity = Binder.clearCallingIdentity();
9783 try {
9784 Set<String> emergencyNumbers = new HashSet<>();
9785 for (Phone phone: PhoneFactory.getPhones()) {
9786 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9787 if (tracker != null) {
9788 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9789 emergencyNumbers.add(num.getNumber());
9790 }
9791 }
9792 }
9793 return new ArrayList<>(emergencyNumbers);
9794 } finally {
9795 Binder.restoreCallingIdentity(identity);
9796 }
9797 }
9798
chen xud6b45bd2018-10-30 22:27:10 -07009799 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009800 public int getEmergencyNumberDbVersion(int subId) {
9801 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9802
9803 final long identity = Binder.clearCallingIdentity();
9804 try {
9805 final Phone phone = getPhone(subId);
9806 if (phone == null) {
9807 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9808 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9809 }
9810 return phone.getEmergencyNumberDbVersion();
9811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 }
9815
9816 @Override
9817 public void notifyOtaEmergencyNumberDbInstalled() {
9818 enforceModifyPermission();
9819
9820 final long identity = Binder.clearCallingIdentity();
9821 try {
9822 for (Phone phone: PhoneFactory.getPhones()) {
9823 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9824 if (tracker != null) {
9825 tracker.updateOtaEmergencyNumberDatabase();
9826 }
9827 }
9828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
9833 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009834 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009835 enforceActiveEmergencySessionPermission();
9836
9837 final long identity = Binder.clearCallingIdentity();
9838 try {
9839 for (Phone phone: PhoneFactory.getPhones()) {
9840 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9841 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009842 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9843 }
9844 }
9845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
9849
9850 @Override
9851 public void resetOtaEmergencyNumberDbFilePath() {
9852 enforceActiveEmergencySessionPermission();
9853
9854 final long identity = Binder.clearCallingIdentity();
9855 try {
9856 for (Phone phone: PhoneFactory.getPhones()) {
9857 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9858 if (tracker != null) {
9859 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009860 }
9861 }
9862 } finally {
9863 Binder.restoreCallingIdentity(identity);
9864 }
9865 }
9866
9867 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009868 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9869 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9870 Phone phone = getPhone(subId);
9871 if (phone == null) {
9872 return null;
9873 }
9874 final long identity = Binder.clearCallingIdentity();
9875 try {
9876 UiccProfile profile = UiccController.getInstance()
9877 .getUiccProfileForPhone(phone.getPhoneId());
9878 if (profile != null) {
9879 return profile.getCertsFromCarrierPrivilegeAccessRules();
9880 }
9881 } finally {
9882 Binder.restoreCallingIdentity(identity);
9883 }
9884 return null;
9885 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009886
9887 /**
9888 * Enable or disable a modem stack.
9889 */
9890 @Override
9891 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9892 enforceModifyPermission();
9893
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
9896 Phone phone = PhoneFactory.getPhone(slotIndex);
9897 if (phone == null) {
9898 return false;
9899 } else {
9900 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9901 }
9902 } finally {
9903 Binder.restoreCallingIdentity(identity);
9904 }
9905 }
Michelecea4cf22018-12-21 15:00:11 -08009906
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009907 /**
9908 * Whether a modem stack is enabled or not.
9909 */
9910 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009911 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9912 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009913 Phone phone = PhoneFactory.getPhone(slotIndex);
9914 if (phone == null) return false;
9915
9916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009917 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9918 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009919 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9920 }
9921
9922 final long identity = Binder.clearCallingIdentity();
9923 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009924 try {
9925 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9926 } catch (NoSuchElementException ex) {
9927 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9928 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009929 } finally {
9930 Binder.restoreCallingIdentity(identity);
9931 }
9932 }
9933
Michelecea4cf22018-12-21 15:00:11 -08009934 @Override
Michele0ea7d782019-03-19 14:58:42 -07009935 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009936 enforceModifyPermission();
9937
9938 final long identity = Binder.clearCallingIdentity();
9939 try {
9940 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009941 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009942 .commit();
9943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 }
9947
9948 @Override
Michele0ea7d782019-03-19 14:58:42 -07009949 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009950 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009952 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9953 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009954 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009955 }
Michelecea4cf22018-12-21 15:00:11 -08009956
9957 final long identity = Binder.clearCallingIdentity();
9958 try {
Michele0ea7d782019-03-19 14:58:42 -07009959 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009960 } finally {
9961 Binder.restoreCallingIdentity(identity);
9962 }
9963 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009964
Michele0ea7d782019-03-19 14:58:42 -07009965 @TelephonyManager.IsMultiSimSupportedResult
9966 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009967 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9968 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9969 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009970 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9971 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009972 }
9973 // Check if the hardware supports multisim functionality. If usage of multisim is not
9974 // supported by the modem, indicate that it is restricted.
9975 PhoneCapability staticCapability =
9976 mPhoneConfigurationManager.getStaticPhoneCapability();
9977 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009978 loge("isMultiSimSupportedInternal: no static configuration available");
9979 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009980 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009981 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009982 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9983 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009984 }
9985 // Check if support of multiple SIMs is restricted by carrier
9986 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009987 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009988 }
9989
Michele0ea7d782019-03-19 14:58:42 -07009990 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009991 }
9992
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009993 /**
9994 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009995 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9996 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9997 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009998 * @param numOfSims number of active sims we want to switch to
9999 */
10000 @Override
10001 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010002 if (numOfSims == 1) {
10003 enforceModifyPermission();
10004 } else {
10005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10006 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10007 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010008 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010009
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010010 try {
Michele30b57b22019-03-01 12:01:14 -080010011 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010012 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010013 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10014 return;
10015 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010016 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10017 } finally {
10018 Binder.restoreCallingIdentity(identity);
10019 }
10020 }
10021
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010022 @Override
10023 public boolean isApplicationOnUicc(int subId, int appType) {
10024 enforceReadPrivilegedPermission("isApplicationOnUicc");
10025 Phone phone = getPhone(subId);
10026 if (phone == null) {
10027 return false;
10028 }
10029 final long identity = Binder.clearCallingIdentity();
10030 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010031 UiccPort uiccPort = phone.getUiccPort();
10032 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010033 return false;
10034 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010035 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010036 if (uiccProfile == null) {
10037 return false;
10038 }
10039 if (TelephonyManager.APPTYPE_SIM <= appType
10040 && appType <= TelephonyManager.APPTYPE_ISIM) {
10041 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10042 }
10043 return false;
10044 } finally {
10045 Binder.restoreCallingIdentity(identity);
10046 }
10047 }
10048
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010049 /**
chen xub4baa772019-04-03 10:23:41 -070010050 * Get whether making changes to modem configurations will trigger reboot.
10051 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010052 */
10053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010054 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10055 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010057 mApp, subId, callingPackage, callingFeatureId,
10058 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010059 return false;
10060 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010061 final long identity = Binder.clearCallingIdentity();
10062 try {
10063 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10064 } finally {
10065 Binder.restoreCallingIdentity(identity);
10066 }
10067 }
10068
Nathan Harold29f5f052019-02-15 13:41:57 -080010069 private void updateModemStateMetrics() {
10070 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10071 // TODO: check the state for each modem if the api is ready.
10072 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10073 }
10074
Pengquan Meng3889a572019-01-23 11:16:29 -080010075 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010076 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010077 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010078 // Verify that the callingPackage belongs to the calling UID
10079 mApp.getSystemService(AppOpsManager.class)
10080 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010081 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010082 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010083 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010084 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10085 if (slotInfos != null) {
10086 for (int i = 0; i < slotInfos.length; i++) {
10087 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10088 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10089 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10090 portInfo.getLogicalSlotIndex()));
10091 }
10092 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010093 }
10094 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010095 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010096 } finally {
10097 Binder.restoreCallingIdentity(identity);
10098 }
10099 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010100
10101 /**
10102 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010103 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010104 */
jimsunf9ec1622022-09-13 21:18:43 +080010105 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010106 @Override
10107 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010108 return getHalVersion(HAL_SERVICE_RADIO);
10109 }
10110
10111 /**
10112 * Get the HAL Version of a specific service
10113 */
10114 @Override
10115 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010116 Phone phone = getDefaultPhone();
10117 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010118 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010119 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10120 return hv.major * 100 + hv.minor;
10121 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010122
10123 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010124 * Get the current calling package name.
10125 * @return the current calling package name
10126 */
10127 @Override
10128 public String getCurrentPackageName() {
10129 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10130 }
10131
10132 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010133 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10134 * corresponding network requests on a subId.
10135 *
10136 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010137 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010138 * 2) APN is un-metered for this subscription, or
10139 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010140 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010141 *
10142 * @return whether data is allowed for a apn type.
10143 *
10144 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010145 */
10146 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010147 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010148 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10149 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010150
10151 // Now that all security checks passes, perform the operation as ourselves.
10152 final long identity = Binder.clearCallingIdentity();
10153 try {
10154 Phone phone = getPhone(subId);
10155 if (phone == null) return false;
10156
Jack Yu27422a52022-03-21 10:38:05 -070010157 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010158 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010159 isMetered = phone.getDataNetworkController().getDataConfigManager()
10160 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10161 phone.getServiceState().getDataRoaming());
10162 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010163 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010164 } finally {
10165 Binder.restoreCallingIdentity(identity);
10166 }
10167 }
10168
10169 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010170 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010171 enforceReadPrivilegedPermission("isApnMetered");
10172
10173 // Now that all security checks passes, perform the operation as ourselves.
10174 final long identity = Binder.clearCallingIdentity();
10175 try {
10176 Phone phone = getPhone(subId);
10177 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010178 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10179 DataUtils.apnTypeToNetworkCapability(apnType),
10180 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010185
10186 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010187 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10188 int subscriptionId, IBooleanConsumer resultCallback) {
10189 enforceModifyPermission();
10190 long token = Binder.clearCallingIdentity();
10191 try {
10192 Phone phone = getPhone(subscriptionId);
10193 if (phone == null) {
10194 try {
10195 if (resultCallback != null) {
10196 resultCallback.accept(false);
10197 }
10198 } catch (RemoteException e) {
10199 // ignore
10200 }
10201 return;
10202 }
10203 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10204 Pair.create(specifiers, (x) -> {
10205 try {
10206 if (resultCallback != null) {
10207 resultCallback.accept(x);
10208 }
10209 } catch (RemoteException e) {
10210 // ignore
10211 }
10212 });
10213 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10214 } finally {
10215 Binder.restoreCallingIdentity(token);
10216 }
10217 }
10218
10219 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010220 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10221 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010222 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010223 mApp, subId, "getSystemSelectionChannels");
10224 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10225 final long identity = Binder.clearCallingIdentity();
10226 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010227 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10228 if (result instanceof IllegalStateException) {
10229 throw (IllegalStateException) result;
10230 }
10231 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010232 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10233 return specifiers;
10234 } finally {
10235 Binder.restoreCallingIdentity(identity);
10236 }
10237 }
10238
10239 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010240 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010241 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010242 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010243 }
10244
10245 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010246 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10247 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010248 if (callingPackage == null) {
10249 callingPackage = getCurrentPackageName();
10250 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010251 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10252 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010253 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10254 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010255 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10256 }
10257 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10258 Intent intent = new Intent();
10259 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10260 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10261 // Bring up choose default SMS subscription dialog right now
10262 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10263 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10264 mApp.startActivity(intent);
10265 }
chen xud5ca2d52019-05-28 15:20:57 -070010266
10267 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010268 public void showSwitchToManagedProfileDialog() {
10269 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010270 try {
10271 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10272 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10273 // for work telephony.
10274 Intent intent = new Intent(Intent.ACTION_SENDTO);
10275 intent.setData(Uri.parse("smsto:"));
10276 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10277 mApp.startActivity(intent);
10278 } catch (ActivityNotFoundException e) {
10279 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10280 Intent intent = new Intent();
10281 intent.setClass(mApp, ErrorDialogActivity.class);
10282 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10283 mApp.startActivity(intent);
10284 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010285 }
10286
10287 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010288 public String getMmsUAProfUrl(int subId) {
10289 //TODO investigate if this API should require proper permission check in R b/133791609
10290 final long identity = Binder.clearCallingIdentity();
10291 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010292 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10293 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10294 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10295 return carrierUAProfUrl;
10296 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010297 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10298 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010299 } finally {
10300 Binder.restoreCallingIdentity(identity);
10301 }
10302 }
10303
10304 @Override
10305 public String getMmsUserAgent(int subId) {
10306 //TODO investigate if this API should require proper permission check in R b/133791609
10307 final long identity = Binder.clearCallingIdentity();
10308 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010309 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10310 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10311 if (!TextUtils.isEmpty(carrierUserAgent)) {
10312 return carrierUserAgent;
10313 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010314 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10315 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
Jack Yub07d4972019-05-28 16:12:25 -070010320
10321 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010322 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10323 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010324
Jack Yub07d4972019-05-28 16:12:25 -070010325 final long identity = Binder.clearCallingIdentity();
10326 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010327 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010328 if (phone == null) return false;
10329
Ling Maf188d502022-09-16 15:22:36 -070010330 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010331 } finally {
10332 Binder.restoreCallingIdentity(identity);
10333 }
10334 }
10335
10336 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010337 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010338 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010339 enforceModifyPermission();
10340
changbettyd5c246e2019-12-24 15:40:37 +080010341 final long identity = Binder.clearCallingIdentity();
10342 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010343 Phone phone = getPhone(subscriptionId);
10344 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010345
Ling Maf188d502022-09-16 15:22:36 -070010346 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010347 } finally {
10348 Binder.restoreCallingIdentity(identity);
10349 }
10350 }
10351
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010352 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010353 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010354 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10355 * otherwise.
10356 */
10357 @Override
10358 public void setCepEnabled(boolean isCepEnabled) {
10359 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10360
10361 final long identity = Binder.clearCallingIdentity();
10362 try {
10363 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10364 for (Phone phone : PhoneFactory.getPhones()) {
10365 Phone defaultPhone = phone.getImsPhone();
10366 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10367 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10368 ImsPhoneCallTracker imsPhoneCallTracker =
10369 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10370 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10371 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10372 + imsPhone.getMsisdn());
10373 }
10374 }
10375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 }
allenwtsu46dcc572020-01-08 18:24:03 +080010379
10380 /**
10381 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10382 *
10383 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10384 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10385 * before being read.
10386 */
10387 @Override
10388 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10389 isCompressed) {
10390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10391 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010392 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10393 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10394 }
10395 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010396 // ProvisioningManager can not handle ServiceSpecificException.
10397 // Throw the IllegalStateException and annotate ProvisioningManager.
10398 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010399 }
10400
10401 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010402 try {
Hui Wang761a6682020-10-31 05:12:53 +000010403 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10404 } finally {
10405 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010406 }
10407 }
zoey chene02881a2019-12-30 16:11:23 +080010408
10409 @Override
10410 public boolean isIccLockEnabled(int subId) {
10411 enforceReadPrivilegedPermission("isIccLockEnabled");
10412
10413 // Now that all security checks passes, perform the operation as ourselves.
10414 final long identity = Binder.clearCallingIdentity();
10415 try {
10416 Phone phone = getPhone(subId);
10417 if (phone != null && phone.getIccCard() != null) {
10418 return phone.getIccCard().getIccLockEnabled();
10419 } else {
10420 return false;
10421 }
10422 } finally {
10423 Binder.restoreCallingIdentity(identity);
10424 }
10425 }
10426
10427 /**
10428 * Set the ICC pin lock enabled or disabled.
10429 *
10430 * @return an integer representing the status of IccLock enabled or disabled in the following
10431 * three cases:
10432 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10433 * successfully.
10434 * - Positive number and zero for remaining password attempts.
10435 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10436 *
10437 */
10438 @Override
10439 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10440 enforceModifyPermission();
10441
10442 Phone phone = getPhone(subId);
10443 if (phone == null) {
10444 return 0;
10445 }
10446 // Now that all security checks passes, perform the operation as ourselves.
10447 final long identity = Binder.clearCallingIdentity();
10448 try {
10449 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10450 new Pair<Boolean, String>(enabled, password), phone, null);
10451 return attemptsRemaining;
10452
10453 } catch (Exception e) {
10454 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10455 } finally {
10456 Binder.restoreCallingIdentity(identity);
10457 }
10458 return 0;
10459 }
10460
10461 /**
10462 * Change the ICC password used in ICC pin lock.
10463 *
10464 * @return an integer representing the status of IccLock changed in the following three cases:
10465 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10466 * - Positive number and zero for remaining password attempts.
10467 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10468 *
10469 */
10470 @Override
10471 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10472 enforceModifyPermission();
10473
10474 Phone phone = getPhone(subId);
10475 if (phone == null) {
10476 return 0;
10477 }
10478 // Now that all security checks passes, perform the operation as ourselves.
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10482 new Pair<String, String>(oldPassword, newPassword), phone, null);
10483 return attemptsRemaining;
10484
10485 } catch (Exception e) {
10486 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10487 } finally {
10488 Binder.restoreCallingIdentity(identity);
10489 }
10490 return 0;
10491 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010492
10493 /**
10494 * Request for receiving user activity notification
10495 */
10496 @Override
10497 public void requestUserActivityNotification() {
10498 if (!mNotifyUserActivity.get()
10499 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10500 mNotifyUserActivity.set(true);
10501 }
10502 }
10503
10504 /**
10505 * Called when userActivity is signalled in the power manager.
10506 * This is safe to call from any thread, with any window manager locks held or not.
10507 */
10508 @Override
10509 public void userActivity() {
10510 // ***************************************
10511 // * Inherited from PhoneWindowManager *
10512 // ***************************************
10513 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10514 // WITH ITS LOCKS HELD.
10515 //
10516 // This code must be VERY careful about the locks
10517 // it acquires.
10518 // In fact, the current code acquires way too many,
10519 // and probably has lurking deadlocks.
10520
10521 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10522 throw new SecurityException("Only the OS may call notifyUserActivity()");
10523 }
10524
10525 if (mNotifyUserActivity.getAndSet(false)) {
10526 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10527 USER_ACTIVITY_NOTIFICATION_DELAY);
10528 }
10529 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010530
10531 @Override
10532 public boolean canConnectTo5GInDsdsMode() {
10533 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10534 }
Jack Yud10cdd42020-09-28 20:28:01 -070010535
10536 @Override
10537 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10538 String callingFeatureId) {
10539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10540 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10541 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10542 }
10543
10544 Phone phone = getPhone(subId);
10545 if (phone == null) {
10546 throw new RuntimeException("phone is not available");
10547 }
10548 // Now that all security checks passes, perform the operation as ourselves.
10549 final long identity = Binder.clearCallingIdentity();
10550 try {
10551 return phone.getEquivalentHomePlmns();
10552 } finally {
10553 Binder.restoreCallingIdentity(identity);
10554 }
10555 }
Daniel Bright59e67312020-11-13 11:49:37 -080010556
10557 @Override
10558 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010559 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10560 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010561 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010562 if (radioInterfaceCapabilities == null) {
10563 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010564 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010565 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010566 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010567
Hui Wang641e81c2020-10-12 12:14:23 -070010568 @Override
10569 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10570 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010571 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10572 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10573 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10574 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10575 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010576 if (DBG) {
10577 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10578 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10579 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10580 }
10581
10582 if (!SubscriptionManager.isValidSubscriptionId(subId)
10583 || appType < TelephonyManager.APPTYPE_UNKNOWN
10584 || appType > TelephonyManager.APPTYPE_ISIM
10585 || nafUrl == null || securityProtocol == null || callback == null) {
10586 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10587 if (callback != null) {
10588 try {
10589 callback.onAuthenticationFailure(
10590 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10591 } catch (RemoteException exception) {
10592 log("Fail to notify onAuthenticationFailure due to " + exception);
10593 }
10594 return;
10595 }
10596 }
10597
10598 final long token = Binder.clearCallingIdentity();
10599 try {
10600 getGbaManager(subId).bootstrapAuthenticationRequest(
10601 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010602 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010603 } finally {
10604 Binder.restoreCallingIdentity(token);
10605 }
10606 }
10607
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010608 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010609 * Attempts to set the radio power state for all phones for thermal reason.
10610 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010611 * requested radio power state will actually be set. See {@link
10612 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10613 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010614 * @param enable {@code true} if trying to turn radio on.
10615 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10616 * false}.
10617 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010618 private boolean setRadioPowerForThermal(boolean enable) {
10619 boolean isPhoneAvailable = false;
10620 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10621 Phone phone = PhoneFactory.getPhone(i);
10622 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010623 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010624 isPhoneAvailable = true;
10625 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010626 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010627
10628 // return true if successfully informed the phone object about the thermal radio power
10629 // request.
10630 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010631 }
10632
10633 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010634 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010635 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10636 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10637 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10638 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10639 throw new IllegalArgumentException("modem does not support data throttling");
10640 }
10641
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010642 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10643 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010644 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010645 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10646 }
10647
Sarah Chinecc78c42022-03-31 21:16:48 -070010648 setDataEnabledForReason(
10649 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010650
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010651 if (isDataThrottlingSupported) {
10652 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010653 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010654 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10655 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10656 } else if (thermalMitigationResult
10657 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010658 log("Modem likely does not support data throttling on secondary carrier. Data " +
10659 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10660 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010661 }
10662 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010663 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010664
10665 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010666 }
10667
Jack Nudelman644b91a2021-03-12 14:09:48 -080010668 private static List<String> getThermalMitigationAllowlist(Context context) {
10669 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10670 for (String pckg : context.getResources()
10671 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10672 sThermalMitigationAllowlistedPackages.add(pckg);
10673 }
10674 }
10675
10676 return sThermalMitigationAllowlistedPackages;
10677 }
10678
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010679 private boolean isAnyPhoneInEmergencyState() {
10680 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10681 if (tm.isInEmergencyCall()) {
10682 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10683 return true;
10684 }
10685 for (Phone phone : PhoneFactory.getPhones()) {
10686 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10687 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010688 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10689 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010690 return true;
10691 }
10692 }
10693
10694 return false;
10695 }
10696
Jack Nudelman644b91a2021-03-12 14:09:48 -080010697 /**
10698 * Used by shell commands to add an authorized package name for thermal mitigation.
10699 * @param packageName name of package to be allowlisted
10700 * @param context
10701 */
10702 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10703 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10704 sThermalMitigationAllowlistedPackages.add(packageName);
10705 }
10706
10707 /**
10708 * Used by shell commands to remove an authorized package name for thermal mitigation.
10709 * @param packageName name of package to remove from allowlist
10710 * @param context
10711 */
10712 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10713 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10714 sThermalMitigationAllowlistedPackages.remove(packageName);
10715 }
10716
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010717 /**
10718 * Thermal mitigation request to control functionalities at modem.
10719 *
10720 * @param subId the id of the subscription.
10721 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010722 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010723 *
10724 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10725 */
10726 @Override
10727 @ThermalMitigationResult
10728 public int sendThermalMitigationRequest(
10729 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010730 ThermalMitigationRequest thermalMitigationRequest,
10731 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010732 enforceModifyPermission();
10733
Jack Nudelman644b91a2021-03-12 14:09:48 -080010734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10735 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10736 .contains(callingPackage)) {
10737 throw new SecurityException("Calling package must be configured in the device config. "
10738 + "calling package: " + callingPackage);
10739 }
10740
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010741 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10742 final long identity = Binder.clearCallingIdentity();
10743
10744 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10745 try {
10746 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10747 switch (thermalMitigationAction) {
10748 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10749 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010750 handleDataThrottlingRequest(subId,
10751 thermalMitigationRequest.getDataThrottlingRequest(),
10752 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010753 break;
10754 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10755 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10756 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10757 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10758 }
10759
10760 // Ensure that radio is on. If not able to power on due to phone being
10761 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010762 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010763 thermalMitigationResult =
10764 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10765 break;
10766 }
10767
10768 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010769 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010770 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10771 break;
10772 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10773 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10774 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10775 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10776 }
10777
10778 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10779 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010780 Phone phone = getPhone(subId);
10781 if (phone == null) {
10782 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010783 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010784 break;
10785 }
10786
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010787 TelephonyConnectionService service =
10788 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010789 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010790 Log.e(LOG_TAG, "An emergency call is pending");
10791 thermalMitigationResult =
10792 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10793 break;
10794 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010795 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010796 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010797 break;
10798 }
10799 } else {
10800 thermalMitigationResult =
10801 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10802 break;
10803 }
10804
10805 // Turn radio off. If not able to power off due to phone being unavailable,
10806 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010807 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010808 thermalMitigationResult =
10809 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10810 break;
10811 }
10812 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010813 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010814 break;
10815 default:
10816 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10817 + "not exist. Requested action: " + thermalMitigationAction);
10818 }
10819 } catch (IllegalArgumentException e) {
10820 throw e;
10821 } catch (Exception e) {
10822 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10823 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10824 } finally {
10825 Binder.restoreCallingIdentity(identity);
10826 }
10827
10828 if (DBG) {
10829 log("thermalMitigationRequest returning with thermalMitigationResult: "
10830 + thermalMitigationResult);
10831 }
10832
10833 return thermalMitigationResult;
10834 }
Hui Wang641e81c2020-10-12 12:14:23 -070010835
10836 /**
10837 * Set the GbaService Package Name that Telephony will bind to.
10838 *
10839 * @param subId The sim that the GbaService is associated with.
10840 * @param packageName The name of the package to be replaced with.
10841 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10842 */
10843 @Override
10844 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10845 enforceModifyPermission();
10846
10847 final long identity = Binder.clearCallingIdentity();
10848 try {
10849 return getGbaManager(subId).overrideServicePackage(packageName);
10850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
10854
10855 /**
10856 * Return the package name of the currently bound GbaService.
10857 *
10858 * @param subId The sim that the GbaService is associated with.
10859 * @return the package name of the GbaService configuration, null if GBA is not supported.
10860 */
10861 @Override
10862 public String getBoundGbaService(int subId) {
10863 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10864
10865 final long identity = Binder.clearCallingIdentity();
10866 try {
10867 return getGbaManager(subId).getServicePackage();
10868 } finally {
10869 Binder.restoreCallingIdentity(identity);
10870 }
10871 }
10872
10873 /**
10874 * Set the release time for telephony to unbind GbaService.
10875 *
10876 * @param subId The sim that the GbaService is associated with.
10877 * @param interval The release time to unbind GbaService by millisecond.
10878 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10879 */
10880 @Override
10881 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10882 enforceModifyPermission();
10883
10884 final long identity = Binder.clearCallingIdentity();
10885 try {
10886 return getGbaManager(subId).overrideReleaseTime(interval);
10887 } finally {
10888 Binder.restoreCallingIdentity(identity);
10889 }
10890 }
10891
10892 /**
10893 * Return the release time for telephony to unbind GbaService.
10894 *
10895 * @param subId The sim that the GbaService is associated with.
10896 * @return The release time to unbind GbaService by millisecond.
10897 */
10898 @Override
10899 public int getGbaReleaseTime(int subId) {
10900 enforceReadPrivilegedPermission("getGbaReleaseTime");
10901
10902 final long identity = Binder.clearCallingIdentity();
10903 try {
10904 return getGbaManager(subId).getReleaseTime();
10905 } finally {
10906 Binder.restoreCallingIdentity(identity);
10907 }
10908 }
10909
10910 private GbaManager getGbaManager(int subId) {
10911 GbaManager instance = GbaManager.getInstance(subId);
10912 if (instance == null) {
10913 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10914 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10915 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10916 }
10917 return instance;
10918 }
Hui Wang761a6682020-10-31 05:12:53 +000010919
10920 /**
10921 * indicate whether the device and the carrier can support
10922 * RCS VoLTE single registration.
10923 */
10924 @Override
10925 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010926 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10927 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10928 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10929 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010930
10931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10932 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10933 }
10934
10935 final long identity = Binder.clearCallingIdentity();
10936 try {
10937 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10938 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010939 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10940 if (isCapable != null) {
10941 return isCapable;
10942 }
Hui Wang761a6682020-10-31 05:12:53 +000010943 }
Hui Wang67af90e2021-06-04 16:57:15 -070010944 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10945 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010946 } finally {
10947 Binder.restoreCallingIdentity(identity);
10948 }
10949 }
10950
10951 /**
10952 * Register RCS provisioning callback.
10953 */
10954 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010955 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010956 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010957 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010958 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010959 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10960 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010961
10962 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10963 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10964 }
10965 if (!isImsAvailableOnDevice()) {
10966 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10967 "IMS not available on device.");
10968 }
10969
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010972 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010973 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010974 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10975 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010976 }
Hui Wang761a6682020-10-31 05:12:53 +000010977 } finally {
10978 Binder.restoreCallingIdentity(identity);
10979 }
10980 }
10981
10982 /**
10983 * Unregister RCS provisioning callback.
10984 */
10985 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010986 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010987 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010988 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010989 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010990 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10991 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010992
10993 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10994 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10995 }
10996 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010997 // operation failed silently
10998 Rlog.w(LOG_TAG, "IMS not available on device.");
10999 return;
Hui Wang761a6682020-10-31 05:12:53 +000011000 }
11001
11002 final long identity = Binder.clearCallingIdentity();
11003 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011004 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011005 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011006 } finally {
11007 Binder.restoreCallingIdentity(identity);
11008 }
11009 }
11010
11011 /**
11012 * trigger RCS reconfiguration.
11013 */
11014 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011015 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11016 "triggerRcsReconfiguration",
11017 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011018
11019 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11020 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11021 }
11022 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011023 // ProvisioningManager can not handle ServiceSpecificException.
11024 // Throw the IllegalStateException and annotate ProvisioningManager.
11025 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011026 }
11027
11028 final long identity = Binder.clearCallingIdentity();
11029 try {
11030 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
11035
11036 /**
11037 * Provide the client configuration parameters of the RCS application.
11038 */
11039 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011040 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11041 "setRcsClientConfiguration",
11042 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011043
11044 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11045 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11046 }
11047 if (!isImsAvailableOnDevice()) {
11048 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11049 "IMS not available on device.");
11050 }
11051
11052 final long identity = Binder.clearCallingIdentity();
11053
11054 try {
11055 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11056 if (configBinder == null) {
11057 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011058 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11059 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011060 } else {
11061 configBinder.setRcsClientConfiguration(rcc);
11062 }
joonhunshin3e154242021-09-17 06:33:39 +000011063
11064 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11065 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011066 } catch (RemoteException e) {
11067 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011068 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11069 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011070 } finally {
11071 Binder.restoreCallingIdentity(identity);
11072 }
11073 }
11074
11075 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011076 * Enables or disables the test mode for RCS VoLTE single registration.
11077 */
11078 @Override
11079 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11080 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11081 "setRcsSingleRegistrationTestModeEnabled");
11082
11083 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11084 }
11085
11086 /**
11087 * Gets the test mode for RCS VoLTE single registration.
11088 */
11089 @Override
11090 public boolean getRcsSingleRegistrationTestModeEnabled() {
11091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11092 "getRcsSingleRegistrationTestModeEnabled");
11093
11094 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11095 }
11096
11097 /**
Hui Wang761a6682020-10-31 05:12:53 +000011098 * Overrides the config of RCS VoLTE single registration enabled for the device.
11099 */
11100 @Override
11101 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11102 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11103 "setDeviceSingleRegistrationEnabledOverride");
11104 enforceModifyPermission();
11105
11106 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11107 : Boolean.parseBoolean(enabledStr);
11108 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011109 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011110 }
11111
11112 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011113 * Sends a device to device communication message. Only usable via shell.
11114 * @param message message to send.
11115 * @param value message value.
11116 */
11117 @Override
11118 public void sendDeviceToDeviceMessage(int message, int value) {
11119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011120 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011121 enforceModifyPermission();
11122
11123 final long identity = Binder.clearCallingIdentity();
11124 try {
11125 TelephonyConnectionService service =
11126 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11127 if (service == null) {
11128 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11129 return;
11130 }
11131 service.sendTestDeviceToDeviceMessage(message, value);
11132 } finally {
11133 Binder.restoreCallingIdentity(identity);
11134 }
11135 }
11136
Tyler Gunnbabbda02021-02-10 11:05:02 -080011137 /**
11138 * Sets the specified device to device transport active.
11139 * @param transport The transport to set active.
11140 */
11141 @Override
11142 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11144 "setActiveDeviceToDeviceTransport");
11145 enforceModifyPermission();
11146
11147 final long identity = Binder.clearCallingIdentity();
11148 try {
11149 TelephonyConnectionService service =
11150 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11151 if (service == null) {
11152 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11153 return;
11154 }
11155 service.setActiveDeviceToDeviceTransport(transport);
11156 } finally {
11157 Binder.restoreCallingIdentity(identity);
11158 }
11159 }
Tyler Gunn92479152021-01-20 16:30:10 -080011160
Tyler Gunnd4339262021-05-03 14:46:49 -070011161 @Override
11162 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11163 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11164 "setDeviceToDeviceForceEnabled");
11165
11166 final long identity = Binder.clearCallingIdentity();
11167 try {
11168 Arrays.stream(PhoneFactory.getPhones()).forEach(
11169 p -> {
11170 Phone thePhone = p.getImsPhone();
11171 if (thePhone != null && thePhone instanceof ImsPhone) {
11172 ImsPhone imsPhone = (ImsPhone) thePhone;
11173 CallTracker tracker = imsPhone.getCallTracker();
11174 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11175 ImsPhoneCallTracker imsPhoneCallTracker =
11176 (ImsPhoneCallTracker) tracker;
11177 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11178 }
11179 }
11180 }
11181 );
11182 } finally {
11183 Binder.restoreCallingIdentity(identity);
11184 }
11185 }
11186
Tyler Gunn92479152021-01-20 16:30:10 -080011187 /**
Hui Wang761a6682020-10-31 05:12:53 +000011188 * Gets the config of RCS VoLTE single registration enabled for the device.
11189 */
11190 @Override
11191 public boolean getDeviceSingleRegistrationEnabled() {
11192 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11193 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11194 }
11195
11196 /**
11197 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11198 */
11199 @Override
11200 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11201 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11202 "setCarrierSingleRegistrationEnabledOverride");
11203 enforceModifyPermission();
11204
11205 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11206 : Boolean.parseBoolean(enabledStr);
11207 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11208 subId, enabled);
11209 }
11210
11211 /**
11212 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11213 */
11214 @Override
11215 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11216 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11217 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11218 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011219
11220 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011221 * Overrides the ims feature validation result
11222 */
11223 @Override
11224 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11225 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11226 "setImsFeatureValidationOverride");
11227
11228 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11229 : Boolean.parseBoolean(enabledStr);
11230 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11231 subId, enabled);
11232 }
11233
11234 /**
11235 * Gets the ims feature validation override value
11236 */
11237 @Override
11238 public boolean getImsFeatureValidationOverride(int subId) {
11239 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11240 "getImsFeatureValidationOverride");
11241 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11242 }
11243
11244 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011245 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11246 * their mobile plan.
11247 */
11248 @Override
11249 public String getMobileProvisioningUrl() {
11250 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11251 final long identity = Binder.clearCallingIdentity();
11252 try {
11253 return getDefaultPhone().getMobileProvisioningUrl();
11254 } finally {
11255 Binder.restoreCallingIdentity(identity);
11256 }
11257 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011258
James.cf Linbcdf8b32021-01-14 16:44:13 +080011259 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011260 * Get the EAB contact from the EAB database.
11261 */
11262 @Override
11263 public String getContactFromEab(String contact) {
11264 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11265 enforceModifyPermission();
11266 final long identity = Binder.clearCallingIdentity();
11267 try {
11268 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11269 } finally {
11270 Binder.restoreCallingIdentity(identity);
11271 }
11272 }
11273
11274 /**
Calvin Pana1434322021-07-01 19:27:01 +080011275 * Get the EAB capability from the EAB database.
11276 */
11277 @Override
11278 public String getCapabilityFromEab(String contact) {
11279 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11280 enforceModifyPermission();
11281 final long identity = Binder.clearCallingIdentity();
11282 try {
11283 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11284 } finally {
11285 Binder.restoreCallingIdentity(identity);
11286 }
11287 }
11288
11289 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011290 * Remove the EAB contacts from the EAB database.
11291 */
11292 @Override
11293 public int removeContactFromEab(int subId, String contacts) {
11294 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11295 enforceModifyPermission();
11296 final long identity = Binder.clearCallingIdentity();
11297 try {
11298 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11299 } finally {
11300 Binder.restoreCallingIdentity(identity);
11301 }
11302 }
11303
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011304 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011305 public boolean getDeviceUceEnabled() {
11306 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11307 final long identity = Binder.clearCallingIdentity();
11308 try {
11309 return mApp.getDeviceUceEnabled();
11310 } finally {
11311 Binder.restoreCallingIdentity(identity);
11312 }
11313 }
11314
11315 @Override
11316 public void setDeviceUceEnabled(boolean isEnabled) {
11317 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11318 final long identity = Binder.clearCallingIdentity();
11319 try {
11320 mApp.setDeviceUceEnabled(isEnabled);
11321 } finally {
11322 Binder.restoreCallingIdentity(identity);
11323 }
11324 }
11325
Brad Ebinger14d467f2021-02-12 06:18:28 +000011326 /**
11327 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11328 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11329 */
11330 // Used for SHELL command only right now.
11331 @Override
11332 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11333 List<String> featureTags) {
11334 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11335 "addUceRegistrationOverrideShell");
11336 final long identity = Binder.clearCallingIdentity();
11337 try {
11338 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11339 new ArraySet<>(featureTags));
11340 } catch (ImsException e) {
11341 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11342 } finally {
11343 Binder.restoreCallingIdentity(identity);
11344 }
11345 }
11346
11347 /**
11348 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11349 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11350 */
11351 // Used for SHELL command only right now.
11352 @Override
11353 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11354 List<String> featureTags) {
11355 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11356 "removeUceRegistrationOverrideShell");
11357 final long identity = Binder.clearCallingIdentity();
11358 try {
11359 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11360 new ArraySet<>(featureTags));
11361 } catch (ImsException e) {
11362 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11363 } finally {
11364 Binder.restoreCallingIdentity(identity);
11365 }
11366 }
11367
11368 /**
11369 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11370 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11371 */
11372 // Used for SHELL command only right now.
11373 @Override
11374 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11375 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11376 "clearUceRegistrationOverrideShell");
11377 final long identity = Binder.clearCallingIdentity();
11378 try {
11379 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11380 } catch (ImsException e) {
11381 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11382 } finally {
11383 Binder.restoreCallingIdentity(identity);
11384 }
11385 }
11386
11387 /**
11388 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11389 */
11390 // Used for SHELL command only right now.
11391 @Override
11392 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11393 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11394 "getLatestRcsContactUceCapabilityShell");
11395 final long identity = Binder.clearCallingIdentity();
11396 try {
11397 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11398 } catch (ImsException e) {
11399 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11400 } finally {
11401 Binder.restoreCallingIdentity(identity);
11402 }
11403 }
11404
11405 /**
11406 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11407 * device does not have an active PUBLISH.
11408 */
11409 // Used for SHELL command only right now.
11410 @Override
11411 public String getLastUcePidfXmlShell(int subId) {
11412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11413 final long identity = Binder.clearCallingIdentity();
11414 try {
11415 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11416 } catch (ImsException e) {
11417 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11418 } finally {
11419 Binder.restoreCallingIdentity(identity);
11420 }
11421 }
11422
James.cf Line8713a42021-04-29 16:04:26 +080011423 /**
11424 * Remove UCE requests cannot be sent to the network status.
11425 */
11426 // Used for SHELL command only right now.
11427 @Override
11428 public boolean removeUceRequestDisallowedStatus(int subId) {
11429 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11430 final long identity = Binder.clearCallingIdentity();
11431 try {
11432 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11433 } catch (ImsException e) {
11434 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11435 } finally {
11436 Binder.restoreCallingIdentity(identity);
11437 }
11438 }
11439
James.cf Lin18bb9002021-05-25 01:37:38 +080011440 /**
11441 * Remove UCE requests cannot be sent to the network status.
11442 */
11443 // Used for SHELL command only.
11444 @Override
11445 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11446 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11447 final long identity = Binder.clearCallingIdentity();
11448 try {
11449 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11450 } catch (ImsException e) {
11451 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11452 } finally {
11453 Binder.restoreCallingIdentity(identity);
11454 }
11455 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011456
James.cf Lin4b784aa2021-01-31 03:25:15 +080011457 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011458 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11459 String callingPackage) {
11460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11461 mApp, subId, "setSignalStrengthUpdateRequest");
11462
11463 final int callingUid = Binder.getCallingUid();
11464 // Verify that tha callingPackage belongs to the calling UID
11465 mApp.getSystemService(AppOpsManager.class)
11466 .checkPackage(callingUid, callingPackage);
11467
Rambo Wang3607f502021-02-01 21:51:40 -080011468 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011469
11470 final long identity = Binder.clearCallingIdentity();
11471 try {
11472 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11473 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11474
11475 if (result instanceof IllegalStateException) {
11476 throw (IllegalStateException) result;
11477 }
11478 } finally {
11479 Binder.restoreCallingIdentity(identity);
11480 }
11481 }
11482
11483 @Override
11484 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11485 String callingPackage) {
11486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11487 mApp, subId, "clearSignalStrengthUpdateRequest");
11488
11489 final int callingUid = Binder.getCallingUid();
11490 // Verify that tha callingPackage belongs to the calling UID
11491 mApp.getSystemService(AppOpsManager.class)
11492 .checkPackage(callingUid, callingPackage);
11493
11494 final long identity = Binder.clearCallingIdentity();
11495 try {
11496 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11497 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11498
11499 if (result instanceof IllegalStateException) {
11500 throw (IllegalStateException) result;
11501 }
11502 } finally {
11503 Binder.restoreCallingIdentity(identity);
11504 }
11505 }
11506
Rambo Wang3607f502021-02-01 21:51:40 -080011507 private static void validateSignalStrengthUpdateRequest(Context context,
11508 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011509 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11510 // phone/system process do not have further restriction on request
11511 return;
11512 }
11513
11514 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011515 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011516 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011517 context.enforceCallingOrSelfPermission(
11518 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11519 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011520 }
11521
11522 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011523 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011524 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011525 || info.isEnabled()) {
11526 throw new IllegalArgumentException(
11527 "Only system can set hide fields in SignalThresholdInfo");
11528 }
11529
11530 // Thresholds length for each RAN need in range. This has been validated in
11531 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11532 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11533 final int[] thresholds = info.getThresholds();
11534 Objects.requireNonNull(thresholds);
11535 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11536 || thresholds.length
11537 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11538 throw new IllegalArgumentException(
11539 "thresholds length is out of range: " + thresholds.length);
11540 }
11541 }
11542 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011543
11544 /**
11545 * Gets the current phone capability.
11546 *
11547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11548 * @return the PhoneCapability which describes the data connection capability of modem.
11549 * It's used to evaluate possible phone config change, for example from single
11550 * SIM device to multi-SIM device.
11551 */
11552 @Override
11553 public PhoneCapability getPhoneCapability() {
11554 enforceReadPrivilegedPermission("getPhoneCapability");
11555 final long identity = Binder.clearCallingIdentity();
11556 try {
11557 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11558 } finally {
11559 Binder.restoreCallingIdentity(identity);
11560 }
11561 }
Michele Berionne5e411512020-11-13 02:36:59 +000011562
11563 /**
11564 * Prepare TelephonyManager for an unattended reboot. The reboot is
11565 * required to be done shortly after the API is invoked.
11566 */
11567 @Override
11568 @TelephonyManager.PrepareUnattendedRebootResult
11569 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011570 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011571 enforceRebootPermission();
11572
11573 final long identity = Binder.clearCallingIdentity();
11574 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011575 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011576 } finally {
11577 Binder.restoreCallingIdentity(identity);
11578 }
11579 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011580
11581 /**
11582 * Request to get the current slicing configuration including URSP rules and
11583 * NSSAIs (configured, allowed and rejected).
11584 *
11585 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11586 */
11587 @Override
11588 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011589 TelephonyPermissions
11590 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11591 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011592
11593 final long identity = Binder.clearCallingIdentity();
11594 try {
11595 Phone phone = getDefaultPhone();
11596 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11597 } finally {
11598 Binder.restoreCallingIdentity(identity);
11599 }
11600 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011601
11602 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011603 * Check whether the given premium capability is available for purchase from the carrier.
11604 *
11605 * @param capability The premium capability to check.
11606 * @param subId The subId to check the premium capability for.
11607 *
11608 * @return Whether the given premium capability is available to purchase.
11609 */
11610 @Override
11611 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11612 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11613 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11614 log("Premium capability "
11615 + TelephonyManager.convertPremiumCapabilityToString(capability)
11616 + " is not available for purchase due to missing permissions.");
11617 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11618 + "permission READ_BASIC_PHONE_STATE.");
11619 }
11620
11621 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011622 if (phone == null) {
11623 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11624 return false;
11625 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011626 final long identity = Binder.clearCallingIdentity();
11627 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070011628 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011629 .isPremiumCapabilityAvailableForPurchase(capability);
11630 } finally {
11631 Binder.restoreCallingIdentity(identity);
11632 }
11633 }
11634
11635 /**
11636 * Purchase the given premium capability from the carrier.
11637 *
11638 * @param capability The premium capability to purchase.
11639 * @param callback The result of the purchase request.
11640 * @param subId The subId to purchase the premium capability for.
11641 */
11642 @Override
11643 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11644 log("purchasePremiumCapability: capability="
11645 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11646 + getCurrentPackageName());
11647
11648 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11649 mApp, "purchasePremiumCapability")) {
11650 log("purchasePremiumCapability "
11651 + TelephonyManager.convertPremiumCapabilityToString(capability)
11652 + " failed due to missing permissions.");
11653 throw new SecurityException("purchasePremiumCapability requires permission "
11654 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011655 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11656 mApp, "purchasePremiumCapability")) {
11657 log("purchasePremiumCapability "
11658 + TelephonyManager.convertPremiumCapabilityToString(capability)
11659 + " failed due to missing permissions.");
11660 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011661 }
11662
11663 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011664 if (phone == null) {
11665 try {
11666 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11667 callback.accept(result);
11668 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11669 } catch (RemoteException e) {
11670 String logStr = "Purchase premium capability "
11671 + TelephonyManager.convertPremiumCapabilityToString(capability)
11672 + " failed due to RemoteException handling null phone: " + e;
11673 if (DBG) log(logStr);
11674 AnomalyReporter.reportAnomaly(
11675 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11676 }
11677 return;
11678 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011679
11680 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011681 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011682 callingProcess = mApp.getPackageManager().getApplicationInfo(
11683 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011684 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011685 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011686 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011687
11688 boolean isVisible = false;
11689 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11690 if (am != null) {
11691 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11692 if (processes != null) {
11693 for (ActivityManager.RunningAppProcessInfo process : processes) {
11694 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011695 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011696 if (process.processName.equals(callingProcess) && process.importance
11697 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11698 isVisible = true;
11699 break;
11700 }
11701 }
11702 }
11703 }
11704
11705 if (!isVisible) {
11706 try {
11707 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11708 callback.accept(result);
11709 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11710 } catch (RemoteException e) {
11711 String logStr = "Purchase premium capability "
11712 + TelephonyManager.convertPremiumCapabilityToString(capability)
11713 + " failed due to RemoteException handling background application: " + e;
11714 if (DBG) log(logStr);
11715 AnomalyReporter.reportAnomaly(
11716 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11717 }
11718 return;
11719 }
11720
Sarah Chin71b3a852022-09-28 15:54:19 -070011721 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011722 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011723 }
11724
11725 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011726 * Register an IMS connection state callback
11727 */
11728 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011729 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11730 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011731 if (feature == ImsFeature.FEATURE_MMTEL) {
11732 // ImsMmTelManager
11733 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11734 TelephonyPermissions
11735 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11736 mApp, subId, "registerImsStateCallback");
11737 } else if (feature == ImsFeature.FEATURE_RCS) {
11738 // ImsRcsManager or SipDelegateManager
11739 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11740 Binder.getCallingUid(), "registerImsStateCallback",
11741 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11742 Manifest.permission.READ_PRECISE_PHONE_STATE,
11743 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11744 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11745 }
11746
11747 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11748 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11749 "IMS not available on device.");
11750 }
11751
11752 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11753 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11754 }
11755
11756 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11757 if (controller == null) {
11758 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11759 "IMS not available on device.");
11760 }
11761
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011762 if (callingPackage == null) {
11763 callingPackage = getCurrentPackageName();
11764 }
11765
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011766 final long token = Binder.clearCallingIdentity();
11767 try {
11768 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011769 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011770 } catch (ImsException e) {
11771 throw new ServiceSpecificException(e.getCode());
11772 } finally {
11773 Binder.restoreCallingIdentity(token);
11774 }
11775 }
11776
11777 /**
11778 * Unregister an IMS connection state callback
11779 */
11780 @Override
11781 public void unregisterImsStateCallback(IImsStateCallback cb) {
11782 final long token = Binder.clearCallingIdentity();
11783 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11784 if (controller == null) {
11785 return;
11786 }
11787 try {
11788 controller.unregisterImsStateCallback(cb);
11789 } finally {
11790 Binder.restoreCallingIdentity(token);
11791 }
11792 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011793
11794 /**
11795 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11796 *
11797 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11798 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11799 * SecurityException.
11800 * If there is current registered network this value will be same as the registered cell
11801 * identity. If the device goes out of service the previous cell identity is cached and
11802 * will be returned. If the cache age of the Cell identity is more than 24 hours
11803 * it will be cleared and null will be returned.
11804 *
11805 */
11806 @Override
11807 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11808 String callingFeatureId) {
11809 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11810 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11811 LocationAccessPolicy.checkLocationPermission(mApp,
11812 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11813 .setCallingPackage(callingPackage)
11814 .setCallingFeatureId(callingFeatureId)
11815 .setCallingPid(Binder.getCallingPid())
11816 .setCallingUid(Binder.getCallingUid())
11817 .setMethod("getLastKnownCellIdentity")
11818 .setLogAsInfo(true)
11819 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11820 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11821 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11822 .build());
11823
11824 boolean hasFinePermission =
11825 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11826 if (!hasFinePermission
11827 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11828 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011829 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011830 }
11831
11832 final long identity = Binder.clearCallingIdentity();
11833 try {
Ling Mac28f0212023-03-24 16:07:15 -070011834 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011835 if (sst == null) return null;
11836 return sst.getLastKnownCellIdentity();
11837 } finally {
11838 Binder.restoreCallingIdentity(identity);
11839 }
11840 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011841
jimsun3b9ccac2021-10-26 15:01:23 +080011842 /**
11843 * Sets the modem service class Name that Telephony will bind to.
11844 *
11845 * @param serviceName The class name of the modem service.
11846 * @return true if the operation is succeed, otherwise false.
11847 */
11848 public boolean setModemService(String serviceName) {
11849 Log.d(LOG_TAG, "setModemService - " + serviceName);
11850 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011852 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11853 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011854 return mPhoneConfigurationManager.setModemService(serviceName);
11855 }
11856
11857 /**
11858 * Return the class name of the currently bounded modem service.
11859 *
11860 * @return the class name of the modem service.
11861 */
11862 public String getModemService() {
11863 String result;
11864 Log.d(LOG_TAG, "getModemService");
11865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11866 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011867 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011868 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11869 "getModemService");
11870 result = mPhoneConfigurationManager.getModemService();
11871 Log.d(LOG_TAG, "result = " + result);
11872 return result;
11873 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011874
11875 @Override
11876 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11877 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11878 mApp.enforceCallingOrSelfPermission(
11879 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11880 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11881
11882 final long identity = Binder.clearCallingIdentity();
11883 try {
11884 Phone phone = getPhone(subId);
11885 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011886 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11887 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011888 phone.setVoiceServiceStateOverride(hasService);
11889 } finally {
11890 Binder.restoreCallingIdentity(identity);
11891 }
11892 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011893
11894 /**
11895 * set removable eSIM as default eUICC.
11896 *
11897 * @hide
11898 */
11899 @Override
11900 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11901 enforceModifyPermission();
11902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11903
11904 final long identity = Binder.clearCallingIdentity();
11905 try {
11906 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11907 } finally {
11908 Binder.restoreCallingIdentity(identity);
11909 }
11910 }
11911
11912 /**
11913 * Returns whether the removable eSIM is default eUICC or not.
11914 *
11915 * @hide
11916 */
11917 @Override
11918 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11919 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11921
11922 final long identity = Binder.clearCallingIdentity();
11923 try {
11924 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11925 } finally {
11926 Binder.restoreCallingIdentity(identity);
11927 }
11928 }
11929
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011930 /**
11931 * Get the component name of the default app to direct respond-via-message intent for the
11932 * user associated with this subscription, update the cache if there is no respond-via-message
11933 * application currently configured for this user.
11934 * @return component name of the app and class to direct Respond Via Message intent to, or
11935 * {@code null} if the functionality is not supported.
11936 * @hide
11937 */
11938 @Override
11939 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11940 boolean updateIfNeeded) {
11941 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011942
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011943 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11944
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011945 UserHandle userHandle = null;
11946 final long identity = Binder.clearCallingIdentity();
11947 try {
11948 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11949 } finally {
11950 Binder.restoreCallingIdentity(identity);
11951 }
11952 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11953 updateIfNeeded, userHandle);
11954 }
Jack Yuf5badd92022-12-08 00:50:53 -080011955
11956 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011957 * Set whether the device is able to connect with null ciphering or integrity
11958 * algorithms. This is a global setting and will apply to all active subscriptions
11959 * and all new subscriptions after this.
11960 *
11961 * @param enabled when true, null cipher and integrity algorithms are allowed.
11962 * @hide
11963 */
11964 @Override
11965 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11966 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11967 enforceModifyPermission();
11968 checkForNullCipherAndIntegritySupport();
11969
11970 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11971 // for listening to these preference changes and applying them immediately.
11972 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11973 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11974 editor.apply();
11975
11976 for (Phone phone: PhoneFactory.getPhones()) {
11977 phone.handleNullCipherEnabledChange();
11978 }
11979 }
11980
11981
11982 /**
11983 * Get whether the device is able to connect with null ciphering or integrity
11984 * algorithms. Note that this retrieves the phone-global preference and not
11985 * the state of the radio.
11986 *
11987 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11988 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11989 * version for this feature.
11990 * @hide
11991 */
11992 @Override
11993 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11994 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11995 enforceReadPermission();
11996 checkForNullCipherAndIntegritySupport();
11997 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11998 }
11999
12000 private void checkForNullCipherAndIntegritySupport() {
12001 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12002 throw new UnsupportedOperationException(
12003 "Null cipher and integrity operations require HAL 2.1 or above");
12004 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012005 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12006 throw new UnsupportedOperationException(
12007 "Null cipher and integrity operations unsupported by modem");
12008 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012009 }
12010
Gil Cukierman06403e12023-11-29 16:33:03 +000012011 private void checkForIdentifierDisclosureNotificationSupport() {
12012 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12013 throw new UnsupportedOperationException(
12014 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12015 + "above");
12016 }
12017 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12018 throw new UnsupportedOperationException(
12019 "Cellular identifier disclosure transparency operations unsupported by modem");
12020 }
12021 }
12022
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012023 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012024 * Get the SIM state for the slot index.
12025 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12026 *
12027 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12028 */
12029 @Override
12030 @SimState
12031 public int getSimStateForSlotIndex(int slotIndex) {
12032 IccCardConstants.State simState;
12033 if (slotIndex < 0) {
12034 simState = IccCardConstants.State.UNKNOWN;
12035 } else {
12036 Phone phone = null;
12037 try {
12038 phone = PhoneFactory.getPhone(slotIndex);
12039 } catch (IllegalStateException e) {
12040 // ignore
12041 }
12042 if (phone == null) {
12043 simState = IccCardConstants.State.UNKNOWN;
12044 } else {
12045 IccCard icc = phone.getIccCard();
12046 if (icc == null) {
12047 simState = IccCardConstants.State.UNKNOWN;
12048 } else {
12049 simState = icc.getState();
12050 }
12051 }
12052 }
12053 return simState.ordinal();
12054 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012055
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012056 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12057 boolean enableLogcat,
12058 long logcatStartTimestampMillis, boolean enableTelecomDump,
12059 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012060 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12061 TelephonyManager.EmergencyCallDiagnosticParams edp =
12062 new TelephonyManager.EmergencyCallDiagnosticParams();
12063 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12064 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12065 edp.setTelecomDumpSysCollection(enableTelecomDump);
12066 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12067 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12068 Executors.newCachedThreadPool(), db,
12069 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12070 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012071 }
12072
12073 /**
12074 * Request telephony to persist state for debugging emergency call failures.
12075 *
12076 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12077 * @param enableLogcat whether to collect logcat output
12078 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12079 * @param enableTelecomDump whether to collect telecom dumpsys
12080 * @param enableTelephonyDump whether to collect telephony dumpsys
12081 */
12082 @Override
12083 @RequiresPermission(android.Manifest.permission.DUMP)
12084 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12085 long logcatStartTimestampMillis, boolean enableTelecomDump,
12086 boolean enableTelephonyDump) {
12087 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12088 "persistEmergencyCallDiagnosticData");
12089 final long identity = Binder.clearCallingIdentity();
12090 try {
12091 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12092 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12093
12094 } finally {
12095 Binder.restoreCallingIdentity(identity);
12096 }
12097 }
12098
Hui Wang9b5793a2022-12-05 14:38:06 -060012099 /**
12100 * Get current cell broadcast ranges.
12101 */
12102 @Override
12103 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12104 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12105 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12106 "getCellBroadcastIdRanges");
12107 final long identity = Binder.clearCallingIdentity();
12108 try {
12109 return getPhone(subId).getCellBroadcastIdRanges();
12110 } finally {
12111 Binder.restoreCallingIdentity(identity);
12112 }
12113 }
12114
12115 /**
12116 * Set reception of cell broadcast messages with the list of the given ranges
12117 *
12118 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12119 */
12120 @Override
12121 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12122 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12123 @Nullable IIntegerConsumer callback) {
12124 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12125 "setCellBroadcastIdRanges");
12126 final long identity = Binder.clearCallingIdentity();
12127 try {
12128 Phone phone = getPhoneFromSubId(subId);
12129 if (DBG) {
12130 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12131 }
12132 phone.setCellBroadcastIdRanges(ranges, result -> {
12133 if (callback != null) {
12134 try {
12135 callback.accept(result);
12136 } catch (RemoteException e) {
12137 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12138 }
12139 }
12140 });
12141 } finally {
12142 Binder.restoreCallingIdentity(identity);
12143 }
12144 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012145
12146 /**
12147 * Returns whether the device supports the domain selection service.
12148 *
12149 * @return {@code true} if the device supports the domain selection service.
12150 */
12151 @Override
12152 public boolean isDomainSelectionSupported() {
12153 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12154 "isDomainSelectionSupported");
12155
12156 final long identity = Binder.clearCallingIdentity();
12157 try {
12158 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12159 } finally {
12160 Binder.restoreCallingIdentity(identity);
12161 }
12162 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012163
12164 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012165 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12166 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12167 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012168 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012169 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012170 * @param enableSatellite {@code true} to enable the satellite modem and
12171 * {@code false} to disable.
12172 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12173 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012174 *
12175 * @throws SecurityException if the caller doesn't have the required permission.
12176 */
12177 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012178 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12179 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012180 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012181 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12182 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012183 }
12184
12185 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012186 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012187 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012188 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012189 * @param result The result receiver that returns whether the satellite modem is enabled
12190 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012191 *
12192 * @throws SecurityException if the caller doesn't have the required permission.
12193 */
12194 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012195 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12196 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012197 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012198 }
12199
12200 /**
Sarah Chin43457982023-02-15 17:50:38 -080012201 * Request to get whether the satellite service demo mode is enabled.
12202 *
12203 * @param subId The subId of the subscription to check whether the satellite demo mode
12204 * is enabled for.
12205 * @param result The result receiver that returns whether the satellite demo mode is enabled
12206 * if the request is successful or an error code if the request failed.
12207 *
12208 * @throws SecurityException if the caller doesn't have the required permission.
12209 */
12210 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012211 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12212 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12213 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012214 }
12215
12216 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012217 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012218 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012219 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012220 * @param result The result receiver that returns whether the satellite service is supported on
12221 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012222 */
12223 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012224 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012225 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012226 }
12227
12228 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012229 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012230 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012231 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012232 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12233 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012234 *
12235 * @throws SecurityException if the caller doesn't have required permission.
12236 */
12237 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012238 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12239 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012240 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012241 }
12242
12243 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012244 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012245 * This can be called by the pointing UI when the user starts pointing to the satellite.
12246 * Modem should continue to report the pointing input as the device or satellite moves.
12247 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012248 * @param subId The subId of the subscription to start satellite transmission updates for.
12249 * @param resultCallback The callback to get the result of the request.
12250 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012251 *
12252 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012253 */
12254 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012255 public void startSatelliteTransmissionUpdates(int subId,
12256 @NonNull IIntegerConsumer resultCallback,
12257 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12258 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12259 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012260 }
12261
12262 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012263 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012264 * This can be called by the pointing UI when the user stops pointing to the satellite.
12265 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012266 * @param subId The subId of the subscription to stop satellite transmission updates for.
12267 * @param resultCallback The callback to get the result of the request.
12268 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12269 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012270 *
12271 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012272 */
12273 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012274 public void stopSatelliteTransmissionUpdates(int subId,
12275 @NonNull IIntegerConsumer resultCallback,
12276 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12277 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12278 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012279 }
12280
12281 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012282 * Register the subscription with a satellite provider.
12283 * This is needed to register the subscription if the provider allows dynamic registration.
12284 *
12285 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012286 * @param token The token to be used as a unique identifier for provisioning with satellite
12287 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012288 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012289 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012290 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012291 * @return The signal transport used by the caller to cancel the provision request,
12292 * or {@code null} if the request failed.
12293 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012294 * @throws SecurityException if the caller doesn't have the required permission.
12295 */
12296 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012297 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012298 @NonNull String token, @NonNull byte[] provisionData,
12299 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012300 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012301 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12302 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012303 }
12304
12305 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012306 * Unregister the device/subscription with the satellite provider.
12307 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012308 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012309 * should report as deprovisioned.
12310 *
12311 * @param subId The subId of the subscription to be deprovisioned.
12312 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012313 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012314 *
12315 * @throws SecurityException if the caller doesn't have the required permission.
12316 */
12317 @Override
12318 public void deprovisionSatelliteService(int subId,
12319 @NonNull String token, @NonNull IIntegerConsumer callback) {
12320 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012321 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012322 }
12323
12324 /**
Sarah Chin43457982023-02-15 17:50:38 -080012325 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012326 *
Sarah Chin43457982023-02-15 17:50:38 -080012327 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012328 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012329 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012330 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012331 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012332 * @throws SecurityException if the caller doesn't have the required permission.
12333 */
12334 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012335 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12336 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012337 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012338 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012339 }
12340
12341 /**
Sarah Chin43457982023-02-15 17:50:38 -080012342 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012343 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012344 *
Sarah Chin43457982023-02-15 17:50:38 -080012345 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012346 * @param callback The callback that was passed to
12347 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012348 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012349 * @throws SecurityException if the caller doesn't have the required permission.
12350 */
12351 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012352 public void unregisterForSatelliteProvisionStateChanged(
12353 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012354 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012355 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012356 }
12357
12358 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012359 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012360 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012361 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012362 * @param result The result receiver that returns whether the device is provisioned with a
12363 * satellite provider if the request is successful or an error code if the
12364 * request failed.
12365 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012366 * @throws SecurityException if the caller doesn't have the required permission.
12367 */
12368 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012369 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12370 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012371 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012372 }
12373
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012374 /**
Sarah Chin43457982023-02-15 17:50:38 -080012375 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012376 *
Sarah Chin43457982023-02-15 17:50:38 -080012377 * @param subId The subId of the subscription to register for satellite modem state changed.
12378 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012379 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012380 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012381 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012382 * @throws SecurityException if the caller doesn't have the required permission.
12383 */
12384 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012385 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012386 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012387 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012388 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012389 }
12390
12391 /**
Sarah Chin43457982023-02-15 17:50:38 -080012392 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012393 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012394 *
Sarah Chin43457982023-02-15 17:50:38 -080012395 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012396 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012397 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012398 *
12399 * @throws SecurityException if the caller doesn't have the required permission.
12400 */
12401 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012402 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012403 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012404 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012405 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012406 }
12407
12408 /**
12409 * Register to receive incoming datagrams over satellite.
12410 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012411 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012412 * @param callback The callback to handle incoming datagrams over satellite.
12413 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012414 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012415 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012416 * @throws SecurityException if the caller doesn't have the required permission.
12417 */
12418 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012419 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012420 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012421 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012422 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012423 }
12424
12425 /**
12426 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012427 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012428 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012429 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12430 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012431 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012432 *
12433 * @throws SecurityException if the caller doesn't have the required permission.
12434 */
12435 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012436 public void unregisterForSatelliteDatagram(int subId,
12437 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012438 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012439 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012440 }
12441
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012442 /**
12443 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012444 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012445 * This method requests modem to check if there are any pending datagrams to be received over
12446 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012447 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012448 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012449 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012450 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012451 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012452 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012453 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012454 @Override
12455 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012456 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012457 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012458 }
12459
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012460 /**
12461 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012462 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012463 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12464 * input to this method. Datagram received here will be passed down to modem without any
12465 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012466 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012467 * @param subId The subId of the subscription to send satellite datagrams for.
12468 * @param datagramType datagram type indicating whether the datagram is of type
12469 * SOS_SMS or LOCATION_SHARING.
12470 * @param datagram encoded gateway datagram which is encrypted by the caller.
12471 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012472 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12473 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012474 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012475 *
12476 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012477 */
12478 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012479 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12480 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12481 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012482 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012483 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12484 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012485 }
12486
Sarah Chindf715ec2023-02-13 13:46:24 -080012487 /**
12488 * Request to get whether satellite communication is allowed for the current location.
12489 *
12490 * @param subId The subId of the subscription to check whether satellite communication is
12491 * allowed for the current location for.
12492 * @param result The result receiver that returns whether satellite communication is allowed
12493 * for the current location if the request is successful or an error code
12494 * if the request failed.
12495 *
12496 * @throws SecurityException if the caller doesn't have the required permission.
12497 */
12498 @Override
12499 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12500 @NonNull ResultReceiver result) {
12501 enforceSatelliteCommunicationPermission(
12502 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012503 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12504 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012505 }
12506
12507 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012508 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012509 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012510 * @param subId The subId to get the time after which the satellite will be visible for.
12511 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012512 * be visible if the request is successful or an error code if the request failed.
12513 *
12514 * @throws SecurityException if the caller doesn't have the required permission.
12515 */
12516 @Override
12517 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12518 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012519 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012520 }
12521
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012522 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012523 * Inform that Device is aligned to satellite for demo mode.
12524 *
12525 * @param subId The subId to get the time after which the satellite will be visible for.
12526 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12527 * {@code false} Device fails to align with the satellite for demo mode.
12528 *
12529 * @throws SecurityException if the caller doesn't have required permission.
12530 */
12531 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12532
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012533 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012534 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012535 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012536 }
12537
12538 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012539 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12540 * by modem.
12541 *
12542 * @param subId The subId of the subscription to request for.
12543 * @param reason Reason for disallowing satellite communication for carrier.
12544 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12545 * operation.
12546 *
12547 * @throws SecurityException if the caller doesn't have required permission.
12548 */
12549 public void addSatelliteAttachRestrictionForCarrier(int subId,
12550 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12551 @NonNull IIntegerConsumer callback) {
12552 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12553 final long identity = Binder.clearCallingIdentity();
12554 try {
12555 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12556 } finally {
12557 Binder.restoreCallingIdentity(identity);
12558 }
12559 }
12560
12561 /**
12562 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12563 * by modem.
12564 *
12565 * @param subId The subId of the subscription to request for.
12566 * @param reason Reason for disallowing satellite communication.
12567 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12568 * operation.
12569 *
12570 * @throws SecurityException if the caller doesn't have required permission.
12571 */
12572 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12573 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12574 @NonNull IIntegerConsumer callback) {
12575 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12576 final long identity = Binder.clearCallingIdentity();
12577 try {
12578 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12579 callback);
12580 } finally {
12581 Binder.restoreCallingIdentity(identity);
12582 }
12583 }
12584
12585 /**
12586 * Get reasons for disallowing satellite communication, as requested by
12587 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12588 *
12589 * @param subId The subId of the subscription to request for.
12590 *
12591 * @return Integer array of reasons for disallowing satellite communication.
12592 *
12593 * @throws SecurityException if the caller doesn't have the required permission.
12594 */
12595 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12596 int subId) {
12597 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12598 final long identity = Binder.clearCallingIdentity();
12599 try {
12600 Set<Integer> reasonSet =
12601 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12602 return reasonSet.stream().mapToInt(i->i).toArray();
12603 } finally {
12604 Binder.restoreCallingIdentity(identity);
12605 }
12606 }
12607
12608 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012609 * Request to get the signal strength of the satellite connection.
12610 *
12611 * @param subId The subId of the subscription to request for.
12612 * @param result Result receiver to get the error code of the request and the current signal
12613 * strength of the satellite connection.
12614 *
12615 * @throws SecurityException if the caller doesn't have required permission.
12616 */
12617 @Override
12618 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12619 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12620 final long identity = Binder.clearCallingIdentity();
12621 try {
12622 mSatelliteController.requestNtnSignalStrength(subId, result);
12623 } finally {
12624 Binder.restoreCallingIdentity(identity);
12625 }
12626 }
12627
12628 /**
12629 * Registers for NTN signal strength changed from satellite modem.
12630 *
12631 * @param subId The subId of the subscription to request for.
12632 * @param callback The callback to handle the NTN signal strength changed event.
12633 *
12634 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12635 *
12636 * @throws SecurityException if the caller doesn't have the required permission.
12637 */
12638 @Override
12639 @SatelliteManager.SatelliteResult public int registerForNtnSignalStrengthChanged(
12640 int subId, @NonNull INtnSignalStrengthCallback callback) {
12641 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12642 final long identity = Binder.clearCallingIdentity();
12643 try {
12644 return mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
12645 } finally {
12646 Binder.restoreCallingIdentity(identity);
12647 }
12648 }
12649
12650 /**
12651 * Unregisters for NTN signal strength changed from satellite modem.
12652 * If callback was not registered before, the request will be ignored.
12653 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000012654 * @param subId The subId of the subscription to unregister for listening NTN signal strength
12655 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000012656 * @param callback The callback that was passed to
12657 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12658 *
12659 * @throws SecurityException if the caller doesn't have the required permission.
12660 */
12661 @Override
12662 public void unregisterForNtnSignalStrengthChanged(
12663 int subId, @NonNull INtnSignalStrengthCallback callback) {
12664 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12665 final long identity = Binder.clearCallingIdentity();
12666 try {
12667 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12668 } finally {
12669 Binder.restoreCallingIdentity(identity);
12670 }
12671 }
12672
12673 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000012674 * Registers for satellite capabilities change event from the satellite service.
12675 *
12676 * @param subId The subId of the subscription to request for.
12677 * @param callback The callback to handle the satellite capabilities changed event.
12678 *
12679 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12680 *
12681 * @throws SecurityException if the caller doesn't have required permission.
12682 */
12683 @Override
12684 @SatelliteManager.SatelliteResult public int registerForSatelliteCapabilitiesChanged(
12685 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12686 enforceSatelliteCommunicationPermission("registerForSatelliteCapabilitiesChanged");
12687 final long identity = Binder.clearCallingIdentity();
12688 try {
12689 return mSatelliteController.registerForSatelliteCapabilitiesChanged(subId, callback);
12690 } finally {
12691 Binder.restoreCallingIdentity(identity);
12692 }
12693 }
12694
12695 /**
12696 * Unregisters for satellite capabilities change event from the satellite service.
12697 * If callback was not registered before, the request will be ignored.
12698 *
12699 * @param subId The subId of the subscription to unregister for satellite capabilities change.
12700 * @param callback The callback that was passed to.
12701 * {@link #registerForSatelliteCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
12702 *
12703 * @throws SecurityException if the caller doesn't have required permission.
12704 */
12705 @Override
12706 public void unregisterForSatelliteCapabilitiesChanged(
12707 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
12708 enforceSatelliteCommunicationPermission("unregisterForSatelliteCapabilitiesChanged");
12709 final long identity = Binder.clearCallingIdentity();
12710 try {
12711 mSatelliteController.unregisterForSatelliteCapabilitiesChanged(subId, callback);
12712 } finally {
12713 Binder.restoreCallingIdentity(identity);
12714 }
12715 }
12716
12717 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012718 * This API can be used by only CTS to update satellite vendor service package name.
12719 *
12720 * @param servicePackageName The package name of the satellite vendor service.
12721 * @return {@code true} if the satellite vendor service is set successfully,
12722 * {@code false} otherwise.
12723 */
12724 public boolean setSatelliteServicePackageName(String servicePackageName) {
12725 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12726 TelephonyPermissions.enforceShellOnly(
12727 Binder.getCallingUid(), "setSatelliteServicePackageName");
12728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12729 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12730 "setSatelliteServicePackageName");
12731 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12732 }
12733
12734 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012735 * This API can be used by only CTS to update satellite gateway service package name.
12736 *
12737 * @param servicePackageName The package name of the satellite gateway service.
12738 * @return {@code true} if the satellite gateway service is set successfully,
12739 * {@code false} otherwise.
12740 */
12741 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12742 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12743 TelephonyPermissions.enforceShellOnly(
12744 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12746 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12747 "setSatelliteGatewayServicePackageName");
12748 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12749 }
12750
12751 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012752 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12753 *
12754 * @param packageName The package name of the satellite pointing UI app.
12755 * @param className The class name of the satellite pointing UI app.
12756 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12757 * {@code false} otherwise.
12758 */
12759 public boolean setSatellitePointingUiClassName(
12760 @Nullable String packageName, @Nullable String className) {
12761 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12762 + ", className=" + className);
12763 TelephonyPermissions.enforceShellOnly(
12764 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12766 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12767 "setSatelliteGatewayServicePackageName");
12768 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12769 }
12770
12771 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012772 * This API can be used by only CTS to update the timeout duration in milliseconds that
12773 * satellite should stay at listening mode to wait for the next incoming page before disabling
12774 * listening mode.
12775 *
12776 * @param timeoutMillis The timeout duration in millisecond.
12777 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12778 */
12779 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12780 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12781 TelephonyPermissions.enforceShellOnly(
12782 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12784 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12785 "setSatelliteListeningTimeoutDuration");
12786 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12787 }
12788
12789 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012790 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12791 * the device is aligned with the satellite for demo mode
12792 *
12793 * @param timeoutMillis The timeout duration in millisecond.
12794 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12795 */
12796 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12797 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12798 TelephonyPermissions.enforceShellOnly(
12799 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12801 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12802 "setDeviceAlignedTimeoutDuration");
12803 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12804 }
12805
12806 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070012807 * This API can be used in only testing to override connectivity status in monitoring emergency
12808 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
12809 *
12810 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
12811 * of the following values to enable the override:
12812 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
12813 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
12814 * To disable the override, use -1 for handoverType.
12815 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
12816 * delaySeconds after the emergency call starts.
12817 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
12818 */
12819 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
12820 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
12821 TelephonyPermissions.enforceShellOnly(
12822 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
12823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12824 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12825 "setEmergencyCallToSatelliteHandoverType");
12826 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
12827 handoverType, delaySeconds);
12828 }
12829
12830 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000012831 * This API can be used by only CTS to override the cached value for the device overlay config
12832 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
12833 * outgoing satellite datagrams should be sent to modem in demo mode.
12834 *
12835 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
12836 * satellite modem or not.
12837 *
12838 * @return {@code true} if the operation is successful, {@code false} otherwise.
12839 */
12840 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
12841 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
12842 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
12843 + "disabled");
12844 return false;
12845 }
12846 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
12847 TelephonyPermissions.enforceShellOnly(
12848 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
12849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12850 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12851 "setShouldSendDatagramToModemInDemoMode");
12852 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
12853 shouldSendToModemInDemoMode);
12854 }
12855
12856 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000012857 * Enable or disable notifications sent for cellular identifier disclosure events.
12858 *
12859 * Disclosure events are defined as instances where a device has sent a cellular identifier
12860 * on the Non-access stratum (NAS) before a security context is established. As a result the
12861 * identifier is sent in the clear, which has privacy implications for the user.
12862 *
12863 * @param enable if notifications about disclosure events should be enabled
12864 * @throws SecurityException if the caller does not have the required privileges
12865 * @throws UnsupportedOperationException if the modem does not support this feature.
12866 */
12867 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
12868 public void enableCellularIdentifierDisclosureNotifications(boolean enable) {
12869 enforceModifyPermission();
12870 checkForIdentifierDisclosureNotificationSupport();
12871
12872 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12873 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
12874 editor.apply();
12875
12876 // Each phone instance is responsible for updating its respective modem immediately
12877 // after we've made a preference change.
12878 for (Phone phone : PhoneFactory.getPhones()) {
12879 phone.handleIdentifierDisclosureNotificationPreferenceChange();
12880 }
12881 }
12882
12883 /**
12884 * Get whether or not cellular identifier disclosure notifications are enabled.
12885 *
12886 * @throws SecurityException if the caller does not have the required privileges
12887 * @throws UnsupportedOperationException if the modem does not support this feature.
12888 */
12889 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
12890 public boolean isCellularIdentifierDisclosureNotificationEnabled() {
12891 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
12892 checkForIdentifierDisclosureNotificationSupport();
12893 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
12894 }
12895
12896 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012897 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12898 *
12899 * <p>This method behaves in one of the following ways:
12900 * <ul>
12901 * <li>return true : if the calling package has the appop permission {@link
12902 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12903 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12904 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12905 * Owner device identifier access check, or the calling package has carrier privileges</>
12906 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12907 * </ul>
12908 */
12909 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12910 String callingPackage, @Nullable String callingFeatureId, String message) {
12911 for (Phone phone : PhoneFactory.getPhones()) {
12912 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12913 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12914 return true;
12915 }
12916 }
12917 return false;
12918 }
arunvoddud7401012022-12-15 16:08:12 +000012919
12920 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012921 * @return The subscription manager service instance.
12922 */
12923 public SubscriptionManagerService getSubscriptionManagerService() {
12924 return SubscriptionManagerService.getInstance();
12925 }
12926
12927 /**
arunvoddud7401012022-12-15 16:08:12 +000012928 * Class binds the consumer[callback] and carrierId.
12929 */
12930 private static class CallerCallbackInfo {
12931 private final Consumer<Integer> mConsumer;
12932 private final int mCarrierId;
12933
12934 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12935 mConsumer = consumer;
12936 mCarrierId = carrierId;
12937 }
12938
12939 public Consumer<Integer> getConsumer() {
12940 return mConsumer;
12941 }
12942
12943 public int getCarrierId() {
12944 return mCarrierId;
12945 }
12946 }
Jack Yufa8ed012023-02-11 15:42:28 -080012947}