blob: 2a9826f66c16b0780fd099d8500a22b965deb2c9 [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;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000042import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070043import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070044import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.content.Context;
46import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070047import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070048import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070049import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.net.Uri;
51import android.os.AsyncResult;
52import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080053import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080055import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070057import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080058import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080059import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.Looper;
61import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070062import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080063import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070064import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070065import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080066import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080067import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070068import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070069import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080070import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070072import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070074import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070075import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080076import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070077import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000078import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090079import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080080import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080081import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070082import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080083import android.telephony.AccessNetworkConstants;
84import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070085import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070086import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070088import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080089import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070090import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080091import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060092import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070093import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080094import android.telephony.CellIdentityCdma;
95import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070097import android.telephony.CellInfoGsm;
98import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070099import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800100import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700101import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700102import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700103import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800104import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700105import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800106import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700107import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800108import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800109import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700110import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800111import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800113import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800114import android.telephony.SignalStrengthUpdateRequest;
115import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800116import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800118import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700119import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700120import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800121import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800122import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800123import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800124import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000125import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000126import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000127import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700128import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700129import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800130import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800131import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700132import android.telephony.gba.GbaAuthRequest;
133import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700134import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000136import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000137import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700138import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000139import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700140import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800141import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700142import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800143import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700144import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000145import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700146import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800147import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800148import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000149import android.telephony.satellite.INtnSignalStrengthCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800150import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800151import android.telephony.satellite.ISatelliteProvisionStateCallback;
152import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800153import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800154import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000155import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800157import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800158import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700161import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800163import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164
Andrew Lee312e8172014-10-23 17:01:36 -0700165import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800166import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800167import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800168import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800169import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700171import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700172import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800173import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800174import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800177import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700178import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800179import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800180import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800181import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700182import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000183import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800185import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800188import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800189import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700190import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700191import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700192import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700194import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800195import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700196import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700197import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700198import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700199import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800200import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800201import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700202import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000203import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700204import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700205import com.android.internal.telephony.SmsPermissions;
Peter Wang59571be2020-01-27 12:35:15 +0800206import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800207import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700208import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000209import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700211import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700212import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800213import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700214import com.android.internal.telephony.imsphone.ImsPhone;
215import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000216import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800217import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000218import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800219import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
220import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700221import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700222import com.android.internal.telephony.uicc.IccIoResult;
223import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800224import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700225import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800226import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700227import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000228import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800229import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000230import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800231import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000232import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700233import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700234import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800235import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800236import com.android.phone.callcomposer.CallComposerPictureManager;
237import com.android.phone.callcomposer.CallComposerPictureTransfer;
238import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700239import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700240import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000241import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700242import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800243import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700244import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700245import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800246import com.android.services.telephony.TelecomAccountRegistry;
247import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800248import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800249
Hall Liu82694d52020-12-11 18:22:04 -0800250import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700251import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800252import java.io.IOException;
253import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700254import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800256import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000257import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800258import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800259import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800260import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800261import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100262import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800263import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800265import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800266import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700267import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800268import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800269import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800270import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
272/**
273 * Implementation of the ITelephony interface.
274 */
Santos Cordon117fee72014-05-16 17:56:12 -0700275public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 private static final String LOG_TAG = "PhoneInterfaceManager";
277 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
278 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800279 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280
281 // Message codes used with mMainThreadHandler
282 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700283 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
284 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700285 private static final int CMD_OPEN_CHANNEL = 9;
286 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
287 private static final int CMD_CLOSE_CHANNEL = 11;
288 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800289 private static final int CMD_NV_READ_ITEM = 13;
290 private static final int EVENT_NV_READ_ITEM_DONE = 14;
291 private static final int CMD_NV_WRITE_ITEM = 15;
292 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
293 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
294 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700295 private static final int CMD_RESET_MODEM_CONFIG = 19;
296 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800297 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
298 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800299 private static final int CMD_SEND_ENVELOPE = 25;
300 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700301 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
302 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
303 private static final int CMD_EXCHANGE_SIM_IO = 31;
304 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800305 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
306 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700307 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
308 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700309 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
310 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700311 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
312 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
313 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
314 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700315 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
316 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
317 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
318 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700319 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800320 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
321 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000322 private static final int CMD_SWITCH_SLOTS = 50;
323 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700324 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
325 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
326 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
327 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
328 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
329 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
330 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
331 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700332 private static final int CMD_GET_ALL_CELL_INFO = 60;
333 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
334 private static final int CMD_GET_CELL_LOCATION = 62;
335 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700336 private static final int CMD_MODEM_REBOOT = 64;
337 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700338 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
339 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800340 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
341 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700342 private static final int CMD_GET_MODEM_STATUS = 70;
343 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700344 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
345 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700346 private static final int CMD_ERASE_MODEM_CONFIG = 74;
347 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800348 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
349 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
350 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
351 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800352 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
353 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800354 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800355 private static final int CMD_GET_CALL_FORWARDING = 83;
356 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
357 private static final int CMD_SET_CALL_FORWARDING = 85;
358 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
359 private static final int CMD_GET_CALL_WAITING = 87;
360 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
361 private static final int CMD_SET_CALL_WAITING = 89;
362 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700363 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
364 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
365 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
366 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700367 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
368 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800369 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
370 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800371 private static final int CMD_SET_DATA_THROTTLING = 99;
372 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800373 private static final int CMD_SET_SIM_POWER = 101;
374 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800375 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
376 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
377 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
378 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800379 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
380 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000381 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800382 private static final int CMD_GET_SLICING_CONFIG = 110;
383 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800384 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700385 private static final int CMD_ENABLE_VONR = 113;
386 private static final int EVENT_ENABLE_VONR_DONE = 114;
387 private static final int CMD_IS_VONR_ENABLED = 115;
388 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700389 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
390 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000391
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800392 // Parameters of select command.
393 private static final int SELECT_COMMAND = 0xA4;
394 private static final int SELECT_P1 = 0x04;
395 private static final int SELECT_P2 = 0;
396 private static final int SELECT_P3 = 0x10;
397
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000398 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
399 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 /** The singleton instance. */
402 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800403 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
Sarah Chin4beb2b72023-02-14 14:47:54 -0800405 private final PhoneGlobals mApp;
Sarah Chincc5446f2023-10-23 17:57:19 -0700406 private final FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800407 private final CallManager mCM;
408 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000409
410 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800411 private final UserManager mUserManager;
412 private final AppOpsManager mAppOps;
413 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800414 private final SharedPreferences mTelephonySharedPreferences;
415 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800416 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Peter Wangdafb9ac2020-01-15 14:13:38 -0800418 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800419 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800420 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
421
Sarah Chin4beb2b72023-02-14 14:47:54 -0800422 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800423
Derek Tan97ebb422014-09-05 16:55:38 -0700424 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
425 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800426 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800427 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700428
Michelecea4cf22018-12-21 15:00:11 -0800429 // String to store multi SIM allowed
430 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
431
Derek Tan740e1672017-06-27 14:56:27 -0700432 // The AID of ISD-R.
433 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
434
yinxub1bed742017-04-17 11:45:04 -0700435 private NetworkScanRequestTracker mNetworkScanRequestTracker;
436
David Kelly5e06a7f2018-03-12 14:10:59 +0000437 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
438 private static final int MANUFACTURER_CODE_LENGTH = 8;
439
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800440 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800441 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800442
Sarah Chin2ec39f62022-08-31 17:03:26 -0700443 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
444 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
445
Derek Tan89e89d42014-07-08 17:00:10 -0700446 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700447 * Experiment flag to enable erase modem config on reset network, default value is false
448 */
449 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
450 "reset_network_erase_modem_config_enabled";
451
Rambo Wang0f050d82021-02-12 11:43:36 -0800452 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800453
Gary Jian76280a42022-12-07 16:18:33 +0800454 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
455
sandeepjsb6c87872021-09-27 15:34:44 +0000456 /**
457 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
458 * one ICCID active at the same time.
459 * Apps should use below API signatures if targeting SDK is T and beyond.
460 *
461 * @hide
462 */
463 @ChangeId
464 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
465 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800466
Naina Nallurid63128d2019-09-17 14:10:30 -0700467 /**
Chen Xu540470b2021-12-14 17:15:47 -0800468 * Apps targeting on Android T and beyond will get exception whenever icc close channel
469 * operation fails.
470 */
471 @ChangeId
472 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
473 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
474
475 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 * A request object to use for transmitting data to an ICC.
477 */
478 private static final class IccAPDUArgument {
479 public int channel, cla, command, p1, p2, p3;
480 public String data;
481
482 public IccAPDUArgument(int channel, int cla, int command,
483 int p1, int p2, int p3, String data) {
484 this.channel = channel;
485 this.cla = cla;
486 this.command = command;
487 this.p1 = p1;
488 this.p2 = p2;
489 this.p3 = p3;
490 this.data = data;
491 }
492 }
493
494 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700495 * A request object to use for transmitting data to an ICC.
496 */
497 private static final class ManualNetworkSelectionArgument {
498 public OperatorInfo operatorInfo;
499 public boolean persistSelection;
500
501 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
502 this.operatorInfo = operatorInfo;
503 this.persistSelection = persistSelection;
504 }
505 }
506
Sarah Chin71b3a852022-09-28 15:54:19 -0700507 private static final class PurchasePremiumCapabilityArgument {
508 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700509 public @NonNull IIntegerConsumer callback;
510
511 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800512 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700514 this.callback = callback;
515 }
516 }
517
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700518 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
520 * request after sending. The main thread will notify the request when it is complete.
521 */
522 private static final class MainThreadRequest {
523 /** The argument to use for the request */
524 public Object argument;
525 /** The result of the request that is run on the main thread */
526 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800527 // The subscriber id that this request applies to. Defaults to
528 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
529 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
Nathan Harold92bed182018-10-12 18:16:49 -0700531 // In cases where subId is unavailable, the caller needs to specify the phone.
532 public Phone phone;
533
vagdeviaf9a5b92018-08-15 16:01:53 -0700534 public WorkSource workSource;
535
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 public MainThreadRequest(Object argument) {
537 this.argument = argument;
538 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800539
Nathan Harold92bed182018-10-12 18:16:49 -0700540 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
541 this.argument = argument;
542 if (phone != null) {
543 this.phone = phone;
544 }
545 this.workSource = workSource;
546 }
547
vagdeviaf9a5b92018-08-15 16:01:53 -0700548 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800549 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800550 if (subId != null) {
551 this.subId = subId;
552 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700553 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 }
556
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800557 private static final class IncomingThirdPartyCallArgs {
558 public final ComponentName component;
559 public final String callId;
560 public final String callerDisplayName;
561
562 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
563 String callerDisplayName) {
564 this.component = component;
565 this.callId = callId;
566 this.callerDisplayName = callerDisplayName;
567 }
568 }
569
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 /**
571 * A handler that processes messages on the main thread in the phone process. Since many
572 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
573 * inbound binder threads to the main thread in the phone process. The Binder thread
574 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
575 * on, which will be notified when the operation completes and will contain the result of the
576 * request.
577 *
578 * <p>If a MainThreadRequest object is provided in the msg.obj field,
579 * note that request.result must be set to something non-null for the calling thread to
580 * unblock.
581 */
582 private final class MainThreadHandler extends Handler {
583 @Override
584 public void handleMessage(Message msg) {
585 MainThreadRequest request;
586 Message onCompleted;
587 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800590 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591
592 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 case CMD_HANDLE_USSD_REQUEST: {
594 request = (MainThreadRequest) msg.obj;
595 final Phone phone = getPhoneFromRequest(request);
596 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800597 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700599
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 if (!isUssdApiAllowed(request.subId)) {
601 // Carrier does not support use of this API, return failure.
602 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
603 UssdResponse response = new UssdResponse(ussdRequest, null);
604 Bundle returnData = new Bundle();
605 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
606 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700607
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 request.result = true;
609 notifyRequester(request);
610 return;
611 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700612
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 try {
614 request.result = phone != null
615 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
616 } catch (CallStateException cse) {
617 request.result = false;
618 }
619 // Wake up the requesting thread
620 notifyRequester(request);
621 break;
pkanwar32d516d2016-10-14 19:37:38 -0700622 }
623
Yorke Lee716f67e2015-06-17 15:39:16 -0700624 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700626 final Phone phone = getPhoneFromRequest(request);
627 request.result = phone != null ?
628 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
629 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000638 uiccPort = getUiccPortFromRequest(request);
639 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800641 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000646 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800647 iccArgument.channel, iccArgument.cla, iccArgument.command,
648 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
649 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 break;
652
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result;
658 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800659 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 if (ar.result == null) {
661 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800662 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800664 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
666 loge("iccTransmitApduLogicalChannel: Unknown exception");
667 }
668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 break;
671
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
673 request = (MainThreadRequest) msg.obj;
674 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800678 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 } else {
681 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800684 iccArgument.cla, iccArgument.command, iccArgument.p1,
685 iccArgument.p2,
686 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 }
688 break;
689
690 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result;
695 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800696 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 if (ar.result == null) {
698 loge("iccTransmitApduBasicChannel: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("iccTransmitApduBasicChannel: CommandException: " +
701 ar.exception);
702 } else {
703 loge("iccTransmitApduBasicChannel: Unknown exception");
704 }
705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 break;
708
709 case CMD_EXCHANGE_SIM_IO:
710 request = (MainThreadRequest) msg.obj;
711 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 uiccPort = getUiccPortFromRequest(request);
713 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800715 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 } else {
718 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
719 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000720 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
722 iccArgument.data, onCompleted);
723 }
724 break;
725
726 case EVENT_EXCHANGE_SIM_IO_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
729 if (ar.exception == null && ar.result != null) {
730 request.result = ar.result;
731 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800732 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 break;
736
Derek Tan4d5e5c12014-02-04 11:54:58 -0800737 case CMD_SEND_ENVELOPE:
738 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000739 uiccPort = getUiccPortFromRequest(request);
740 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800746 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800748 break;
749
750 case EVENT_SEND_ENVELOPE_DONE:
751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700753 if (ar.exception == null && ar.result != null) {
754 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800755 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800756 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700757 if (ar.result == null) {
758 loge("sendEnvelopeWithStatus: Empty response");
759 } else if (ar.exception instanceof CommandException) {
760 loge("sendEnvelopeWithStatus: CommandException: " +
761 ar.exception);
762 } else {
763 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
764 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800767 break;
768
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 case CMD_OPEN_CHANNEL:
770 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000771 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800772 IccLogicalChannelRequest openChannelRequest =
773 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000774 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800776 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800777 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 } else {
780 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800781 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
782 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
786 case EVENT_OPEN_CHANNEL_DONE:
787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700789 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700791 int[] result = (int[]) ar.result;
792 int channelId = result[0];
793 byte[] selectResponse = null;
794 if (result.length > 1) {
795 selectResponse = new byte[result.length - 1];
796 for (int i = 1; i < result.length; ++i) {
797 selectResponse[i - 1] = (byte) result[i];
798 }
799 }
800 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800801 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800802
803 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700804 if (uiccPort == null) {
805 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
806 } else {
807 IccLogicalChannelRequest channelRequest =
808 (IccLogicalChannelRequest) request.argument;
809 channelRequest.channel = channelId;
810 uiccPort.onLogicalChannelOpened(channelRequest);
811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 if (ar.result == null) {
814 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 if (ar.exception != null) {
817 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
818 }
819
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700820 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800823 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700824 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700825 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700826 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700827 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700828 }
829 }
830 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800831 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700833 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700834 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 break;
836
837 case CMD_CLOSE_CHANNEL:
838 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000839 uiccPort = getUiccPortFromRequest(request);
840 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700841 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800842 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800843 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800844 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700845 } else {
846 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000847 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 break;
850
851 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null) {
855 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800856 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700857 if (uiccPort == null) {
858 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
859 } else {
860 final int channelId = (Integer) request.argument;
861 uiccPort.onLogicalChannelClosed(channelId);
862 }
Chen Xu540470b2021-12-14 17:15:47 -0800863 } else {
864 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800865 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800866 if (ar.exception instanceof CommandException) {
867 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
868 CommandException.Error error =
869 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800870 if (error == CommandException.Error.INVALID_ARGUMENTS) {
871 // should only throw exceptions from the binder threads.
872 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800873 "iccCloseLogicalChannel: invalid argument ");
874 }
875 } else {
876 loge("iccCloseLogicalChannel: Unknown exception");
877 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800878 request.result = (exception != null) ? exception :
879 new IllegalStateException(
880 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800881 }
882 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800883 break;
884
885 case CMD_NV_READ_ITEM:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800888 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
889 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800890 break;
891
892 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800898 request.result = "";
899 if (ar.result == null) {
900 loge("nvReadItem: Empty response");
901 } else if (ar.exception instanceof CommandException) {
902 loge("nvReadItem: CommandException: " +
903 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700904 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800905 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700906 }
907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700909 break;
910
Jake Hambye994d462014-02-03 13:10:13 -0800911 case CMD_NV_WRITE_ITEM:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
914 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700916 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800917 break;
918
919 case EVENT_NV_WRITE_ITEM_DONE:
920 handleNullReturnEvent(msg, "nvWriteItem");
921 break;
922
923 case CMD_NV_WRITE_CDMA_PRL:
924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800926 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800927 break;
928
929 case EVENT_NV_WRITE_CDMA_PRL_DONE:
930 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
931 break;
932
chen xu6dac5ab2018-10-26 17:39:23 -0700933 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800934 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700935 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800937 break;
938
chen xu6dac5ab2018-10-26 17:39:23 -0700939 case EVENT_RESET_MODEM_CONFIG_DONE:
940 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800941 break;
942
Sooraj Sasindran37444802020-08-11 10:40:43 -0700943 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
946 request);
947 Phone phone = getPhoneFromRequest(request);
948 if (phone != null) {
949 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
950 } else {
951 loge("isNRDualConnectivityEnabled: No phone object");
952 request.result = false;
953 notifyRequester(request);
954 }
955 break;
956 }
957
958 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
959 ar = (AsyncResult) msg.obj;
960 request = (MainThreadRequest) ar.userObj;
961 if (ar.exception == null && ar.result != null) {
962 request.result = ar.result;
963 } else {
964 // request.result must be set to something non-null
965 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700966 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700967 request.result = ar.result;
968 } else {
969 request.result = false;
970 }
971 if (ar.result == null) {
972 loge("isNRDualConnectivityEnabled: Empty response");
973 } else if (ar.exception instanceof CommandException) {
974 loge("isNRDualConnectivityEnabled: CommandException: "
975 + ar.exception);
976 } else {
977 loge("isNRDualConnectivityEnabled: Unknown exception");
978 }
979 }
980 notifyRequester(request);
981 break;
982
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700983 case CMD_IS_VONR_ENABLED: {
984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
986 request);
987 Phone phone = getPhoneFromRequest(request);
988 if (phone != null) {
989 phone.isVoNrEnabled(onCompleted, request.workSource);
990 } else {
991 loge("isVoNrEnabled: No phone object");
992 request.result = false;
993 notifyRequester(request);
994 }
995 break;
996 }
997
998 case EVENT_IS_VONR_ENABLED_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null && ar.result != null) {
1002 request.result = ar.result;
1003 } else {
1004 // request.result must be set to something non-null
1005 // for the calling thread to unblock
1006 if (ar.result != null) {
1007 request.result = ar.result;
1008 } else {
1009 request.result = false;
1010 }
1011 if (ar.result == null) {
1012 loge("isVoNrEnabled: Empty response");
1013 } else if (ar.exception instanceof CommandException) {
1014 loge("isVoNrEnabled: CommandException: "
1015 + ar.exception);
1016 } else {
1017 loge("isVoNrEnabled: Unknown exception");
1018 }
1019 }
1020 notifyRequester(request);
1021 break;
1022
Sooraj Sasindran37444802020-08-11 10:40:43 -07001023 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1026 Phone phone = getPhoneFromRequest(request);
1027 if (phone != null) {
1028 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1029 request.workSource);
1030 } else {
1031 loge("enableNrDualConnectivity: No phone object");
1032 request.result =
1033 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1034 notifyRequester(request);
1035 }
1036 break;
1037 }
1038
1039 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 if (ar.exception == null) {
1043 request.result =
1044 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1045 } else {
1046 request.result =
1047 TelephonyManager
1048 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1049 if (ar.exception instanceof CommandException) {
1050 CommandException.Error error =
1051 ((CommandException) (ar.exception)).getCommandError();
1052 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1053 request.result =
1054 TelephonyManager
1055 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001056 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1057 request.result =
1058 TelephonyManager
1059 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001060 }
1061 loge("enableNrDualConnectivity" + ": CommandException: "
1062 + ar.exception);
1063 } else {
1064 loge("enableNrDualConnectivity" + ": Unknown exception");
1065 }
1066 }
1067 notifyRequester(request);
1068 break;
1069 }
1070
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001071 case CMD_ENABLE_VONR: {
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1074 Phone phone = getPhoneFromRequest(request);
1075 if (phone != null) {
1076 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1077 request.workSource);
1078 } else {
1079 loge("setVoNrEnabled: No phone object");
1080 request.result =
1081 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1082 notifyRequester(request);
1083 }
1084 break;
1085 }
1086
1087 case EVENT_ENABLE_VONR_DONE: {
1088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
1090 if (ar.exception == null) {
1091 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1092 } else {
1093 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1094 if (ar.exception instanceof CommandException) {
1095 CommandException.Error error =
1096 ((CommandException) (ar.exception)).getCommandError();
1097 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1098 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1099 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1100 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1101 } else {
1102 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1103 }
1104 loge("setVoNrEnabled" + ": CommandException: "
1105 + ar.exception);
1106 } else {
1107 loge("setVoNrEnabled" + ": Unknown exception");
1108 }
1109 }
1110 notifyRequester(request);
1111 break;
1112 }
1113
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1117 request);
1118 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 break;
1120
SongFerngWang3ef3e072020-12-21 16:41:52 +08001121 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001122 ar = (AsyncResult) msg.obj;
1123 request = (MainThreadRequest) ar.userObj;
1124 if (ar.exception == null && ar.result != null) {
1125 request.result = ar.result; // Integer
1126 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301127 // request.result must be set to something non-null
1128 // for the calling thread to unblock
1129 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001132 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001133 loge("getAllowedNetworkTypesBitmask: CommandException: "
1134 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001136 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 }
1138 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1145 request);
1146 Pair<Integer, Long> reasonWithNetworkTypes =
1147 (Pair<Integer, Long>) request.argument;
1148 getPhoneFromRequest(request).setAllowedNetworkTypes(
1149 reasonWithNetworkTypes.first,
1150 reasonWithNetworkTypes.second,
1151 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 break;
1153
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1155 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001158 case CMD_SET_VOICEMAIL_NUMBER:
1159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1161 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001162 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1163 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001164 break;
1165
1166 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1167 handleNullReturnEvent(msg, "setVoicemailNumber");
1168 break;
1169
Stuart Scott54788802015-03-30 13:18:01 -07001170 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1171 request = (MainThreadRequest) msg.obj;
1172 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1173 request);
1174 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1175 break;
1176
1177 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1178 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1179 break;
1180
Shishir Agrawal302c8692015-06-19 13:49:39 -07001181 case CMD_PERFORM_NETWORK_SCAN:
1182 request = (MainThreadRequest) msg.obj;
1183 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1184 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1185 break;
1186
Hall Liu27d24262020-09-18 19:04:59 -07001187 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001188 request = (MainThreadRequest) msg.obj;
1189 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001190 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1191 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1192 request.argument;
1193 int callForwardingReason = args.first;
1194 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001195 break;
Hall Liu27d24262020-09-18 19:04:59 -07001196 }
1197 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001198 ar = (AsyncResult) msg.obj;
1199 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001200 TelephonyManager.CallForwardingInfoCallback callback =
1201 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1202 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001203 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001204 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1206 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1207 // Service Class is a bit mask per 3gpp 27.007. Search for
1208 // any service for voice call.
1209 if ((callForwardInfo.serviceClass
1210 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001211 callForwardingInfo = new CallForwardingInfo(
1212 callForwardInfo.status
1213 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001214 callForwardInfo.reason,
1215 callForwardInfo.number,
1216 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001217 break;
1218 }
1219 }
1220 // Didn't find a call forward info for voice call.
1221 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001222 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1223 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 }
Hall Liu27d24262020-09-18 19:04:59 -07001225 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 } else {
1227 if (ar.result == null) {
1228 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1229 }
1230 if (ar.exception != null) {
1231 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1232 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001233 int errorCode = TelephonyManager
1234 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 errorCode = TelephonyManager
1240 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001241 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001242 errorCode = TelephonyManager
1243 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001244 }
1245 }
Hall Liu27d24262020-09-18 19:04:59 -07001246 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001254 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001255 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001256 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1257 request.argument).first;
1258 request.phone.setCallForwardingOption(
1259 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001260 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001261 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001262 callForwardingInfoToSet.getReason(),
1263 callForwardingInfoToSet.getNumber(),
1264 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1265 break;
Hall Liu27d24262020-09-18 19:04:59 -07001266 }
Shuo Qian4a594052020-01-23 11:59:30 -08001267
Hall Liu27d24262020-09-18 19:04:59 -07001268 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001271 Consumer<Integer> callback =
1272 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1273 request.argument).second;
1274 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001275 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001276 int errorCode = TelephonyManager.CallForwardingInfoCallback
1277 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001278 if (ar.exception instanceof CommandException) {
1279 CommandException.Error error =
1280 ((CommandException) (ar.exception)).getCommandError();
1281 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001282 errorCode = TelephonyManager.CallForwardingInfoCallback
1283 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001284 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001285 errorCode = TelephonyManager.CallForwardingInfoCallback
1286 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
1288 }
1289 callback.accept(errorCode);
1290 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001291 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001292 }
Shuo Qian4a594052020-01-23 11:59:30 -08001293 break;
Hall Liu27d24262020-09-18 19:04:59 -07001294 }
Shuo Qian4a594052020-01-23 11:59:30 -08001295
Hall Liu27d24262020-09-18 19:04:59 -07001296 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 request = (MainThreadRequest) msg.obj;
1298 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1299 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1300 break;
Hall Liu27d24262020-09-18 19:04:59 -07001301 }
Shuo Qian4a594052020-01-23 11:59:30 -08001302
Hall Liu27d24262020-09-18 19:04:59 -07001303 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001306 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001307 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001308 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001309 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001310 // Service Class is a bit mask per 3gpp 27.007.
1311 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001312 if (callForwardResults.length > 1
1313 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001314 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001315 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001316 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1317 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001318 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001319 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001320 }
1321 } else {
1322 if (ar.result == null) {
1323 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1324 }
1325 if (ar.exception != null) {
1326 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1327 }
1328 if (ar.exception instanceof CommandException) {
1329 CommandException.Error error =
1330 ((CommandException) (ar.exception)).getCommandError();
1331 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001333 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001334 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1335 callWaitingStatus =
1336 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001337 }
1338 }
1339 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001340 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001341 break;
Hall Liu27d24262020-09-18 19:04:59 -07001342 }
Shuo Qian4a594052020-01-23 11:59:30 -08001343
Hall Liu27d24262020-09-18 19:04:59 -07001344 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001345 request = (MainThreadRequest) msg.obj;
1346 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001347 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1348 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001349 break;
Hall Liu27d24262020-09-18 19:04:59 -07001350 }
Shuo Qian4a594052020-01-23 11:59:30 -08001351
Hall Liu27d24262020-09-18 19:04:59 -07001352 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001353 ar = (AsyncResult) msg.obj;
1354 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001355 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1356 Consumer<Integer> callback =
1357 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1358 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001359 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001360 if (ar.exception instanceof CommandException) {
1361 CommandException.Error error =
1362 ((CommandException) (ar.exception)).getCommandError();
1363 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1364 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001365 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1366 callback.accept(
1367 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001368 } else {
1369 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1370 }
1371 } else {
1372 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1373 }
1374 } else {
1375 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1376 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001377 }
Shuo Qian4a594052020-01-23 11:59:30 -08001378 break;
Hall Liu27d24262020-09-18 19:04:59 -07001379 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001380 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1381 ar = (AsyncResult) msg.obj;
1382 request = (MainThreadRequest) ar.userObj;
1383 CellNetworkScanResult cellScanResult;
1384 if (ar.exception == null && ar.result != null) {
1385 cellScanResult = new CellNetworkScanResult(
1386 CellNetworkScanResult.STATUS_SUCCESS,
1387 (List<OperatorInfo>) ar.result);
1388 } else {
1389 if (ar.result == null) {
1390 loge("getCellNetworkScanResults: Empty response");
1391 }
1392 if (ar.exception != null) {
1393 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1394 }
1395 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1396 if (ar.exception instanceof CommandException) {
1397 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001398 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001399 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1400 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1401 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1402 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1403 }
1404 }
1405 cellScanResult = new CellNetworkScanResult(errorCode, null);
1406 }
1407 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001408 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001409 break;
1410
1411 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1412 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001413 ManualNetworkSelectionArgument selArg =
1414 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001415 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1416 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001417 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1418 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001419 break;
1420
1421 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 if (ar.exception == null) {
1425 request.result = true;
1426 } else {
1427 request.result = false;
1428 loge("setNetworkSelectionModeManual " + ar.exception);
1429 }
1430 notifyRequester(request);
1431 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 break;
1433
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 case CMD_GET_MODEM_ACTIVITY_INFO:
1435 request = (MainThreadRequest) msg.obj;
1436 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001437 if (defaultPhone != null) {
1438 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001439 } else {
1440 ResultReceiver result = (ResultReceiver) request.argument;
1441 Bundle bundle = new Bundle();
1442 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001443 new ModemActivityInfo(0, 0, 0,
1444 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001445 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001446 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 break;
1448
Hall Liud0f208c2020-10-14 16:54:44 -07001449 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001453 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001454 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001455 if (mLastModemActivityInfo == null) {
1456 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1457 mLastModemActivitySpecificInfo[0] =
1458 new ActivityStatsTechSpecificInfo(
1459 0,
1460 0,
1461 new int[ModemActivityInfo.getNumTxPowerLevels()],
1462 0);
1463 mLastModemActivityInfo =
1464 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1465 }
1466
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001468 // Update the last modem activity info and the result of the request.
1469 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1470 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001471 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001472 } else {
1473 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001474 }
Kai Shi917fdc62022-11-28 14:01:02 -08001475 // This is needed to decouple ret from mLastModemActivityInfo
1476 // We don't want to return mLastModemActivityInfo which is updated
1477 // inside mergeModemActivityInfo()
1478 ret = new ModemActivityInfo(
1479 mLastModemActivityInfo.getTimestampMillis(),
1480 mLastModemActivityInfo.getSleepTimeMillis(),
1481 mLastModemActivityInfo.getIdleTimeMillis(),
1482 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001483
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001484 } else {
1485 if (ar.result == null) {
1486 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001487 error = TelephonyManager.ModemActivityInfoException
1488 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001489 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001490 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001491 error = TelephonyManager.ModemActivityInfoException
1492 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 } else {
1494 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001495 error = TelephonyManager.ModemActivityInfoException
1496 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 }
1498 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001499 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001500 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001501 bundle.putParcelable(
1502 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001503 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001504 } else {
1505 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1506 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001507 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001508 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001509 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001510 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001512 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001513 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001514 CarrierRestrictionRules argument =
1515 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001516 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001517 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001519 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001520
1521 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1522 ar = (AsyncResult) msg.obj;
1523 request = (MainThreadRequest) ar.userObj;
1524 if (ar.exception == null && ar.result != null) {
1525 request.result = ar.result;
1526 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001527 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1528 if (ar.exception instanceof CommandException) {
1529 loge("setAllowedCarriers: CommandException: " + ar.exception);
1530 CommandException.Error error =
1531 ((CommandException) (ar.exception)).getCommandError();
1532 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1533 request.result =
1534 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1535 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 } else {
1537 loge("setAllowedCarriers: Unknown exception");
1538 }
1539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541 break;
1542
1543 case CMD_GET_ALLOWED_CARRIERS:
1544 request = (MainThreadRequest) msg.obj;
1545 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001546 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 break;
1548
1549 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception == null && ar.result != null) {
1553 request.result = ar.result;
1554 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001555 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001556 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001557 if (ar.result == null) {
1558 loge("getAllowedCarriers: Empty response");
1559 } else if (ar.exception instanceof CommandException) {
1560 loge("getAllowedCarriers: CommandException: " +
1561 ar.exception);
1562 } else {
1563 loge("getAllowedCarriers: Unknown exception");
1564 }
1565 }
arunvoddud7401012022-12-15 16:08:12 +00001566 if (request.argument != null) {
1567 // This is for the implementation of carrierRestrictionStatus.
1568 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1569 Consumer<Integer> callback = callbackInfo.getConsumer();
1570 int callerCarrierId = callbackInfo.getCarrierId();
1571 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1572 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1573 CarrierRestrictionRules carrierRestrictionRules =
1574 (CarrierRestrictionRules) ar.result;
1575 int carrierId = -1;
1576 try {
1577 CarrierIdentifier carrierIdentifier =
1578 carrierRestrictionRules.getAllowedCarriers().get(0);
1579 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1580 carrierIdentifier);
1581 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1582 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1583 }
1584 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1585 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1586 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001587 lockStatus = TelephonyManager
1588 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001589 }
1590 } else {
1591 Rlog.e(LOG_TAG,
1592 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1593 }
1594 callback.accept(lockStatus);
1595 } else {
1596 // This is for the implementation of getAllowedCarriers.
1597 notifyRequester(request);
1598 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001599 break;
1600
Nathan Haroldb3014052017-01-25 15:57:32 -08001601 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 if (ar.exception == null && ar.result != null) {
1605 request.result = ar.result;
1606 } else {
1607 request.result = new IllegalArgumentException(
1608 "Failed to retrieve Forbidden Plmns");
1609 if (ar.result == null) {
1610 loge("getForbiddenPlmns: Empty response");
1611 } else {
1612 loge("getForbiddenPlmns: Unknown exception");
1613 }
1614 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001615 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001616 break;
1617
1618 case CMD_GET_FORBIDDEN_PLMNS:
1619 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001620 uiccPort = getUiccPortFromRequest(request);
1621 if (uiccPort == null) {
1622 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001623 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001624 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001625 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001626 break;
1627 }
1628 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001629 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001630 if (uiccApp == null) {
1631 loge("getForbiddenPlmns() no app with specified type -- "
1632 + appType);
1633 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001634 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001635 break;
1636 } else {
1637 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1638 + " specified type -- " + appType);
1639 }
1640 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1641 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001642 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001643 break;
1644
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001645 case CMD_SWITCH_SLOTS:
1646 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001647 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001648 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001649 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001650 break;
1651
1652 case EVENT_SWITCH_SLOTS_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
1655 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001656 notifyRequester(request);
1657 break;
1658 case CMD_GET_NETWORK_SELECTION_MODE:
1659 request = (MainThreadRequest) msg.obj;
1660 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1661 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1662 break;
1663
1664 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
1667 if (ar.exception != null) {
1668 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1669 } else {
1670 int mode = ((int[]) ar.result)[0];
1671 if (mode == 0) {
1672 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1673 } else {
1674 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1675 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001677 notifyRequester(request);
1678 break;
1679 case CMD_GET_CDMA_ROAMING_MODE:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1682 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1683 break;
1684 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 if (ar.exception != null) {
1688 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1689 } else {
1690 request.result = ((int[]) ar.result)[0];
1691 }
1692 notifyRequester(request);
1693 break;
1694 case CMD_SET_CDMA_ROAMING_MODE:
1695 request = (MainThreadRequest) msg.obj;
1696 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1697 int mode = (int) request.argument;
1698 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1699 break;
1700 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 request.result = ar.exception == null;
1704 notifyRequester(request);
1705 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001706 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1707 request = (MainThreadRequest) msg.obj;
1708 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1709 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1710 break;
1711 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 if (ar.exception != null) {
1715 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1716 } else {
1717 request.result = ((int[]) ar.result)[0];
1718 }
1719 notifyRequester(request);
1720 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001721 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1724 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001725 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1726 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001727 break;
1728 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = ar.exception == null;
1732 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001733 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001734 case CMD_GET_ALL_CELL_INFO:
1735 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001737 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 case EVENT_GET_ALL_CELL_INFO_DONE:
1740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001742 // If a timeout occurs, the response will be null
1743 request.result = (ar.exception == null && ar.result != null)
1744 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 synchronized (request) {
1746 request.notifyAll();
1747 }
1748 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001749 case CMD_REQUEST_CELL_INFO_UPDATE:
1750 request = (MainThreadRequest) msg.obj;
1751 request.phone.requestCellInfoUpdate(request.workSource,
1752 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1753 break;
1754 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1758 try {
1759 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001760 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001761 cb.onError(
1762 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1763 ar.exception.getClass().getName(),
1764 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001765 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001766 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001767 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001768 } else {
1769 // use the result as returned
1770 cb.onCellInfo((List<CellInfo>) ar.result);
1771 }
1772 } catch (RemoteException re) {
1773 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1774 }
1775 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001776 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001777 request = (MainThreadRequest) msg.obj;
1778 WorkSource ws = (WorkSource) request.argument;
1779 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001780 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001781 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001782 }
1783 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 if (ar.exception == null) {
1787 request.result = ar.result;
1788 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001789 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001791 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001792 }
1793
1794 synchronized (request) {
1795 request.notifyAll();
1796 }
1797 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001798 }
chen xu6dac5ab2018-10-26 17:39:23 -07001799 case CMD_MODEM_REBOOT:
1800 request = (MainThreadRequest) msg.obj;
1801 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001802 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001803 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001804 case EVENT_CMD_MODEM_REBOOT_DONE:
1805 handleNullReturnEvent(msg, "rebootModem");
1806 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001807 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001808 request = (MainThreadRequest) msg.obj;
1809 boolean enable = (boolean) request.argument;
1810 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001811 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001812 PhoneConfigurationManager.getInstance()
1813 .enablePhone(request.phone, enable, onCompleted);
1814 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001815 }
Michele Berionne5e411512020-11-13 02:36:59 +00001816 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001820 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001821 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001822 if ((boolean) request.result) {
1823 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1824 updateModemStateMetrics();
1825 } else {
1826 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1827 + ar.exception);
1828 }
1829 notifyRequester(request);
1830 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001831 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001832 case CMD_GET_MODEM_STATUS:
1833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1835 PhoneConfigurationManager.getInstance()
1836 .getPhoneStatusFromModem(request.phone, onCompleted);
1837 break;
1838 case EVENT_GET_MODEM_STATUS_DONE:
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 int id = request.phone.getPhoneId();
1842 if (ar.exception == null && ar.result != null) {
1843 request.result = ar.result;
1844 //update the cache as modem status has changed
1845 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1846 (boolean) request.result);
1847 } else {
1848 // Return true if modem status cannot be retrieved. For most cases,
1849 // modem status is on. And for older version modems, GET_MODEM_STATUS
1850 // and disable modem are not supported. Modem is always on.
1851 // TODO: this should be fixed in R to support a third
1852 // status UNKNOWN b/131631629
1853 request.result = true;
1854 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1855 + ar.exception);
1856 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001857 notifyRequester(request);
1858 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001859 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1860 request = (MainThreadRequest) msg.obj;
1861 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1862 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1863 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1864 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1865 break;
1866 }
1867 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1868 ar = (AsyncResult) msg.obj;
1869 request = (MainThreadRequest) ar.userObj;
1870 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1871 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1872 args.second.accept(ar.exception == null);
1873 notifyRequester(request);
1874 break;
1875 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001876 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1877 request = (MainThreadRequest) msg.obj;
1878 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1879 Phone phone = getPhoneFromRequest(request);
1880 if (phone != null) {
1881 phone.getSystemSelectionChannels(onCompleted);
1882 } else {
1883 loge("getSystemSelectionChannels: No phone object");
1884 request.result = new ArrayList<RadioAccessSpecifier>();
1885 notifyRequester(request);
1886 }
1887 break;
1888 }
1889 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1890 ar = (AsyncResult) msg.obj;
1891 request = (MainThreadRequest) ar.userObj;
1892 if (ar.exception == null && ar.result != null) {
1893 request.result = ar.result;
1894 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001895 request.result = new IllegalStateException(
1896 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001897 if (ar.result == null) {
1898 loge("getSystemSelectionChannels: Empty response");
1899 } else {
1900 loge("getSystemSelectionChannels: Unknown exception");
1901 }
1902 }
1903 notifyRequester(request);
1904 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001905 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1906 ar = (AsyncResult) msg.obj;
1907 request = (MainThreadRequest) ar.userObj;
1908 if (ar.exception == null && ar.result != null) {
1909 request.result = ar.result;
1910 } else {
1911 request.result = -1;
1912 loge("Failed to set Forbidden Plmns");
1913 if (ar.result == null) {
1914 loge("setForbidenPlmns: Empty response");
1915 } else if (ar.exception != null) {
1916 loge("setForbiddenPlmns: Exception: " + ar.exception);
1917 request.result = -1;
1918 } else {
1919 loge("setForbiddenPlmns: Unknown exception");
1920 }
1921 }
1922 notifyRequester(request);
1923 break;
1924 case CMD_SET_FORBIDDEN_PLMNS:
1925 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001926 uiccPort = getUiccPortFromRequest(request);
1927 if (uiccPort == null) {
1928 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001929 request.result = -1;
1930 notifyRequester(request);
1931 break;
1932 }
1933 Pair<Integer, List<String>> setFplmnsArgs =
1934 (Pair<Integer, List<String>>) request.argument;
1935 appType = setFplmnsArgs.first;
1936 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001937 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001938 if (uiccApp == null) {
1939 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1940 request.result = -1;
1941 loge("Failed to get UICC App");
1942 notifyRequester(request);
1943 } else {
1944 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1945 ((SIMRecords) uiccApp.getIccRecords())
1946 .setForbiddenPlmns(onCompleted, fplmns);
1947 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001948 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001949 case CMD_ERASE_MODEM_CONFIG:
1950 request = (MainThreadRequest) msg.obj;
1951 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1952 defaultPhone.eraseModemConfig(onCompleted);
1953 break;
1954 case EVENT_ERASE_MODEM_CONFIG_DONE:
1955 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001956 break;
zoey chene02881a2019-12-30 16:11:23 +08001957
Kai Shif70f46f2021-03-03 13:59:46 -08001958 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1959 request = (MainThreadRequest) msg.obj;
1960 request.result = defaultPhone.eraseDataInSharedPreferences();
1961 notifyRequester(request);
1962 break;
1963
zoey chene02881a2019-12-30 16:11:23 +08001964 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1965 request = (MainThreadRequest) msg.obj;
1966 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1967 Pair<String, String> changed = (Pair<String, String>) request.argument;
1968 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1969 changed.first, changed.second, onCompleted);
1970 break;
1971 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1972 ar = (AsyncResult) msg.obj;
1973 request = (MainThreadRequest) ar.userObj;
1974 if (ar.exception == null) {
1975 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001976 // If the operation is successful, update the PIN storage
1977 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1978 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001979 UiccController.getInstance().getPinStorage()
1980 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001981 } else {
1982 request.result = msg.arg1;
1983 }
1984 notifyRequester(request);
1985 break;
1986
Michele Berionne5e411512020-11-13 02:36:59 +00001987 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001988 request = (MainThreadRequest) msg.obj;
1989 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1990 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1991 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1992 enabled.first, enabled.second, onCompleted);
1993 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001994 }
zoey chene02881a2019-12-30 16:11:23 +08001995 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1996 ar = (AsyncResult) msg.obj;
1997 request = (MainThreadRequest) ar.userObj;
1998 if (ar.exception == null) {
1999 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002000 // If the operation is successful, update the PIN storage
2001 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2002 int phoneId = getPhoneFromRequest(request).getPhoneId();
2003 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002004 UiccController.getInstance().getPinStorage()
2005 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002006 } else {
2007 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2008 }
zoey chene02881a2019-12-30 16:11:23 +08002009 } else {
2010 request.result = msg.arg1;
2011 }
Michele Berionne5e411512020-11-13 02:36:59 +00002012
2013
zoey chene02881a2019-12-30 16:11:23 +08002014 notifyRequester(request);
2015 break;
2016
Peter Wangdafb9ac2020-01-15 14:13:38 -08002017 case MSG_NOTIFY_USER_ACTIVITY:
2018 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002019 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002020 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2021 getDefaultPhone().getContext().sendBroadcastAsUser(
2022 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2023 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002024
2025 case CMD_SET_DATA_THROTTLING: {
2026 request = (MainThreadRequest) msg.obj;
2027 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2028 DataThrottlingRequest dataThrottlingRequest =
2029 (DataThrottlingRequest) request.argument;
2030 Phone phone = getPhoneFromRequest(request);
2031 if (phone != null) {
2032 phone.setDataThrottling(onCompleted,
2033 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2034 dataThrottlingRequest.getCompletionDurationMillis());
2035 } else {
2036 loge("setDataThrottling: No phone object");
2037 request.result =
2038 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2039 notifyRequester(request);
2040 }
2041
2042 break;
2043 }
2044 case EVENT_SET_DATA_THROTTLING_DONE:
2045 ar = (AsyncResult) msg.obj;
2046 request = (MainThreadRequest) ar.userObj;
2047
2048 if (ar.exception == null) {
2049 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2050 } else if (ar.exception instanceof CommandException) {
2051 loge("setDataThrottling: CommandException: " + ar.exception);
2052 CommandException.Error error =
2053 ((CommandException) (ar.exception)).getCommandError();
2054
2055 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2056 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002057 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002058 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2059 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002060 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2061 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002062 } else {
2063 request.result =
2064 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2065 }
2066 } else {
2067 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2068 }
2069 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2070 notifyRequester(request);
2071 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002072
2073 case CMD_SET_SIM_POWER: {
2074 request = (MainThreadRequest) msg.obj;
2075 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2076 request = (MainThreadRequest) msg.obj;
2077 int stateToSet =
2078 ((Pair<Integer, IIntegerConsumer>)
2079 request.argument).first;
2080 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2081 break;
2082 }
2083 case EVENT_SET_SIM_POWER_DONE: {
2084 ar = (AsyncResult) msg.obj;
2085 request = (MainThreadRequest) ar.userObj;
2086 IIntegerConsumer callback =
2087 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2088 if (ar.exception != null) {
2089 loge("setSimPower exception: " + ar.exception);
2090 int errorCode = TelephonyManager.CallForwardingInfoCallback
2091 .RESULT_ERROR_UNKNOWN;
2092 if (ar.exception instanceof CommandException) {
2093 CommandException.Error error =
2094 ((CommandException) (ar.exception)).getCommandError();
2095 if (error == CommandException.Error.SIM_ERR) {
2096 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2097 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2098 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2099 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2100 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2101 } else {
2102 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2103 }
2104 }
2105 try {
2106 callback.accept(errorCode);
2107 } catch (RemoteException e) {
2108 // Ignore if the remote process is no longer available to call back.
2109 Log.w(LOG_TAG, "setSimPower: callback not available.");
2110 }
2111 } else {
2112 try {
2113 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2114 } catch (RemoteException e) {
2115 // Ignore if the remote process is no longer available to call back.
2116 Log.w(LOG_TAG, "setSimPower: callback not available.");
2117 }
2118 }
2119 break;
2120 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002121 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2122 request = (MainThreadRequest) msg.obj;
2123
2124 final Phone phone = getPhoneFromRequest(request);
2125 if (phone == null || phone.getServiceStateTracker() == null) {
2126 request.result = new IllegalStateException("Phone or SST is null");
2127 notifyRequester(request);
2128 break;
2129 }
2130
2131 Pair<Integer, SignalStrengthUpdateRequest> pair =
2132 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2133 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2134 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002135 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002136 request.subId, pair.first /*callingUid*/,
2137 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002138 break;
2139 }
2140 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2141 ar = (AsyncResult) msg.obj;
2142 request = (MainThreadRequest) ar.userObj;
2143 // request.result will be the exception of ar if present, true otherwise.
2144 // Be cautious not to leave result null which will wait() forever
2145 request.result = ar.exception != null ? ar.exception : true;
2146 notifyRequester(request);
2147 break;
2148 }
2149 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2150 request = (MainThreadRequest) msg.obj;
2151
2152 Phone phone = getPhoneFromRequest(request);
2153 if (phone == null || phone.getServiceStateTracker() == null) {
2154 request.result = new IllegalStateException("Phone or SST is null");
2155 notifyRequester(request);
2156 break;
2157 }
2158
2159 Pair<Integer, SignalStrengthUpdateRequest> pair =
2160 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2161 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2162 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002163 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002164 request.subId, pair.first /*callingUid*/,
2165 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002166 break;
2167 }
2168 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2169 ar = (AsyncResult) msg.obj;
2170 request = (MainThreadRequest) ar.userObj;
2171 request.result = ar.exception != null ? ar.exception : true;
2172 notifyRequester(request);
2173 break;
2174 }
Jordan Liu109698e2020-11-24 14:50:34 -08002175
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002176 case CMD_GET_SLICING_CONFIG: {
2177 request = (MainThreadRequest) msg.obj;
2178 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2179 request.phone.getSlicingConfig(onCompleted);
2180 break;
2181 }
2182 case EVENT_GET_SLICING_CONFIG_DONE: {
2183 ar = (AsyncResult) msg.obj;
2184 request = (MainThreadRequest) ar.userObj;
2185 ResultReceiver result = (ResultReceiver) request.argument;
2186
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002187 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002188 Bundle bundle = new Bundle();
2189 int resultCode = 0;
2190 if (ar.exception != null) {
2191 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2192 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002193 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002194 } else if (ar.result == null) {
2195 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002196 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002197 } else {
2198 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002199 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2200 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002201 }
2202
2203 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002204 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 }
2206 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2207 result.send(resultCode, bundle);
2208 notifyRequester(request);
2209 break;
2210 }
2211
Sarah Chin71b3a852022-09-28 15:54:19 -07002212 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002213 request = (MainThreadRequest) msg.obj;
2214 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002215 PurchasePremiumCapabilityArgument arg =
2216 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002217 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2218 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002219 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002220 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002221
Sarah Chin71b3a852022-09-28 15:54:19 -07002222 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002223 ar = (AsyncResult) msg.obj;
2224 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002225 PurchasePremiumCapabilityArgument arg =
2226 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002227 try {
2228 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002229 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002230 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002231 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002232 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002233 + TelephonyManager.convertPurchaseResultToString(result));
2234 } catch (RemoteException e) {
2235 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002237 + " failed: " + e;
2238 if (DBG) log(logStr);
2239 AnomalyReporter.reportAnomaly(
2240 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2241 }
2242 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244
Michele Berionne5e411512020-11-13 02:36:59 +00002245 case CMD_PREPARE_UNATTENDED_REBOOT:
2246 request = (MainThreadRequest) msg.obj;
2247 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002248 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002249 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002250 notifyRequester(request);
2251 break;
2252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 default:
2254 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2255 break;
2256 }
2257 }
Jake Hambye994d462014-02-03 13:10:13 -08002258
Pengquan Menga1bb6272018-09-06 09:59:22 -07002259 private void notifyRequester(MainThreadRequest request) {
2260 synchronized (request) {
2261 request.notifyAll();
2262 }
2263 }
2264
Jake Hambye994d462014-02-03 13:10:13 -08002265 private void handleNullReturnEvent(Message msg, String command) {
2266 AsyncResult ar = (AsyncResult) msg.obj;
2267 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2268 if (ar.exception == null) {
2269 request.result = true;
2270 } else {
2271 request.result = false;
2272 if (ar.exception instanceof CommandException) {
2273 loge(command + ": CommandException: " + ar.exception);
2274 } else {
2275 loge(command + ": Unknown exception");
2276 }
2277 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002278 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
2282 /**
2283 * Posts the specified command to be executed on the main thread,
2284 * waits for the request to complete, and returns the result.
2285 * @see #sendRequestAsync
2286 */
2287 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002288 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2289 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002290 }
2291
2292 /**
2293 * Posts the specified command to be executed on the main thread,
2294 * waits for the request to complete, and returns the result.
2295 * @see #sendRequestAsync
2296 */
2297 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2298 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002299 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002300 }
2301
2302 /**
2303 * Posts the specified command to be executed on the main thread,
2304 * waits for the request to complete, and returns the result.
2305 * @see #sendRequestAsync
2306 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002307 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002308 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2309 }
2310
2311 /**
2312 * Posts the specified command to be executed on the main thread,
2313 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2314 * if not timeout or null otherwise.
2315 * @see #sendRequestAsync
2316 */
2317 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2318 long timeoutInMs) {
2319 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002320 }
2321
2322 /**
2323 * Posts the specified command to be executed on the main thread,
2324 * waits for the request to complete, and returns the result.
2325 * @see #sendRequestAsync
2326 */
Nathan Harold92bed182018-10-12 18:16:49 -07002327 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002328 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002329 }
2330
2331 /**
2332 * Posts the specified command to be executed on the main thread,
2333 * waits for the request to complete, and returns the result.
2334 * @see #sendRequestAsync
2335 */
2336 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002337 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2338 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002339 }
2340
2341 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002342 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2343 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2344 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002345 * @see #sendRequestAsync
2346 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002347 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2348 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2350 throw new RuntimeException("This method will deadlock if called from the main thread.");
2351 }
2352
Nathan Harold92bed182018-10-12 18:16:49 -07002353 MainThreadRequest request = null;
2354 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2355 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2356 } else if (phone != null) {
2357 request = new MainThreadRequest(argument, phone, workSource);
2358 } else {
2359 request = new MainThreadRequest(argument, subId, workSource);
2360 }
2361
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 Message msg = mMainThreadHandler.obtainMessage(command, request);
2363 msg.sendToTarget();
2364
Rambo Wang0f050d82021-02-12 11:43:36 -08002365
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002367 if (timeoutInMs >= 0) {
2368 // Wait for at least timeoutInMs before returning null request result
2369 long now = SystemClock.elapsedRealtime();
2370 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002371 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002372 try {
2373 request.wait(deadline - now);
2374 } catch (InterruptedException e) {
2375 // Do nothing, go back and check if request is completed or timeout
2376 } finally {
2377 now = SystemClock.elapsedRealtime();
2378 }
2379 }
2380 } else {
2381 // Wait for the request to complete
2382 while (request.result == null) {
2383 try {
2384 request.wait();
2385 } catch (InterruptedException e) {
2386 // Do nothing, go back and wait until the request is complete
2387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 }
2389 }
2390 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002391 if (request.result == null) {
2392 Log.wtf(LOG_TAG,
2393 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 return request.result;
2396 }
2397
2398 /**
2399 * Asynchronous ("fire and forget") version of sendRequest():
2400 * Posts the specified command to be executed on the main thread, and
2401 * returns immediately.
2402 * @see #sendRequest
2403 */
2404 private void sendRequestAsync(int command) {
2405 mMainThreadHandler.sendEmptyMessage(command);
2406 }
2407
2408 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002409 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002410 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002411 */
2412 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002413 sendRequestAsync(command, argument, null, null);
2414 }
2415
2416 /**
2417 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2418 * @see {@link #sendRequest(int,Object)}
2419 */
2420 private void sendRequestAsync(
2421 int command, Object argument, Phone phone, WorkSource workSource) {
2422 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002423 Message msg = mMainThreadHandler.obtainMessage(command, request);
2424 msg.sendToTarget();
2425 }
2426
2427 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 * Initialize the singleton PhoneInterfaceManager instance.
2429 * This is only done once, at startup, from PhoneApp.onCreate().
2430 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002431 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 synchronized (PhoneInterfaceManager.class) {
2433 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002434 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 } else {
2436 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2437 }
2438 return sInstance;
2439 }
2440 }
2441
2442 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002443 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002445 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002447 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002448 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002449 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2451 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002452 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002453 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002454 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002455 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002456 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002457 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 publish();
arunvoddud7401012022-12-15 16:08:12 +00002459 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002462 @VisibleForTesting
2463 public SharedPreferences getSharedPreferences() {
2464 return mTelephonySharedPreferences;
2465 }
2466
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002467 /**
2468 * Get the default phone for this device.
2469 */
2470 @VisibleForTesting
2471 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002472 Phone thePhone = getPhone(getDefaultSubscription());
2473 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2474 }
2475
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 private void publish() {
2477 if (DBG) log("publish: " + this);
2478
Peter Wangc035ce42020-01-08 21:00:22 -08002479 TelephonyFrameworkInitializer
2480 .getTelephonyServiceManager()
2481 .getTelephonyServiceRegisterer()
2482 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
2484
Stuart Scott584921c2015-01-15 17:10:34 -08002485 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002486 if (request.phone != null) {
2487 return request.phone;
2488 } else {
2489 return getPhoneFromSubId(request.subId);
2490 }
2491 }
2492
2493 private Phone getPhoneFromSubId(int subId) {
2494 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2495 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002496 }
2497
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002498 /**
2499 * Get phone object associated with a subscription.
2500 * Return default phone if phone object associated with subscription is null
2501 * @param subId - subscriptionId
2502 * @return phone object associated with a subscription or default phone if null.
2503 */
Ling Mac28f0212023-03-24 16:07:15 -07002504 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002505 Phone phone = getPhoneFromSubId(subId);
2506 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002507 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002508 phone = getDefaultPhone();
2509 }
2510 return phone;
2511 }
2512
Rambo Wange53e07d2022-05-10 13:01:13 -07002513 @Nullable
2514 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002515 Phone phone = getPhoneFromRequest(request);
2516 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002517 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002518 }
2519
Ling Mac28f0212023-03-24 16:07:15 -07002520 /**
2521 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2522 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2523 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2524 * @return The Phone associated the sub Id
2525 */
2526 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002527 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529
Kai Shif70f46f2021-03-03 13:59:46 -08002530 private void sendEraseModemConfig(@NonNull Phone phone) {
2531 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2532 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2533 }
2534
2535 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2536 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2537 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002538 }
2539
Peter Wang44b186e2020-01-13 23:33:09 -08002540 private boolean isImsAvailableOnDevice() {
2541 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2542 if (pm == null) {
2543 // For some reason package manger is not available.. This will fail internally anyway,
2544 // so do not throw error and allow.
2545 return true;
2546 }
2547 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2548 }
2549
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002551 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002552 }
2553
Wink Savilleb564aae2014-10-23 10:18:09 -07002554 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 if (DBG) log("dial: " + number);
2556 // No permission check needed here: This is just a wrapper around the
2557 // ACTION_DIAL intent, which is available to any app since it puts up
2558 // the UI before it does anything.
2559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 String url = createTelUrl(number);
2563 if (url == null) {
2564 return;
2565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567 // PENDING: should we just silently fail if phone is offhook or ringing?
2568 PhoneConstants.State state = mCM.getState(subId);
2569 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2570 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2571 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2572 mApp.startActivity(intent);
2573 }
2574 } finally {
2575 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 }
2577 }
2578
2579 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002580 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002581 }
2582
Wink Savilleb564aae2014-10-23 10:18:09 -07002583 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 if (DBG) log("call: " + number);
2585
2586 // This is just a wrapper around the ACTION_CALL intent, but we still
2587 // need to do a permission check since we're calling startActivity()
2588 // from the context of the phone app.
2589 enforceCallPermission();
2590
Jordan Liu1617b712019-07-10 15:06:26 -07002591 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 != AppOpsManager.MODE_ALLOWED) {
2593 return;
2594 }
2595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 String url = createTelUrl(number);
2599 if (url == null) {
2600 return;
2601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 boolean isValid = false;
2604 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2605 if (slist != null) {
2606 for (SubscriptionInfo subInfoRecord : slist) {
2607 if (subInfoRecord.getSubscriptionId() == subId) {
2608 isValid = true;
2609 break;
2610 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002611 }
Wink Saville08874612014-08-31 19:19:58 -07002612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 if (!isValid) {
2614 return;
2615 }
Wink Saville08874612014-08-31 19:19:58 -07002616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2618 intent.putExtra(SUBSCRIPTION_KEY, subId);
2619 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2620 mApp.startActivity(intent);
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 }
2625
Wink Savilleb564aae2014-10-23 10:18:09 -07002626 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002627 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002628 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2629 }
2630
Wink Savilleb564aae2014-10-23 10:18:09 -07002631 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002632 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002633 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2634 }
2635
Wink Savilleb564aae2014-10-23 10:18:09 -07002636 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002641 Phone phone = getPhone(subId);
2642 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 checkSimPin.start();
2644 return checkSimPin.unlockSim(null, pin);
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
2647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 }
2649
Wink Savilleb564aae2014-10-23 10:18:09 -07002650 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002655 Phone phone = getPhone(subId);
2656 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 checkSimPuk.start();
2658 return checkSimPuk.unlockSim(puk, pin);
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
2663
2664 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002665 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 * a synchronous one.
2667 */
2668 private static class UnlockSim extends Thread {
2669
2670 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002671 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672
2673 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002674 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2675 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676
2677 // For replies from SimCard interface
2678 private Handler mHandler;
2679
2680 // For async handler to identify request type
2681 private static final int SUPPLY_PIN_COMPLETE = 100;
2682
Michele Berionne5e411512020-11-13 02:36:59 +00002683 UnlockSim(int phoneId, IccCard simCard) {
2684 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 mSimCard = simCard;
2686 }
2687
2688 @Override
2689 public void run() {
2690 Looper.prepare();
2691 synchronized (UnlockSim.this) {
2692 mHandler = new Handler() {
2693 @Override
2694 public void handleMessage(Message msg) {
2695 AsyncResult ar = (AsyncResult) msg.obj;
2696 switch (msg.what) {
2697 case SUPPLY_PIN_COMPLETE:
2698 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2699 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002700 mRetryCount = msg.arg1;
2701 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002702 CommandException.Error error = null;
2703 if (ar.exception instanceof CommandException) {
2704 error = ((CommandException) (ar.exception))
2705 .getCommandError();
2706 }
2707 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002708 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002709 } else if (error == CommandException.Error.ABORTED) {
2710 /* When UiccCardApp dispose, handle message and return
2711 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002712 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002713 } else {
2714 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2715 }
2716 } else {
2717 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 mDone = true;
2720 UnlockSim.this.notifyAll();
2721 }
2722 break;
2723 }
2724 }
2725 };
2726 UnlockSim.this.notifyAll();
2727 }
2728 Looper.loop();
2729 }
2730
2731 /*
2732 * Use PIN or PUK to unlock SIM card
2733 *
2734 * If PUK is null, unlock SIM card with PIN
2735 *
2736 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302737 *
2738 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2739 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 */
Wink Saville9de0f752013-10-22 19:04:03 -07002741 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742
2743 while (mHandler == null) {
2744 try {
2745 wait();
2746 } catch (InterruptedException e) {
2747 Thread.currentThread().interrupt();
2748 }
2749 }
2750 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2751
2752 if (puk == null) {
2753 mSimCard.supplyPin(pin, callback);
2754 } else {
2755 mSimCard.supplyPuk(puk, pin, callback);
2756 }
2757
2758 while (!mDone) {
2759 try {
2760 Log.d(LOG_TAG, "wait for done");
2761 wait();
2762 } catch (InterruptedException e) {
2763 // Restore the interrupted status
2764 Thread.currentThread().interrupt();
2765 }
2766 }
2767 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002768 int[] resultArray = new int[2];
2769 resultArray[0] = mResult;
2770 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002771
2772 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002773 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002774 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302775 // This instance is no longer reused, so quit its thread's looper.
2776 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002777
Wink Saville9de0f752013-10-22 19:04:03 -07002778 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780 }
2781
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002782 /**
2783 * This method has been removed due to privacy and stability concerns.
2784 */
2785 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002787 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2788 return;
Wink Saville36469e72014-06-11 15:17:00 -07002789 }
2790
Nathan Harold1f889d82020-06-04 17:05:26 -07002791 @Override
2792 public void updateServiceLocationWithPackageName(String callingPackage) {
2793 mApp.getSystemService(AppOpsManager.class)
2794 .checkPackage(Binder.getCallingUid(), callingPackage);
2795
Nathan Haroldf096d982020-11-18 17:18:06 -08002796 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002797 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2798 // Callers targeting S have no business invoking this method.
2799 return;
2800 }
2801
2802 LocationAccessPolicy.LocationPermissionResult locationResult =
2803 LocationAccessPolicy.checkLocationPermission(mApp,
2804 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2805 .setCallingPackage(callingPackage)
2806 .setCallingFeatureId(null)
2807 .setCallingPid(Binder.getCallingPid())
2808 .setCallingUid(Binder.getCallingUid())
2809 .setMethod("updateServiceLocation")
2810 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2811 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2812 .build());
2813 // Apps that lack location permission have no business calling this method;
2814 // however, because no permission was declared in the public API, denials must
2815 // all be "soft".
2816 switch (locationResult) {
2817 case DENIED_HARD: /* fall through */
2818 case DENIED_SOFT:
2819 return;
2820 }
2821
2822 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 final long identity = Binder.clearCallingIdentity();
2824 try {
Ling Mac28f0212023-03-24 16:07:15 -07002825 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 }
2830
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002831 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002832 @Override
2833 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002834 return isRadioOnWithFeature(callingPackage, null);
2835 }
2836
2837
2838 @Override
2839 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2840 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2841 callingFeatureId);
2842 }
2843
2844 @Deprecated
2845 @Override
2846 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2847 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002848 }
2849
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002850 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002851 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2852 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002854 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002855 return false;
2856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 return isRadioOnForSubscriber(subId);
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
2863 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002864 }
2865
2866 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 final Phone phone = getPhone(subId);
2870 if (phone != null) {
2871 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2872 } else {
2873 return false;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
2879
2880 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002881 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
Wink Saville36469e72014-06-11 15:17:00 -07002883
Wink Savilleb564aae2014-10-23 10:18:09 -07002884 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886
2887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 final Phone phone = getPhone(subId);
2890 if (phone != null) {
2891 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2892 }
2893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 }
Wink Saville36469e72014-06-11 15:17:00 -07002896 }
2897
2898 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002899 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002900 }
2901
Wink Savilleb564aae2014-10-23 10:18:09 -07002902 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002903 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 final Phone phone = getPhone(subId);
2908 if (phone == null) {
2909 return false;
2910 }
2911 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2912 toggleRadioOnOffForSubscriber(subId);
2913 }
2914 return true;
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 }
Wink Saville36469e72014-06-11 15:17:00 -07002919
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002920 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002921 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002922 /*
2923 * If any of the Radios are available, it will need to be
2924 * shutdown. So return true if any Radio is available.
2925 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2929 Phone phone = PhoneFactory.getPhone(i);
2930 if (phone != null && phone.isRadioAvailable()) return true;
2931 }
2932 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2933 return false;
2934 } finally {
2935 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002936 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002937 }
2938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002940 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 enforceModifyPermission();
2942
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2946 logv("Shutting down Phone " + i);
2947 shutdownRadioUsingPhoneId(i);
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002951 }
2952 }
2953
2954 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002955 Phone phone = PhoneFactory.getPhone(phoneId);
2956 if (phone != null && phone.isRadioAvailable()) {
2957 phone.shutdownRadio();
2958 }
2959 }
2960
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002962 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963
Ling Ma83dc5ea2023-01-12 15:06:04 -08002964 if (!turnOn) {
2965 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2966 }
2967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2971 if (defaultPhone != null) {
2972 defaultPhone.setRadioPower(turnOn);
2973 return true;
2974 } else {
2975 loge("There's no default phone.");
2976 return false;
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002980 }
Wink Saville36469e72014-06-11 15:17:00 -07002981 }
2982
Wink Savilleb564aae2014-10-23 10:18:09 -07002983 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
Ling Ma83dc5ea2023-01-12 15:06:04 -08002986 if (!turnOn) {
2987 log("setRadioPowerForSubscriber off: subId=" + subId
2988 + ",callingPackage=" + getCurrentPackageName());
2989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 final long identity = Binder.clearCallingIdentity();
2991 try {
2992 final Phone phone = getPhone(subId);
2993 if (phone != null) {
2994 phone.setRadioPower(turnOn);
2995 return true;
2996 } else {
2997 return false;
2998 }
2999 } finally {
3000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003002 }
3003
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003004 /**
3005 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3006 * no reason to power it off. When any of the voters want to power it off, it will be turned
3007 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3008 * powering it off, and these radio off votes will be cleared.
3009 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3010 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3011 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3012 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3013 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3014 * check its vote.
3015 *
3016 * @param subId The subscription ID.
3017 * @param reason The reason for powering off radio.
3018 * @return true on success and false on failure.
3019 */
3020 public boolean requestRadioPowerOffForReason(int subId,
3021 @TelephonyManager.RadioPowerReason int reason) {
3022 enforceModifyPermission();
3023
Ling Ma83dc5ea2023-01-12 15:06:04 -08003024 log("requestRadioPowerOffForReason: subId=" + subId
3025 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003026 final long identity = Binder.clearCallingIdentity();
3027 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003028 boolean result = false;
3029 for (Phone phone : PhoneFactory.getPhones()) {
3030 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003031 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003032 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003033 if (!result) {
3034 loge("requestRadioPowerOffForReason: no phone exists");
3035 }
3036 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
3040 }
3041
3042 /**
3043 * Remove the vote on powering off the radio for a reason, as requested by
3044 * {@link requestRadioPowerOffForReason}.
3045 *
3046 * @param subId The subscription ID.
3047 * @param reason The reason for powering off radio.
3048 * @return true on success and false on failure.
3049 */
3050 public boolean clearRadioPowerOffForReason(int subId,
3051 @TelephonyManager.RadioPowerReason int reason) {
3052 enforceModifyPermission();
3053
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003056 boolean result = false;
3057 for (Phone phone : PhoneFactory.getPhones()) {
3058 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003059 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003060 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003061 if (!result) {
3062 loge("clearRadioPowerOffForReason: no phone exists");
3063 }
3064 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 /**
3071 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3072 *
3073 * @param subId The subscription ID.
3074 * @param callingPackage The package making the call.
3075 * @param callingFeatureId The feature in the package.
3076 * @return List of reasons for powering off radio.
3077 */
3078 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3079 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3080
3081 final long identity = Binder.clearCallingIdentity();
3082 List result = new ArrayList();
3083 try {
3084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3085 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3086 return result;
3087 }
3088
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003089 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003090 if (phone != null) {
3091 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003092 } else {
3093 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 }
3095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
3098 return result;
3099 }
3100
Wink Saville36469e72014-06-11 15:17:00 -07003101 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003102 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003103 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105
3106 final long identity = Binder.clearCallingIdentity();
3107 try {
Jack Yu285100e2022-12-02 22:48:35 -08003108 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109 final Phone phone = getPhone(subId);
3110 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003111 phone.getDataSettingsManager().setDataEnabled(
3112 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 return true;
3114 } else {
3115 return false;
3116 }
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121
Wink Saville36469e72014-06-11 15:17:00 -07003122 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003123 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003124 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126
3127 final long identity = Binder.clearCallingIdentity();
3128 try {
Jack Yu285100e2022-12-02 22:48:35 -08003129 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130 final Phone phone = getPhone(subId);
3131 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003132 phone.getDataSettingsManager().setDataEnabled(
3133 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 return true;
3135 } else {
3136 return false;
3137 }
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 }
3142
Sanket Padawe356d7632015-06-22 14:03:32 -07003143 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003144 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 final Phone phone = getPhone(subId);
3148 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003149 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 } else {
3151 return false;
3152 }
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157
3158 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003159 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003160 }
3161
pkanwarae03a6b2016-11-06 20:37:09 -08003162 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003163 enforceCallPermission();
3164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3168 return;
3169 }
3170 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3171 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3172 } finally {
3173 Binder.restoreCallingIdentity(identity);
3174 }
pkanwar32d516d2016-10-14 19:37:38 -07003175 };
3176
Wink Savilleb564aae2014-10-23 10:18:09 -07003177 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179
3180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3183 return false;
3184 }
3185 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 }
3190
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003191 /**
3192 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3193 * tag on getCallState Binder call.
3194 */
3195 @Deprecated
3196 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003198 if (CompatChanges.isChangeEnabled(
3199 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3200 Binder.getCallingUid())) {
3201 // Do not allow this API to be called on API version 31+, it should only be
3202 // called on old apps using this Binder call directly.
3203 throw new SecurityException("This method can only be used for applications "
3204 + "targeting API version 30 or less.");
3205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 final long identity = Binder.clearCallingIdentity();
3207 try {
Ling Mac28f0212023-03-24 16:07:15 -07003208 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3209 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
3213 }
3214
3215 @Override
3216 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3217 if (CompatChanges.isChangeEnabled(
3218 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3219 Binder.getCallingUid())) {
3220 // Check READ_PHONE_STATE for API version 31+
3221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3222 featureId, "getCallStateForSubscription")) {
3223 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3224 + "targeting API level 31+.");
3225 }
3226 }
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3231 PhoneConstantConversions.convertCallState(phone.getState());
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 }
3236
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003238 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003239 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003240 }
3241
3242 @Override
3243 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244 final long identity = Binder.clearCallingIdentity();
3245 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003246 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003248 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249 } else {
3250 return PhoneConstantConversions.convertDataState(
3251 PhoneConstants.DataState.DISCONNECTED);
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
Sanket Padawe356d7632015-06-22 14:03:32 -07003258 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003259 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003260 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003261 }
3262
3263 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003264 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 final long identity = Binder.clearCallingIdentity();
3266 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003267 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003269 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 } else {
3271 return TelephonyManager.DATA_ACTIVITY_NONE;
3272 }
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003276 }
3277
3278 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003279 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003280 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003281 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003282
3283 LocationAccessPolicy.LocationPermissionResult locationResult =
3284 LocationAccessPolicy.checkLocationPermission(mApp,
3285 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3286 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003287 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003288 .setCallingPid(Binder.getCallingPid())
3289 .setCallingUid(Binder.getCallingUid())
3290 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003291 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003292 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3293 .build());
3294 switch (locationResult) {
3295 case DENIED_HARD:
3296 throw new SecurityException("Not allowed to access cell location");
3297 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003298 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3299 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
3301
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003306 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003307 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
Svetoslav64fad262015-04-14 14:35:21 -07003311 }
3312
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003314 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003315 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3316 // registered cell info, so return a NULL country instead.
3317 final long identity = Binder.clearCallingIdentity();
3318 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003319 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3320 // Get default phone in this case.
3321 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3322 }
Jack Yu285100e2022-12-02 22:48:35 -08003323 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003325 if (phone == null) return "";
3326 ServiceStateTracker sst = phone.getServiceStateTracker();
3327 if (sst == null) return "";
3328 LocaleTracker lt = sst.getLocaleTracker();
3329 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003330 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003334 }
3335
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003336 /**
3337 * This method was removed due to potential issues caused by performing partial
3338 * updates of service state, and lack of a credible use case.
3339 *
3340 * This has the ability to break the telephony implementation by disabling notification of
3341 * changes in device connectivity. DO NOT USE THIS!
3342 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003343 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 public void enableLocationUpdates() {
3345 mApp.enforceCallingOrSelfPermission(
3346 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003347 }
3348
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003349 /**
3350 * This method was removed due to potential issues caused by performing partial
3351 * updates of service state, and lack of a credible use case.
3352 *
3353 * This has the ability to break the telephony implementation by disabling notification of
3354 * changes in device connectivity. DO NOT USE THIS!
3355 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003356 @Override
3357 public void disableLocationUpdates() {
3358 mApp.enforceCallingOrSelfPermission(
3359 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003360 }
3361
3362 @Override
3363 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003364 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3365 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003366 try {
3367 mApp.getSystemService(AppOpsManager.class)
3368 .checkPackage(Binder.getCallingUid(), callingPackage);
3369 } catch (SecurityException e) {
3370 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3371 throw e;
3372 }
3373
Nathan Haroldf096d982020-11-18 17:18:06 -08003374 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003375 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3376 throw new SecurityException(
3377 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3378 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003379
Jordan Liu1617b712019-07-10 15:06:26 -07003380 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003381 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3382 return null;
3383 }
Svetoslav64fad262015-04-14 14:35:21 -07003384
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003385 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003387 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003388 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389
Nathan Haroldf180aac2018-06-01 18:43:55 -07003390 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3391 for (CellInfo ci : info) {
3392 if (ci instanceof CellInfoGsm) {
3393 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3394 } else if (ci instanceof CellInfoWcdma) {
3395 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003398 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 }
3400
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003401 private List<CellInfo> getCachedCellInfo() {
3402 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3403 for (Phone phone : PhoneFactory.getPhones()) {
3404 List<CellInfo> info = phone.getAllCellInfo();
3405 if (info != null) cellInfos.addAll(info);
3406 }
3407 return cellInfos;
3408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003409
3410 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003411 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003412 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003413 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003414
3415 LocationAccessPolicy.LocationPermissionResult locationResult =
3416 LocationAccessPolicy.checkLocationPermission(mApp,
3417 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3418 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003419 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003420 .setCallingPid(Binder.getCallingPid())
3421 .setCallingUid(Binder.getCallingUid())
3422 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003423 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003424 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3425 .build());
3426 switch (locationResult) {
3427 case DENIED_HARD:
3428 throw new SecurityException("Not allowed to access cell info");
3429 case DENIED_SOFT:
3430 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 }
3432
Nathan Haroldf096d982020-11-18 17:18:06 -08003433 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003434 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3435 return getCachedCellInfo();
3436 }
3437
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003438 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003439 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3443 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003444 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003445 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 if (info != null) cellInfos.addAll(info);
3447 }
3448 return cellInfos;
3449 } finally {
3450 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 }
3452 }
3453
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003454 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003455 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3456 String callingFeatureId) {
3457 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3458 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003459 }
3460
3461 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003462 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3463 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003464 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003465 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003466 }
3467
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003468 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3469 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003470 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003471 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003472
3473 LocationAccessPolicy.LocationPermissionResult locationResult =
3474 LocationAccessPolicy.checkLocationPermission(mApp,
3475 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3476 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003477 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003478 .setCallingPid(Binder.getCallingPid())
3479 .setCallingUid(Binder.getCallingUid())
3480 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003481 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3482 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003483 .build());
3484 switch (locationResult) {
3485 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003486 if (TelephonyPermissions
3487 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003488 // Safetynet logging for b/154934934
3489 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3490 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003491 throw new SecurityException("Not allowed to access cell info");
3492 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003493 if (TelephonyPermissions
3494 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003495 // Safetynet logging for b/154934934
3496 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3497 }
Nathan Harold5320c422019-05-09 10:26:08 -07003498 try {
3499 cb.onCellInfo(new ArrayList<CellInfo>());
3500 } catch (RemoteException re) {
3501 // Drop without consequences
3502 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003503 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003504 }
3505
Nathan Harolda939a962019-05-09 10:13:47 -07003506
3507 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003508 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3509
3510 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3511 }
3512
3513 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003514 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003515 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003516 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517
3518 final long identity = Binder.clearCallingIdentity();
3519 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003520 Phone phone = getPhone(subId);
3521 if (phone == null) {
3522 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3523 } else {
3524 phone.setCellInfoListRate(rateInMillis, workSource);
3525 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003526 } finally {
3527 Binder.restoreCallingIdentity(identity);
3528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 }
3530
Shishir Agrawala9f32182016-04-12 12:00:16 -07003531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003532 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003533 Phone phone = PhoneFactory.getPhone(slotIndex);
3534 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003535 return null;
3536 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003538 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003539 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003540 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 return null;
3542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 return phone.getImei();
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
3549 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003550 }
3551
3552 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003553 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3554 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3555 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3556 callingFeatureId, "getPrimaryImei")) {
3557 throw new SecurityException("Caller does not have permission");
3558 }
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 for (Phone phone : PhoneFactory.getPhones()) {
3562 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3563 return phone.getImei();
3564 }
3565 }
3566 throw new UnsupportedOperationException("Operation not supported");
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
3569 }
3570 }
3571
3572 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003573 public String getTypeAllocationCodeForSlot(int slotIndex) {
3574 Phone phone = PhoneFactory.getPhone(slotIndex);
3575 String tac = null;
3576 if (phone != null) {
3577 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003578 try {
3579 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3580 } catch (IndexOutOfBoundsException e) {
3581 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3582 return null;
3583 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003584 }
3585 return tac;
3586 }
3587
3588 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003589 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003590 try {
3591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3592 } catch (SecurityException se) {
3593 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3594 throw new SecurityException("Package " + callingPackage + " does not belong to "
3595 + Binder.getCallingUid());
3596 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003597 Phone phone = PhoneFactory.getPhone(slotIndex);
3598 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003599 return null;
3600 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601
Jeff Davidson913390f2018-02-23 17:11:49 -08003602 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003603 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003604 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003605 return null;
3606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607
3608 final long identity = Binder.clearCallingIdentity();
3609 try {
3610 return phone.getMeid();
3611 } finally {
3612 Binder.restoreCallingIdentity(identity);
3613 }
Jack Yu2af8d712017-03-15 17:14:14 -07003614 }
3615
3616 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003617 public String getManufacturerCodeForSlot(int slotIndex) {
3618 Phone phone = PhoneFactory.getPhone(slotIndex);
3619 String manufacturerCode = null;
3620 if (phone != null) {
3621 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003622 try {
3623 manufacturerCode =
3624 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3625 } catch (IndexOutOfBoundsException e) {
3626 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3627 return null;
3628 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003629 }
3630 return manufacturerCode;
3631 }
3632
3633 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003634 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3635 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003636 Phone phone = PhoneFactory.getPhone(slotIndex);
3637 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003638 return null;
3639 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 int subId = phone.getSubId();
3641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003642 mApp, subId, callingPackage, callingFeatureId,
3643 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 return null;
3645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 return phone.getDeviceSvn();
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003653 }
3654
fionaxu43304da2017-11-27 22:51:16 -08003655 @Override
3656 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 final long identity = Binder.clearCallingIdentity();
3658 try {
3659 final Phone phone = getPhone(subId);
3660 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
fionaxu43304da2017-11-27 22:51:16 -08003664 }
3665
3666 @Override
3667 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 final Phone phone = getPhone(subId);
3671 return phone == null ? null : phone.getCarrierName();
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
fionaxu43304da2017-11-27 22:51:16 -08003675 }
3676
calvinpanffe225e2018-11-01 19:43:06 +08003677 @Override
chen xu0026ca62019-03-06 15:28:50 -08003678 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 final Phone phone = getPhone(subId);
3682 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003683 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
3687 }
3688
3689 @Override
chen xu0026ca62019-03-06 15:28:50 -08003690 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003694 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
3698 }
3699
chen xu651eec72018-11-11 19:03:44 -08003700 @Override
chen xu864e11c2018-12-06 22:10:03 -08003701 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3702 if (!isSubscriptionMccMnc) {
3703 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3704 }
chen xu651eec72018-11-11 19:03:44 -08003705 final Phone phone = PhoneFactory.getPhone(slotIndex);
3706 if (phone == null) {
3707 return TelephonyManager.UNKNOWN_CARRIER_ID;
3708 }
3709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003717 //
3718 // Internal helper methods.
3719 //
3720
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003721 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003722 * Make sure the caller is the calling package itself
3723 *
3724 * @throws SecurityException if the caller is not the calling package
3725 */
3726 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3727 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003728 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3729 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003730 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003731 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003732 } catch (PackageManager.NameNotFoundException e) {
3733 // packageUid is -1
3734 }
3735 if (packageUid != callingUid) {
3736 throw new SecurityException(message + ": Package " + callingPackage
3737 + " does not belong to " + callingUid);
3738 }
3739 }
3740
3741 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003742 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3743 *
3744 * @throws SecurityException if the caller does not have the required permission
3745 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003746 @VisibleForTesting
3747 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003748 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3749 }
3750
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003751 /**
arunvoddud7401012022-12-15 16:08:12 +00003752 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003753 *
3754 * @throws SecurityException if the caller does not have the required permission
3755 */
3756 @VisibleForTesting
3757 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003758 enforceReadPermission(null);
3759 }
3760
3761 /**
3762 * Make sure the caller has the READ_PHONE_STATE permissions.
3763 *
3764 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3765 */
3766 @VisibleForTesting
3767 public void enforceReadPermission(String msg) {
3768 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003769 }
3770
Shuo Qian3b6ee772019-11-13 17:43:31 -08003771 private void enforceActiveEmergencySessionPermission() {
3772 mApp.enforceCallingOrSelfPermission(
3773 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3774 }
3775
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003776 /**
3777 * Make sure the caller has the CALL_PHONE permission.
3778 *
3779 * @throws SecurityException if the caller does not have the required permission
3780 */
3781 private void enforceCallPermission() {
3782 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3783 }
3784
paulhu5a773602019-08-23 19:17:33 +08003785 private void enforceSettingsPermission() {
3786 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003787 }
3788
Michele Berionne5e411512020-11-13 02:36:59 +00003789 private void enforceRebootPermission() {
3790 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3791 }
3792
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003793 /**
3794 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3795 * @param message - log message to print.
3796 * @throws SecurityException if the caller does not have the required permission
3797 */
3798 private void enforceSatelliteCommunicationPermission(String message) {
3799 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3800 }
3801
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003802 private String createTelUrl(String number) {
3803 if (TextUtils.isEmpty(number)) {
3804 return null;
3805 }
3806
Jake Hambye994d462014-02-03 13:10:13 -08003807 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003808 }
3809
Ihab Awadf9e92732013-12-05 18:02:52 -08003810 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003811 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 }
3813
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003814 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003815 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003816 }
3817
Ihab Awadf9e92732013-12-05 18:02:52 -08003818 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003819 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003820 }
3821
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003822 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003823 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003824 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003825 }
3826
Sanket Padawe356d7632015-06-22 14:03:32 -07003827 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003828 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 final Phone phone = PhoneFactory.getPhone(slotIndex);
3832 if (phone == null) {
3833 return PhoneConstants.PHONE_TYPE_NONE;
3834 } else {
3835 return phone.getPhoneType();
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003840 }
3841
3842 /**
3843 * Returns the CDMA ERI icon index to display
3844 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003846 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3847 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3848 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003849 }
3850
Sanket Padawe356d7632015-06-22 14:03:32 -07003851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003852 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3853 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003855 mApp, subId, callingPackage, callingFeatureId,
3856 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003857 return -1;
3858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859
3860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 final Phone phone = getPhone(subId);
3863 if (phone != null) {
3864 return phone.getCdmaEriIconIndex();
3865 } else {
3866 return -1;
3867 }
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003871 }
3872
3873 /**
3874 * Returns the CDMA ERI icon mode,
3875 * 0 - ON
3876 * 1 - FLASHING
3877 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003878 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003879 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3880 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3881 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003882 }
3883
Sanket Padawe356d7632015-06-22 14:03:32 -07003884 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003885 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3886 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003888 mApp, subId, callingPackage, callingFeatureId,
3889 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003890 return -1;
3891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 final Phone phone = getPhone(subId);
3896 if (phone != null) {
3897 return phone.getCdmaEriIconMode();
3898 } else {
3899 return -1;
3900 }
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003904 }
3905
3906 /**
3907 * Returns the CDMA ERI text,
3908 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003910 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3911 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3912 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003913 }
3914
Sanket Padawe356d7632015-06-22 14:03:32 -07003915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003916 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3917 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003919 mApp, subId, callingPackage, callingFeatureId,
3920 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003921 return null;
3922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 final Phone phone = getPhone(subId);
3927 if (phone != null) {
3928 return phone.getCdmaEriText();
3929 } else {
3930 return null;
3931 }
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003934 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003935 }
3936
3937 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003938 * Returns the CDMA MDN.
3939 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003940 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003941 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3943 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944
3945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003948 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 return phone.getLine1Number();
3950 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003951 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 return null;
3953 }
3954 } finally {
3955 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003956 }
3957 }
3958
3959 /**
3960 * Returns the CDMA MIN.
3961 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003962 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003963 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3965 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966
3967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 final Phone phone = getPhone(subId);
3970 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3971 return phone.getCdmaMin();
3972 } else {
3973 return null;
3974 }
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003977 }
3978 }
3979
Hall Liud892bec2018-11-30 14:51:45 -08003980 @Override
3981 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3982 INumberVerificationCallback callback, String callingPackage) {
3983 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3984 != PERMISSION_GRANTED) {
3985 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3986 }
3987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3988
3989 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3990 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003991 throw new SecurityException("Calling package must be configured in the device config: "
3992 + "calling package: " + callingPackage
3993 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003994 }
3995
3996 if (range == null) {
3997 throw new NullPointerException("Range must be non-null");
3998 }
3999
4000 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004001 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004002
4003 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4004 }
4005
Junda Liuca05d5d2014-08-14 22:36:34 -07004006 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004007 * Returns true if CDMA provisioning needs to run.
4008 */
4009 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 final long identity = Binder.clearCallingIdentity();
4011 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004012 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004016 }
4017
4018 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004019 * Sets the voice mail number of a given subId.
4020 */
4021 @Override
4022 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004023 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4024 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025
4026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4029 new Pair<String, String>(alphaTag, number), new Integer(subId));
4030 return success;
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004034 }
4035
Ta-wei Yen87c49842016-05-13 21:19:52 -07004036 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004037 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4038 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004039 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4040 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004041 if (!TextUtils.equals(callingPackage, systemDialer)) {
4042 throw new SecurityException("caller must be system dialer");
4043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044
4045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4048 if (phoneAccountHandle == null) {
4049 return null;
4050 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004051 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 } finally {
4053 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004054 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004055 }
4056
4057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004058 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4059 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004060 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004062 mApp, subId, callingPackage, callingFeatureId,
4063 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004064 return null;
4065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004066
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004067 final long identity = Binder.clearCallingIdentity();
4068 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004069 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004073 }
4074
4075 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004076 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4077 VisualVoicemailSmsFilterSettings settings) {
4078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079
4080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004083 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004087 }
4088
4089 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004090 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4091 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092
4093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004096 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 } finally {
4098 Binder.restoreCallingIdentity(identity);
4099 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004100 }
4101
4102 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004103 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4104 String callingPackage, int subId) {
4105 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106
4107 final long identity = Binder.clearCallingIdentity();
4108 try {
4109 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004114 }
4115
4116 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004117 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004119
4120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004123 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004127 }
4128
4129 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004130 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4131 String callingAttributionTag, int subId, String number, int port, String text,
4132 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004134 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004135 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004136 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004137 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4138 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004139 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004140
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004141 /**
fionaxu0152e512016-11-14 13:36:14 -08004142 * Sets the voice activation state of a given subId.
4143 */
4144 @Override
4145 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4147 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148
4149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 final Phone phone = getPhone(subId);
4152 if (phone != null) {
4153 phone.setVoiceActivationState(activationState);
4154 } else {
4155 loge("setVoiceActivationState fails with invalid subId: " + subId);
4156 }
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004159 }
4160 }
4161
4162 /**
4163 * Sets the data activation state of a given subId.
4164 */
4165 @Override
4166 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4168 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169
4170 final long identity = Binder.clearCallingIdentity();
4171 try {
4172 final Phone phone = getPhone(subId);
4173 if (phone != null) {
4174 phone.setDataActivationState(activationState);
4175 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004176 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 }
4178 } finally {
4179 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004180 }
4181 }
4182
4183 /**
4184 * Returns the voice activation state of a given subId.
4185 */
4186 @Override
4187 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189
fionaxu0152e512016-11-14 13:36:14 -08004190 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 if (phone != null) {
4194 return phone.getVoiceActivationState();
4195 } else {
4196 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4197 }
4198 } finally {
4199 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004200 }
4201 }
4202
4203 /**
4204 * Returns the data activation state of a given subId.
4205 */
4206 @Override
4207 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209
fionaxu0152e512016-11-14 13:36:14 -08004210 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
4213 if (phone != null) {
4214 return phone.getDataActivationState();
4215 } else {
4216 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4217 }
4218 } finally {
4219 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004220 }
4221 }
4222
4223 /**
Wink Saville36469e72014-06-11 15:17:00 -07004224 * Returns the unread count of voicemails for a subId
4225 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004226 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004227 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4228 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 mApp, subId, callingPackage, callingFeatureId,
4231 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004232 return 0;
4233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004234 final long identity = Binder.clearCallingIdentity();
4235 try {
4236 final Phone phone = getPhone(subId);
4237 if (phone != null) {
4238 return phone.getVoiceMessageCount();
4239 } else {
4240 return 0;
4241 }
4242 } finally {
4243 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004245 }
4246
4247 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004248 * returns true, if the device is in a state where both voice and data
4249 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004250 */
4251 @Override
4252 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 final long identity = Binder.clearCallingIdentity();
4254 try {
Ling Mac28f0212023-03-24 16:07:15 -07004255 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004259 }
4260
4261 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004262 * Send the dialer code if called from the current default dialer or the caller has
4263 * carrier privilege.
4264 * @param inputCode The dialer code to send
4265 */
4266 @Override
4267 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004268 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004270 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4271 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004272 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004273 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004274 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004279 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
fionaxu235cc5e2017-03-06 22:25:57 -08004283 }
4284
Pengquan Menga1bb6272018-09-06 09:59:22 -07004285 @Override
4286 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004287 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004288 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4289 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 if (!isActiveSubscription(subId)) {
4293 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4294 }
4295 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4296 } finally {
4297 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004299 }
4300
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004302 public boolean isInEmergencySmsMode() {
4303 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4304 final long identity = Binder.clearCallingIdentity();
4305 try {
4306 for (Phone phone : PhoneFactory.getPhones()) {
4307 if (phone.isInEmergencySmsMode()) {
4308 return true;
4309 }
4310 }
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
4314 return false;
4315 }
4316
shilu366312e2019-12-17 09:28:10 -08004317 /**
4318 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4319 * @param subId The subscription to use to check the configuration.
4320 * @param c The callback that will be used to send the result.
4321 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004322 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004323 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4324 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004325 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004326 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004327
4328 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4329 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4330 "IMS not available on device.");
4331 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 final long token = Binder.clearCallingIdentity();
4333 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004334 int slotId = getSlotIndexOrException(subId);
4335 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004336
4337 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4338 if (controller != null) {
4339 ImsManager imsManager = controller.getImsManager(subId);
4340 if (imsManager != null) {
4341 imsManager.addRegistrationCallbackForSubscription(c, subId);
4342 } else {
4343 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4344 }
4345 } else {
4346 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4347 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004348 } catch (ImsException e) {
4349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 } finally {
4351 Binder.restoreCallingIdentity(token);
4352 }
4353 }
4354
shilu366312e2019-12-17 09:28:10 -08004355 /**
4356 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4357 * @param subId The subscription to use to check the configuration.
4358 * @param c The callback that will be used to send the result.
4359 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004361 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004362 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004363 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004364 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4365 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4366 }
Meng Wangafbc5852019-09-19 17:37:13 -07004367 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004368
Meng Wangafbc5852019-09-19 17:37:13 -07004369 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004370 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4371 if (controller != null) {
4372 ImsManager imsManager = controller.getImsManager(subId);
4373 if (imsManager != null) {
4374 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4375 } else {
4376 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4377 + "is inactive, ignoring unregister.");
4378 // If the ImsManager is not valid, just return, since the callback
4379 // will already have been removed internally.
4380 }
4381 }
Meng Wangafbc5852019-09-19 17:37:13 -07004382 } finally {
4383 Binder.restoreCallingIdentity(token);
4384 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 }
4386
Brad Ebingera34a6c22019-10-22 17:36:18 -07004387 /**
4388 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4389 */
4390 @Override
4391 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4392 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4393 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4394 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4395 "IMS not available on device.");
4396 }
4397 final long token = Binder.clearCallingIdentity();
4398 try {
4399 Phone phone = getPhone(subId);
4400 if (phone == null) {
4401 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4402 + subId + "'");
4403 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4404 }
4405 phone.getImsRegistrationState(regState -> {
4406 try {
4407 consumer.accept((regState == null)
4408 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4409 } catch (RemoteException e) {
4410 // Ignore if the remote process is no longer available to call back.
4411 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4412 }
4413 });
4414 } finally {
4415 Binder.restoreCallingIdentity(token);
4416 }
4417 }
4418
4419 /**
4420 * Get the transport type for the IMS service registration state.
4421 */
4422 @Override
4423 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004424 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004425 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004426 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4427 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4428 "IMS not available on device.");
4429 }
4430 final long token = Binder.clearCallingIdentity();
4431 try {
4432 Phone phone = getPhone(subId);
4433 if (phone == null) {
4434 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4435 + subId + "'");
4436 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4437 }
4438 phone.getImsRegistrationTech(regTech -> {
4439 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4440 int regTechConverted = (regTech == null)
4441 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4442 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4443 regTechConverted);
4444 try {
4445 consumer.accept(regTechConverted);
4446 } catch (RemoteException e) {
4447 // Ignore if the remote process is no longer available to call back.
4448 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4449 }
4450 });
4451 } finally {
4452 Binder.restoreCallingIdentity(token);
4453 }
4454 }
4455
shilu366312e2019-12-17 09:28:10 -08004456 /**
4457 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4458 * @param subId The subscription to use to check the configuration.
4459 * @param c The callback that will be used to send the result.
4460 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004462 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4463 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004464 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004465 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004466 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4467 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4468 "IMS not available on device.");
4469 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 final long token = Binder.clearCallingIdentity();
4471 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004472 int slotId = getSlotIndexOrException(subId);
4473 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004474
4475 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4476 if (controller != null) {
4477 ImsManager imsManager = controller.getImsManager(subId);
4478 if (imsManager != null) {
4479 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4480 } else {
4481 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4482 }
4483 } else {
4484 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4485 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004486 } catch (ImsException e) {
4487 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 } finally {
4489 Binder.restoreCallingIdentity(token);
4490 }
4491 }
4492
shilu366312e2019-12-17 09:28:10 -08004493 /**
4494 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4495 * @param subId The subscription to use to check the configuration.
4496 * @param c The callback that will be used to send the result.
4497 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004499 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004501 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004502 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4503 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4504 }
Meng Wangafbc5852019-09-19 17:37:13 -07004505
4506 final long token = Binder.clearCallingIdentity();
4507 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004508 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4509 if (controller != null) {
4510 ImsManager imsManager = controller.getImsManager(subId);
4511 if (imsManager != null) {
4512 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4513 } else {
4514 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4515 + " is inactive, ignoring unregister.");
4516 // If the ImsManager is not valid, just return, since the callback
4517 // will already have been removed internally.
4518 }
4519 }
Meng Wangafbc5852019-09-19 17:37:13 -07004520 } finally {
4521 Binder.restoreCallingIdentity(token);
4522 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 }
4524
4525 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004526 public boolean isCapable(int subId, int capability, int regTech) {
4527 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 final long token = Binder.clearCallingIdentity();
4529 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004530 int slotId = getSlotIndexOrException(subId);
4531 verifyImsMmTelConfiguredOrThrow(slotId);
4532 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4533 } catch (com.android.ims.ImsException e) {
4534 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4535 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004536 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004537 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4538 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004539 } finally {
4540 Binder.restoreCallingIdentity(token);
4541 }
4542 }
4543
4544 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004545 public boolean isAvailable(int subId, int capability, int regTech) {
4546 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 final long token = Binder.clearCallingIdentity();
4548 try {
4549 Phone phone = getPhone(subId);
4550 if (phone == null) return false;
4551 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004552 } catch (com.android.ims.ImsException e) {
4553 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4554 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004555 } finally {
4556 Binder.restoreCallingIdentity(token);
4557 }
4558 }
4559
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004560 /**
4561 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4562 * subscription.
4563 * @param subId The subscription to use to check the configuration.
4564 * @param callback The callback that will be used to send the result.
4565 * @param capability The MmTelFeature capability that will be used to send the result.
4566 * @param transportType The transport type of the MmTelFeature capability.
4567 */
4568 @Override
4569 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4570 int transportType) {
4571 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004572 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4573 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4574 "IMS not available on device.");
4575 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004576 final long token = Binder.clearCallingIdentity();
4577 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004578 int slotId = getSlotIndex(subId);
4579 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4580 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4581 + subId + "'");
4582 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4583 }
4584 verifyImsMmTelConfiguredOrThrow(slotId);
4585 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4586 transportType, aBoolean -> {
4587 try {
4588 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4589 } catch (RemoteException e) {
4590 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4591 + "running. Ignore");
4592 }
4593 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 } catch (ImsException e) {
4595 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004596 } finally {
4597 Binder.restoreCallingIdentity(token);
4598 }
4599 }
4600
shilu366312e2019-12-17 09:28:10 -08004601 /**
4602 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4603 * @param subId The subscription to use to check the configuration.
4604 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004605 @Override
4606 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004607 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004608 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004609
Brad Ebinger35c841c2018-10-01 10:40:55 -07004610 final long token = Binder.clearCallingIdentity();
4611 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004612 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004613 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004614 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004615 } catch (ImsException e) {
4616 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004617 } finally {
4618 Binder.restoreCallingIdentity(token);
4619 }
4620 }
4621
4622 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004623 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004625 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004626 final long identity = Binder.clearCallingIdentity();
4627 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004628 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004629 // This setting doesn't require an active ImsService connection, so do not verify. The
4630 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004631 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004632 } catch (ImsException e) {
4633 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
4637 }
4638
shilu366312e2019-12-17 09:28:10 -08004639 /**
4640 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4641 * @param subId The subscription to use to check the configuration.
4642 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004643 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004644 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004645 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004646 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004647 final long identity = Binder.clearCallingIdentity();
4648 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004649 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004650 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004651 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004652 } catch (ImsException e) {
4653 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
4657 }
4658
4659 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004660 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004662 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 final long identity = Binder.clearCallingIdentity();
4664 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004665 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004666 // This setting doesn't require an active ImsService connection, so do not verify. The
4667 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004668 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004669 } catch (ImsException e) {
4670 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004671 } finally {
4672 Binder.restoreCallingIdentity(identity);
4673 }
4674 }
4675
shilu366312e2019-12-17 09:28:10 -08004676 /**
4677 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4678 * @param subId The subscription to use to check the configuration.
4679 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004680 @Override
4681 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004682 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004683 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004684 final long identity = 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).isWfcEnabledByUser();
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(identity);
4693 }
4694 }
4695
4696 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004697 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004699 "setVoWiFiSettingEnabled");
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).setWfcSetting(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 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004714 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4715 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4716 * @param subId The subscription to use to check the configuration.
4717 */
4718 @Override
4719 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004720 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004721 mApp, subId, "isCrossSimCallingEnabledByUser");
4722 final long identity = Binder.clearCallingIdentity();
4723 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004724 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004725 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004726 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004727 } catch (ImsException e) {
4728 throw new ServiceSpecificException(e.getCode());
4729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
4732 }
4733
4734 /**
4735 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4736 * Requires MODIFY_PHONE_STATE permission.
4737 * @param subId The subscription to use to check the configuration.
4738 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4739 * false otherwise
4740 */
4741 @Override
4742 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4744 "setCrossSimCallingEnabled");
4745 final long identity = Binder.clearCallingIdentity();
4746 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004747 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004748 // This setting doesn't require an active ImsService connection, so do not verify. The
4749 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004750 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004751 } catch (ImsException e) {
4752 throw new ServiceSpecificException(e.getCode());
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
4756 }
4757
4758 /**
shilu366312e2019-12-17 09:28:10 -08004759 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4760 * @param subId The subscription to use to check the configuration.
4761 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004762 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004763
Brad Ebinger35c841c2018-10-01 10:40:55 -07004764 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004765 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004766 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 final long identity = Binder.clearCallingIdentity();
4768 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004769 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004770 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004771 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004772 } catch (ImsException e) {
4773 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004774 } finally {
4775 Binder.restoreCallingIdentity(identity);
4776 }
4777 }
4778
4779 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004780 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004782 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004783 final long identity = Binder.clearCallingIdentity();
4784 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004785 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004786 // This setting doesn't require an active ImsService connection, so do not verify. The
4787 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004788 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004789 } catch (ImsException e) {
4790 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004791 } finally {
4792 Binder.restoreCallingIdentity(identity);
4793 }
4794 }
4795
4796 @Override
4797 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4799 "setVoWiFiNonPersistent");
4800 final long identity = Binder.clearCallingIdentity();
4801 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004802 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004803 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004804 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004805 } catch (ImsException e) {
4806 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
4810 }
4811
shilu366312e2019-12-17 09:28:10 -08004812 /**
4813 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4814 * @param subId The subscription to use to check the configuration.
4815 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004816 @Override
4817 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004818 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004819 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004820 final long identity = Binder.clearCallingIdentity();
4821 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004822 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004823 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004824 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004825 } catch (ImsException e) {
4826 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
4830 }
4831
4832 @Override
4833 public void setVoWiFiModeSetting(int subId, int mode) {
4834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4835 "setVoWiFiModeSetting");
4836 final long identity = Binder.clearCallingIdentity();
4837 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004838 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004839 // This setting doesn't require an active ImsService connection, so do not verify. The
4840 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004841 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004842 } catch (ImsException e) {
4843 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004844 } finally {
4845 Binder.restoreCallingIdentity(identity);
4846 }
4847 }
4848
4849 @Override
4850 public int getVoWiFiRoamingModeSetting(int subId) {
4851 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4852 final long identity = Binder.clearCallingIdentity();
4853 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004854 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004855 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004856 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004857 } catch (ImsException e) {
4858 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004859 } finally {
4860 Binder.restoreCallingIdentity(identity);
4861 }
4862 }
4863
4864 @Override
4865 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4867 "setVoWiFiRoamingModeSetting");
4868 final long identity = Binder.clearCallingIdentity();
4869 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004870 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004871 // This setting doesn't require an active ImsService connection, so do not verify. The
4872 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004873 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004874 } catch (ImsException e) {
4875 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
4879 }
4880
4881 @Override
4882 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4884 "setRttCapabilityEnabled");
4885 final long identity = Binder.clearCallingIdentity();
4886 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004887 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004888 // This setting doesn't require an active ImsService connection, so do not verify. The
4889 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004890 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004891 } catch (ImsException e) {
4892 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
4896 }
4897
shilu366312e2019-12-17 09:28:10 -08004898 /**
4899 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4900 * @param subId The subscription to use to check the configuration.
4901 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 @Override
4903 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004904 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004905 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004906 final long identity = Binder.clearCallingIdentity();
4907 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004908 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004909 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004910 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004911 } catch (ImsException e) {
4912 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
4916 }
4917
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004918 @Override
4919 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4920 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004921
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 final long identity = Binder.clearCallingIdentity();
4923 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004924 if (!isImsAvailableOnDevice()) {
4925 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4926 "IMS not available on device.");
4927 }
4928 int slotId = getSlotIndexOrException(subId);
4929 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004930
4931 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4932 if (controller != null) {
4933 ImsManager imsManager = controller.getImsManager(subId);
4934 if (imsManager != null) {
4935 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4936 } else {
4937 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4938 }
4939 } else {
4940 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4941 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004942 } catch (ImsException e) {
4943 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
4947 }
4948
4949 @Override
4950 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4951 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004952
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004953 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004954 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4955 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4956 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004957 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004958 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4959 if (controller != null) {
4960 ImsManager imsManager = controller.getImsManager(subId);
4961 if (imsManager != null) {
4962 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4963 } else {
4964 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4965 + " is inactive, ignoring unregister.");
4966 // If the ImsManager is not valid, just return, since the callback will already
4967 // have been removed internally.
4968 }
4969 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
4973 }
4974
joonhunshincffb7fc2021-11-28 07:32:01 +00004975 @Override
4976 public void registerFeatureProvisioningChangedCallback(int subId,
4977 IFeatureProvisioningCallback callback) {
4978 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4979 mApp, subId, "registerFeatureProvisioningChangedCallback");
4980
4981 final long identity = Binder.clearCallingIdentity();
4982 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4983 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4984 }
4985
joonhunshin91bc1952022-04-29 08:47:15 +00004986 try {
4987 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4988 if (controller == null) {
4989 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4990 "Device does not support IMS");
4991 }
4992 controller.addFeatureProvisioningChangedCallback(subId, callback);
4993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004996 }
4997
4998 @Override
4999 public void unregisterFeatureProvisioningChangedCallback(int subId,
5000 IFeatureProvisioningCallback callback) {
5001 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5002 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5003
5004 final long identity = Binder.clearCallingIdentity();
5005 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5006 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5007 }
5008
joonhunshin91bc1952022-04-29 08:47:15 +00005009 try {
5010 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5011 if (controller == null) {
5012 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5013 return;
5014 }
5015 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5016 } finally {
5017 Binder.restoreCallingIdentity(identity);
5018 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005019 }
allenwtsu99c623b2020-01-03 18:24:23 +08005020
5021 private void checkModifyPhoneStatePermission(int subId, String message) {
5022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5023 message);
5024 }
5025
allenwtsu99c623b2020-01-03 18:24:23 +08005026 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005027 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005028 boolean isProvisioned) {
5029 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5030
5031 final long identity = Binder.clearCallingIdentity();
5032 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005033 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5034 if (controller == null) {
5035 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5036 return;
5037 }
5038 controller.setRcsProvisioningStatusForCapability(
5039 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005040 } finally {
5041 Binder.restoreCallingIdentity(identity);
5042 }
allenwtsu99c623b2020-01-03 18:24:23 +08005043 }
5044
5045
5046 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005047 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5048 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5049 mApp, subId, "getRcsProvisioningStatusForCapability");
5050
allenwtsu99c623b2020-01-03 18:24:23 +08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005053 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5054 if (controller == null) {
5055 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5056
5057 // device does not support IMS, this method will return true always.
5058 return true;
5059 }
5060 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005061 } finally {
5062 Binder.restoreCallingIdentity(identity);
5063 }
5064 }
5065
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005066 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005067 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5068 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005069 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005070
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005073 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5074 if (controller == null) {
5075 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5076 return;
5077 }
5078 controller.setImsProvisioningStatusForCapability(
5079 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005080 } finally {
5081 Binder.restoreCallingIdentity(identity);
5082 }
5083 }
5084
5085 @Override
5086 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005087 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5088 mApp, subId, "getProvisioningStatusForCapability");
5089
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005092 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5093 if (controller == null) {
5094 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005095
joonhunshin91bc1952022-04-29 08:47:15 +00005096 // device does not support IMS, this method will return true always.
5097 return true;
5098 }
5099 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
5103 }
5104
5105 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005106 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5107 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5108 mApp, subId, "isProvisioningRequiredForCapability");
5109
5110 final long identity = Binder.clearCallingIdentity();
5111 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005112 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5113 if (controller == null) {
5114 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5115
5116 // device does not support IMS, this method will return false
5117 return false;
5118 }
5119 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005120 } finally {
5121 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005122 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005123 }
5124
5125 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005126 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5127 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5128 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005129
joonhunshincffb7fc2021-11-28 07:32:01 +00005130 final long identity = Binder.clearCallingIdentity();
5131 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005132 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5133 if (controller == null) {
5134 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5135
5136 // device does not support IMS, this method will return false
5137 return false;
5138 }
5139 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005143 }
5144
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005145 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005146 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005147 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5148 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5149 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005150 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5151 mApp, subId, "getImsProvisioningInt");
5152
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005156 int slotId = getSlotIndex(subId);
5157 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5158 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5159 + subId + "' for key:" + key);
5160 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5161 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005162
joonhunshin91bc1952022-04-29 08:47:15 +00005163 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5164 if (controller == null) {
5165 loge("getImsProvisioningInt: Device does not support IMS");
5166
5167 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5168 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5169 }
5170 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005171 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5172 return retVal;
5173 }
5174
calvinpanb5a34062021-02-08 19:59:36 +08005175 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005176 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005177 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5178 + subId + "' for key:" + key);
5179 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
5183 }
5184
5185 @Override
5186 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005187 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5188 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5189 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005190 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5191 mApp, subId, "getImsProvisioningString");
5192
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005193 final long identity = Binder.clearCallingIdentity();
5194 try {
5195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005196 int slotId = getSlotIndex(subId);
5197 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5198 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5199 + subId + "' for key:" + key);
5200 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5201 }
calvinpanb5a34062021-02-08 19:59:36 +08005202 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005203 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005204 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5205 + subId + "' for key:" + key);
5206 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
5210 }
5211
5212 @Override
5213 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005214 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5215 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5216 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5218 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005219
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005220 final long identity = Binder.clearCallingIdentity();
5221 try {
5222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005223 int slotId = getSlotIndex(subId);
5224 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5225 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5226 + subId + "' for key:" + key);
5227 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5228 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005229
joonhunshin91bc1952022-04-29 08:47:15 +00005230 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5231 if (controller == null) {
5232 loge("setImsProvisioningInt: Device does not support IMS");
5233
5234 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5235 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5236 }
5237 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005238 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5239 return retVal;
5240 }
5241
calvinpanb5a34062021-02-08 19:59:36 +08005242 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5243 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005244 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005245 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005246 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
5250 }
5251
5252 @Override
5253 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005254 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5255 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5256 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5258 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005259 final long identity = Binder.clearCallingIdentity();
5260 try {
5261 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005262 int slotId = getSlotIndex(subId);
5263 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5264 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5265 + subId + "' for key:" + key);
5266 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5267 }
calvinpanb5a34062021-02-08 19:59:36 +08005268 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5269 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005270 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005271 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005272 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
5276 }
5277
Brad Ebinger919631e2021-06-02 17:46:35 -07005278 /**
5279 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5280 * for the given slot ID or no ImsResolver instance has been created.
5281 * @param slotId The slot ID that the IMS service is created for.
5282 * @throws ImsException If there is no ImsService configured for this slot.
5283 */
5284 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5285 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5286 ImsFeature.FEATURE_MMTEL)) {
5287 throw new ImsException("This subscription does not support MMTEL over IMS",
5288 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5289 }
5290 }
5291
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005292 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005293 int slotId = SubscriptionManager.getSlotIndex(subId);
5294 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005295 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5296 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005297 }
5298 return slotId;
5299 }
5300
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005301 private int getSlotIndex(int subId) {
5302 int slotId = SubscriptionManager.getSlotIndex(subId);
5303 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5304 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5305 }
5306 return slotId;
5307 }
5308
Wink Saville36469e72014-06-11 15:17:00 -07005309 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005310 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005311 */
5312 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005313 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5314 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005315 try {
5316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5317 } catch (SecurityException se) {
5318 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5319 throw new SecurityException("Package " + callingPackage + " does not belong to "
5320 + Binder.getCallingUid());
5321 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005322 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005323 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005324 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005325 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005326 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005327 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005328 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005329 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5330 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 final Phone phone = getPhone(subId);
5335 if (phone != null) {
5336 return phone.getServiceState().getDataNetworkType();
5337 } else {
5338 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5339 }
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005343 }
5344
5345 /**
5346 * Returns the data network type
5347 */
5348 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005349 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005350 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005351 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005352 }
5353
5354 /**
5355 * Returns the data network type for a subId
5356 */
5357 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005358 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5359 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005360 String functionName = "getDataNetworkTypeForSubscriber";
5361 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5362 mApp, functionName)) {
5363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5364 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5365 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5366 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005367 }
5368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
5371 final Phone phone = getPhone(subId);
5372 if (phone != null) {
5373 return phone.getServiceState().getDataNetworkType();
5374 } else {
5375 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5376 }
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005380 }
5381
5382 /**
Wink Saville36469e72014-06-11 15:17:00 -07005383 * Returns the Voice network type for a subId
5384 */
5385 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005386 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5387 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005388 String functionName = "getVoiceNetworkTypeForSubscriber";
5389 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5390 mApp, functionName)) {
5391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5392 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5393 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5394 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005395 }
5396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 final Phone phone = getPhone(subId);
5400 if (phone != null) {
5401 return phone.getServiceState().getVoiceNetworkType();
5402 } else {
5403 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5404 }
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005408 }
5409
5410 /**
5411 * @return true if a ICC card is present
5412 */
5413 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005414 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005415 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005416 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005417 }
5418
5419 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005420 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005421 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005422 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005423 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 final Phone phone = PhoneFactory.getPhone(slotIndex);
5427 if (phone != null) {
5428 return phone.getIccCard().hasIccCard();
5429 } else {
5430 return false;
5431 }
5432 } finally {
5433 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005435 }
5436
5437 /**
5438 * Return if the current radio is LTE on CDMA. This
5439 * is a tri-state return value as for a period of time
5440 * the mode may be unknown.
5441 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005442 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005443 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005444 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005445 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005446 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005447 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5448 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5449 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005450 }
5451
Sanket Padawe356d7632015-06-22 14:03:32 -07005452 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005453 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5454 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005455 try {
5456 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5457 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005458 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5459 }
5460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 final Phone phone = getPhone(subId);
5464 if (phone == null) {
5465 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5466 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005467 return TelephonyProperties.lte_on_cdma_device()
5468 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 }
5470 } finally {
5471 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005472 }
Wink Saville36469e72014-06-11 15:17:00 -07005473 }
5474
Wink Saville36469e72014-06-11 15:17:00 -07005475 /**
5476 * {@hide}
5477 * Returns Default subId, 0 in the case of single standby.
5478 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005479 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005480 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005481 }
5482
Shishir Agrawala9f32182016-04-12 12:00:16 -07005483 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005484 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005485 }
5486
Wink Savilleb564aae2014-10-23 10:18:09 -07005487 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005488 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005489 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005490
Pengquan Menge92a50d2018-09-21 15:54:48 -07005491 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005492 return getSubscriptionManagerService().isActiveSubId(subId,
5493 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005494 }
5495
Ihab Awadf2177b72013-11-25 13:33:23 -08005496 /**
5497 * @see android.telephony.TelephonyManager.WifiCallingChoices
5498 */
5499 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 final long identity = Binder.clearCallingIdentity();
5501 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005502 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5504 getWhenToMakeWifiCallsDefaultPreference());
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005508 }
5509
5510 /**
5511 * @see android.telephony.TelephonyManager.WifiCallingChoices
5512 */
5513 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 final long identity = Binder.clearCallingIdentity();
5515 try {
5516 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005517 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
5521 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005522 }
5523
Sailesh Nepald1e68152013-12-12 19:08:02 -08005524 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005525 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005526 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005527 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005528
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005529 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5530 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5531 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005532 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005533 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005534 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005535 }
5536 return PhoneFactory.getPhone(phoneId);
5537 }
5538
Shishir Agrawal566b7612013-10-28 14:41:00 -07005539 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005540 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005541 @NonNull IccLogicalChannelRequest request) {
5542 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5543 /*message=*/ "iccOpenLogicalChannel");
5544
5545 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5546 // Verify that the callingPackage in the request belongs to the calling UID
5547 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5548
5549 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005550 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005551
Rambo Wanga1782702021-11-10 20:15:19 -08005552 private Phone getPhoneFromValidIccLogicalChannelRequest(
5553 @NonNull IccLogicalChannelRequest request, String message) {
5554 Phone phone;
5555 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5557 mApp, request.subId, message);
5558 phone = getPhoneFromSubId(request.subId);
5559 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5560 enforceModifyPermission();
5561 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5562 } else {
5563 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005564 }
Rambo Wanga1782702021-11-10 20:15:19 -08005565 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005566 }
5567
5568 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005569 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 final long identity = Binder.clearCallingIdentity();
5571 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005572 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005574 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5575 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005576 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5577 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 loge("The calling package is not allowed to access ISD-R.");
5579 throw new SecurityException(
5580 "The calling package is not allowed to access ISD-R.");
5581 }
Derek Tan740e1672017-06-27 14:56:27 -07005582 }
Derek Tan740e1672017-06-27 14:56:27 -07005583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005585 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5586 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 return response;
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005591 }
5592
5593 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005594 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5595 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5596 /*message=*/"iccCloseLogicalChannel");
5597
5598 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5599
5600 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005602
Rambo Wanga1782702021-11-10 20:15:19 -08005603 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5604 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005605 // before this feature is enabled, this API should only return false if
5606 // the operation fails instead of throwing runtime exception for
5607 // backward-compatibility.
5608 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5609 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 final long identity = Binder.clearCallingIdentity();
5611 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005612 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005613 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 }
Chen Xue9d737e2022-01-01 23:41:31 -08005615 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005616 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005617 Boolean success = false;
5618 if (result instanceof RuntimeException) {
5619 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005620 if (shouldThrowExceptionOnFailure) {
5621 throw (RuntimeException) result;
5622 } else {
5623 return false;
5624 }
Chen Xue9d737e2022-01-01 23:41:31 -08005625 } else if (result instanceof Boolean) {
5626 success = (Boolean) result;
5627 } else {
5628 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5629 }
Rambo Wanga1782702021-11-10 20:15:19 -08005630 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631 return success;
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005635 }
5636
5637 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005638 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005639 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5641 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005642 if (DBG) {
5643 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5644 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5645 + p3 + " data=" + data);
5646 }
5647 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5648 command, p1, p2, p3, data);
5649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005650
Jordan Liu4c733742019-02-28 12:03:40 -08005651 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005652 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005653 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005654 enforceModifyPermission();
5655 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005656 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005657 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5658 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005659 }
5660 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005661 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5662 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005663 }
5664
5665 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5666 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 final long identity = Binder.clearCallingIdentity();
5668 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005669 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 return "";
5671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005674 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5675 null /* workSource */);
5676 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 // Append the returned status code to the end of the response payload.
5679 String s = Integer.toHexString(
5680 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5681 if (response.payload != null) {
5682 s = IccUtils.bytesToHexString(response.payload) + s;
5683 }
5684 return s;
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005688 }
Jake Hambye994d462014-02-03 13:10:13 -08005689
Evan Charltonc66da362014-05-16 14:06:40 -07005690 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005691 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5692 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005696 if (DBG) {
5697 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5698 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5699 }
5700 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5701 cla, command, p1, p2, p3, data);
5702 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005703
Jordan Liu4c733742019-02-28 12:03:40 -08005704 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005705 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005706 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005707 enforceModifyPermission();
5708 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5709 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005710 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005711 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5712 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005713 }
5714
5715 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005716 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5717 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005718 }
5719
5720 // open APDU basic channel assuming the caller has sufficient permissions
5721 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5722 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5726 && TextUtils.equals(ISDR_AID, data)) {
5727 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005728 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5729 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 if (bestComponent == null
5731 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5732 loge("The calling package is not allowed to select ISD-R.");
5733 throw new SecurityException(
5734 "The calling package is not allowed to select ISD-R.");
5735 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005736 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005739 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5740 null /* workSource */);
5741 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 // Append the returned status code to the end of the response payload.
5744 String s = Integer.toHexString(
5745 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5746 if (response.payload != null) {
5747 s = IccUtils.bytesToHexString(response.payload) + s;
5748 }
5749 return s;
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005752 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005753 }
5754
5755 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005756 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005757 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5759 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 final long identity = Binder.clearCallingIdentity();
5762 try {
5763 if (DBG) {
5764 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5765 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5766 }
5767
5768 IccIoResult response =
5769 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5770 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5771 subId);
5772
5773 if (DBG) {
5774 log("Exchange SIM_IO [R]" + response);
5775 }
5776
5777 byte[] result = null;
5778 int length = 2;
5779 if (response.payload != null) {
5780 length = 2 + response.payload.length;
5781 result = new byte[length];
5782 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5783 } else {
5784 result = new byte[length];
5785 }
5786
5787 result[length - 1] = (byte) response.sw2;
5788 result[length - 2] = (byte) response.sw1;
5789 return result;
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005792 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005793 }
5794
Nathan Haroldb3014052017-01-25 15:57:32 -08005795 /**
5796 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5797 * on a particular subscription
5798 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005799 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5800 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005802 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005803 return null;
5804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 if (appType != TelephonyManager.APPTYPE_USIM
5809 && appType != TelephonyManager.APPTYPE_SIM) {
5810 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5811 return null;
5812 }
5813 Object response = sendRequest(
5814 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5815 if (response instanceof String[]) {
5816 return (String[]) response;
5817 }
yincheng zhao2737e882019-09-06 17:06:54 -07005818 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005820 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 } finally {
5822 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005823 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005824 }
5825
yincheng zhao2737e882019-09-06 17:06:54 -07005826 /**
5827 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5828 * subscription.
5829 *
5830 * @param subId the id of the subscription.
5831 * @param appType the uicc app type, must be USIM or SIM.
5832 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5833 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005834 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005835 * @return number of fplmns that is successfully written to the SIM.
5836 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005837 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5838 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5840 mApp, subId, "setForbiddenPlmns");
5841
yincheng zhao2737e882019-09-06 17:06:54 -07005842 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5843 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5844 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5845 }
5846 if (fplmns == null) {
5847 throw new IllegalArgumentException("Fplmn List provided is null");
5848 }
5849 for (String fplmn : fplmns) {
5850 if (!CellIdentity.isValidPlmn(fplmn)) {
5851 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5852 }
5853 }
5854 final long identity = Binder.clearCallingIdentity();
5855 try {
5856 Object response = sendRequest(
5857 CMD_SET_FORBIDDEN_PLMNS,
5858 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5859 subId);
5860 return (int) response;
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
5864 }
5865
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005866 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005867 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5869 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5874 if (response.payload == null) {
5875 return "";
5876 }
Evan Charltonc66da362014-05-16 14:06:40 -07005877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 // Append the returned status code to the end of the response payload.
5879 String s = Integer.toHexString(
5880 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5881 s = IccUtils.bytesToHexString(response.payload) + s;
5882 return s;
5883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Evan Charltonc66da362014-05-16 14:06:40 -07005886 }
5887
Jake Hambye994d462014-02-03 13:10:13 -08005888 /**
5889 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5890 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5891 *
5892 * @param itemID the ID of the item to read
5893 * @return the NV item as a String, or null on error.
5894 */
5895 @Override
5896 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5899 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900
5901 final long identity = Binder.clearCallingIdentity();
5902 try {
5903 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005904 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5906 return value;
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Jake Hambye994d462014-02-03 13:10:13 -08005910 }
5911
5912 /**
5913 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5914 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5915 *
5916 * @param itemID the ID of the item to read
5917 * @param itemValue the value to write, as a String
5918 * @return true on success; false on any failure
5919 */
5920 @Override
5921 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005922 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5924 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925
5926 final long identity = Binder.clearCallingIdentity();
5927 try {
5928 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5929 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005930 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5932 return success;
5933 } finally {
5934 Binder.restoreCallingIdentity(identity);
5935 }
Jake Hambye994d462014-02-03 13:10:13 -08005936 }
5937
5938 /**
5939 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5940 * Used for device configuration by some CDMA operators.
5941 *
5942 * @param preferredRoamingList byte array containing the new PRL
5943 * @return true on success; false on any failure
5944 */
5945 @Override
5946 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5948 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949
5950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5953 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5954 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5955 return success;
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Jake Hambye994d462014-02-03 13:10:13 -08005959 }
5960
5961 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005962 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005963 * Used for device configuration by some CDMA operators.
5964 *
chen xu6dac5ab2018-10-26 17:39:23 -07005965 * @param slotIndex - device slot.
5966 *
Jake Hambye994d462014-02-03 13:10:13 -08005967 * @return true on success; false on any failure
5968 */
5969 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005970 public boolean resetModemConfig(int slotIndex) {
5971 Phone phone = PhoneFactory.getPhone(slotIndex);
5972 if (phone != null) {
5973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5974 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975
chen xu6dac5ab2018-10-26 17:39:23 -07005976 final long identity = Binder.clearCallingIdentity();
5977 try {
5978 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5979 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5980 return success;
5981 } finally {
5982 Binder.restoreCallingIdentity(identity);
5983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 }
chen xu6dac5ab2018-10-26 17:39:23 -07005985 return false;
5986 }
5987
5988 /**
5989 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5990 *
5991 * @param slotIndex - device slot.
5992 *
5993 * @return true on success; false on any failure
5994 */
5995 @Override
5996 public boolean rebootModem(int slotIndex) {
5997 Phone phone = PhoneFactory.getPhone(slotIndex);
5998 if (phone != null) {
5999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, phone.getSubId(), "rebootModem");
6001
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
6004 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6005 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6006 return success;
6007 } finally {
6008 Binder.restoreCallingIdentity(identity);
6009 }
6010 }
6011 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006012 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006013
Brad Ebinger51f743a2017-01-23 13:50:20 -08006014 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006015 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6016 * {@link #disableIms(int)}.
6017 * @param slotIndex device slot.
6018 */
6019 public void resetIms(int slotIndex) {
6020 enforceModifyPermission();
6021
6022 final long identity = Binder.clearCallingIdentity();
6023 try {
6024 if (mImsResolver == null) {
6025 // may happen if the does not support IMS.
6026 return;
6027 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006028 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006029 } finally {
6030 Binder.restoreCallingIdentity(identity);
6031 }
6032 }
6033
6034 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006035 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6036 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006037 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006038 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006039 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040
6041 final long identity = Binder.clearCallingIdentity();
6042 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006043 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006044 // may happen if the device does not support IMS.
6045 return;
6046 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006047 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 } finally {
6049 Binder.restoreCallingIdentity(identity);
6050 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006051 }
6052
6053 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006054 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6055 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006056 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006057 public void disableIms(int slotId) {
6058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059
6060 final long identity = Binder.clearCallingIdentity();
6061 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006062 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006063 // may happen if the device does not support IMS.
6064 return;
6065 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006066 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 } finally {
6068 Binder.restoreCallingIdentity(identity);
6069 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006070 }
6071
6072 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006073 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6074 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006075 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006076 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006077 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079
6080 final long identity = Binder.clearCallingIdentity();
6081 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006082 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006083 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6084 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006085 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006086 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006090 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006091 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006092 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6093 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006094 @Override
6095 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006096 enforceModifyPermission();
6097
6098 final long identity = Binder.clearCallingIdentity();
6099 try {
6100 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006101 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006102 } finally {
6103 Binder.restoreCallingIdentity(identity);
6104 }
6105 }
6106
6107 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006108 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006109 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006110 */
6111 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113
6114 final long identity = Binder.clearCallingIdentity();
6115 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006116 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006117 // may happen if the device does not support IMS.
6118 return null;
6119 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006120 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006124 }
6125
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006126 /**
6127 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006128 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006129 */
6130 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132
6133 final long identity = Binder.clearCallingIdentity();
6134 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006135 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006136 // may happen if the device does not support IMS.
6137 return null;
6138 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006139 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 } finally {
6141 Binder.restoreCallingIdentity(identity);
6142 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006143 }
6144
Brad Ebinger884c07b2018-02-15 16:17:40 -08006145 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006146 * Sets the ImsService Package Name that Telephony will bind to.
6147 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006148 * @param slotIndex the slot ID that the ImsService should bind for.
6149 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006150 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006151 * @param featureTypes An integer array of feature types associated with a packageName.
6152 * @param packageName The name of the package that the current configuration will be replaced
6153 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006154 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006155 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006156 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6157 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006158 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006160 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 final long identity = Binder.clearCallingIdentity();
6163 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006164 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006165 // may happen if the device does not support IMS.
6166 return false;
6167 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006168 Map<Integer, String> featureConfig = new HashMap<>();
6169 for (int featureType : featureTypes) {
6170 featureConfig.put(featureType, packageName);
6171 }
6172 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6173 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 } finally {
6175 Binder.restoreCallingIdentity(identity);
6176 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006177 }
6178
6179 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006180 * Clears any carrier ImsService overrides for the slot index specified that were previously
6181 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6182 *
6183 * This should only be used for testing.
6184 *
6185 * @param slotIndex the slot ID that the ImsService should bind for.
6186 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6187 */
6188 @Override
6189 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006190 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6191 "clearCarrierImsServiceOverride");
6192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006193 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006194
6195 final long identity = Binder.clearCallingIdentity();
6196 try {
6197 if (mImsResolver == null) {
6198 // may happen if the device does not support IMS.
6199 return false;
6200 }
6201 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
6204 }
6205 }
6206
6207 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006208 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006209 *
6210 * @param slotId The slot that the ImsService is associated with.
6211 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6212 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006213 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006214 * @return the package name of the ImsService configuration.
6215 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006216 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6217 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006218 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006219 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6220 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 final long identity = Binder.clearCallingIdentity();
6223 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006224 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006225 // may happen if the device does not support IMS.
6226 return "";
6227 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006228 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006229 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6230 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006234 }
6235
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006236 /**
6237 * Get the MmTelFeature state associated with the requested subscription id.
6238 * @param subId The subscription that the MmTelFeature is associated with.
6239 * @param callback A callback with an integer containing the
6240 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6241 */
6242 @Override
6243 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6244 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006245 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6247 "IMS not available on device.");
6248 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006249 final long token = Binder.clearCallingIdentity();
6250 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006251 int slotId = getSlotIndex(subId);
6252 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6253 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6254 + subId + "'");
6255 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6256 }
6257 verifyImsMmTelConfiguredOrThrow(slotId);
6258 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6259 try {
6260 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6261 } catch (RemoteException e) {
6262 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6263 + "Ignore");
6264 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006265 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006266 } catch (ImsException e) {
6267 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006268 } finally {
6269 Binder.restoreCallingIdentity(token);
6270 }
6271 }
6272
Daniel Brightbb5840b2021-01-12 15:48:18 -08006273 /**
6274 * Sets the ims registration state on all valid {@link Phone}s.
6275 */
6276 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006277 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278
6279 final long identity = Binder.clearCallingIdentity();
6280 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006281 // NOTE: Before S, this method only set the default phone.
6282 for (final Phone phone : PhoneFactory.getPhones()) {
6283 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6284 phone.setImsRegistrationState(registered);
6285 }
6286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
Wink Saville36469e72014-06-11 15:17:00 -07006290 }
6291
6292 /**
Stuart Scott54788802015-03-30 13:18:01 -07006293 * Set the network selection mode to automatic.
6294 *
6295 */
6296 @Override
6297 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6299 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300
6301 final long identity = Binder.clearCallingIdentity();
6302 try {
shilufc958392020-01-20 11:36:01 -08006303 if (!isActiveSubscription(subId)) {
6304 return;
6305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006307 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6308 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 } finally {
6310 Binder.restoreCallingIdentity(identity);
6311 }
Stuart Scott54788802015-03-30 13:18:01 -07006312 }
6313
Jack Yud10cdd42020-09-28 20:28:01 -07006314 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006315 * Ask the radio to connect to the input network and change selection mode to manual.
6316 *
6317 * @param subId the id of the subscription.
6318 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6319 * the operator to attach to.
6320 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6321 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6322 * normal network selection next time.
6323 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006324 */
6325 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006326 public boolean setNetworkSelectionModeManual(
6327 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6329 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006330
Jack Yu285100e2022-12-02 22:48:35 -08006331 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006332 if (!isActiveSubscription(subId)) {
6333 return false;
6334 }
6335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006337 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006339 if (DBG) {
6340 log("setNetworkSelectionModeManual: subId: " + subId
6341 + " operator: " + operatorInfo);
6342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
6346 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006347 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006348 /**
shilu84f6e8b2019-12-19 13:58:01 -08006349 * Get the manual network selection
6350 *
6351 * @param subId the id of the subscription.
6352 *
6353 * @return the previously saved user selected PLMN
6354 */
6355 @Override
6356 public String getManualNetworkSelectionPlmn(int subId) {
6357 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006358 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6359 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006360
6361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006364 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006365 }
6366
6367 final Phone phone = getPhone(subId);
6368 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006369 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006370 }
6371 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6372 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006373 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006374 } finally {
6375 Binder.restoreCallingIdentity(identity);
6376 }
6377 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006378
6379 /**
6380 * Scans for available networks.
6381 */
6382 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006383 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6384 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6386 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006387 LocationAccessPolicy.LocationPermissionResult locationResult =
6388 LocationAccessPolicy.checkLocationPermission(mApp,
6389 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6390 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006391 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006392 .setCallingPid(Binder.getCallingPid())
6393 .setCallingUid(Binder.getCallingUid())
6394 .setMethod("getCellNetworkScanResults")
6395 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006396 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6397 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006398 .build());
6399 switch (locationResult) {
6400 case DENIED_HARD:
6401 throw new SecurityException("Not allowed to access scan results -- location");
6402 case DENIED_SOFT:
6403 return null;
6404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405
Pengquan Menga1bb6272018-09-06 09:59:22 -07006406 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 try {
6408 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006409 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006414 }
6415
6416 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006417 * Get the call forwarding info, given the call forwarding reason.
6418 */
6419 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006420 public void getCallForwarding(int subId, int callForwardingReason,
6421 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006422 enforceReadPrivilegedPermission("getCallForwarding");
6423 long identity = Binder.clearCallingIdentity();
6424 try {
6425 if (DBG) {
6426 log("getCallForwarding: subId " + subId
6427 + " callForwardingReason" + callForwardingReason);
6428 }
Hall Liu27d24262020-09-18 19:04:59 -07006429
6430 Phone phone = getPhone(subId);
6431 if (phone == null) {
6432 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006433 callback.onError(
6434 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006435 } catch (RemoteException e) {
6436 // ignore
6437 }
6438 return;
6439 }
6440
6441 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6442 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6443 @Override
6444 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6445 try {
6446 callback.onCallForwardingInfoAvailable(info);
6447 } catch (RemoteException e) {
6448 // ignore
6449 }
6450 }
6451
6452 @Override
6453 public void onError(int error) {
6454 try {
6455 callback.onError(error);
6456 } catch (RemoteException e) {
6457 // ignore
6458 }
6459 }
6460 });
6461 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006462 } finally {
6463 Binder.restoreCallingIdentity(identity);
6464 }
6465 }
6466
6467 /**
6468 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6469 * reason, the number to forward, and the timeout before the forwarding is attempted.
6470 */
6471 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006472 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6473 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006474 enforceModifyPermission();
6475 long identity = Binder.clearCallingIdentity();
6476 try {
6477 if (DBG) {
6478 log("setCallForwarding: subId " + subId
6479 + " callForwardingInfo" + callForwardingInfo);
6480 }
Hall Liu27d24262020-09-18 19:04:59 -07006481
6482 Phone phone = getPhone(subId);
6483 if (phone == null) {
6484 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006485 callback.accept(
6486 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006487 } catch (RemoteException e) {
6488 // ignore
6489 }
6490 return;
6491 }
6492
6493 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6494 FunctionalUtils.ignoreRemoteException(callback::accept));
6495
6496 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
6500 }
6501
6502 /**
Hall Liu27d24262020-09-18 19:04:59 -07006503 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006504 */
6505 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006506 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006507 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006508 long identity = Binder.clearCallingIdentity();
6509 try {
Hall Liu27d24262020-09-18 19:04:59 -07006510 Phone phone = getPhone(subId);
6511 if (phone == null) {
6512 try {
6513 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6514 } catch (RemoteException e) {
6515 // ignore
6516 }
6517 return;
6518 }
SongFerngWang0e767992021-03-31 22:08:45 +08006519 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6520 PersistableBundle c = configManager.getConfigForSubId(subId);
6521 boolean requireUssd = c.getBoolean(
6522 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006523
Shuo Qian4a594052020-01-23 11:59:30 -08006524 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006525 if (requireUssd) {
6526 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6527 getSubscriptionCarrierId(subId));
6528 String newUssdCommand = "";
6529 try {
6530 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006531 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006532 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6533 } catch (NullPointerException e) {
6534 loge("Failed to generate USSD number" + e);
6535 }
6536 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6537 mMainThreadHandler, callback, carrierXmlParser,
6538 CarrierXmlParser.SsEntry.SSAction.QUERY);
6539 final String ussdCommand = newUssdCommand;
6540 Executors.newSingleThreadExecutor().execute(() -> {
6541 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6542 });
6543 } else {
6544 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6545 callback::accept);
6546 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6547 }
Shuo Qian4a594052020-01-23 11:59:30 -08006548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
6551 }
6552
6553 /**
Hall Liu27d24262020-09-18 19:04:59 -07006554 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006555 */
6556 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006557 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006558 enforceModifyPermission();
6559 long identity = Binder.clearCallingIdentity();
6560 try {
Hall Liu27d24262020-09-18 19:04:59 -07006561 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6562
6563 Phone phone = getPhone(subId);
6564 if (phone == null) {
6565 try {
6566 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6567 } catch (RemoteException e) {
6568 // ignore
6569 }
6570 return;
6571 }
6572
SongFerngWang0e767992021-03-31 22:08:45 +08006573 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6574 PersistableBundle c = configManager.getConfigForSubId(subId);
6575 boolean requireUssd = c.getBoolean(
6576 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006577
SongFerngWang0e767992021-03-31 22:08:45 +08006578 if (DBG) log("getCallWaitingStatus: subId " + subId);
6579 if (requireUssd) {
6580 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6581 getSubscriptionCarrierId(subId));
6582 CarrierXmlParser.SsEntry.SSAction ssAction =
6583 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6584 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6585 String newUssdCommand = "";
6586 try {
6587 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006588 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006589 .makeCommand(ssAction, null);
6590 } catch (NullPointerException e) {
6591 loge("Failed to generate USSD number" + e);
6592 }
6593 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6594 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6595 final String ussdCommand = newUssdCommand;
6596 Executors.newSingleThreadExecutor().execute(() -> {
6597 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6598 });
6599 } else {
6600 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6601 FunctionalUtils.ignoreRemoteException(callback::accept));
6602
6603 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6604 }
Shuo Qian4a594052020-01-23 11:59:30 -08006605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
6608 }
6609
6610 /**
yinxub1bed742017-04-17 11:45:04 -07006611 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006612 *
yinxub1bed742017-04-17 11:45:04 -07006613 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006614 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6615 * location related information which will be sent if the caller already possess
6616 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006617 * @param request contains the radio access networks with bands/channels to scan
6618 * @param messenger callback messenger for scan results or errors
6619 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006620 * @return the id of the requested scan which can be used to stop the scan.
6621 */
6622 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006623 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6624 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006625 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6627 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006628 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006629 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6630 if (!renounceFineLocationAccess) {
6631 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006632 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6633 .setCallingPackage(callingPackage)
6634 .setCallingFeatureId(callingFeatureId)
6635 .setCallingPid(Binder.getCallingPid())
6636 .setCallingUid(Binder.getCallingUid())
6637 .setMethod("requestNetworkScan")
6638 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6639 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6640 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6641 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006642 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006643 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006644 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6645 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006646 if (e != null) {
6647 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6648 throw e;
6649 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006650 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006651 return TelephonyScanManager.INVALID_SCAN_ID;
6652 }
6653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 }
Hall Liu912dfd32019-04-25 14:02:26 -07006655 int callingUid = Binder.getCallingUid();
6656 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006660 renounceFineLocationAccess, request, messenger, binder,
6661 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006662 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006663 } finally {
6664 Binder.restoreCallingIdentity(identity);
6665 }
yinxu504e1392017-04-12 16:03:22 -07006666 }
6667
Hall Liub2ac8ef2019-02-28 15:56:23 -08006668 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006669 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006670 boolean hasCarrierPriv;
6671 final long identity = Binder.clearCallingIdentity();
6672 try {
6673 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6674 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6675 } finally {
6676 Binder.restoreCallingIdentity(identity);
6677 }
Hall Liu558027f2019-05-15 19:14:05 -07006678 boolean hasNetworkScanPermission =
6679 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006680 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006681
6682 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6683 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6684 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006685 }
6686
6687 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6688 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006689 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6690 return new SecurityException("Specific channels must not be"
6691 + " scanned without location access.");
6692 }
6693 }
6694 }
6695
Hall Liub2ac8ef2019-02-28 15:56:23 -08006696 return null;
6697 }
6698
yinxu504e1392017-04-12 16:03:22 -07006699 /**
6700 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006701 *
6702 * @param subId id of the subscription
6703 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006704 */
6705 @Override
6706 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6708 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006709
Hall Liu912dfd32019-04-25 14:02:26 -07006710 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 final long identity = Binder.clearCallingIdentity();
6712 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006713 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 } finally {
6715 Binder.restoreCallingIdentity(identity);
6716 }
yinxu504e1392017-04-12 16:03:22 -07006717 }
6718
6719 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006720 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006721 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006722 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006723 */
6724 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006725 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006726 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006727 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006728 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729
6730 final long identity = Binder.clearCallingIdentity();
6731 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006732 if (DBG) log("getAllowedNetworkTypesBitmask");
6733 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6734 int networkTypesBitmask = (result != null ? result[0] : -1);
6735 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6736 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737 } finally {
6738 Binder.restoreCallingIdentity(identity);
6739 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006740 }
6741
6742 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006743 * Get the allowed network types for certain reason.
6744 *
6745 * @param subId the id of the subscription.
6746 * @param reason the reason the allowed network type change is taking place
6747 * @return the allowed network types.
6748 */
6749 @Override
6750 public long getAllowedNetworkTypesForReason(int subId,
6751 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006752 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006753 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006754 final long identity = Binder.clearCallingIdentity();
6755 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006756 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
6760 }
6761
6762 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006763 * Enable/Disable E-UTRA-NR Dual Connectivity
6764 * @param subId subscription id of the sim card
6765 * @param nrDualConnectivityState expected NR dual connectivity state
6766 * This can be passed following states
6767 * <ol>
6768 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6769 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6770 * <li>Disable NR dual connectivity and force secondary cell to be released
6771 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6772 * </ol>
6773 * @return operation result.
6774 */
6775 @Override
6776 public int setNrDualConnectivityState(int subId,
6777 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6779 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006780 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006781 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6782 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6783 }
6784
Sooraj Sasindran37444802020-08-11 10:40:43 -07006785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
6788 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6789 nrDualConnectivityState, subId,
6790 workSource);
6791 if (DBG) log("enableNRDualConnectivity result: " + result);
6792 return result;
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
6795 }
6796 }
6797
6798 /**
6799 * Is E-UTRA-NR Dual Connectivity enabled
6800 * @return true if dual connectivity is enabled else false
6801 */
6802 @Override
6803 public boolean isNrDualConnectivityEnabled(int subId) {
6804 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006805 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006806 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006807 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006808 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6809 return false;
6810 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006811 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6815 null, subId, workSource);
6816 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6817 return isEnabled;
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
6821 }
6822
6823 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006824 * Set the allowed network types of the device and
6825 * provide the reason triggering the allowed network change.
6826 *
6827 * @param subId the id of the subscription.
6828 * @param reason the reason the allowed network type change is taking place
6829 * @param allowedNetworkTypes the allowed network types.
6830 * @return true on success; false on any failure.
6831 */
6832 @Override
6833 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006834 @TelephonyManager.AllowedNetworkTypesReason int reason,
6835 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6837 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006838 // If the caller only has carrier privileges, then they should not be able to override
6839 // any network types which were set for security reasons.
6840 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6841 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006842 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006843 throw new SecurityException(
6844 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006845 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006846 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006847 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006848 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006849 return false;
6850 }
6851 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6852 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006853 return false;
6854 }
6855
Jack Yu5b494332023-01-23 18:18:04 +00006856 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6857 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006858
Jack Yue37dd262022-12-16 11:53:37 -08006859 Phone phone = getPhone(subId);
6860 if (phone == null) {
6861 return false;
6862 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006863
Jack Yue37dd262022-12-16 11:53:37 -08006864 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006865 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006866 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006867 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006868
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006869 final long identity = Binder.clearCallingIdentity();
6870 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006871 Boolean success = (Boolean) sendRequest(
6872 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6873 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6874
6875 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6876 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006877 } finally {
6878 Binder.restoreCallingIdentity(identity);
6879 }
6880 }
6881
6882 /**
Miaoa84611c2019-03-15 09:21:10 +08006883 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006884 *
Miaoa84611c2019-03-15 09:21:10 +08006885 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006886 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006887 * @hide
6888 */
6889 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006890 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006893 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 try {
Miaoa84611c2019-03-15 09:21:10 +08006895 if (phone != null) {
6896 return phone.hasMatchedTetherApnSetting();
6897 } else {
6898 return false;
6899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900 } finally {
6901 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006902 }
Junda Liu475951f2014-11-07 16:45:03 -08006903 }
6904
6905 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006906 * Get the user enabled state of Mobile Data.
6907 *
6908 * TODO: remove and use isUserDataEnabled.
6909 * This can't be removed now because some vendor codes
6910 * calls through ITelephony directly while they should
6911 * use TelephonyManager.
6912 *
6913 * @return true on enabled
6914 */
6915 @Override
6916 public boolean getDataEnabled(int subId) {
6917 return isUserDataEnabled(subId);
6918 }
6919
6920 /**
6921 * Get whether mobile data is enabled per user setting.
6922 *
6923 * There are other factors deciding whether mobile data is actually enabled, but they are
6924 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006925 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006926 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6927 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006928 *
6929 * @return {@code true} if data is enabled else {@code false}
6930 */
6931 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006932 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006933 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006934 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006935 try {
6936 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6937 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006938 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006939 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6940 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006941 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006943 mApp, subId, functionName);
6944
Robert Greenwalt646120a2014-05-23 11:54:03 -07006945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946
6947 final long identity = Binder.clearCallingIdentity();
6948 try {
Jack Yu285100e2022-12-02 22:48:35 -08006949 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6951 Phone phone = PhoneFactory.getPhone(phoneId);
6952 if (phone != null) {
6953 boolean retVal = phone.isUserDataEnabled();
6954 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6955 return retVal;
6956 } else {
6957 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6958 return false;
6959 }
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006962 }
6963 }
6964
6965 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006966 * Checks if the device is capable of mobile data by considering whether whether the
6967 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6968 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006969 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006970 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006971 */
6972 @Override
6973 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006974 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006975 try {
6976 try {
6977 mApp.enforceCallingOrSelfPermission(
6978 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006979 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006980 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006981 try {
6982 mApp.enforceCallingOrSelfPermission(
6983 android.Manifest.permission.READ_PHONE_STATE,
6984 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006985 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006986 mApp.enforceCallingOrSelfPermission(
6987 permission.READ_BASIC_PHONE_STATE, functionName);
6988 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006989 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006990 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006991 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
Jack Yu285100e2022-12-02 22:48:35 -08006996 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 Phone phone = PhoneFactory.getPhone(phoneId);
6998 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006999 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007000 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 return retVal;
7002 } else {
7003 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7004 return false;
7005 }
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007008 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007009 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007010
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007011 /**
7012 * Check if data is enabled for a specific reason
7013 * @param subId Subscription index
7014 * @param reason the reason the data enable change is taking place
7015 * @return {@code true} if the overall data is enabled; {@code false} if not.
7016 */
7017 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007018 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007019 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007020 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007021 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007022 try {
7023 mApp.enforceCallingOrSelfPermission(
7024 android.Manifest.permission.ACCESS_NETWORK_STATE,
7025 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007026 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007027 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7028 functionName);
7029 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007030 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007031 try {
7032 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007033 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007034 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007036 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007037 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007038 }
7039
7040
7041 final long identity = Binder.clearCallingIdentity();
7042 try {
Jack Yu285100e2022-12-02 22:48:35 -08007043 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007044 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007045 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007046 + " reason=" + reason);
7047 }
7048 Phone phone = PhoneFactory.getPhone(phoneId);
7049 if (phone != null) {
7050 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007051 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007052 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007053 return retVal;
7054 } else {
7055 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007056 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007057 + subId + " retVal=false");
7058 }
7059 return false;
7060 }
7061 } finally {
7062 Binder.restoreCallingIdentity(identity);
7063 }
7064 }
7065
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007066 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007067 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007068 // No permission needed; this only lets the caller inspect their own status.
7069 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007070 }
Junda Liu29340342014-07-10 15:23:27 -07007071
7072 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007073 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007074 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007075 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7076 }
7077
7078 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7079 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007080 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007081 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007082 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7083 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007084 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7085 if (cpt == null) {
7086 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007087 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7088 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007089 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007090 }
7091
7092 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007093 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007094 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007095 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007096 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007097 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007098 Phone phone = getPhone(subId);
7099 if (phone == null) {
7100 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7101 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7102 }
7103 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7104 if (cpt == null) {
7105 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007106 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7107 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007108 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007109 }
7110
7111 @Override
7112 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007113 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007114 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7115 }
7116
7117 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007118 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007119 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007120 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007121 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007122 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7123 Phone phone = PhoneFactory.getPhone(phoneId);
7124 if (phone == null) {
7125 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007126 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007127 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7128 if (cpt == null) {
7129 continue;
7130 }
7131 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007132 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7133 break;
7134 }
7135 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007136 return result;
Junda Liu29340342014-07-10 15:23:27 -07007137 }
Derek Tan89e89d42014-07-08 17:00:10 -07007138
7139 @Override
Junda Liue64de782015-04-16 17:19:16 -07007140 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007141 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007142 Phone phone = PhoneFactory.getPhone(phoneId);
7143 if (phone == null) {
7144 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007145 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007146 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7147 if (cpt == null) {
7148 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007149 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007150 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007151 }
7152
Amith Yamasani6e118872016-02-19 12:53:51 -08007153 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007154 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007155 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007156 Phone phone = PhoneFactory.getPhone(phoneId);
7157 if (phone == null) {
7158 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007159 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007160 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7161 if (cpt == null) {
7162 return Collections.emptyList();
7163 }
7164 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007165 }
7166
chen xuf7e9fe82019-05-09 19:31:02 -07007167 @Override
7168 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007169 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007170 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007171 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007172 try {
7173 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7174 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7175 }
7176 } finally {
7177 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007178 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007179 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007180 }
7181
Rambo Wang6812ffb2022-03-15 16:54:17 -07007182 @Override
7183 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7184 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7185
7186 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7187 if (phone == null) {
7188 return null;
7189 }
7190 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7191 if (cpt == null) {
7192 return null;
7193 }
7194 return cpt.getCarrierServicePackageName();
7195 }
7196
Wink Savilleb564aae2014-10-23 10:18:09 -07007197 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007198 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007199 UiccPort port = phone == null ? null : phone.getUiccPort();
7200 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007201 return null;
7202 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007203 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007204 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007205 return null;
7206 }
7207 return iccId;
7208 }
7209
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007210 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007211 public void setCallComposerStatus(int subId, int status) {
7212 enforceModifyPermission();
7213
7214 final long identity = Binder.clearCallingIdentity();
7215 try {
7216 Phone phone = getPhone(subId);
7217 if (phone != null) {
7218 Phone defaultPhone = phone.getImsPhone();
7219 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7220 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7221 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007222 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7223 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007224 }
7225 }
Shuo Qian284ae752020-12-22 19:10:14 -08007226 } catch (ImsException e) {
7227 throw new ServiceSpecificException(e.getCode());
7228 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007229 Binder.restoreCallingIdentity(identity);
7230 }
7231 }
7232
7233 @Override
7234 public int getCallComposerStatus(int subId) {
7235 enforceReadPrivilegedPermission("getCallComposerStatus");
7236
7237 final long identity = Binder.clearCallingIdentity();
7238 try {
7239 Phone phone = getPhone(subId);
7240 if (phone != null) {
7241 Phone defaultPhone = phone.getImsPhone();
7242 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7243 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7244 return imsPhone.getCallComposerStatus();
7245 }
7246 }
7247 } finally {
7248 Binder.restoreCallingIdentity(identity);
7249 }
7250 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7251 }
7252
7253 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007254 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7255 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007256 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007257 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 final long identity = Binder.clearCallingIdentity();
7260 try {
7261 final String iccId = getIccId(subId);
7262 final Phone phone = getPhone(subId);
7263 if (phone == null) {
7264 return false;
7265 }
7266 final String subscriberId = phone.getSubscriberId();
7267
7268 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007269 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 + subscriberId + " to " + number);
7271 }
7272
7273 if (TextUtils.isEmpty(iccId)) {
7274 return false;
7275 }
7276
7277 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7278
7279 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7280 if (alphaTag == null) {
7281 editor.remove(alphaTagPrefKey);
7282 } else {
7283 editor.putString(alphaTagPrefKey, alphaTag);
7284 }
7285
7286 // Record both the line number and IMSI for this ICCID, since we need to
7287 // track all merged IMSIs based on line number
7288 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7289 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7290 if (number == null) {
7291 editor.remove(numberPrefKey);
7292 editor.remove(subscriberPrefKey);
7293 } else {
7294 editor.putString(numberPrefKey, number);
7295 editor.putString(subscriberPrefKey, subscriberId);
7296 }
7297
7298 editor.commit();
7299 return true;
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007302 }
Derek Tan7226c842014-07-02 17:42:23 -07007303 }
7304
7305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007306 public String getLine1NumberForDisplay(int subId, String callingPackage,
7307 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007308 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007310 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007311 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007312 return null;
7313 }
Derek Tan97ebb422014-09-05 16:55:38 -07007314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 String iccId = getIccId(subId);
7318 if (iccId != null) {
7319 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7320 if (DBG_MERGE) {
7321 log("getLine1NumberForDisplay returning "
7322 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7323 }
7324 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7327 return null;
7328 } finally {
7329 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007330 }
Derek Tan7226c842014-07-02 17:42:23 -07007331 }
7332
7333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007334 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7335 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007337 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007338 return null;
7339 }
Derek Tan97ebb422014-09-05 16:55:38 -07007340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 final long identity = Binder.clearCallingIdentity();
7342 try {
7343 String iccId = getIccId(subId);
7344 if (iccId != null) {
7345 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7346 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7347 }
7348 return null;
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007351 }
Derek Tan7226c842014-07-02 17:42:23 -07007352 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007353
7354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007355 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7356 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007357 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7358 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007360 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007361 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007362 return null;
7363 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007364
Jordan Liub49b04b2019-05-06 14:45:15 -07007365 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7366 // the process, where TelephonyManager was instantiated.
7367 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007368 final long identity = Binder.clearCallingIdentity();
7369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007370 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 final TelephonyManager tele = TelephonyManager.from(context);
7372 final SubscriptionManager sub = SubscriptionManager.from(context);
7373
7374 // Figure out what subscribers are currently active
7375 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376
Jordan Liub49b04b2019-05-06 14:45:15 -07007377 // Only consider subs which match the current subId
7378 // This logic can be simplified. See b/131189269 for progress.
7379 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007380 activeSubscriberIds.add(tele.getSubscriberId(subId));
7381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382
7383 // First pass, find a number override for an active subscriber
7384 String mergeNumber = null;
7385 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7386 for (String key : prefs.keySet()) {
7387 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7388 final String subscriberId = (String) prefs.get(key);
7389 if (activeSubscriberIds.contains(subscriberId)) {
7390 final String iccId = key.substring(
7391 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7392 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7393 mergeNumber = (String) prefs.get(numberKey);
7394 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007395 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 + " for active subscriber " + subscriberId);
7397 }
7398 if (!TextUtils.isEmpty(mergeNumber)) {
7399 break;
7400 }
7401 }
7402 }
7403 }
7404
7405 // Shortcut when no active merged subscribers
7406 if (TextUtils.isEmpty(mergeNumber)) {
7407 return null;
7408 }
7409
7410 // Second pass, find all subscribers under that line override
7411 final ArraySet<String> result = new ArraySet<>();
7412 for (String key : prefs.keySet()) {
7413 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7414 final String number = (String) prefs.get(key);
7415 if (mergeNumber.equals(number)) {
7416 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7417 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7418 final String subscriberId = (String) prefs.get(subscriberKey);
7419 if (!TextUtils.isEmpty(subscriberId)) {
7420 result.add(subscriberId);
7421 }
7422 }
7423 }
7424 }
7425
7426 final String[] resultArray = result.toArray(new String[result.size()]);
7427 Arrays.sort(resultArray);
7428 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007429 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7431 }
7432 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007433 } finally {
7434 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007435 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007436 }
7437
7438 @Override
zoey chen38003472019-12-13 17:16:31 +08007439 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7440 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007441
7442 final long identity = Binder.clearCallingIdentity();
7443 try {
7444 final TelephonyManager telephonyManager = mApp.getSystemService(
7445 TelephonyManager.class);
7446 String subscriberId = telephonyManager.getSubscriberId(subId);
7447 if (subscriberId == null) {
7448 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007449 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007450 + subId);
7451 }
7452 return null;
7453 }
7454
Jack Yu3beaf9d2023-04-14 09:17:27 -07007455 final SubscriptionInfo info = getSubscriptionManagerService()
7456 .getSubscriptionInfo(subId);
7457 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007458 // If it doesn't belong to any group, return just subscriberId of itself.
7459 if (groupUuid == null) {
7460 return new String[]{subscriberId};
7461 }
7462
7463 // Get all subscriberIds from the group.
7464 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007465 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7466 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7467 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007468 for (SubscriptionInfo subInfo : groupInfos) {
7469 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7470 if (subscriberId != null) {
7471 mergedSubscriberIds.add(subscriberId);
7472 }
7473 }
7474
7475 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478
7479 }
7480 }
7481
7482 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007483 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007484 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007485 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
7489 final Phone phone = getPhone(subId);
7490 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007494 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007495
7496 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007497 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007498 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7499 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007500 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7501 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 final Phone phone = getPhone(subId);
7506 if (phone == null) {
7507 return false;
7508 }
7509 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7510 cdmaNonRoamingList);
7511 } finally {
7512 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007513 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007514 }
7515
7516 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007517 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007518 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007519 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007520 if (phone == null) {
7521 return raf;
7522 }
7523
Shuo Qiandee53402020-05-29 14:08:15 -07007524 try {
7525 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007526 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007527 mApp, phone.getSubId(), "getRadioAccessFamily");
7528 } catch (SecurityException e) {
7529 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7530 throw e;
7531 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 final long identity = Binder.clearCallingIdentity();
7534 try {
chen xub97461a2018-10-26 14:17:57 -07007535 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 } finally {
7537 Binder.restoreCallingIdentity(identity);
7538 }
chen xub97461a2018-10-26 14:17:57 -07007539 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007540 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007541
7542 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007543 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007544 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007545 try {
7546 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7547 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007548 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007549 }
7550 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007551 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007552 }
7553 RoleManager rm = mApp.getSystemService(RoleManager.class);
7554 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7555 if (!dialerRoleHolders.contains(callingPackage)) {
7556 throw new SecurityException("App must be the dialer role holder to"
7557 + " upload a call composer pic");
7558 }
7559
7560 Executors.newSingleThreadExecutor().execute(() -> {
7561 ByteArrayOutputStream output = new ByteArrayOutputStream(
7562 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7563 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7564 boolean readUntilEnd = false;
7565 int totalBytesRead = 0;
7566 byte[] buffer = new byte[16 * 1024];
7567 while (true) {
7568 int numRead;
7569 try {
7570 numRead = input.read(buffer);
7571 } catch (IOException e) {
7572 try {
7573 fd.checkError();
7574 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7575 null);
7576 } catch (IOException e1) {
7577 // This means that the other side closed explicitly with an error. If this
7578 // happens, log and ignore.
7579 loge("Remote end of call composer picture pipe closed: " + e1);
7580 }
7581 break;
7582 }
7583 if (numRead == -1) {
7584 readUntilEnd = true;
7585 break;
7586 }
7587 totalBytesRead += numRead;
7588 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7589 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7590 try {
7591 input.close();
7592 } catch (IOException e) {
7593 // ignore
7594 }
7595 break;
7596 }
7597 output.write(buffer, 0, numRead);
7598 }
7599 // Generally, the remote end will close the file descriptors. The only case where we
7600 // close is above, where the picture size is too big.
7601
7602 try {
7603 fd.checkError();
7604 } catch (IOException e) {
7605 loge("Remote end for call composer closed with an error: " + e);
7606 return;
7607 }
7608
Hall Liuaa4211e2021-01-20 15:43:39 -08007609 if (!readUntilEnd) {
7610 loge("Did not finish reading entire image; aborting");
7611 return;
7612 }
Hall Liu82694d52020-12-11 18:22:04 -08007613
Hall Liuaa4211e2021-01-20 15:43:39 -08007614 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7615 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7616 new CallComposerPictureTransfer.Factory() {},
7617 imageData,
7618 (result) -> {
7619 if (result.first != null) {
7620 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7621 Bundle outputResult = new Bundle();
7622 outputResult.putParcelable(
7623 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7624 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7625 outputResult);
7626 } else {
7627 callback.send(result.second, null);
7628 }
7629 }
7630 );
Hall Liu82694d52020-12-11 18:22:04 -08007631 });
7632 }
7633
7634 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007635 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007636 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638
7639 final long identity = Binder.clearCallingIdentity();
7640 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007641 ImsManager.getInstance(defaultPhone.getContext(),
7642 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 } finally {
7644 Binder.restoreCallingIdentity(identity);
7645 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007646 }
7647
7648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007649 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007650 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7652 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007653 return false;
7654 }
Svet Ganovb320e182015-04-16 12:30:10 -07007655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 final long identity = Binder.clearCallingIdentity();
7657 try {
7658 // Check the user preference and the system-level IMS setting. Even if the user has
7659 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7660 // In the long run, we may instead need to check if there exists a connection service
7661 // which can support video calling.
7662 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007663 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 return imsManager.isVtEnabledByPlatform()
7665 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7666 && imsManager.isVtEnabledByUser();
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007670 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007671
Andrew Leea1239f22015-03-02 17:44:07 -08007672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007673 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7674 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007676 mApp, subId, callingPackage, callingFeatureId,
7677 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 return false;
7679 }
7680
7681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 CarrierConfigManager configManager =
7684 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007685 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
7689 }
Andrew Leea1239f22015-03-02 17:44:07 -08007690 }
7691
7692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007693 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007695 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 return false;
7697 }
7698
7699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 CarrierConfigManager configManager =
7702 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007703 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007704 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7705 } finally {
7706 Binder.restoreCallingIdentity(identity);
7707 }
Andrew Leea1239f22015-03-02 17:44:07 -08007708 }
7709
Andrew Lee9431b832015-03-09 18:46:45 -07007710 @Override
7711 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007712 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007713 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007714 }
7715
7716 @Override
7717 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 final long identity = Binder.clearCallingIdentity();
7719 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007720 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 } finally {
7722 Binder.restoreCallingIdentity(identity);
7723 }
Andrew Lee9431b832015-03-09 18:46:45 -07007724 }
7725
Hall Liuf6668912018-10-31 17:05:23 -07007726 /**
7727 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7728 * support for the feature and device firmware support.
7729 *
7730 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7731 */
7732 @Override
7733 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007735 final Phone phone = getPhone(subscriptionId);
7736 if (phone == null) {
7737 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7738 return false;
7739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7743 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007744 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 return isCarrierSupported && isDeviceSupported;
7746 } finally {
7747 Binder.restoreCallingIdentity(identity);
7748 }
Hall Liu98187582018-01-22 19:15:32 -08007749 }
7750
Hall Liuf6668912018-10-31 17:05:23 -07007751 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007752 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7753 * RTT setting, will return true if the device and carrier both support RTT.
7754 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007755 */
7756 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 final long identity = Binder.clearCallingIdentity();
7758 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007759 boolean isRttSupported = isRttSupported(subscriptionId);
7760 boolean isUserRttSettingOn = Settings.Secure.getInt(
7761 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7762 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7763 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7764 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007768 }
7769
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007770 @Deprecated
7771 @Override
7772 public String getDeviceId(String callingPackage) {
7773 return getDeviceIdWithFeature(callingPackage, null);
7774 }
7775
Sanket Padawe7310cc72015-01-14 09:53:20 -08007776 /**
7777 * Returns the unique device ID of phone, for example, the IMEI for
7778 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7779 *
7780 * <p>Requires Permission:
7781 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7782 */
7783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007784 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007785 try {
7786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7787 } catch (SecurityException se) {
7788 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7789 throw new SecurityException("Package " + callingPackage + " does not belong to "
7790 + Binder.getCallingUid());
7791 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007792 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007793 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007794 return null;
7795 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007796 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007797 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007798 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007799 return null;
7800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801
7802 final long identity = Binder.clearCallingIdentity();
7803 try {
7804 return phone.getDeviceId();
7805 } finally {
7806 Binder.restoreCallingIdentity(identity);
7807 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007808 }
7809
Ping Sunc67b7c22016-03-02 19:16:45 +08007810 /**
7811 * {@hide}
7812 * Returns the IMS Registration Status on a particular subid
7813 *
7814 * @param subId
7815 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007816 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007817 Phone phone = getPhone(subId);
7818 if (phone != null) {
7819 return phone.isImsRegistered();
7820 } else {
7821 return false;
7822 }
7823 }
7824
Santos Cordon7a1885b2015-02-03 11:15:19 -08007825 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007826 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007827 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007829 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007830 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7831 }
7832 final long identity = Binder.clearCallingIdentity();
7833 try {
7834 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
7838 }
7839
7840 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007841 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007842 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007843 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007844 mApp,
7845 subscriptionId,
7846 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7847 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007848 final long identity = Binder.clearCallingIdentity();
7849 try {
7850 Phone phone = getPhone(subscriptionId);
7851 if (phone == null) {
7852 return null;
7853 }
7854 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7855 } finally {
7856 Binder.restoreCallingIdentity(identity);
7857 }
7858 }
7859
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007860 /**
7861 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007862 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007863 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 final long identity = Binder.clearCallingIdentity();
7865 try {
7866 Phone phone = getPhone(subId);
7867 if (phone != null) {
7868 return phone.isWifiCallingEnabled();
7869 } else {
7870 return false;
7871 }
7872 } finally {
7873 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007874 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007875 }
7876
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007877 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007878 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007879 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007880 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007881 final long identity = Binder.clearCallingIdentity();
7882 try {
7883 Phone phone = getPhone(subId);
7884 if (phone != null) {
7885 return phone.isVideoEnabled();
7886 } else {
7887 return false;
7888 }
7889 } finally {
7890 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007891 }
7892 }
7893
7894 /**
7895 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7896 * defined in {@link ImsRegistrationImplBase}.
7897 */
7898 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 final long identity = Binder.clearCallingIdentity();
7900 try {
7901 Phone phone = getPhone(subId);
7902 if (phone != null) {
7903 return phone.getImsRegistrationTech();
7904 } else {
7905 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7906 }
7907 } finally {
7908 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007909 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007910 }
7911
Stuart Scott8eef64f2015-04-08 15:13:54 -07007912 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007913 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007914 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007915 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7916 return;
7917 }
Kai Shif70f46f2021-03-03 13:59:46 -08007918 Phone defaultPhone = getDefaultPhone();
7919 if (defaultPhone != null) {
7920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7921 mApp, getDefaultPhone().getSubId(), "factoryReset");
7922 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007923 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007924
Svet Ganovcc087f82015-05-12 20:35:54 -07007925 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007926 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7927 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007928 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007929 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007930 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007931 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007932 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007933 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007934 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007935 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007936 // There has been issues when Sms raw table somehow stores orphan
7937 // fragments. They lead to garbled message when new fragments come
7938 // in and combined with those stale ones. In case this happens again,
7939 // user can reset all network settings which will clean up this table.
7940 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007941 // Clean up IMS settings as well here.
7942 int slotId = getSlotIndex(subId);
7943 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7944 ImsManager.getInstance(mApp, slotId).factoryReset();
7945 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007946
Kai Shif70f46f2021-03-03 13:59:46 -08007947 if (defaultPhone == null) {
7948 return;
7949 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007950 // Erase modem config if erase modem on network setting is enabled.
7951 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7952 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7953 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007954 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007955 }
Kai Shif70f46f2021-03-03 13:59:46 -08007956
7957 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007958 } finally {
7959 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007960 }
7961 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007962
SongFerngWangfd89b102021-05-27 22:44:54 +08007963 @VisibleForTesting
7964 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7965 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7966 return;
7967 }
7968 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7969 RILConstants.PREFERRED_NETWORK_MODE);
7970 SubscriptionManager.setSubscriptionProperty(subId,
7971 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7972 "user=" + defaultNetworkType);
7973 phone.loadAllowedNetworksFromSubscriptionDatabase();
7974 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7975 defaultNetworkType, null);
7976 }
7977
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007978 private void cleanUpSmsRawTable(Context context) {
7979 ContentResolver resolver = context.getContentResolver();
7980 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7981 resolver.delete(uri, null, null);
7982 }
7983
Narayan Kamath1c496c22015-04-16 14:40:19 +01007984 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007985 public String getSimLocaleForSubscriber(int subId) {
7986 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7987 final Phone phone = getPhone(subId);
7988 if (phone == null) {
7989 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007990 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 final long identity = Binder.clearCallingIdentity();
7993 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07007994 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
7995 phone.getContext().getOpPackageName(),
7996 phone.getContext().getAttributionTag());
7997 if (info == null) {
7998 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7999 return null;
chen xu6291c472019-02-04 12:55:53 -08008000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 // Try and fetch the locale from the carrier properties or from the SIM language
8002 // preferences (EF-PL and EF-LI)...
8003 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008005 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8006 if (localeFromDefaultSim != null) {
8007 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8008 if (DBG) log("Using locale from subId: " + subId + " locale: "
8009 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008010 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008011 } else {
8012 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 }
8014 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 // The SIM language preferences only store a language (e.g. fr = French), not an
8017 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8018 // the SIM and carrier preferences does not include a country we add the country
8019 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008020 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008022 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008023 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 }
8025
8026 if (DBG) log("No locale found - returning null");
8027 return null;
8028 } finally {
8029 Binder.restoreCallingIdentity(identity);
8030 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008031 }
8032
tom hsu0b59d292022-09-29 23:49:21 +08008033 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008034 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008035 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008036 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008037 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008038 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8039 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008040 Locale.forLanguageTag(localeTag).getCountry())) {
8041 return localeTag;
8042 }
8043 }
8044 return inputLocale.toLanguageTag();
8045 }
8046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 /**
8048 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8049 */
8050 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008051 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008052 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008053 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008054
Gary Jian3aa9a762022-01-24 16:41:19 +08008055 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8056 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008057
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008058 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008059 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8060 * representing the state of the modem.
8061 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008062 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8063 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008064 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008065 */
8066 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008067 public void requestModemActivityInfo(ResultReceiver result) {
8068 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008069 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070
8071 final long identity = Binder.clearCallingIdentity();
8072 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008073 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 } finally {
8075 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008076 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008077 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008078
Gary Jian76280a42022-12-07 16:18:33 +08008079 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008080 // less than total activity duration.
8081 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8082 if (info == null) {
8083 return false;
8084 }
8085 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008086 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008087 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8088
Hall Liu49656c02020-10-09 19:00:11 -07008089 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8090
Siddharth Rayb8114062018-06-17 15:02:38 -07008091 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008092 && (info.getSleepTimeMillis() <= activityDurationMs)
8093 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008094 }
8095
Gary Jian3aa9a762022-01-24 16:41:19 +08008096 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8097 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8098 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8099 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8100
8101 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8102 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8103 }
8104
8105 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8106 mLastModemActivityInfo.setReceiveTimeMillis(
8107 rat,
8108 freq,
8109 info.getReceiveTimeMillis(rat, freq)
8110 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8111 }
8112
8113 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8114 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8115 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8116 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8117
8118 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8119 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8120 }
8121 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8122 mLastModemActivityInfo.setReceiveTimeMillis(
8123 rat,
8124 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8125 }
8126
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008127 /**
8128 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8129 * @param info recent ModemActivityInfo
8130 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008131 private void mergeModemActivityInfo(ModemActivityInfo info) {
8132 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008133 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008134 boolean matched;
8135 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8136 matched = false;
8137 int rat = info.getSpecificInfoRat(i);
8138 int freq = info.getSpecificInfoFrequencyRange(i);
8139 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8140 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8141 //if it already exists
8142 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8143 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8144 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8145 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8146 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8147 updateLastModemActivityInfo(info, rat, freq);
8148 matched = true;
8149 }
8150 } else {
8151 updateLastModemActivityInfo(info, rat);
8152 matched = true;
8153 }
8154 }
8155 }
8156
8157 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008158 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008159 new ActivityStatsTechSpecificInfo(
8160 rat,
8161 freq,
8162 info.getTransmitTimeMillis(rat, freq),
8163 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008164 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008165 }
8166 }
8167 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8168 mLastModemActivitySpecificInfo =
8169 new ActivityStatsTechSpecificInfo[merged.size()];
8170 merged.toArray(mLastModemActivitySpecificInfo);
8171
8172 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8173 mLastModemActivityInfo.setSleepTimeMillis(
8174 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008175 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008176 mLastModemActivityInfo.setIdleTimeMillis(
8177 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008178 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008179
8180 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008181 new ModemActivityInfo(
8182 mLastModemActivityInfo.getTimestampMillis(),
8183 mLastModemActivityInfo.getSleepTimeMillis(),
8184 mLastModemActivityInfo.getIdleTimeMillis(),
8185 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008186 }
8187
8188 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8189 ActivityStatsTechSpecificInfo[] info) {
8190 int infoSize = info.length;
8191 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8192 for (int i = 0; i < infoSize; i++) {
8193 ret[i] = new ActivityStatsTechSpecificInfo(
8194 info[i].getRat(), info[i].getFrequencyRange(),
8195 info[i].getTransmitTimeMillis(),
8196 (int) info[i].getReceiveTimeMillis());
8197 }
8198 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008199 }
8200
Jack Yu85bd38a2015-11-09 11:34:32 -08008201 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008202 * Returns the service state information on specified subscription.
8203 */
8204 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008205 public ServiceState getServiceStateForSubscriber(int subId,
8206 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8207 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008209 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008210 return null;
8211 }
8212
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008213 boolean hasFinePermission = false;
8214 boolean hasCoarsePermission = false;
8215 if (!renounceFineLocationAccess) {
8216 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8217 LocationAccessPolicy.checkLocationPermission(mApp,
8218 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8219 .setCallingPackage(callingPackage)
8220 .setCallingFeatureId(callingFeatureId)
8221 .setCallingPid(Binder.getCallingPid())
8222 .setCallingUid(Binder.getCallingUid())
8223 .setMethod("getServiceStateForSubscriber")
8224 .setLogAsInfo(true)
8225 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8226 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8227 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8228 .build());
8229 hasFinePermission =
8230 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8231 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008232
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008233 if (!renounceCoarseLocationAccess) {
8234 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8235 LocationAccessPolicy.checkLocationPermission(mApp,
8236 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8237 .setCallingPackage(callingPackage)
8238 .setCallingFeatureId(callingFeatureId)
8239 .setCallingPid(Binder.getCallingPid())
8240 .setCallingUid(Binder.getCallingUid())
8241 .setMethod("getServiceStateForSubscriber")
8242 .setLogAsInfo(true)
8243 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8244 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8245 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8246 .build());
8247 hasCoarsePermission =
8248 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8249 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008250
Jack Yu479f40e2020-10-27 21:29:25 -07008251 final Phone phone = getPhone(subId);
8252 if (phone == null) {
8253 return null;
8254 }
8255
Jordan Liu0f2bc442020-11-18 16:47:37 -08008256 final long identity = Binder.clearCallingIdentity();
8257
Jack Yu479f40e2020-10-27 21:29:25 -07008258 boolean isCallingPackageDataService = phone.getDataServicePackages()
8259 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008261 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008262 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8263 .getSubscriptionInfoInternal(subId);
8264 if (subInfo == null || !subInfo.isActive()) {
8265 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8266 + "subId=" + subId);
8267 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008268 }
8269
Hall Liuf19c44f2018-11-27 14:38:17 -08008270 ServiceState ss = phone.getServiceState();
8271
8272 // Scrub out the location info in ServiceState depending on what level of access
8273 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008274 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008275 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8276 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008280 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008281
8282 /**
8283 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8284 *
8285 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8286 * voicemail ringtone.
8287 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8288 * PhoneAccount.
8289 */
8290 @Override
8291 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 final long identity = Binder.clearCallingIdentity();
8293 try {
8294 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8295 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008296 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008303 }
8304
8305 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008306 * Sets the per-account voicemail ringtone.
8307 *
8308 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8309 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8310 *
8311 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8312 * voicemail ringtone.
8313 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8314 * PhoneAccount.
8315 */
8316 @Override
8317 public void setVoicemailRingtoneUri(String callingPackage,
8318 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008319 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008321 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8322 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8324 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8325 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327
8328 final long identity = Binder.clearCallingIdentity();
8329 try {
8330 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8331 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008332 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 }
8334 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8335 } finally {
8336 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008337 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008338 }
8339
8340 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008341 * Returns whether vibration is set for voicemail notification in Phone settings.
8342 *
8343 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8344 * voicemail vibration setting.
8345 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8346 */
8347 @Override
8348 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349 final long identity = Binder.clearCallingIdentity();
8350 try {
8351 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8352 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008353 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008354 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008360 }
8361
Youhan Wange64578a2016-05-02 15:32:42 -07008362 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008363 * Sets the per-account voicemail vibration.
8364 *
8365 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8366 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8367 *
8368 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8369 * voicemail vibration setting.
8370 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8371 * specific PhoneAccount.
8372 */
8373 @Override
8374 public void setVoicemailVibrationEnabled(String callingPackage,
8375 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008376 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008377 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008378 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8379 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8381 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8382 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008383 }
8384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 final long identity = Binder.clearCallingIdentity();
8386 try {
8387 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8388 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008389 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 }
8391 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8392 } finally {
8393 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008394 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008395 }
8396
8397 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008398 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8399 *
8400 * @throws SecurityException if the caller does not have the required permission
8401 */
arunvoddud7401012022-12-15 16:08:12 +00008402 @VisibleForTesting
8403 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008405 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008406 }
8407
8408 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008409 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8410 * permission.
8411 *
8412 * @throws SecurityException if the caller does not have the required permission
8413 */
8414 private void enforceSendSmsPermission() {
8415 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8416 }
8417
8418 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008419 * Make sure either called from same process as self (phone) or IPC caller has interact across
8420 * users permission.
8421 *
8422 * @throws SecurityException if the caller does not have the required permission
8423 */
8424 private void enforceInteractAcrossUsersPermission(String message) {
8425 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8426 }
8427
8428 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008429 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008430 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008431 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008432 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008433 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 final long identity = Binder.clearCallingIdentity();
8435 try {
8436 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008437 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438 if (componentName == null) {
8439 throw new SecurityException(
8440 "Caller not current active visual voicemail package[null]");
8441 }
8442 String vvmPackage = componentName.getPackageName();
8443 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008444 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445 }
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008448 }
8449 }
8450
8451 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008452 * Return the application ID for the app type.
8453 *
8454 * @param subId the subscription ID that this request applies to.
8455 * @param appType the uicc app type.
8456 * @return Application ID for specificied app type, or null if no uicc.
8457 */
8458 @Override
8459 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008460 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008461 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462
8463 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008464 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465 if (phone == null) {
8466 return null;
8467 }
8468 String aid = null;
8469 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008470 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 .getApplicationByType(appType).getAid();
8472 } catch (Exception e) {
8473 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8474 }
8475 return aid;
8476 } finally {
8477 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008478 }
Youhan Wange64578a2016-05-02 15:32:42 -07008479 }
8480
Youhan Wang4001d252016-05-11 10:29:41 -07008481 /**
8482 * Return the Electronic Serial Number.
8483 *
8484 * @param subId the subscription ID that this request applies to.
8485 * @return ESN or null if error.
8486 */
8487 @Override
8488 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008489 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008490 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008491
8492 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008493 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008494 if (phone == null) {
8495 return null;
8496 }
8497 String esn = null;
8498 try {
8499 esn = phone.getEsn();
8500 } catch (Exception e) {
8501 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8502 }
8503 return esn;
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008506 }
Youhan Wang4001d252016-05-11 10:29:41 -07008507 }
8508
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008509 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008510 * Return the Preferred Roaming List Version.
8511 *
8512 * @param subId the subscription ID that this request applies to.
8513 * @return PRLVersion or null if error.
8514 */
8515 @Override
8516 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008517 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008518 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008519
8520 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008521 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008522 if (phone == null) {
8523 return null;
8524 }
8525 String cdmaPrlVersion = null;
8526 try {
8527 cdmaPrlVersion = phone.getCdmaPrlVersion();
8528 } catch (Exception e) {
8529 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8530 }
8531 return cdmaPrlVersion;
8532 } finally {
8533 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008534 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008535 }
8536
8537 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008538 * Get snapshot of Telephony histograms
8539 * @return List of Telephony histograms
8540 * @hide
8541 */
8542 @Override
8543 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8545 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546
8547 final long identity = Binder.clearCallingIdentity();
8548 try {
8549 return RIL.getTelephonyRILTimingHistograms();
8550 } finally {
8551 Binder.restoreCallingIdentity(identity);
8552 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008553 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008554
8555 /**
8556 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008557 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8558 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008559 * Require system privileges. In the future we may add this to carrier APIs.
8560 *
Michele Berionne482f8202018-11-27 18:57:59 -08008561 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008562 */
8563 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008564 @TelephonyManager.SetCarrierRestrictionResult
8565 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008566 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008568
Michele Berionne482f8202018-11-27 18:57:59 -08008569 if (carrierRestrictionRules == null) {
8570 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008571 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008573 final long identity = Binder.clearCallingIdentity();
8574 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008575 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008576 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008580 }
8581
8582 /**
8583 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008584 * Get the allowed carrier list and the excluded carrier list, including the priority between
8585 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008586 * Require system privileges. In the future we may add this to carrier APIs.
8587 *
Michele Berionne482f8202018-11-27 18:57:59 -08008588 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008589 */
8590 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008591 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008592 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008593 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594
8595 final long identity = Binder.clearCallingIdentity();
8596 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008597 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8598 if (response instanceof CarrierRestrictionRules) {
8599 return (CarrierRestrictionRules) response;
8600 }
8601 // Response is an Exception of some kind,
8602 // which is signalled to the user as a NULL retval
8603 return null;
8604 } catch (Exception e) {
8605 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8606 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008610 }
8611
fionaxu59545b42016-05-25 15:53:37 -07008612 /**
arunvoddud7401012022-12-15 16:08:12 +00008613 * Fetches the carrier restriction status of the device and sends the status to the caller
8614 * through the callback.
8615 *
8616 * @param callback The callback that will be used to send the result.
8617 * @throws SecurityException if the caller does not have the required permission/privileges or
8618 * the caller is not allowlisted.
8619 */
8620 @Override
8621 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8622 enforceReadPermission("getCarrierRestrictionStatus");
8623 int carrierId = validateCallerAndGetCarrierId(packageName);
8624 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8625 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8626 throw new SecurityException("Not an authorized caller");
8627 }
8628 final long identity = Binder.clearCallingIdentity();
8629 try {
8630 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8631 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8632 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
8636 }
8637
arunvoddu567f2b42023-04-25 17:22:00 +00008638 @Override
8639 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8640 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8641 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8642 return allowListInfo.getShaIdList(pkgName, carrierId);
8643 }
8644
arunvoddud7401012022-12-15 16:08:12 +00008645 @VisibleForTesting
8646 public int validateCallerAndGetCarrierId(String packageName) {
8647 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8648 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8649 }
8650
8651 /**
fionaxu59545b42016-05-25 15:53:37 -07008652 * Action set from carrier signalling broadcast receivers to enable/disable radio
8653 * @param subId the subscription ID that this action applies to.
8654 * @param enabled control enable or disable radio.
8655 * {@hide}
8656 */
8657 @Override
8658 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8659 enforceModifyPermission();
8660 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008661
8662 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008663 if (phone == null) {
8664 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8665 return;
8666 }
8667 try {
8668 phone.carrierActionSetRadioEnabled(enabled);
8669 } catch (Exception e) {
8670 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008671 } finally {
8672 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008673 }
8674 }
8675
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008676 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008677 * Enable or disable Voice over NR (VoNR)
8678 * @param subId the subscription ID that this action applies to.
8679 * @param enabled enable or disable VoNR.
8680 * @return operation result.
8681 */
8682 @Override
8683 public int setVoNrEnabled(int subId, boolean enabled) {
8684 enforceModifyPermission();
8685 final Phone phone = getPhone(subId);
8686
8687 final long identity = Binder.clearCallingIdentity();
8688 if (phone == null) {
8689 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8690 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8691 }
8692
8693 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8694 try {
8695 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8696 workSource);
8697 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008698
8699 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8700 if (DBG) {
8701 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8702 }
8703 SubscriptionManager.setSubscriptionProperty(
8704 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8705 (enabled ? "1" : "0"));
8706 }
8707
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008708 return result;
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 }
8713
8714 /**
8715 * Is voice over NR enabled
8716 * @return true if VoNR is enabled else false
8717 */
8718 @Override
8719 public boolean isVoNrEnabled(int subId) {
8720 enforceReadPrivilegedPermission("isVoNrEnabled");
8721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8722 final long identity = Binder.clearCallingIdentity();
8723 try {
8724 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8725 null, subId, workSource);
8726 if (DBG) log("isVoNrEnabled: " + isEnabled);
8727 return isEnabled;
8728 } finally {
8729 Binder.restoreCallingIdentity(identity);
8730 }
8731 }
8732
8733 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008734 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8735 * network status based on which carrier apps could apply actions accordingly,
8736 * enable/disable default url handler for example.
8737 *
8738 * @param subId the subscription ID that this action applies to.
8739 * @param report control start/stop reporting the default network status.
8740 * {@hide}
8741 */
8742 @Override
8743 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8744 enforceModifyPermission();
8745 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008746
8747 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008748 if (phone == null) {
8749 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8750 return;
8751 }
8752 try {
8753 phone.carrierActionReportDefaultNetworkStatus(report);
8754 } catch (Exception e) {
8755 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008756 } finally {
8757 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008758 }
8759 }
8760
8761 /**
fionaxud9622282017-07-17 17:51:30 -07008762 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8763 * @param subId the subscription ID that this action applies to.
8764 * {@hide}
8765 */
8766 @Override
8767 public void carrierActionResetAll(int subId) {
8768 enforceModifyPermission();
8769 final Phone phone = getPhone(subId);
8770 if (phone == null) {
8771 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8772 return;
8773 }
8774 try {
8775 phone.carrierActionResetAll();
8776 } catch (Exception e) {
8777 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8778 }
8779 }
8780
8781 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008782 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8783 * bug report is being generated.
8784 */
8785 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008786 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008787 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8788 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008789 writer.println("Permission Denial: can't dump Phone from pid="
8790 + Binder.getCallingPid()
8791 + ", uid=" + Binder.getCallingUid()
8792 + "without permission "
8793 + android.Manifest.permission.DUMP);
8794 return;
8795 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008796 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008797 }
Jack Yueb89b242016-06-22 13:27:47 -07008798
Brad Ebingerdac2f002018-04-03 15:17:52 -07008799 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008800 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8801 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8802 @NonNull String[] args) {
8803 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8804 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008805 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008806 }
8807
Jack Yueb89b242016-06-22 13:27:47 -07008808 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008809 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008810 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008811 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008812 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008813 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008814 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008815 */
8816 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008817 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008818 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008819 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8820 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8821 try {
8822 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008823 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008824 } catch (SecurityException se) {
8825 enforceModifyPermission();
8826 }
8827 } else {
8828 enforceModifyPermission();
8829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008830
8831 final long identity = Binder.clearCallingIdentity();
8832 try {
8833 Phone phone = getPhone(subId);
8834 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008835 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8836 phone.carrierActionSetMeteredApnsEnabled(enabled);
8837 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008838 phone.getDataSettingsManager().setDataEnabled(
8839 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008840 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008841 }
8842 } finally {
8843 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008844 }
8845 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008846
8847 /**
8848 * Get Client request stats
8849 * @return List of Client Request Stats
8850 * @hide
8851 */
8852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008853 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8854 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008856 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008857 return null;
8858 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008859 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861 final long identity = Binder.clearCallingIdentity();
8862 try {
8863 if (phone != null) {
8864 return phone.getClientRequestStats();
8865 }
8866
8867 return null;
8868 } finally {
8869 Binder.restoreCallingIdentity(identity);
8870 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008871 }
8872
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008873 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008874 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008875 if (uid == Process.ROOT_UID && packageName == null) {
8876 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8877 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8878 // exception. ROOT_UID seems not to have a valid package name returned by
8879 // PackageManager, so just fake it here to avoid issues when running telephony shell
8880 // commands that plumb through the RIL as root, like so:
8881 // $ adb root
8882 // $ adb shell cmd phone ...
8883 packageName = "root";
8884 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008885 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008886 }
Jack Yueb4124c2017-02-16 15:32:43 -08008887
8888 /**
Grace Chen70990072017-03-24 17:21:30 -07008889 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008890 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008891 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008892 * @param state State of SIM (power down, power up, pass through)
8893 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8894 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8895 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008896 *
8897 **/
8898 @Override
Grace Chen70990072017-03-24 17:21:30 -07008899 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008900 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008901 Phone phone = PhoneFactory.getPhone(slotIndex);
8902
vagdeviaf9a5b92018-08-15 16:01:53 -07008903 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008905 final long identity = Binder.clearCallingIdentity();
8906 try {
8907 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008908 phone.setSimPowerState(state, null, workSource);
8909 }
8910 } finally {
8911 Binder.restoreCallingIdentity(identity);
8912 }
8913 }
8914
8915 /**
8916 * Set SIM card power state.
8917 *
8918 * @param slotIndex SIM slot id.
8919 * @param state State of SIM (power down, power up, pass through)
8920 * @param callback callback to trigger after success or failure
8921 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8922 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8923 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8924 *
8925 **/
8926 @Override
8927 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8928 IIntegerConsumer callback) {
8929 enforceModifyPermission();
8930 Phone phone = PhoneFactory.getPhone(slotIndex);
8931
8932 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8933
8934 final long identity = Binder.clearCallingIdentity();
8935 try {
8936 if (phone != null) {
8937 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8938 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008939 }
8940 } finally {
8941 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008942 }
8943 }
Shuo Qiandd210312017-04-12 22:11:33 +00008944
Tyler Gunn65d45c22017-06-05 11:22:26 -07008945 private boolean isUssdApiAllowed(int subId) {
8946 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008947 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008948 if (configManager == null) {
8949 return false;
8950 }
8951 PersistableBundle pb = configManager.getConfigForSubId(subId);
8952 if (pb == null) {
8953 return false;
8954 }
8955 return pb.getBoolean(
8956 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8957 }
8958
Shuo Qiandd210312017-04-12 22:11:33 +00008959 /**
Ling Mac28f0212023-03-24 16:07:15 -07008960 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008961 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008962 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008963 */
goneil9c5f4872017-12-05 14:07:56 -08008964 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008965 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008966 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008967 final long identity = Binder.clearCallingIdentity();
8968 try {
Ling Mac28f0212023-03-24 16:07:15 -07008969 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008970 } finally {
8971 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008972 }
8973 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008974
8975 /**
8976 * Get the current signal strength information for the given subscription.
8977 * Because this information is not updated when the device is in a low power state
8978 * it should not be relied-upon to be current.
8979 * @param subId Subscription index
8980 * @return the most recent cached signal strength info from the modem
8981 */
8982 @Override
8983 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984 final long identity = Binder.clearCallingIdentity();
8985 try {
8986 Phone p = getPhone(subId);
8987 if (p == null) {
8988 return null;
8989 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008991 return p.getSignalStrength();
8992 } finally {
8993 Binder.restoreCallingIdentity(identity);
8994 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008995 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008996
Pengquan Meng77b7f132018-08-22 14:49:57 -07008997 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008998 * Get the current modem radio state for the given slot.
8999 * @param slotIndex slot index.
9000 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009001 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009002 * @return the current radio power state from the modem
9003 */
9004 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009005 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009006 Phone phone = PhoneFactory.getPhone(slotIndex);
9007 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9009 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009010 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9011 }
9012
9013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 return phone.getRadioPowerState();
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
9018 }
9019 }
9020 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9021 }
9022
9023 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009024 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9025 *
9026 * <p>Requires one of the following permissions:
9027 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009028 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009029 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9030 * privileges.
9031 *
9032 * @param subId subscription id
9033 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9034 * {@code false}.
9035 */
9036 @Override
9037 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009038 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009039 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009040 try {
9041 mApp.enforceCallingOrSelfPermission(
9042 android.Manifest.permission.ACCESS_NETWORK_STATE,
9043 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009044 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009045 mApp.enforceCallingOrSelfPermission(
9046 permission.READ_BASIC_PHONE_STATE, functionName);
9047 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009048 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009049 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009050 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009051 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009052
Pengquan Menga1bb6272018-09-06 09:59:22 -07009053 boolean isEnabled = false;
9054 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009055 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009056 Phone phone = getPhone(subId);
9057 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009058 } finally {
9059 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009060 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009061 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009062 }
9063
9064
9065 /**
9066 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9067 *
9068 * <p> Requires permission:
9069 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9070 * privileges.
9071 *
9072 * @param subId subscription id
9073 * @param isEnabled {@code true} means enable, {@code false} means disable.
9074 */
9075 @Override
9076 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9078 mApp, subId, "setDataRoamingEnabled");
9079
Pengquan Menga1bb6272018-09-06 09:59:22 -07009080 final long identity = Binder.clearCallingIdentity();
9081 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009082 Phone phone = getPhone(subId);
9083 if (phone != null) {
9084 phone.setDataRoamingEnabled(isEnabled);
9085 }
9086 } finally {
9087 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009088 }
9089 }
9090
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009091 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009092 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009093 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009094 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009095 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009096
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009097 boolean isAllowed = true;
9098 final long identity = Binder.clearCallingIdentity();
9099 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009100 Phone phone = getPhone(subId);
9101 if (phone != null) {
9102 isAllowed = phone.isCspPlmnEnabled();
9103 }
9104 } finally {
9105 Binder.restoreCallingIdentity(identity);
9106 }
9107 return isAllowed;
9108 }
9109
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009110 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9111 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009112 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009113 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009114 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009115 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9116 if (phone == null) {
9117 return false;
9118 }
9119 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9120 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9121 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009122 }
9123
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009124 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009125 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009126 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009127 mApp.getSystemService(AppOpsManager.class)
9128 .checkPackage(Binder.getCallingUid(), callingPackage);
9129
Jordan Liu1e142fc2019-04-22 15:10:43 -07009130 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009131 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009132 try {
9133 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009134 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009135 } catch (SecurityException e) {
9136 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9137 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009138 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009139 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009140 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009141 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009142 }
sandeepjsb6c87872021-09-27 15:34:44 +00009143 // checking compatibility, if calling app's target SDK is T and beyond.
9144 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9145 Binder.getCallingUid())) {
9146 isIccIdAccessRestricted = true;
9147 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009148 final long identity = Binder.clearCallingIdentity();
9149 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009150 UiccController uiccController = UiccController.getInstance();
9151 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009152 if (hasReadPermission) {
9153 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009154 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009155
9156 // Remove private info if the caller doesn't have access
9157 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9158 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009159 //setting the value after compatibility check
9160 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009161 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9162 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009163 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009164 if (card == null) {
9165 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009166 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009167 continue;
9168 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009169 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9170 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009171 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009172 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009173 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009174 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9175 for (UiccPortInfo portInfo : portInfos) {
9176 UiccPort port = uiccController.getUiccPortForSlot(
9177 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9178 if (port == null) {
9179 // assume no access if port is null
9180 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9181 continue;
9182 }
9183 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9184 uiccPortInfos.add(portInfo);
9185 } else {
9186 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9187 }
9188 }
9189 filteredInfos.add(new UiccCardInfo(
9190 cardInfo.isEuicc(),
9191 cardInfo.getCardId(),
9192 null,
9193 cardInfo.getPhysicalSlotIndex(),
9194 cardInfo.isRemovable(),
9195 cardInfo.isMultipleEnabledProfilesSupported(),
9196 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009197 }
9198 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 }
9203
sandeepjsb6c87872021-09-27 15:34:44 +00009204 /**
9205 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9206 * generally private and require carrier privileges to view.
9207 *
9208 * @hide
9209 */
9210 @NonNull
9211 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9212 List<UiccPortInfo> portinfo = new ArrayList<>();
9213 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9214 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9215 }
9216 return new UiccCardInfo(
9217 cardInfo.isEuicc(),
9218 cardInfo.getCardId(),
9219 null,
9220 cardInfo.getPhysicalSlotIndex(),
9221 cardInfo.isRemovable(),
9222 cardInfo.isMultipleEnabledProfilesSupported(),
9223 portinfo
9224 );
9225 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009226
sandeepjsb6c87872021-09-27 15:34:44 +00009227 /**
9228 * @hide
9229 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9230 * These values are generally private and require carrier privileges to view.
9231 */
9232 @NonNull
9233 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9234 return new UiccPortInfo(
9235 UiccPortInfo.ICCID_REDACTED,
9236 portInfo.getPortIndex(),
9237 portInfo.getLogicalSlotIndex(),
9238 portInfo.isActive()
9239 );
9240 }
9241 @Override
9242 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009243 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009244 mApp.getSystemService(AppOpsManager.class)
9245 .checkPackage(Binder.getCallingUid(), callingPackage);
9246
sandeepjsb6c87872021-09-27 15:34:44 +00009247 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009248
Aman Guptaf3c90b32022-03-17 04:54:16 +00009249 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9250 // we are reading iccId which is PII data.
9251 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009252
9253 // checking compatibility, if calling app's target SDK is T and beyond.
9254 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9255 Binder.getCallingUid())) {
9256 isLogicalSlotAccessRestricted = true;
9257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009258 final long identity = Binder.clearCallingIdentity();
9259 try {
9260 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009261 if (slots == null || slots.length == 0) {
9262 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009263 return null;
9264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009265 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9266 for (int i = 0; i < slots.length; i++) {
9267 UiccSlot slot = slots[i];
9268 if (slot == null) {
9269 continue;
9270 }
9271
Jordan Liu7be7e652019-05-06 18:55:02 +00009272 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009273 UiccCard card = slot.getUiccCard();
9274 if (card != null) {
9275 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009276 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009277 cardId = slot.getEid();
9278 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009279 // If cardId is null, use iccId of default port as cardId.
9280 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009282 }
9283
Jordan Liu857451f2019-05-09 16:35:35 -07009284 if (cardId != null) {
9285 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9286 // if cardId is an EID, it's all digits so this is fine
9287 cardId = IccUtils.stripTrailingFs(cardId);
9288 }
9289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009290 int cardState = 0;
9291 switch (slot.getCardState()) {
9292 case CARDSTATE_ABSENT:
9293 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9294 break;
9295 case CARDSTATE_PRESENT:
9296 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9297 break;
9298 case CARDSTATE_ERROR:
9299 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9300 break;
9301 case CARDSTATE_RESTRICTED:
9302 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9303 break;
9304 default:
9305 break;
9306
9307 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009308 List<UiccPortInfo> portInfos = new ArrayList<>();
9309 int[] portIndexes = slot.getPortList();
9310 for (int portIdx : portIndexes) {
9311 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009312 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009313 portInfos.add(new UiccPortInfo(iccId, portIdx,
9314 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009316 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009317 slot.isEuicc(),
9318 cardId,
9319 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009320 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009321 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009322 //setting the value after compatibility check
9323 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009324 }
9325 return infos;
9326 } finally {
9327 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009328 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009329 }
9330
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009331 /* Returns null if doesn't have read permission or carrier privilege access. */
9332 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9333 boolean hasReadPermission) {
9334 String iccId = slot.getIccId(portIndex);
9335 if (hasReadPermission) { // if has read permission
9336 return iccId;
9337 } else {
9338 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9339 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9340 // if no read permission, checking carrier privilege access
9341 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9342 return iccId;
9343 }
9344 }
9345 }
9346 // No read permission or carrier privilege access.
9347 return UiccPortInfo.ICCID_REDACTED;
9348 }
9349
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009350 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009351 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009352 public boolean switchSlots(int[] physicalSlots) {
9353 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009354
9355 final long identity = Binder.clearCallingIdentity();
9356 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009357 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9358 for (int i = 0; i < physicalSlots.length; i++) {
9359 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9360 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9361 physicalSlots[i], i));
9362 }
9363 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009367 }
Jack Yu4c988042018-02-27 15:30:01 -08009368
9369 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009370 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9371 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9372 enforceModifyPermission();
9373
9374 final long identity = Binder.clearCallingIdentity();
9375 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009376 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009377 } finally {
9378 Binder.restoreCallingIdentity(identity);
9379 }
9380 }
9381
9382 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009383 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009384 final long identity = Binder.clearCallingIdentity();
9385 try {
9386 return UiccController.getInstance().getCardIdForDefaultEuicc();
9387 } finally {
9388 Binder.restoreCallingIdentity(identity);
9389 }
9390 }
9391
Pengquan Meng85728fb2018-03-12 16:31:21 -07009392 /**
goneil47ffb6e2018-04-06 15:40:58 -07009393 * A test API to reload the UICC profile.
9394 *
9395 * <p>Requires that the calling app has permission
9396 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9397 * @hide
9398 */
9399 @Override
9400 public void refreshUiccProfile(int subId) {
9401 enforceModifyPermission();
9402
9403 final long identity = Binder.clearCallingIdentity();
9404 try {
9405 Phone phone = getPhone(subId);
9406 if (phone == null) {
9407 return;
9408 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009409 UiccPort uiccPort = phone.getUiccPort();
9410 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009411 return;
9412 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009413 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009414 if (uiccProfile == null) {
9415 return;
9416 }
9417 uiccProfile.refresh();
9418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
9421 }
9422
9423 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009424 * Returns false if the mobile data is disabled by default, otherwise return true.
9425 */
9426 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009427 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009428 }
9429
9430 /**
9431 * Returns true if the data roaming is enabled by default, i.e the system property
9432 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9433 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9434 */
9435 private boolean getDefaultDataRoamingEnabled(int subId) {
9436 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009437 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009438 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009439 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9440 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9441 return isDataRoamingEnabled;
9442 }
9443
9444 /**
9445 * Returns the default network type for the given {@code subId}, if the default network type is
9446 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9447 */
9448 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009449 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009450 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009451 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9452 return list.get(phoneId);
9453 }
9454 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009455 }
fionaxua13278b2018-03-21 00:08:13 -07009456
9457 @Override
9458 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009459 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009460 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009461
9462 final long identity = Binder.clearCallingIdentity();
9463 try {
9464 final Phone phone = getPhone(subId);
9465 if (phone == null) {
9466 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9467 return;
9468 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009469 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9470 if (cpt != null) {
9471 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9472 }
9473 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009474 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9475 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009476 if (carrierPrivilegeRules == null) {
9477 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9478 } else {
9479 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009481 } finally {
9482 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009483 }
fionaxua13278b2018-03-21 00:08:13 -07009484 }
9485
9486 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009487 public void setCarrierServicePackageOverride(
9488 int subId, String carrierServicePackage, String callingPackage) {
9489 TelephonyPermissions.enforceShellOnly(
9490 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9491
Benedict Wong66477622023-02-03 23:30:57 +00009492 final long identity = Binder.clearCallingIdentity();
9493 try {
9494 final Phone phone = getPhone(subId);
9495 if (phone == null || phone.getSubId() != subId) {
9496 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9497 throw new IllegalArgumentException("No phone for subid");
9498 }
9499 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9500 if (cpt == null) {
9501 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9502 throw new IllegalStateException("No CPT for phone");
9503 }
9504 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9505 } finally {
9506 Binder.restoreCallingIdentity(identity);
9507 }
9508 }
9509
9510 @Override
fionaxua13278b2018-03-21 00:08:13 -07009511 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009512 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009513
9514 final long identity = Binder.clearCallingIdentity();
9515 try {
9516 final Phone phone = getPhone(subId);
9517 if (phone == null) {
9518 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9519 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9520 }
9521 return phone.getCarrierIdListVersion();
9522 } finally {
9523 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009524 }
fionaxua13278b2018-03-21 00:08:13 -07009525 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009526
9527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009528 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9529 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009531 mApp, subId, callingPackage, callingFeatureId,
9532 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009533 return -1;
9534 }
9535
9536 final long identity = Binder.clearCallingIdentity();
9537 try {
9538 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9539 } finally {
9540 Binder.restoreCallingIdentity(identity);
9541 }
9542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009543
9544 @Override
9545 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009546 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009547 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009548 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009549
9550 final long identity = Binder.clearCallingIdentity();
9551 try {
9552 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
9558 @Override
9559 public boolean setCdmaRoamingMode(int subId, int mode) {
9560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9561 mApp, subId, "setCdmaRoamingMode");
9562
9563 final long identity = Binder.clearCallingIdentity();
9564 try {
9565 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9566 } finally {
9567 Binder.restoreCallingIdentity(identity);
9568 }
9569 }
9570
9571 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009572 public int getCdmaSubscriptionMode(int subId) {
9573 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009574 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009575 mApp, subId, "getCdmaSubscriptionMode");
9576
9577 final long identity = Binder.clearCallingIdentity();
9578 try {
9579 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
9582 }
9583 }
9584
9585 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009586 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9588 mApp, subId, "setCdmaSubscriptionMode");
9589
9590 final long identity = Binder.clearCallingIdentity();
9591 try {
9592 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009597
sqianc5eccab2018-10-19 18:46:41 -07009598 @Override
sqian8c685422019-02-22 15:55:18 -08009599 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009600 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009602 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9603 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009604 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9605 }
9606 final long identity = Binder.clearCallingIdentity();
9607 try {
sqian854d44b2018-12-12 16:48:18 -08009608 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9609 for (Phone phone: PhoneFactory.getPhones()) {
9610 if (phone.getEmergencyNumberTracker() != null
9611 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9612 emergencyNumberListInternal.put(
9613 phone.getSubId(),
9614 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9615 }
sqian11b7a0e2018-12-05 18:48:28 -08009616 }
sqian854d44b2018-12-12 16:48:18 -08009617 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009618 } finally {
9619 Binder.restoreCallingIdentity(identity);
9620 }
sqianc5eccab2018-10-19 18:46:41 -07009621 }
9622
9623 @Override
sqian8c685422019-02-22 15:55:18 -08009624 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009625 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009626 if (!exactMatch) {
9627 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009628 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009629 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009630 }
9631 final long identity = Binder.clearCallingIdentity();
9632 try {
sqian854d44b2018-12-12 16:48:18 -08009633 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009634 //Note: we ignore passed in param exactMatch. We can remove it once
9635 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009636 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009637 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009638 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009639 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009640 }
sqian11b7a0e2018-12-05 18:48:28 -08009641 }
9642 return false;
9643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
9647
sqianf4ca7ed2019-01-15 18:32:07 -08009648 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009649 * Start emergency callback mode for GsmCdmaPhone for testing.
9650 */
9651 @Override
9652 public void startEmergencyCallbackMode() {
9653 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9654 "startEmergencyCallbackMode");
9655 enforceModifyPermission();
9656 final long identity = Binder.clearCallingIdentity();
9657 try {
9658 for (Phone phone : PhoneFactory.getPhones()) {
9659 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9660 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9661 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9662 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9663 gsmCdmaPhone.obtainMessage(
9664 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9665 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9666 }
9667 }
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
9672
9673 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009674 * Update emergency number list for test mode.
9675 */
9676 @Override
9677 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9678 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9679 "updateEmergencyNumberListTestMode");
9680
9681 final long identity = Binder.clearCallingIdentity();
9682 try {
9683 for (Phone phone: PhoneFactory.getPhones()) {
9684 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9685 if (tracker != null) {
9686 tracker.executeEmergencyNumberTestModeCommand(action, num);
9687 }
9688 }
9689 } finally {
9690 Binder.restoreCallingIdentity(identity);
9691 }
9692 }
9693
9694 /**
9695 * Get the full emergency number list for test mode.
9696 */
9697 @Override
9698 public List<String> getEmergencyNumberListTestMode() {
9699 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9700 "getEmergencyNumberListTestMode");
9701
9702 final long identity = Binder.clearCallingIdentity();
9703 try {
9704 Set<String> emergencyNumbers = new HashSet<>();
9705 for (Phone phone: PhoneFactory.getPhones()) {
9706 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9707 if (tracker != null) {
9708 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9709 emergencyNumbers.add(num.getNumber());
9710 }
9711 }
9712 }
9713 return new ArrayList<>(emergencyNumbers);
9714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
chen xud6b45bd2018-10-30 22:27:10 -07009719 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009720 public int getEmergencyNumberDbVersion(int subId) {
9721 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9722
9723 final long identity = Binder.clearCallingIdentity();
9724 try {
9725 final Phone phone = getPhone(subId);
9726 if (phone == null) {
9727 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9728 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9729 }
9730 return phone.getEmergencyNumberDbVersion();
9731 } finally {
9732 Binder.restoreCallingIdentity(identity);
9733 }
9734 }
9735
9736 @Override
9737 public void notifyOtaEmergencyNumberDbInstalled() {
9738 enforceModifyPermission();
9739
9740 final long identity = Binder.clearCallingIdentity();
9741 try {
9742 for (Phone phone: PhoneFactory.getPhones()) {
9743 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9744 if (tracker != null) {
9745 tracker.updateOtaEmergencyNumberDatabase();
9746 }
9747 }
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009754 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009755 enforceActiveEmergencySessionPermission();
9756
9757 final long identity = Binder.clearCallingIdentity();
9758 try {
9759 for (Phone phone: PhoneFactory.getPhones()) {
9760 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9761 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009762 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9763 }
9764 }
9765 } finally {
9766 Binder.restoreCallingIdentity(identity);
9767 }
9768 }
9769
9770 @Override
9771 public void resetOtaEmergencyNumberDbFilePath() {
9772 enforceActiveEmergencySessionPermission();
9773
9774 final long identity = Binder.clearCallingIdentity();
9775 try {
9776 for (Phone phone: PhoneFactory.getPhones()) {
9777 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9778 if (tracker != null) {
9779 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009780 }
9781 }
9782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
9786
9787 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009788 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9789 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9790 Phone phone = getPhone(subId);
9791 if (phone == null) {
9792 return null;
9793 }
9794 final long identity = Binder.clearCallingIdentity();
9795 try {
9796 UiccProfile profile = UiccController.getInstance()
9797 .getUiccProfileForPhone(phone.getPhoneId());
9798 if (profile != null) {
9799 return profile.getCertsFromCarrierPrivilegeAccessRules();
9800 }
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 return null;
9805 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009806
9807 /**
9808 * Enable or disable a modem stack.
9809 */
9810 @Override
9811 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9812 enforceModifyPermission();
9813
9814 final long identity = Binder.clearCallingIdentity();
9815 try {
9816 Phone phone = PhoneFactory.getPhone(slotIndex);
9817 if (phone == null) {
9818 return false;
9819 } else {
9820 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9821 }
9822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 }
Michelecea4cf22018-12-21 15:00:11 -08009826
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009827 /**
9828 * Whether a modem stack is enabled or not.
9829 */
9830 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009831 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9832 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009833 Phone phone = PhoneFactory.getPhone(slotIndex);
9834 if (phone == null) return false;
9835
9836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009837 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9838 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009839 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9840 }
9841
9842 final long identity = Binder.clearCallingIdentity();
9843 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009844 try {
9845 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9846 } catch (NoSuchElementException ex) {
9847 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9848 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009849 } finally {
9850 Binder.restoreCallingIdentity(identity);
9851 }
9852 }
9853
Michelecea4cf22018-12-21 15:00:11 -08009854 @Override
Michele0ea7d782019-03-19 14:58:42 -07009855 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009856 enforceModifyPermission();
9857
9858 final long identity = Binder.clearCallingIdentity();
9859 try {
9860 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009861 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009862 .commit();
9863 } finally {
9864 Binder.restoreCallingIdentity(identity);
9865 }
9866 }
9867
9868 @Override
Michele0ea7d782019-03-19 14:58:42 -07009869 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009870 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009872 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9873 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009874 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009875 }
Michelecea4cf22018-12-21 15:00:11 -08009876
9877 final long identity = Binder.clearCallingIdentity();
9878 try {
Michele0ea7d782019-03-19 14:58:42 -07009879 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009884
Michele0ea7d782019-03-19 14:58:42 -07009885 @TelephonyManager.IsMultiSimSupportedResult
9886 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009887 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9888 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9889 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009890 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9891 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009892 }
9893 // Check if the hardware supports multisim functionality. If usage of multisim is not
9894 // supported by the modem, indicate that it is restricted.
9895 PhoneCapability staticCapability =
9896 mPhoneConfigurationManager.getStaticPhoneCapability();
9897 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009898 loge("isMultiSimSupportedInternal: no static configuration available");
9899 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009900 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009901 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009902 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9903 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009904 }
9905 // Check if support of multiple SIMs is restricted by carrier
9906 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009907 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009908 }
9909
Michele0ea7d782019-03-19 14:58:42 -07009910 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009911 }
9912
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009913 /**
9914 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009915 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9916 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9917 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009918 * @param numOfSims number of active sims we want to switch to
9919 */
9920 @Override
9921 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009922 if (numOfSims == 1) {
9923 enforceModifyPermission();
9924 } else {
9925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9926 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9927 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009928 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009929
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009930 try {
Michele30b57b22019-03-01 12:01:14 -08009931 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009932 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009933 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9934 return;
9935 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009936 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9937 } finally {
9938 Binder.restoreCallingIdentity(identity);
9939 }
9940 }
9941
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009942 @Override
9943 public boolean isApplicationOnUicc(int subId, int appType) {
9944 enforceReadPrivilegedPermission("isApplicationOnUicc");
9945 Phone phone = getPhone(subId);
9946 if (phone == null) {
9947 return false;
9948 }
9949 final long identity = Binder.clearCallingIdentity();
9950 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009951 UiccPort uiccPort = phone.getUiccPort();
9952 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009953 return false;
9954 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009955 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009956 if (uiccProfile == null) {
9957 return false;
9958 }
9959 if (TelephonyManager.APPTYPE_SIM <= appType
9960 && appType <= TelephonyManager.APPTYPE_ISIM) {
9961 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9962 }
9963 return false;
9964 } finally {
9965 Binder.restoreCallingIdentity(identity);
9966 }
9967 }
9968
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009969 /**
chen xub4baa772019-04-03 10:23:41 -07009970 * Get whether making changes to modem configurations will trigger reboot.
9971 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009972 */
9973 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009974 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9975 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009977 mApp, subId, callingPackage, callingFeatureId,
9978 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009979 return false;
9980 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009981 final long identity = Binder.clearCallingIdentity();
9982 try {
9983 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9984 } finally {
9985 Binder.restoreCallingIdentity(identity);
9986 }
9987 }
9988
Nathan Harold29f5f052019-02-15 13:41:57 -08009989 private void updateModemStateMetrics() {
9990 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9991 // TODO: check the state for each modem if the api is ready.
9992 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9993 }
9994
Pengquan Meng3889a572019-01-23 11:16:29 -08009995 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009996 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009997 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009998 // Verify that the callingPackage belongs to the calling UID
9999 mApp.getSystemService(AppOpsManager.class)
10000 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010001 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010002 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010003 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010004 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10005 if (slotInfos != null) {
10006 for (int i = 0; i < slotInfos.length; i++) {
10007 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10008 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10009 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10010 portInfo.getLogicalSlotIndex()));
10011 }
10012 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010013 }
10014 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010015 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010016 } finally {
10017 Binder.restoreCallingIdentity(identity);
10018 }
10019 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010020
10021 /**
10022 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010023 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010024 */
jimsunf9ec1622022-09-13 21:18:43 +080010025 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010026 @Override
10027 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010028 return getHalVersion(HAL_SERVICE_RADIO);
10029 }
10030
10031 /**
10032 * Get the HAL Version of a specific service
10033 */
10034 @Override
10035 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010036 Phone phone = getDefaultPhone();
10037 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010038 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010039 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10040 return hv.major * 100 + hv.minor;
10041 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010042
10043 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010044 * Get the current calling package name.
10045 * @return the current calling package name
10046 */
10047 @Override
10048 public String getCurrentPackageName() {
10049 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10050 }
10051
10052 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010053 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10054 * corresponding network requests on a subId.
10055 *
10056 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010057 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010058 * 2) APN is un-metered for this subscription, or
10059 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010060 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010061 *
10062 * @return whether data is allowed for a apn type.
10063 *
10064 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010065 */
10066 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010067 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010068 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10069 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010070
10071 // Now that all security checks passes, perform the operation as ourselves.
10072 final long identity = Binder.clearCallingIdentity();
10073 try {
10074 Phone phone = getPhone(subId);
10075 if (phone == null) return false;
10076
Jack Yu27422a52022-03-21 10:38:05 -070010077 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010078 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010079 isMetered = phone.getDataNetworkController().getDataConfigManager()
10080 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10081 phone.getServiceState().getDataRoaming());
10082 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010083 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010084 } finally {
10085 Binder.restoreCallingIdentity(identity);
10086 }
10087 }
10088
10089 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010090 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010091 enforceReadPrivilegedPermission("isApnMetered");
10092
10093 // Now that all security checks passes, perform the operation as ourselves.
10094 final long identity = Binder.clearCallingIdentity();
10095 try {
10096 Phone phone = getPhone(subId);
10097 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010098 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10099 DataUtils.apnTypeToNetworkCapability(apnType),
10100 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010101 } finally {
10102 Binder.restoreCallingIdentity(identity);
10103 }
10104 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010105
10106 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010107 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10108 int subscriptionId, IBooleanConsumer resultCallback) {
10109 enforceModifyPermission();
10110 long token = Binder.clearCallingIdentity();
10111 try {
10112 Phone phone = getPhone(subscriptionId);
10113 if (phone == null) {
10114 try {
10115 if (resultCallback != null) {
10116 resultCallback.accept(false);
10117 }
10118 } catch (RemoteException e) {
10119 // ignore
10120 }
10121 return;
10122 }
10123 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10124 Pair.create(specifiers, (x) -> {
10125 try {
10126 if (resultCallback != null) {
10127 resultCallback.accept(x);
10128 }
10129 } catch (RemoteException e) {
10130 // ignore
10131 }
10132 });
10133 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10134 } finally {
10135 Binder.restoreCallingIdentity(token);
10136 }
10137 }
10138
10139 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010140 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10141 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010142 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010143 mApp, subId, "getSystemSelectionChannels");
10144 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10145 final long identity = Binder.clearCallingIdentity();
10146 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010147 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10148 if (result instanceof IllegalStateException) {
10149 throw (IllegalStateException) result;
10150 }
10151 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010152 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10153 return specifiers;
10154 } finally {
10155 Binder.restoreCallingIdentity(identity);
10156 }
10157 }
10158
10159 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010160 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010161 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010162 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010163 }
10164
10165 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010166 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10167 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010168 if (callingPackage == null) {
10169 callingPackage = getCurrentPackageName();
10170 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010171 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10172 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010173 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10174 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010175 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10176 }
10177 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10178 Intent intent = new Intent();
10179 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10180 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10181 // Bring up choose default SMS subscription dialog right now
10182 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10183 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10184 mApp.startActivity(intent);
10185 }
chen xud5ca2d52019-05-28 15:20:57 -070010186
10187 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010188 public void showSwitchToManagedProfileDialog() {
10189 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010190 try {
10191 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10192 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10193 // for work telephony.
10194 Intent intent = new Intent(Intent.ACTION_SENDTO);
10195 intent.setData(Uri.parse("smsto:"));
10196 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10197 mApp.startActivity(intent);
10198 } catch (ActivityNotFoundException e) {
10199 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10200 Intent intent = new Intent();
10201 intent.setClass(mApp, ErrorDialogActivity.class);
10202 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10203 mApp.startActivity(intent);
10204 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010205 }
10206
10207 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010208 public String getMmsUAProfUrl(int subId) {
10209 //TODO investigate if this API should require proper permission check in R b/133791609
10210 final long identity = Binder.clearCallingIdentity();
10211 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010212 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10213 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10214 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10215 return carrierUAProfUrl;
10216 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010217 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10218 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222 }
10223
10224 @Override
10225 public String getMmsUserAgent(int subId) {
10226 //TODO investigate if this API should require proper permission check in R b/133791609
10227 final long identity = Binder.clearCallingIdentity();
10228 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010229 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10230 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10231 if (!TextUtils.isEmpty(carrierUserAgent)) {
10232 return carrierUserAgent;
10233 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010234 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10235 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010236 } finally {
10237 Binder.restoreCallingIdentity(identity);
10238 }
10239 }
Jack Yub07d4972019-05-28 16:12:25 -070010240
10241 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010242 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10243 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010244
Jack Yub07d4972019-05-28 16:12:25 -070010245 final long identity = Binder.clearCallingIdentity();
10246 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010247 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010248 if (phone == null) return false;
10249
Ling Maf188d502022-09-16 15:22:36 -070010250 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010251 } finally {
10252 Binder.restoreCallingIdentity(identity);
10253 }
10254 }
10255
10256 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010257 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010258 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010259 enforceModifyPermission();
10260
changbettyd5c246e2019-12-24 15:40:37 +080010261 final long identity = Binder.clearCallingIdentity();
10262 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010263 Phone phone = getPhone(subscriptionId);
10264 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010265
Ling Maf188d502022-09-16 15:22:36 -070010266 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010267 } finally {
10268 Binder.restoreCallingIdentity(identity);
10269 }
10270 }
10271
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010272 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010273 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010274 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10275 * otherwise.
10276 */
10277 @Override
10278 public void setCepEnabled(boolean isCepEnabled) {
10279 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10280
10281 final long identity = Binder.clearCallingIdentity();
10282 try {
10283 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10284 for (Phone phone : PhoneFactory.getPhones()) {
10285 Phone defaultPhone = phone.getImsPhone();
10286 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10287 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10288 ImsPhoneCallTracker imsPhoneCallTracker =
10289 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10290 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10291 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10292 + imsPhone.getMsisdn());
10293 }
10294 }
10295 } finally {
10296 Binder.restoreCallingIdentity(identity);
10297 }
10298 }
allenwtsu46dcc572020-01-08 18:24:03 +080010299
10300 /**
10301 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10302 *
10303 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10304 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10305 * before being read.
10306 */
10307 @Override
10308 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10309 isCompressed) {
10310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10311 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010312 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10313 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10314 }
10315 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010316 // ProvisioningManager can not handle ServiceSpecificException.
10317 // Throw the IllegalStateException and annotate ProvisioningManager.
10318 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010319 }
10320
10321 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010322 try {
Hui Wang761a6682020-10-31 05:12:53 +000010323 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10324 } finally {
10325 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010326 }
10327 }
zoey chene02881a2019-12-30 16:11:23 +080010328
10329 @Override
10330 public boolean isIccLockEnabled(int subId) {
10331 enforceReadPrivilegedPermission("isIccLockEnabled");
10332
10333 // Now that all security checks passes, perform the operation as ourselves.
10334 final long identity = Binder.clearCallingIdentity();
10335 try {
10336 Phone phone = getPhone(subId);
10337 if (phone != null && phone.getIccCard() != null) {
10338 return phone.getIccCard().getIccLockEnabled();
10339 } else {
10340 return false;
10341 }
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
10346
10347 /**
10348 * Set the ICC pin lock enabled or disabled.
10349 *
10350 * @return an integer representing the status of IccLock enabled or disabled in the following
10351 * three cases:
10352 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10353 * successfully.
10354 * - Positive number and zero for remaining password attempts.
10355 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10356 *
10357 */
10358 @Override
10359 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10360 enforceModifyPermission();
10361
10362 Phone phone = getPhone(subId);
10363 if (phone == null) {
10364 return 0;
10365 }
10366 // Now that all security checks passes, perform the operation as ourselves.
10367 final long identity = Binder.clearCallingIdentity();
10368 try {
10369 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10370 new Pair<Boolean, String>(enabled, password), phone, null);
10371 return attemptsRemaining;
10372
10373 } catch (Exception e) {
10374 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 return 0;
10379 }
10380
10381 /**
10382 * Change the ICC password used in ICC pin lock.
10383 *
10384 * @return an integer representing the status of IccLock changed in the following three cases:
10385 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10386 * - Positive number and zero for remaining password attempts.
10387 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10388 *
10389 */
10390 @Override
10391 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10392 enforceModifyPermission();
10393
10394 Phone phone = getPhone(subId);
10395 if (phone == null) {
10396 return 0;
10397 }
10398 // Now that all security checks passes, perform the operation as ourselves.
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10402 new Pair<String, String>(oldPassword, newPassword), phone, null);
10403 return attemptsRemaining;
10404
10405 } catch (Exception e) {
10406 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10407 } finally {
10408 Binder.restoreCallingIdentity(identity);
10409 }
10410 return 0;
10411 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010412
10413 /**
10414 * Request for receiving user activity notification
10415 */
10416 @Override
10417 public void requestUserActivityNotification() {
10418 if (!mNotifyUserActivity.get()
10419 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10420 mNotifyUserActivity.set(true);
10421 }
10422 }
10423
10424 /**
10425 * Called when userActivity is signalled in the power manager.
10426 * This is safe to call from any thread, with any window manager locks held or not.
10427 */
10428 @Override
10429 public void userActivity() {
10430 // ***************************************
10431 // * Inherited from PhoneWindowManager *
10432 // ***************************************
10433 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10434 // WITH ITS LOCKS HELD.
10435 //
10436 // This code must be VERY careful about the locks
10437 // it acquires.
10438 // In fact, the current code acquires way too many,
10439 // and probably has lurking deadlocks.
10440
10441 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10442 throw new SecurityException("Only the OS may call notifyUserActivity()");
10443 }
10444
10445 if (mNotifyUserActivity.getAndSet(false)) {
10446 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10447 USER_ACTIVITY_NOTIFICATION_DELAY);
10448 }
10449 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010450
10451 @Override
10452 public boolean canConnectTo5GInDsdsMode() {
10453 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10454 }
Jack Yud10cdd42020-09-28 20:28:01 -070010455
10456 @Override
10457 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10458 String callingFeatureId) {
10459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10460 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10461 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10462 }
10463
10464 Phone phone = getPhone(subId);
10465 if (phone == null) {
10466 throw new RuntimeException("phone is not available");
10467 }
10468 // Now that all security checks passes, perform the operation as ourselves.
10469 final long identity = Binder.clearCallingIdentity();
10470 try {
10471 return phone.getEquivalentHomePlmns();
10472 } finally {
10473 Binder.restoreCallingIdentity(identity);
10474 }
10475 }
Daniel Bright59e67312020-11-13 11:49:37 -080010476
10477 @Override
10478 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010479 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10480 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010481 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010482 if (radioInterfaceCapabilities == null) {
10483 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010484 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010485 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010486 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010487
Hui Wang641e81c2020-10-12 12:14:23 -070010488 @Override
10489 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10490 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010491 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10492 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10493 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10494 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10495 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010496 if (DBG) {
10497 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10498 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10499 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10500 }
10501
10502 if (!SubscriptionManager.isValidSubscriptionId(subId)
10503 || appType < TelephonyManager.APPTYPE_UNKNOWN
10504 || appType > TelephonyManager.APPTYPE_ISIM
10505 || nafUrl == null || securityProtocol == null || callback == null) {
10506 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10507 if (callback != null) {
10508 try {
10509 callback.onAuthenticationFailure(
10510 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10511 } catch (RemoteException exception) {
10512 log("Fail to notify onAuthenticationFailure due to " + exception);
10513 }
10514 return;
10515 }
10516 }
10517
10518 final long token = Binder.clearCallingIdentity();
10519 try {
10520 getGbaManager(subId).bootstrapAuthenticationRequest(
10521 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010522 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010523 } finally {
10524 Binder.restoreCallingIdentity(token);
10525 }
10526 }
10527
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010528 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010529 * Attempts to set the radio power state for all phones for thermal reason.
10530 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010531 * requested radio power state will actually be set. See {@link
10532 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10533 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010534 * @param enable {@code true} if trying to turn radio on.
10535 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10536 * false}.
10537 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010538 private boolean setRadioPowerForThermal(boolean enable) {
10539 boolean isPhoneAvailable = false;
10540 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10541 Phone phone = PhoneFactory.getPhone(i);
10542 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010543 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010544 isPhoneAvailable = true;
10545 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010546 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010547
10548 // return true if successfully informed the phone object about the thermal radio power
10549 // request.
10550 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010551 }
10552
10553 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010554 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010555 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10556 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10557 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10558 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10559 throw new IllegalArgumentException("modem does not support data throttling");
10560 }
10561
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010562 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10563 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010564 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010565 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10566 }
10567
Sarah Chinecc78c42022-03-31 21:16:48 -070010568 setDataEnabledForReason(
10569 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010570
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010571 if (isDataThrottlingSupported) {
10572 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010573 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010574 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10575 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10576 } else if (thermalMitigationResult
10577 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010578 log("Modem likely does not support data throttling on secondary carrier. Data " +
10579 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10580 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010581 }
10582 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010583 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010584
10585 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010586 }
10587
Jack Nudelman644b91a2021-03-12 14:09:48 -080010588 private static List<String> getThermalMitigationAllowlist(Context context) {
10589 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10590 for (String pckg : context.getResources()
10591 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10592 sThermalMitigationAllowlistedPackages.add(pckg);
10593 }
10594 }
10595
10596 return sThermalMitigationAllowlistedPackages;
10597 }
10598
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010599 private boolean isAnyPhoneInEmergencyState() {
10600 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10601 if (tm.isInEmergencyCall()) {
10602 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10603 return true;
10604 }
10605 for (Phone phone : PhoneFactory.getPhones()) {
10606 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10607 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010608 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10609 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010610 return true;
10611 }
10612 }
10613
10614 return false;
10615 }
10616
Jack Nudelman644b91a2021-03-12 14:09:48 -080010617 /**
10618 * Used by shell commands to add an authorized package name for thermal mitigation.
10619 * @param packageName name of package to be allowlisted
10620 * @param context
10621 */
10622 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10623 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10624 sThermalMitigationAllowlistedPackages.add(packageName);
10625 }
10626
10627 /**
10628 * Used by shell commands to remove an authorized package name for thermal mitigation.
10629 * @param packageName name of package to remove from allowlist
10630 * @param context
10631 */
10632 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10633 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10634 sThermalMitigationAllowlistedPackages.remove(packageName);
10635 }
10636
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010637 /**
10638 * Thermal mitigation request to control functionalities at modem.
10639 *
10640 * @param subId the id of the subscription.
10641 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010642 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010643 *
10644 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10645 */
10646 @Override
10647 @ThermalMitigationResult
10648 public int sendThermalMitigationRequest(
10649 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010650 ThermalMitigationRequest thermalMitigationRequest,
10651 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010652 enforceModifyPermission();
10653
Jack Nudelman644b91a2021-03-12 14:09:48 -080010654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10655 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10656 .contains(callingPackage)) {
10657 throw new SecurityException("Calling package must be configured in the device config. "
10658 + "calling package: " + callingPackage);
10659 }
10660
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010661 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10662 final long identity = Binder.clearCallingIdentity();
10663
10664 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10665 try {
10666 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10667 switch (thermalMitigationAction) {
10668 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10669 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010670 handleDataThrottlingRequest(subId,
10671 thermalMitigationRequest.getDataThrottlingRequest(),
10672 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010673 break;
10674 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10675 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10676 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10677 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10678 }
10679
10680 // Ensure that radio is on. If not able to power on due to phone being
10681 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010682 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010683 thermalMitigationResult =
10684 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10685 break;
10686 }
10687
10688 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010689 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010690 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10691 break;
10692 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10693 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10694 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10695 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10696 }
10697
10698 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10699 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010700 Phone phone = getPhone(subId);
10701 if (phone == null) {
10702 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010703 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010704 break;
10705 }
10706
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010707 TelephonyConnectionService service =
10708 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010709 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010710 Log.e(LOG_TAG, "An emergency call is pending");
10711 thermalMitigationResult =
10712 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10713 break;
10714 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010715 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010716 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010717 break;
10718 }
10719 } else {
10720 thermalMitigationResult =
10721 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10722 break;
10723 }
10724
10725 // Turn radio off. If not able to power off due to phone being unavailable,
10726 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010727 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010728 thermalMitigationResult =
10729 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10730 break;
10731 }
10732 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010733 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010734 break;
10735 default:
10736 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10737 + "not exist. Requested action: " + thermalMitigationAction);
10738 }
10739 } catch (IllegalArgumentException e) {
10740 throw e;
10741 } catch (Exception e) {
10742 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10743 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747
10748 if (DBG) {
10749 log("thermalMitigationRequest returning with thermalMitigationResult: "
10750 + thermalMitigationResult);
10751 }
10752
10753 return thermalMitigationResult;
10754 }
Hui Wang641e81c2020-10-12 12:14:23 -070010755
10756 /**
10757 * Set the GbaService Package Name that Telephony will bind to.
10758 *
10759 * @param subId The sim that the GbaService is associated with.
10760 * @param packageName The name of the package to be replaced with.
10761 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10762 */
10763 @Override
10764 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10765 enforceModifyPermission();
10766
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 return getGbaManager(subId).overrideServicePackage(packageName);
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
10775 /**
10776 * Return the package name of the currently bound GbaService.
10777 *
10778 * @param subId The sim that the GbaService is associated with.
10779 * @return the package name of the GbaService configuration, null if GBA is not supported.
10780 */
10781 @Override
10782 public String getBoundGbaService(int subId) {
10783 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10784
10785 final long identity = Binder.clearCallingIdentity();
10786 try {
10787 return getGbaManager(subId).getServicePackage();
10788 } finally {
10789 Binder.restoreCallingIdentity(identity);
10790 }
10791 }
10792
10793 /**
10794 * Set the release time for telephony to unbind GbaService.
10795 *
10796 * @param subId The sim that the GbaService is associated with.
10797 * @param interval The release time to unbind GbaService by millisecond.
10798 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10799 */
10800 @Override
10801 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10802 enforceModifyPermission();
10803
10804 final long identity = Binder.clearCallingIdentity();
10805 try {
10806 return getGbaManager(subId).overrideReleaseTime(interval);
10807 } finally {
10808 Binder.restoreCallingIdentity(identity);
10809 }
10810 }
10811
10812 /**
10813 * Return the release time for telephony to unbind GbaService.
10814 *
10815 * @param subId The sim that the GbaService is associated with.
10816 * @return The release time to unbind GbaService by millisecond.
10817 */
10818 @Override
10819 public int getGbaReleaseTime(int subId) {
10820 enforceReadPrivilegedPermission("getGbaReleaseTime");
10821
10822 final long identity = Binder.clearCallingIdentity();
10823 try {
10824 return getGbaManager(subId).getReleaseTime();
10825 } finally {
10826 Binder.restoreCallingIdentity(identity);
10827 }
10828 }
10829
10830 private GbaManager getGbaManager(int subId) {
10831 GbaManager instance = GbaManager.getInstance(subId);
10832 if (instance == null) {
10833 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10834 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10835 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10836 }
10837 return instance;
10838 }
Hui Wang761a6682020-10-31 05:12:53 +000010839
10840 /**
10841 * indicate whether the device and the carrier can support
10842 * RCS VoLTE single registration.
10843 */
10844 @Override
10845 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010846 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10847 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10848 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10849 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010850
10851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10852 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10853 }
10854
10855 final long identity = Binder.clearCallingIdentity();
10856 try {
10857 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10858 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010859 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10860 if (isCapable != null) {
10861 return isCapable;
10862 }
Hui Wang761a6682020-10-31 05:12:53 +000010863 }
Hui Wang67af90e2021-06-04 16:57:15 -070010864 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10865 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010866 } finally {
10867 Binder.restoreCallingIdentity(identity);
10868 }
10869 }
10870
10871 /**
10872 * Register RCS provisioning callback.
10873 */
10874 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010875 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010876 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010877 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010878 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010879 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10880 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010881
10882 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10883 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10884 }
10885 if (!isImsAvailableOnDevice()) {
10886 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10887 "IMS not available on device.");
10888 }
10889
10890 final long identity = Binder.clearCallingIdentity();
10891 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010892 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010893 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010894 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10895 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010896 }
Hui Wang761a6682020-10-31 05:12:53 +000010897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
10901
10902 /**
10903 * Unregister RCS provisioning callback.
10904 */
10905 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010906 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010907 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010908 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010909 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010910 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10911 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010912
10913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10914 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10915 }
10916 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010917 // operation failed silently
10918 Rlog.w(LOG_TAG, "IMS not available on device.");
10919 return;
Hui Wang761a6682020-10-31 05:12:53 +000010920 }
10921
10922 final long identity = Binder.clearCallingIdentity();
10923 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010924 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010925 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010926 } finally {
10927 Binder.restoreCallingIdentity(identity);
10928 }
10929 }
10930
10931 /**
10932 * trigger RCS reconfiguration.
10933 */
10934 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010935 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10936 "triggerRcsReconfiguration",
10937 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010938
10939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10940 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10941 }
10942 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010943 // ProvisioningManager can not handle ServiceSpecificException.
10944 // Throw the IllegalStateException and annotate ProvisioningManager.
10945 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010946 }
10947
10948 final long identity = Binder.clearCallingIdentity();
10949 try {
10950 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10951 } finally {
10952 Binder.restoreCallingIdentity(identity);
10953 }
10954 }
10955
10956 /**
10957 * Provide the client configuration parameters of the RCS application.
10958 */
10959 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010960 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10961 "setRcsClientConfiguration",
10962 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010963
10964 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10965 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10966 }
10967 if (!isImsAvailableOnDevice()) {
10968 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10969 "IMS not available on device.");
10970 }
10971
10972 final long identity = Binder.clearCallingIdentity();
10973
10974 try {
10975 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10976 if (configBinder == null) {
10977 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010978 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10979 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010980 } else {
10981 configBinder.setRcsClientConfiguration(rcc);
10982 }
joonhunshin3e154242021-09-17 06:33:39 +000010983
10984 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10985 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010986 } catch (RemoteException e) {
10987 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010988 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10989 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010990 } finally {
10991 Binder.restoreCallingIdentity(identity);
10992 }
10993 }
10994
10995 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010996 * Enables or disables the test mode for RCS VoLTE single registration.
10997 */
10998 @Override
10999 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11001 "setRcsSingleRegistrationTestModeEnabled");
11002
11003 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11004 }
11005
11006 /**
11007 * Gets the test mode for RCS VoLTE single registration.
11008 */
11009 @Override
11010 public boolean getRcsSingleRegistrationTestModeEnabled() {
11011 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11012 "getRcsSingleRegistrationTestModeEnabled");
11013
11014 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11015 }
11016
11017 /**
Hui Wang761a6682020-10-31 05:12:53 +000011018 * Overrides the config of RCS VoLTE single registration enabled for the device.
11019 */
11020 @Override
11021 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11023 "setDeviceSingleRegistrationEnabledOverride");
11024 enforceModifyPermission();
11025
11026 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11027 : Boolean.parseBoolean(enabledStr);
11028 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011029 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011030 }
11031
11032 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011033 * Sends a device to device communication message. Only usable via shell.
11034 * @param message message to send.
11035 * @param value message value.
11036 */
11037 @Override
11038 public void sendDeviceToDeviceMessage(int message, int value) {
11039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011040 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011041 enforceModifyPermission();
11042
11043 final long identity = Binder.clearCallingIdentity();
11044 try {
11045 TelephonyConnectionService service =
11046 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11047 if (service == null) {
11048 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11049 return;
11050 }
11051 service.sendTestDeviceToDeviceMessage(message, value);
11052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
11056
Tyler Gunnbabbda02021-02-10 11:05:02 -080011057 /**
11058 * Sets the specified device to device transport active.
11059 * @param transport The transport to set active.
11060 */
11061 @Override
11062 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11063 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11064 "setActiveDeviceToDeviceTransport");
11065 enforceModifyPermission();
11066
11067 final long identity = Binder.clearCallingIdentity();
11068 try {
11069 TelephonyConnectionService service =
11070 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11071 if (service == null) {
11072 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11073 return;
11074 }
11075 service.setActiveDeviceToDeviceTransport(transport);
11076 } finally {
11077 Binder.restoreCallingIdentity(identity);
11078 }
11079 }
Tyler Gunn92479152021-01-20 16:30:10 -080011080
Tyler Gunnd4339262021-05-03 14:46:49 -070011081 @Override
11082 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11083 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11084 "setDeviceToDeviceForceEnabled");
11085
11086 final long identity = Binder.clearCallingIdentity();
11087 try {
11088 Arrays.stream(PhoneFactory.getPhones()).forEach(
11089 p -> {
11090 Phone thePhone = p.getImsPhone();
11091 if (thePhone != null && thePhone instanceof ImsPhone) {
11092 ImsPhone imsPhone = (ImsPhone) thePhone;
11093 CallTracker tracker = imsPhone.getCallTracker();
11094 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11095 ImsPhoneCallTracker imsPhoneCallTracker =
11096 (ImsPhoneCallTracker) tracker;
11097 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11098 }
11099 }
11100 }
11101 );
11102 } finally {
11103 Binder.restoreCallingIdentity(identity);
11104 }
11105 }
11106
Tyler Gunn92479152021-01-20 16:30:10 -080011107 /**
Hui Wang761a6682020-10-31 05:12:53 +000011108 * Gets the config of RCS VoLTE single registration enabled for the device.
11109 */
11110 @Override
11111 public boolean getDeviceSingleRegistrationEnabled() {
11112 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11113 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11114 }
11115
11116 /**
11117 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11118 */
11119 @Override
11120 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11121 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11122 "setCarrierSingleRegistrationEnabledOverride");
11123 enforceModifyPermission();
11124
11125 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11126 : Boolean.parseBoolean(enabledStr);
11127 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11128 subId, enabled);
11129 }
11130
11131 /**
11132 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11133 */
11134 @Override
11135 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11136 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11137 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11138 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011139
11140 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011141 * Overrides the ims feature validation result
11142 */
11143 @Override
11144 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11146 "setImsFeatureValidationOverride");
11147
11148 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11149 : Boolean.parseBoolean(enabledStr);
11150 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11151 subId, enabled);
11152 }
11153
11154 /**
11155 * Gets the ims feature validation override value
11156 */
11157 @Override
11158 public boolean getImsFeatureValidationOverride(int subId) {
11159 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11160 "getImsFeatureValidationOverride");
11161 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11162 }
11163
11164 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011165 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11166 * their mobile plan.
11167 */
11168 @Override
11169 public String getMobileProvisioningUrl() {
11170 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11171 final long identity = Binder.clearCallingIdentity();
11172 try {
11173 return getDefaultPhone().getMobileProvisioningUrl();
11174 } finally {
11175 Binder.restoreCallingIdentity(identity);
11176 }
11177 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011178
James.cf Linbcdf8b32021-01-14 16:44:13 +080011179 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011180 * Get the EAB contact from the EAB database.
11181 */
11182 @Override
11183 public String getContactFromEab(String contact) {
11184 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11185 enforceModifyPermission();
11186 final long identity = Binder.clearCallingIdentity();
11187 try {
11188 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11189 } finally {
11190 Binder.restoreCallingIdentity(identity);
11191 }
11192 }
11193
11194 /**
Calvin Pana1434322021-07-01 19:27:01 +080011195 * Get the EAB capability from the EAB database.
11196 */
11197 @Override
11198 public String getCapabilityFromEab(String contact) {
11199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11200 enforceModifyPermission();
11201 final long identity = Binder.clearCallingIdentity();
11202 try {
11203 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11204 } finally {
11205 Binder.restoreCallingIdentity(identity);
11206 }
11207 }
11208
11209 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011210 * Remove the EAB contacts from the EAB database.
11211 */
11212 @Override
11213 public int removeContactFromEab(int subId, String contacts) {
11214 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11215 enforceModifyPermission();
11216 final long identity = Binder.clearCallingIdentity();
11217 try {
11218 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11219 } finally {
11220 Binder.restoreCallingIdentity(identity);
11221 }
11222 }
11223
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011224 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011225 public boolean getDeviceUceEnabled() {
11226 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11227 final long identity = Binder.clearCallingIdentity();
11228 try {
11229 return mApp.getDeviceUceEnabled();
11230 } finally {
11231 Binder.restoreCallingIdentity(identity);
11232 }
11233 }
11234
11235 @Override
11236 public void setDeviceUceEnabled(boolean isEnabled) {
11237 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11238 final long identity = Binder.clearCallingIdentity();
11239 try {
11240 mApp.setDeviceUceEnabled(isEnabled);
11241 } finally {
11242 Binder.restoreCallingIdentity(identity);
11243 }
11244 }
11245
Brad Ebinger14d467f2021-02-12 06:18:28 +000011246 /**
11247 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11248 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11249 */
11250 // Used for SHELL command only right now.
11251 @Override
11252 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11253 List<String> featureTags) {
11254 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11255 "addUceRegistrationOverrideShell");
11256 final long identity = Binder.clearCallingIdentity();
11257 try {
11258 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11259 new ArraySet<>(featureTags));
11260 } catch (ImsException e) {
11261 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11262 } finally {
11263 Binder.restoreCallingIdentity(identity);
11264 }
11265 }
11266
11267 /**
11268 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11269 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11270 */
11271 // Used for SHELL command only right now.
11272 @Override
11273 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11274 List<String> featureTags) {
11275 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11276 "removeUceRegistrationOverrideShell");
11277 final long identity = Binder.clearCallingIdentity();
11278 try {
11279 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11280 new ArraySet<>(featureTags));
11281 } catch (ImsException e) {
11282 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11283 } finally {
11284 Binder.restoreCallingIdentity(identity);
11285 }
11286 }
11287
11288 /**
11289 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11290 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11291 */
11292 // Used for SHELL command only right now.
11293 @Override
11294 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11295 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11296 "clearUceRegistrationOverrideShell");
11297 final long identity = Binder.clearCallingIdentity();
11298 try {
11299 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11300 } catch (ImsException e) {
11301 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11302 } finally {
11303 Binder.restoreCallingIdentity(identity);
11304 }
11305 }
11306
11307 /**
11308 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11309 */
11310 // Used for SHELL command only right now.
11311 @Override
11312 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11313 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11314 "getLatestRcsContactUceCapabilityShell");
11315 final long identity = Binder.clearCallingIdentity();
11316 try {
11317 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11318 } catch (ImsException e) {
11319 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11320 } finally {
11321 Binder.restoreCallingIdentity(identity);
11322 }
11323 }
11324
11325 /**
11326 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11327 * device does not have an active PUBLISH.
11328 */
11329 // Used for SHELL command only right now.
11330 @Override
11331 public String getLastUcePidfXmlShell(int subId) {
11332 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11333 final long identity = Binder.clearCallingIdentity();
11334 try {
11335 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11336 } catch (ImsException e) {
11337 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11338 } finally {
11339 Binder.restoreCallingIdentity(identity);
11340 }
11341 }
11342
James.cf Line8713a42021-04-29 16:04:26 +080011343 /**
11344 * Remove UCE requests cannot be sent to the network status.
11345 */
11346 // Used for SHELL command only right now.
11347 @Override
11348 public boolean removeUceRequestDisallowedStatus(int subId) {
11349 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11350 final long identity = Binder.clearCallingIdentity();
11351 try {
11352 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11353 } catch (ImsException e) {
11354 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11355 } finally {
11356 Binder.restoreCallingIdentity(identity);
11357 }
11358 }
11359
James.cf Lin18bb9002021-05-25 01:37:38 +080011360 /**
11361 * Remove UCE requests cannot be sent to the network status.
11362 */
11363 // Used for SHELL command only.
11364 @Override
11365 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11366 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11367 final long identity = Binder.clearCallingIdentity();
11368 try {
11369 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11370 } catch (ImsException e) {
11371 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11372 } finally {
11373 Binder.restoreCallingIdentity(identity);
11374 }
11375 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011376
James.cf Lin4b784aa2021-01-31 03:25:15 +080011377 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011378 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11379 String callingPackage) {
11380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11381 mApp, subId, "setSignalStrengthUpdateRequest");
11382
11383 final int callingUid = Binder.getCallingUid();
11384 // Verify that tha callingPackage belongs to the calling UID
11385 mApp.getSystemService(AppOpsManager.class)
11386 .checkPackage(callingUid, callingPackage);
11387
Rambo Wang3607f502021-02-01 21:51:40 -080011388 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011389
11390 final long identity = Binder.clearCallingIdentity();
11391 try {
11392 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11393 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11394
11395 if (result instanceof IllegalStateException) {
11396 throw (IllegalStateException) result;
11397 }
11398 } finally {
11399 Binder.restoreCallingIdentity(identity);
11400 }
11401 }
11402
11403 @Override
11404 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11405 String callingPackage) {
11406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11407 mApp, subId, "clearSignalStrengthUpdateRequest");
11408
11409 final int callingUid = Binder.getCallingUid();
11410 // Verify that tha callingPackage belongs to the calling UID
11411 mApp.getSystemService(AppOpsManager.class)
11412 .checkPackage(callingUid, callingPackage);
11413
11414 final long identity = Binder.clearCallingIdentity();
11415 try {
11416 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11417 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11418
11419 if (result instanceof IllegalStateException) {
11420 throw (IllegalStateException) result;
11421 }
11422 } finally {
11423 Binder.restoreCallingIdentity(identity);
11424 }
11425 }
11426
Rambo Wang3607f502021-02-01 21:51:40 -080011427 private static void validateSignalStrengthUpdateRequest(Context context,
11428 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011429 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11430 // phone/system process do not have further restriction on request
11431 return;
11432 }
11433
11434 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011435 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011436 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011437 context.enforceCallingOrSelfPermission(
11438 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11439 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011440 }
11441
11442 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011443 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011444 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011445 || info.isEnabled()) {
11446 throw new IllegalArgumentException(
11447 "Only system can set hide fields in SignalThresholdInfo");
11448 }
11449
11450 // Thresholds length for each RAN need in range. This has been validated in
11451 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11452 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11453 final int[] thresholds = info.getThresholds();
11454 Objects.requireNonNull(thresholds);
11455 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11456 || thresholds.length
11457 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11458 throw new IllegalArgumentException(
11459 "thresholds length is out of range: " + thresholds.length);
11460 }
11461 }
11462 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011463
11464 /**
11465 * Gets the current phone capability.
11466 *
11467 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11468 * @return the PhoneCapability which describes the data connection capability of modem.
11469 * It's used to evaluate possible phone config change, for example from single
11470 * SIM device to multi-SIM device.
11471 */
11472 @Override
11473 public PhoneCapability getPhoneCapability() {
11474 enforceReadPrivilegedPermission("getPhoneCapability");
11475 final long identity = Binder.clearCallingIdentity();
11476 try {
11477 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11478 } finally {
11479 Binder.restoreCallingIdentity(identity);
11480 }
11481 }
Michele Berionne5e411512020-11-13 02:36:59 +000011482
11483 /**
11484 * Prepare TelephonyManager for an unattended reboot. The reboot is
11485 * required to be done shortly after the API is invoked.
11486 */
11487 @Override
11488 @TelephonyManager.PrepareUnattendedRebootResult
11489 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011490 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011491 enforceRebootPermission();
11492
11493 final long identity = Binder.clearCallingIdentity();
11494 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011495 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011496 } finally {
11497 Binder.restoreCallingIdentity(identity);
11498 }
11499 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011500
11501 /**
11502 * Request to get the current slicing configuration including URSP rules and
11503 * NSSAIs (configured, allowed and rejected).
11504 *
11505 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11506 */
11507 @Override
11508 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011509 TelephonyPermissions
11510 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11511 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011512
11513 final long identity = Binder.clearCallingIdentity();
11514 try {
11515 Phone phone = getDefaultPhone();
11516 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11517 } finally {
11518 Binder.restoreCallingIdentity(identity);
11519 }
11520 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011521
11522 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011523 * Check whether the given premium capability is available for purchase from the carrier.
11524 *
11525 * @param capability The premium capability to check.
11526 * @param subId The subId to check the premium capability for.
11527 *
11528 * @return Whether the given premium capability is available to purchase.
11529 */
11530 @Override
11531 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11532 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11533 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11534 log("Premium capability "
11535 + TelephonyManager.convertPremiumCapabilityToString(capability)
11536 + " is not available for purchase due to missing permissions.");
11537 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11538 + "permission READ_BASIC_PHONE_STATE.");
11539 }
11540
11541 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011542 if (phone == null) {
11543 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11544 return false;
11545 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011546 final long identity = Binder.clearCallingIdentity();
11547 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070011548 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011549 .isPremiumCapabilityAvailableForPurchase(capability);
11550 } finally {
11551 Binder.restoreCallingIdentity(identity);
11552 }
11553 }
11554
11555 /**
11556 * Purchase the given premium capability from the carrier.
11557 *
11558 * @param capability The premium capability to purchase.
11559 * @param callback The result of the purchase request.
11560 * @param subId The subId to purchase the premium capability for.
11561 */
11562 @Override
11563 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11564 log("purchasePremiumCapability: capability="
11565 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11566 + getCurrentPackageName());
11567
11568 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11569 mApp, "purchasePremiumCapability")) {
11570 log("purchasePremiumCapability "
11571 + TelephonyManager.convertPremiumCapabilityToString(capability)
11572 + " failed due to missing permissions.");
11573 throw new SecurityException("purchasePremiumCapability requires permission "
11574 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011575 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11576 mApp, "purchasePremiumCapability")) {
11577 log("purchasePremiumCapability "
11578 + TelephonyManager.convertPremiumCapabilityToString(capability)
11579 + " failed due to missing permissions.");
11580 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011581 }
11582
11583 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011584 if (phone == null) {
11585 try {
11586 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11587 callback.accept(result);
11588 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11589 } catch (RemoteException e) {
11590 String logStr = "Purchase premium capability "
11591 + TelephonyManager.convertPremiumCapabilityToString(capability)
11592 + " failed due to RemoteException handling null phone: " + e;
11593 if (DBG) log(logStr);
11594 AnomalyReporter.reportAnomaly(
11595 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11596 }
11597 return;
11598 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011599
11600 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011601 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011602 callingProcess = mApp.getPackageManager().getApplicationInfo(
11603 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011604 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011605 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011606 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011607
11608 boolean isVisible = false;
11609 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11610 if (am != null) {
11611 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11612 if (processes != null) {
11613 for (ActivityManager.RunningAppProcessInfo process : processes) {
11614 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011615 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011616 if (process.processName.equals(callingProcess) && process.importance
11617 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11618 isVisible = true;
11619 break;
11620 }
11621 }
11622 }
11623 }
11624
11625 if (!isVisible) {
11626 try {
11627 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11628 callback.accept(result);
11629 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11630 } catch (RemoteException e) {
11631 String logStr = "Purchase premium capability "
11632 + TelephonyManager.convertPremiumCapabilityToString(capability)
11633 + " failed due to RemoteException handling background application: " + e;
11634 if (DBG) log(logStr);
11635 AnomalyReporter.reportAnomaly(
11636 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11637 }
11638 return;
11639 }
11640
Sarah Chin71b3a852022-09-28 15:54:19 -070011641 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011642 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011643 }
11644
11645 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011646 * Register an IMS connection state callback
11647 */
11648 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011649 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11650 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011651 if (feature == ImsFeature.FEATURE_MMTEL) {
11652 // ImsMmTelManager
11653 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11654 TelephonyPermissions
11655 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11656 mApp, subId, "registerImsStateCallback");
11657 } else if (feature == ImsFeature.FEATURE_RCS) {
11658 // ImsRcsManager or SipDelegateManager
11659 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11660 Binder.getCallingUid(), "registerImsStateCallback",
11661 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11662 Manifest.permission.READ_PRECISE_PHONE_STATE,
11663 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11664 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11665 }
11666
11667 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11668 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11669 "IMS not available on device.");
11670 }
11671
11672 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11673 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11674 }
11675
11676 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11677 if (controller == null) {
11678 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11679 "IMS not available on device.");
11680 }
11681
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011682 if (callingPackage == null) {
11683 callingPackage = getCurrentPackageName();
11684 }
11685
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011686 final long token = Binder.clearCallingIdentity();
11687 try {
11688 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011689 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011690 } catch (ImsException e) {
11691 throw new ServiceSpecificException(e.getCode());
11692 } finally {
11693 Binder.restoreCallingIdentity(token);
11694 }
11695 }
11696
11697 /**
11698 * Unregister an IMS connection state callback
11699 */
11700 @Override
11701 public void unregisterImsStateCallback(IImsStateCallback cb) {
11702 final long token = Binder.clearCallingIdentity();
11703 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11704 if (controller == null) {
11705 return;
11706 }
11707 try {
11708 controller.unregisterImsStateCallback(cb);
11709 } finally {
11710 Binder.restoreCallingIdentity(token);
11711 }
11712 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011713
11714 /**
11715 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11716 *
11717 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11718 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11719 * SecurityException.
11720 * If there is current registered network this value will be same as the registered cell
11721 * identity. If the device goes out of service the previous cell identity is cached and
11722 * will be returned. If the cache age of the Cell identity is more than 24 hours
11723 * it will be cleared and null will be returned.
11724 *
11725 */
11726 @Override
11727 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11728 String callingFeatureId) {
11729 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11730 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11731 LocationAccessPolicy.checkLocationPermission(mApp,
11732 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11733 .setCallingPackage(callingPackage)
11734 .setCallingFeatureId(callingFeatureId)
11735 .setCallingPid(Binder.getCallingPid())
11736 .setCallingUid(Binder.getCallingUid())
11737 .setMethod("getLastKnownCellIdentity")
11738 .setLogAsInfo(true)
11739 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11740 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11741 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11742 .build());
11743
11744 boolean hasFinePermission =
11745 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11746 if (!hasFinePermission
11747 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11748 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011749 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011750 }
11751
11752 final long identity = Binder.clearCallingIdentity();
11753 try {
Ling Mac28f0212023-03-24 16:07:15 -070011754 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011755 if (sst == null) return null;
11756 return sst.getLastKnownCellIdentity();
11757 } finally {
11758 Binder.restoreCallingIdentity(identity);
11759 }
11760 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011761
jimsun3b9ccac2021-10-26 15:01:23 +080011762 /**
11763 * Sets the modem service class Name that Telephony will bind to.
11764 *
11765 * @param serviceName The class name of the modem service.
11766 * @return true if the operation is succeed, otherwise false.
11767 */
11768 public boolean setModemService(String serviceName) {
11769 Log.d(LOG_TAG, "setModemService - " + serviceName);
11770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011772 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11773 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011774 return mPhoneConfigurationManager.setModemService(serviceName);
11775 }
11776
11777 /**
11778 * Return the class name of the currently bounded modem service.
11779 *
11780 * @return the class name of the modem service.
11781 */
11782 public String getModemService() {
11783 String result;
11784 Log.d(LOG_TAG, "getModemService");
11785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11786 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011787 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011788 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11789 "getModemService");
11790 result = mPhoneConfigurationManager.getModemService();
11791 Log.d(LOG_TAG, "result = " + result);
11792 return result;
11793 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011794
11795 @Override
11796 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11797 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11798 mApp.enforceCallingOrSelfPermission(
11799 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11801
11802 final long identity = Binder.clearCallingIdentity();
11803 try {
11804 Phone phone = getPhone(subId);
11805 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011806 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11807 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011808 phone.setVoiceServiceStateOverride(hasService);
11809 } finally {
11810 Binder.restoreCallingIdentity(identity);
11811 }
11812 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011813
11814 /**
11815 * set removable eSIM as default eUICC.
11816 *
11817 * @hide
11818 */
11819 @Override
11820 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11821 enforceModifyPermission();
11822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11823
11824 final long identity = Binder.clearCallingIdentity();
11825 try {
11826 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11827 } finally {
11828 Binder.restoreCallingIdentity(identity);
11829 }
11830 }
11831
11832 /**
11833 * Returns whether the removable eSIM is default eUICC or not.
11834 *
11835 * @hide
11836 */
11837 @Override
11838 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11839 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11840 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11841
11842 final long identity = Binder.clearCallingIdentity();
11843 try {
11844 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11845 } finally {
11846 Binder.restoreCallingIdentity(identity);
11847 }
11848 }
11849
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011850 /**
11851 * Get the component name of the default app to direct respond-via-message intent for the
11852 * user associated with this subscription, update the cache if there is no respond-via-message
11853 * application currently configured for this user.
11854 * @return component name of the app and class to direct Respond Via Message intent to, or
11855 * {@code null} if the functionality is not supported.
11856 * @hide
11857 */
11858 @Override
11859 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11860 boolean updateIfNeeded) {
11861 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011862
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011863 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11864
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011865 UserHandle userHandle = null;
11866 final long identity = Binder.clearCallingIdentity();
11867 try {
11868 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11869 } finally {
11870 Binder.restoreCallingIdentity(identity);
11871 }
11872 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11873 updateIfNeeded, userHandle);
11874 }
Jack Yuf5badd92022-12-08 00:50:53 -080011875
11876 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011877 * Set whether the device is able to connect with null ciphering or integrity
11878 * algorithms. This is a global setting and will apply to all active subscriptions
11879 * and all new subscriptions after this.
11880 *
11881 * @param enabled when true, null cipher and integrity algorithms are allowed.
11882 * @hide
11883 */
11884 @Override
11885 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11886 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11887 enforceModifyPermission();
11888 checkForNullCipherAndIntegritySupport();
11889
11890 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11891 // for listening to these preference changes and applying them immediately.
11892 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11893 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11894 editor.apply();
11895
11896 for (Phone phone: PhoneFactory.getPhones()) {
11897 phone.handleNullCipherEnabledChange();
11898 }
11899 }
11900
11901
11902 /**
11903 * Get whether the device is able to connect with null ciphering or integrity
11904 * algorithms. Note that this retrieves the phone-global preference and not
11905 * the state of the radio.
11906 *
11907 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11908 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11909 * version for this feature.
11910 * @hide
11911 */
11912 @Override
11913 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11914 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11915 enforceReadPermission();
11916 checkForNullCipherAndIntegritySupport();
11917 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11918 }
11919
11920 private void checkForNullCipherAndIntegritySupport() {
11921 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11922 throw new UnsupportedOperationException(
11923 "Null cipher and integrity operations require HAL 2.1 or above");
11924 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011925 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11926 throw new UnsupportedOperationException(
11927 "Null cipher and integrity operations unsupported by modem");
11928 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011929 }
11930
11931 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011932 * Get the SIM state for the slot index.
11933 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11934 *
11935 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11936 */
11937 @Override
11938 @SimState
11939 public int getSimStateForSlotIndex(int slotIndex) {
11940 IccCardConstants.State simState;
11941 if (slotIndex < 0) {
11942 simState = IccCardConstants.State.UNKNOWN;
11943 } else {
11944 Phone phone = null;
11945 try {
11946 phone = PhoneFactory.getPhone(slotIndex);
11947 } catch (IllegalStateException e) {
11948 // ignore
11949 }
11950 if (phone == null) {
11951 simState = IccCardConstants.State.UNKNOWN;
11952 } else {
11953 IccCard icc = phone.getIccCard();
11954 if (icc == null) {
11955 simState = IccCardConstants.State.UNKNOWN;
11956 } else {
11957 simState = icc.getState();
11958 }
11959 }
11960 }
11961 return simState.ordinal();
11962 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011963
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011964 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11965 boolean enableLogcat,
11966 long logcatStartTimestampMillis, boolean enableTelecomDump,
11967 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011968 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11969 TelephonyManager.EmergencyCallDiagnosticParams edp =
11970 new TelephonyManager.EmergencyCallDiagnosticParams();
11971 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11972 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11973 edp.setTelecomDumpSysCollection(enableTelecomDump);
11974 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11975 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
11976 Executors.newCachedThreadPool(), db,
11977 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
11978 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011979 }
11980
11981 /**
11982 * Request telephony to persist state for debugging emergency call failures.
11983 *
11984 * @param dropBoxTag Tag to use when persisting data to dropbox service.
11985 * @param enableLogcat whether to collect logcat output
11986 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
11987 * @param enableTelecomDump whether to collect telecom dumpsys
11988 * @param enableTelephonyDump whether to collect telephony dumpsys
11989 */
11990 @Override
11991 @RequiresPermission(android.Manifest.permission.DUMP)
11992 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
11993 long logcatStartTimestampMillis, boolean enableTelecomDump,
11994 boolean enableTelephonyDump) {
11995 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
11996 "persistEmergencyCallDiagnosticData");
11997 final long identity = Binder.clearCallingIdentity();
11998 try {
11999 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12000 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12001
12002 } finally {
12003 Binder.restoreCallingIdentity(identity);
12004 }
12005 }
12006
Hui Wang9b5793a2022-12-05 14:38:06 -060012007 /**
12008 * Get current cell broadcast ranges.
12009 */
12010 @Override
12011 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12012 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12013 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12014 "getCellBroadcastIdRanges");
12015 final long identity = Binder.clearCallingIdentity();
12016 try {
12017 return getPhone(subId).getCellBroadcastIdRanges();
12018 } finally {
12019 Binder.restoreCallingIdentity(identity);
12020 }
12021 }
12022
12023 /**
12024 * Set reception of cell broadcast messages with the list of the given ranges
12025 *
12026 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12027 */
12028 @Override
12029 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12030 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12031 @Nullable IIntegerConsumer callback) {
12032 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12033 "setCellBroadcastIdRanges");
12034 final long identity = Binder.clearCallingIdentity();
12035 try {
12036 Phone phone = getPhoneFromSubId(subId);
12037 if (DBG) {
12038 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12039 }
12040 phone.setCellBroadcastIdRanges(ranges, result -> {
12041 if (callback != null) {
12042 try {
12043 callback.accept(result);
12044 } catch (RemoteException e) {
12045 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12046 }
12047 }
12048 });
12049 } finally {
12050 Binder.restoreCallingIdentity(identity);
12051 }
12052 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012053
12054 /**
12055 * Returns whether the device supports the domain selection service.
12056 *
12057 * @return {@code true} if the device supports the domain selection service.
12058 */
12059 @Override
12060 public boolean isDomainSelectionSupported() {
12061 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12062 "isDomainSelectionSupported");
12063
12064 final long identity = Binder.clearCallingIdentity();
12065 try {
12066 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12067 } finally {
12068 Binder.restoreCallingIdentity(identity);
12069 }
12070 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012071
12072 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012073 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12074 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12075 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012076 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012077 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012078 * @param enableSatellite {@code true} to enable the satellite modem and
12079 * {@code false} to disable.
12080 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12081 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012082 *
12083 * @throws SecurityException if the caller doesn't have the required permission.
12084 */
12085 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012086 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12087 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012088 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012089 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12090 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012091 }
12092
12093 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012094 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012095 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012096 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012097 * @param result The result receiver that returns whether the satellite modem is enabled
12098 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012099 *
12100 * @throws SecurityException if the caller doesn't have the required permission.
12101 */
12102 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012103 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12104 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012105 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012106 }
12107
12108 /**
Sarah Chin43457982023-02-15 17:50:38 -080012109 * Request to get whether the satellite service demo mode is enabled.
12110 *
12111 * @param subId The subId of the subscription to check whether the satellite demo mode
12112 * is enabled for.
12113 * @param result The result receiver that returns whether the satellite demo mode is enabled
12114 * if the request is successful or an error code if the request failed.
12115 *
12116 * @throws SecurityException if the caller doesn't have the required permission.
12117 */
12118 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012119 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12120 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12121 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012122 }
12123
12124 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012125 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012126 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012127 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012128 * @param result The result receiver that returns whether the satellite service is supported on
12129 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012130 */
12131 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012132 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012133 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012134 }
12135
12136 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012137 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012138 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012139 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012140 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12141 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012142 *
12143 * @throws SecurityException if the caller doesn't have required permission.
12144 */
12145 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012146 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12147 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012148 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012149 }
12150
12151 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012152 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012153 * This can be called by the pointing UI when the user starts pointing to the satellite.
12154 * Modem should continue to report the pointing input as the device or satellite moves.
12155 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012156 * @param subId The subId of the subscription to start satellite transmission updates for.
12157 * @param resultCallback The callback to get the result of the request.
12158 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012159 *
12160 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012161 */
12162 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012163 public void startSatelliteTransmissionUpdates(int subId,
12164 @NonNull IIntegerConsumer resultCallback,
12165 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12166 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12167 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012168 }
12169
12170 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012171 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012172 * This can be called by the pointing UI when the user stops pointing to the satellite.
12173 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012174 * @param subId The subId of the subscription to stop satellite transmission updates for.
12175 * @param resultCallback The callback to get the result of the request.
12176 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12177 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012178 *
12179 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012180 */
12181 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012182 public void stopSatelliteTransmissionUpdates(int subId,
12183 @NonNull IIntegerConsumer resultCallback,
12184 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12185 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12186 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012187 }
12188
12189 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012190 * Register the subscription with a satellite provider.
12191 * This is needed to register the subscription if the provider allows dynamic registration.
12192 *
12193 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012194 * @param token The token to be used as a unique identifier for provisioning with satellite
12195 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012196 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012197 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012198 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012199 * @return The signal transport used by the caller to cancel the provision request,
12200 * or {@code null} if the request failed.
12201 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012202 * @throws SecurityException if the caller doesn't have the required permission.
12203 */
12204 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012205 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012206 @NonNull String token, @NonNull byte[] provisionData,
12207 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012208 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012209 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12210 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012211 }
12212
12213 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012214 * Unregister the device/subscription with the satellite provider.
12215 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012216 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012217 * should report as deprovisioned.
12218 *
12219 * @param subId The subId of the subscription to be deprovisioned.
12220 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012221 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012222 *
12223 * @throws SecurityException if the caller doesn't have the required permission.
12224 */
12225 @Override
12226 public void deprovisionSatelliteService(int subId,
12227 @NonNull String token, @NonNull IIntegerConsumer callback) {
12228 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012229 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012230 }
12231
12232 /**
Sarah Chin43457982023-02-15 17:50:38 -080012233 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012234 *
Sarah Chin43457982023-02-15 17:50:38 -080012235 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012236 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012237 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012238 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012239 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012240 * @throws SecurityException if the caller doesn't have the required permission.
12241 */
12242 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012243 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12244 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012245 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012246 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012247 }
12248
12249 /**
Sarah Chin43457982023-02-15 17:50:38 -080012250 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012251 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012252 *
Sarah Chin43457982023-02-15 17:50:38 -080012253 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012254 * @param callback The callback that was passed to
12255 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012256 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012257 * @throws SecurityException if the caller doesn't have the required permission.
12258 */
12259 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012260 public void unregisterForSatelliteProvisionStateChanged(
12261 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012262 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012263 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012264 }
12265
12266 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012267 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012268 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012269 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012270 * @param result The result receiver that returns whether the device is provisioned with a
12271 * satellite provider if the request is successful or an error code if the
12272 * request failed.
12273 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012274 * @throws SecurityException if the caller doesn't have the required permission.
12275 */
12276 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012277 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12278 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012279 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012280 }
12281
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012282 /**
Sarah Chin43457982023-02-15 17:50:38 -080012283 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012284 *
Sarah Chin43457982023-02-15 17:50:38 -080012285 * @param subId The subId of the subscription to register for satellite modem state changed.
12286 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012287 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012288 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012289 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012290 * @throws SecurityException if the caller doesn't have the required permission.
12291 */
12292 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012293 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012294 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012295 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012296 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012297 }
12298
12299 /**
Sarah Chin43457982023-02-15 17:50:38 -080012300 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012301 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012302 *
Sarah Chin43457982023-02-15 17:50:38 -080012303 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012304 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012305 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012306 *
12307 * @throws SecurityException if the caller doesn't have the required permission.
12308 */
12309 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012310 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012311 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012312 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012313 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012314 }
12315
12316 /**
12317 * Register to receive incoming datagrams over satellite.
12318 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012319 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012320 * @param callback The callback to handle incoming datagrams over satellite.
12321 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012322 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012323 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012324 * @throws SecurityException if the caller doesn't have the required permission.
12325 */
12326 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012327 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012328 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012329 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012330 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012331 }
12332
12333 /**
12334 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012335 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012336 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012337 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12338 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012339 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012340 *
12341 * @throws SecurityException if the caller doesn't have the required permission.
12342 */
12343 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012344 public void unregisterForSatelliteDatagram(int subId,
12345 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012346 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012347 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012348 }
12349
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012350 /**
12351 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012352 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012353 * This method requests modem to check if there are any pending datagrams to be received over
12354 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012355 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012356 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012357 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012358 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012359 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012360 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012361 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012362 @Override
12363 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012364 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012365 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012366 }
12367
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012368 /**
12369 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012370 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012371 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12372 * input to this method. Datagram received here will be passed down to modem without any
12373 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012374 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012375 * @param subId The subId of the subscription to send satellite datagrams for.
12376 * @param datagramType datagram type indicating whether the datagram is of type
12377 * SOS_SMS or LOCATION_SHARING.
12378 * @param datagram encoded gateway datagram which is encrypted by the caller.
12379 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012380 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12381 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012382 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012383 *
12384 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012385 */
12386 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012387 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12388 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12389 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012390 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012391 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12392 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012393 }
12394
Sarah Chindf715ec2023-02-13 13:46:24 -080012395 /**
12396 * Request to get whether satellite communication is allowed for the current location.
12397 *
12398 * @param subId The subId of the subscription to check whether satellite communication is
12399 * allowed for the current location for.
12400 * @param result The result receiver that returns whether satellite communication is allowed
12401 * for the current location if the request is successful or an error code
12402 * if the request failed.
12403 *
12404 * @throws SecurityException if the caller doesn't have the required permission.
12405 */
12406 @Override
12407 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12408 @NonNull ResultReceiver result) {
12409 enforceSatelliteCommunicationPermission(
12410 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012411 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12412 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012413 }
12414
12415 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012416 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012417 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012418 * @param subId The subId to get the time after which the satellite will be visible for.
12419 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012420 * be visible if the request is successful or an error code if the request failed.
12421 *
12422 * @throws SecurityException if the caller doesn't have the required permission.
12423 */
12424 @Override
12425 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12426 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012427 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012428 }
12429
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012430 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012431 * Inform that Device is aligned to satellite for demo mode.
12432 *
12433 * @param subId The subId to get the time after which the satellite will be visible for.
12434 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12435 * {@code false} Device fails to align with the satellite for demo mode.
12436 *
12437 * @throws SecurityException if the caller doesn't have required permission.
12438 */
12439 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12440
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012441 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012442 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012443 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012444 }
12445
12446 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012447 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12448 * by modem.
12449 *
12450 * @param subId The subId of the subscription to request for.
12451 * @param reason Reason for disallowing satellite communication for carrier.
12452 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12453 * operation.
12454 *
12455 * @throws SecurityException if the caller doesn't have required permission.
12456 */
12457 public void addSatelliteAttachRestrictionForCarrier(int subId,
12458 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12459 @NonNull IIntegerConsumer callback) {
12460 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12461 final long identity = Binder.clearCallingIdentity();
12462 try {
12463 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12464 } finally {
12465 Binder.restoreCallingIdentity(identity);
12466 }
12467 }
12468
12469 /**
12470 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12471 * by modem.
12472 *
12473 * @param subId The subId of the subscription to request for.
12474 * @param reason Reason for disallowing satellite communication.
12475 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12476 * operation.
12477 *
12478 * @throws SecurityException if the caller doesn't have required permission.
12479 */
12480 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12481 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12482 @NonNull IIntegerConsumer callback) {
12483 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12484 final long identity = Binder.clearCallingIdentity();
12485 try {
12486 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12487 callback);
12488 } finally {
12489 Binder.restoreCallingIdentity(identity);
12490 }
12491 }
12492
12493 /**
12494 * Get reasons for disallowing satellite communication, as requested by
12495 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12496 *
12497 * @param subId The subId of the subscription to request for.
12498 *
12499 * @return Integer array of reasons for disallowing satellite communication.
12500 *
12501 * @throws SecurityException if the caller doesn't have the required permission.
12502 */
12503 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12504 int subId) {
12505 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12506 final long identity = Binder.clearCallingIdentity();
12507 try {
12508 Set<Integer> reasonSet =
12509 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12510 return reasonSet.stream().mapToInt(i->i).toArray();
12511 } finally {
12512 Binder.restoreCallingIdentity(identity);
12513 }
12514 }
12515
12516 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012517 * Request to get the signal strength of the satellite connection.
12518 *
12519 * @param subId The subId of the subscription to request for.
12520 * @param result Result receiver to get the error code of the request and the current signal
12521 * strength of the satellite connection.
12522 *
12523 * @throws SecurityException if the caller doesn't have required permission.
12524 */
12525 @Override
12526 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12527 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12528 final long identity = Binder.clearCallingIdentity();
12529 try {
12530 mSatelliteController.requestNtnSignalStrength(subId, result);
12531 } finally {
12532 Binder.restoreCallingIdentity(identity);
12533 }
12534 }
12535
12536 /**
12537 * Registers for NTN signal strength changed from satellite modem.
12538 *
12539 * @param subId The subId of the subscription to request for.
12540 * @param callback The callback to handle the NTN signal strength changed event.
12541 *
12542 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12543 *
12544 * @throws SecurityException if the caller doesn't have the required permission.
12545 */
12546 @Override
12547 @SatelliteManager.SatelliteResult public int registerForNtnSignalStrengthChanged(
12548 int subId, @NonNull INtnSignalStrengthCallback callback) {
12549 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12550 final long identity = Binder.clearCallingIdentity();
12551 try {
12552 return mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
12553 } finally {
12554 Binder.restoreCallingIdentity(identity);
12555 }
12556 }
12557
12558 /**
12559 * Unregisters for NTN signal strength changed from satellite modem.
12560 * If callback was not registered before, the request will be ignored.
12561 *
12562 * @param subId The subId of the subscription to unregister for provision state changed.
12563 * @param callback The callback that was passed to
12564 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12565 *
12566 * @throws SecurityException if the caller doesn't have the required permission.
12567 */
12568 @Override
12569 public void unregisterForNtnSignalStrengthChanged(
12570 int subId, @NonNull INtnSignalStrengthCallback callback) {
12571 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12572 final long identity = Binder.clearCallingIdentity();
12573 try {
12574 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12575 } finally {
12576 Binder.restoreCallingIdentity(identity);
12577 }
12578 }
12579
12580 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012581 * This API can be used by only CTS to update satellite vendor service package name.
12582 *
12583 * @param servicePackageName The package name of the satellite vendor service.
12584 * @return {@code true} if the satellite vendor service is set successfully,
12585 * {@code false} otherwise.
12586 */
12587 public boolean setSatelliteServicePackageName(String servicePackageName) {
12588 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12589 TelephonyPermissions.enforceShellOnly(
12590 Binder.getCallingUid(), "setSatelliteServicePackageName");
12591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12592 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12593 "setSatelliteServicePackageName");
12594 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12595 }
12596
12597 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012598 * This API can be used by only CTS to update satellite gateway service package name.
12599 *
12600 * @param servicePackageName The package name of the satellite gateway service.
12601 * @return {@code true} if the satellite gateway service is set successfully,
12602 * {@code false} otherwise.
12603 */
12604 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12605 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12606 TelephonyPermissions.enforceShellOnly(
12607 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12609 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12610 "setSatelliteGatewayServicePackageName");
12611 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12612 }
12613
12614 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012615 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12616 *
12617 * @param packageName The package name of the satellite pointing UI app.
12618 * @param className The class name of the satellite pointing UI app.
12619 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12620 * {@code false} otherwise.
12621 */
12622 public boolean setSatellitePointingUiClassName(
12623 @Nullable String packageName, @Nullable String className) {
12624 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12625 + ", className=" + className);
12626 TelephonyPermissions.enforceShellOnly(
12627 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12629 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12630 "setSatelliteGatewayServicePackageName");
12631 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12632 }
12633
12634 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012635 * This API can be used by only CTS to update the timeout duration in milliseconds that
12636 * satellite should stay at listening mode to wait for the next incoming page before disabling
12637 * listening mode.
12638 *
12639 * @param timeoutMillis The timeout duration in millisecond.
12640 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12641 */
12642 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12643 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12644 TelephonyPermissions.enforceShellOnly(
12645 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12647 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12648 "setSatelliteListeningTimeoutDuration");
12649 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12650 }
12651
12652 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012653 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12654 * the device is aligned with the satellite for demo mode
12655 *
12656 * @param timeoutMillis The timeout duration in millisecond.
12657 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12658 */
12659 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12660 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12661 TelephonyPermissions.enforceShellOnly(
12662 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12664 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12665 "setDeviceAlignedTimeoutDuration");
12666 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12667 }
12668
12669 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012670 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12671 *
12672 * <p>This method behaves in one of the following ways:
12673 * <ul>
12674 * <li>return true : if the calling package has the appop permission {@link
12675 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12676 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12677 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12678 * Owner device identifier access check, or the calling package has carrier privileges</>
12679 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12680 * </ul>
12681 */
12682 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12683 String callingPackage, @Nullable String callingFeatureId, String message) {
12684 for (Phone phone : PhoneFactory.getPhones()) {
12685 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12686 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12687 return true;
12688 }
12689 }
12690 return false;
12691 }
arunvoddud7401012022-12-15 16:08:12 +000012692
12693 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012694 * @return The subscription manager service instance.
12695 */
12696 public SubscriptionManagerService getSubscriptionManagerService() {
12697 return SubscriptionManagerService.getInstance();
12698 }
12699
12700 /**
arunvoddud7401012022-12-15 16:08:12 +000012701 * Class binds the consumer[callback] and carrierId.
12702 */
12703 private static class CallerCallbackInfo {
12704 private final Consumer<Integer> mConsumer;
12705 private final int mCarrierId;
12706
12707 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12708 mConsumer = consumer;
12709 mCarrierId = carrierId;
12710 }
12711
12712 public Consumer<Integer> getConsumer() {
12713 return mConsumer;
12714 }
12715
12716 public int getCarrierId() {
12717 return mCarrierId;
12718 }
12719 }
Jack Yufa8ed012023-02-11 15:42:28 -080012720}