blob: 6c5e916f3f89ffa18c973e4985fbc2ecf9588147 [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;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800149import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800150import android.telephony.satellite.ISatelliteProvisionStateCallback;
151import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800152import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800153import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000154import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800155import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800156import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800157import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800159import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700160import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800162import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800163
Andrew Lee312e8172014-10-23 17:01:36 -0700164import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800165import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800166import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800167import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800168import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700170import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700171import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800172import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800173import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700174import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800176import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700177import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800178import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800179import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800180import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700181import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000182import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800184import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800186import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800187import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800188import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700189import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700190import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700191import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700193import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800194import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700195import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700196import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700197import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700198import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800199import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800200import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700201import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000202import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700203import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700204import com.android.internal.telephony.SmsPermissions;
Peter Wang59571be2020-01-27 12:35:15 +0800205import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800206import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700207import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000208import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700210import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800211import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700212import com.android.internal.telephony.imsphone.ImsPhone;
213import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000214import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800215import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000216import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800217import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
218import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700219import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700220import com.android.internal.telephony.uicc.IccIoResult;
221import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800222import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700223import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800224import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700225import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000226import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800227import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000228import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800229import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000230import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700231import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700232import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800233import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800234import com.android.phone.callcomposer.CallComposerPictureManager;
235import com.android.phone.callcomposer.CallComposerPictureTransfer;
236import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700237import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700238import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000239import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700240import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800241import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700242import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700243import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800244import com.android.services.telephony.TelecomAccountRegistry;
245import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800246import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800247
Hall Liu82694d52020-12-11 18:22:04 -0800248import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700249import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800250import java.io.IOException;
251import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700252import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800254import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000255import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800256import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800257import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800258import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800259import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100260import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800261import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800263import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800264import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700265import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800267import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800268import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270/**
271 * Implementation of the ITelephony interface.
272 */
Santos Cordon117fee72014-05-16 17:56:12 -0700273public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 private static final String LOG_TAG = "PhoneInterfaceManager";
275 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
276 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800277 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278
279 // Message codes used with mMainThreadHandler
280 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700281 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
282 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700283 private static final int CMD_OPEN_CHANNEL = 9;
284 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
285 private static final int CMD_CLOSE_CHANNEL = 11;
286 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800287 private static final int CMD_NV_READ_ITEM = 13;
288 private static final int EVENT_NV_READ_ITEM_DONE = 14;
289 private static final int CMD_NV_WRITE_ITEM = 15;
290 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
291 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
292 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700293 private static final int CMD_RESET_MODEM_CONFIG = 19;
294 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800295 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
296 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800297 private static final int CMD_SEND_ENVELOPE = 25;
298 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700299 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
300 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
301 private static final int CMD_EXCHANGE_SIM_IO = 31;
302 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800303 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
304 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700305 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
306 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700307 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
308 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700309 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
310 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
311 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
312 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700313 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
314 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
315 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
316 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700317 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800318 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
319 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000320 private static final int CMD_SWITCH_SLOTS = 50;
321 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700322 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
323 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
324 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
325 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
326 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
327 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
328 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
329 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700330 private static final int CMD_GET_ALL_CELL_INFO = 60;
331 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
332 private static final int CMD_GET_CELL_LOCATION = 62;
333 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700334 private static final int CMD_MODEM_REBOOT = 64;
335 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700336 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
337 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800338 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
339 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700340 private static final int CMD_GET_MODEM_STATUS = 70;
341 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700342 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
343 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700344 private static final int CMD_ERASE_MODEM_CONFIG = 74;
345 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800346 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
347 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
348 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
349 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800350 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
351 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800352 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800353 private static final int CMD_GET_CALL_FORWARDING = 83;
354 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
355 private static final int CMD_SET_CALL_FORWARDING = 85;
356 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
357 private static final int CMD_GET_CALL_WAITING = 87;
358 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
359 private static final int CMD_SET_CALL_WAITING = 89;
360 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700361 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
362 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
363 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
364 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700365 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
366 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800367 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
368 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800369 private static final int CMD_SET_DATA_THROTTLING = 99;
370 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800371 private static final int CMD_SET_SIM_POWER = 101;
372 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800373 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
374 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
375 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
376 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800377 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
378 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000379 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800380 private static final int CMD_GET_SLICING_CONFIG = 110;
381 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800382 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700383 private static final int CMD_ENABLE_VONR = 113;
384 private static final int EVENT_ENABLE_VONR_DONE = 114;
385 private static final int CMD_IS_VONR_ENABLED = 115;
386 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700387 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
388 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000389
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800390 // Parameters of select command.
391 private static final int SELECT_COMMAND = 0xA4;
392 private static final int SELECT_P1 = 0x04;
393 private static final int SELECT_P2 = 0;
394 private static final int SELECT_P3 = 0x10;
395
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000396 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
397 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
398
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 /** The singleton instance. */
400 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800401 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
Sarah Chin4beb2b72023-02-14 14:47:54 -0800403 private final PhoneGlobals mApp;
404 private final CallManager mCM;
405 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000406
407 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800408 private final UserManager mUserManager;
409 private final AppOpsManager mAppOps;
410 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800411 private final SharedPreferences mTelephonySharedPreferences;
412 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800413 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
Peter Wangdafb9ac2020-01-15 14:13:38 -0800415 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800416 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800417 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
418
Sarah Chin4beb2b72023-02-14 14:47:54 -0800419 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800420
Derek Tan97ebb422014-09-05 16:55:38 -0700421 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
422 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800423 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800424 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700425
Michelecea4cf22018-12-21 15:00:11 -0800426 // String to store multi SIM allowed
427 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
428
Derek Tan740e1672017-06-27 14:56:27 -0700429 // The AID of ISD-R.
430 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
431
yinxub1bed742017-04-17 11:45:04 -0700432 private NetworkScanRequestTracker mNetworkScanRequestTracker;
433
David Kelly5e06a7f2018-03-12 14:10:59 +0000434 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
435 private static final int MANUFACTURER_CODE_LENGTH = 8;
436
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800437 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800438 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800439
Sarah Chin2ec39f62022-08-31 17:03:26 -0700440 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
441 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
442
Derek Tan89e89d42014-07-08 17:00:10 -0700443 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700444 * Experiment flag to enable erase modem config on reset network, default value is false
445 */
446 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
447 "reset_network_erase_modem_config_enabled";
448
Rambo Wang0f050d82021-02-12 11:43:36 -0800449 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800450
Gary Jian76280a42022-12-07 16:18:33 +0800451 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
452
sandeepjsb6c87872021-09-27 15:34:44 +0000453 /**
454 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
455 * one ICCID active at the same time.
456 * Apps should use below API signatures if targeting SDK is T and beyond.
457 *
458 * @hide
459 */
460 @ChangeId
461 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
462 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800463
Naina Nallurid63128d2019-09-17 14:10:30 -0700464 /**
Chen Xu540470b2021-12-14 17:15:47 -0800465 * Apps targeting on Android T and beyond will get exception whenever icc close channel
466 * operation fails.
467 */
468 @ChangeId
469 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
470 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
471
472 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 * A request object to use for transmitting data to an ICC.
474 */
475 private static final class IccAPDUArgument {
476 public int channel, cla, command, p1, p2, p3;
477 public String data;
478
479 public IccAPDUArgument(int channel, int cla, int command,
480 int p1, int p2, int p3, String data) {
481 this.channel = channel;
482 this.cla = cla;
483 this.command = command;
484 this.p1 = p1;
485 this.p2 = p2;
486 this.p3 = p3;
487 this.data = data;
488 }
489 }
490
491 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700492 * A request object to use for transmitting data to an ICC.
493 */
494 private static final class ManualNetworkSelectionArgument {
495 public OperatorInfo operatorInfo;
496 public boolean persistSelection;
497
498 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
499 this.operatorInfo = operatorInfo;
500 this.persistSelection = persistSelection;
501 }
502 }
503
Sarah Chin71b3a852022-09-28 15:54:19 -0700504 private static final class PurchasePremiumCapabilityArgument {
505 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700506 public @NonNull IIntegerConsumer callback;
507
508 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800509 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700510 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700511 this.callback = callback;
512 }
513 }
514
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700515 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
517 * request after sending. The main thread will notify the request when it is complete.
518 */
519 private static final class MainThreadRequest {
520 /** The argument to use for the request */
521 public Object argument;
522 /** The result of the request that is run on the main thread */
523 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800524 // The subscriber id that this request applies to. Defaults to
525 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
526 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527
Nathan Harold92bed182018-10-12 18:16:49 -0700528 // In cases where subId is unavailable, the caller needs to specify the phone.
529 public Phone phone;
530
vagdeviaf9a5b92018-08-15 16:01:53 -0700531 public WorkSource workSource;
532
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700533 public MainThreadRequest(Object argument) {
534 this.argument = argument;
535 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800536
Nathan Harold92bed182018-10-12 18:16:49 -0700537 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
538 this.argument = argument;
539 if (phone != null) {
540 this.phone = phone;
541 }
542 this.workSource = workSource;
543 }
544
vagdeviaf9a5b92018-08-15 16:01:53 -0700545 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800546 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800547 if (subId != null) {
548 this.subId = subId;
549 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700550 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 }
553
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800554 private static final class IncomingThirdPartyCallArgs {
555 public final ComponentName component;
556 public final String callId;
557 public final String callerDisplayName;
558
559 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
560 String callerDisplayName) {
561 this.component = component;
562 this.callId = callId;
563 this.callerDisplayName = callerDisplayName;
564 }
565 }
566
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 /**
568 * A handler that processes messages on the main thread in the phone process. Since many
569 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
570 * inbound binder threads to the main thread in the phone process. The Binder thread
571 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
572 * on, which will be notified when the operation completes and will contain the result of the
573 * request.
574 *
575 * <p>If a MainThreadRequest object is provided in the msg.obj field,
576 * note that request.result must be set to something non-null for the calling thread to
577 * unblock.
578 */
579 private final class MainThreadHandler extends Handler {
580 @Override
581 public void handleMessage(Message msg) {
582 MainThreadRequest request;
583 Message onCompleted;
584 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000585 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800587 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700588
589 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 case CMD_HANDLE_USSD_REQUEST: {
591 request = (MainThreadRequest) msg.obj;
592 final Phone phone = getPhoneFromRequest(request);
593 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800594 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700596
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 if (!isUssdApiAllowed(request.subId)) {
598 // Carrier does not support use of this API, return failure.
599 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
600 UssdResponse response = new UssdResponse(ussdRequest, null);
601 Bundle returnData = new Bundle();
602 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
603 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700604
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 request.result = true;
606 notifyRequester(request);
607 return;
608 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700609
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 try {
611 request.result = phone != null
612 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
613 } catch (CallStateException cse) {
614 request.result = false;
615 }
616 // Wake up the requesting thread
617 notifyRequester(request);
618 break;
pkanwar32d516d2016-10-14 19:37:38 -0700619 }
620
Yorke Lee716f67e2015-06-17 15:39:16 -0700621 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700623 final Phone phone = getPhoneFromRequest(request);
624 request.result = phone != null ?
625 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
626 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000635 uiccPort = getUiccPortFromRequest(request);
636 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800638 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800642 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000643 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800644 iccArgument.channel, iccArgument.cla, iccArgument.command,
645 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
646 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 ar = (AsyncResult) msg.obj;
652 request = (MainThreadRequest) ar.userObj;
653 if (ar.exception == null && ar.result != null) {
654 request.result = ar.result;
655 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800656 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 if (ar.result == null) {
658 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800659 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800661 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
663 loge("iccTransmitApduLogicalChannel: Unknown exception");
664 }
665 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 break;
668
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
670 request = (MainThreadRequest) msg.obj;
671 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000672 uiccPort = getUiccPortFromRequest(request);
673 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800675 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 } else {
678 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800679 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000680 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800681 iccArgument.cla, iccArgument.command, iccArgument.p1,
682 iccArgument.p2,
683 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 }
685 break;
686
687 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result;
692 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800693 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 if (ar.result == null) {
695 loge("iccTransmitApduBasicChannel: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("iccTransmitApduBasicChannel: CommandException: " +
698 ar.exception);
699 } else {
700 loge("iccTransmitApduBasicChannel: Unknown exception");
701 }
702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 break;
705
706 case CMD_EXCHANGE_SIM_IO:
707 request = (MainThreadRequest) msg.obj;
708 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort = getUiccPortFromRequest(request);
710 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800712 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 } else {
715 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
716 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000717 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
719 iccArgument.data, onCompleted);
720 }
721 break;
722
723 case EVENT_EXCHANGE_SIM_IO_DONE:
724 ar = (AsyncResult) msg.obj;
725 request = (MainThreadRequest) ar.userObj;
726 if (ar.exception == null && ar.result != null) {
727 request.result = ar.result;
728 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800729 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700732 break;
733
Derek Tan4d5e5c12014-02-04 11:54:58 -0800734 case CMD_SEND_ENVELOPE:
735 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000736 uiccPort = getUiccPortFromRequest(request);
737 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700738 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800739 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 } else {
742 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800743 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700744 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800745 break;
746
747 case EVENT_SEND_ENVELOPE_DONE:
748 ar = (AsyncResult) msg.obj;
749 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700750 if (ar.exception == null && ar.result != null) {
751 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800752 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800753 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700754 if (ar.result == null) {
755 loge("sendEnvelopeWithStatus: Empty response");
756 } else if (ar.exception instanceof CommandException) {
757 loge("sendEnvelopeWithStatus: CommandException: " +
758 ar.exception);
759 } else {
760 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
761 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800762 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700763 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800764 break;
765
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 case CMD_OPEN_CHANNEL:
767 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000768 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800769 IccLogicalChannelRequest openChannelRequest =
770 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000771 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800773 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800774 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700776 } else {
777 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800778 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
779 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700780 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 break;
782
783 case EVENT_OPEN_CHANNEL_DONE:
784 ar = (AsyncResult) msg.obj;
785 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700786 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700788 int[] result = (int[]) ar.result;
789 int channelId = result[0];
790 byte[] selectResponse = null;
791 if (result.length > 1) {
792 selectResponse = new byte[result.length - 1];
793 for (int i = 1; i < result.length; ++i) {
794 selectResponse[i - 1] = (byte) result[i];
795 }
796 }
797 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800798 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800799
800 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700801 if (uiccPort == null) {
802 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
803 } else {
804 IccLogicalChannelRequest channelRequest =
805 (IccLogicalChannelRequest) request.argument;
806 channelRequest.channel = channelId;
807 uiccPort.onLogicalChannelOpened(channelRequest);
808 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700809 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 if (ar.result == null) {
811 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700813 if (ar.exception != null) {
814 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
815 }
816
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700817 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700818 if (ar.exception instanceof CommandException) {
819 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800820 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700821 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700822 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700823 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700824 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700825 }
826 }
827 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800828 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700829 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700830 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700831 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 break;
833
834 case CMD_CLOSE_CHANNEL:
835 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000836 uiccPort = getUiccPortFromRequest(request);
837 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700838 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800839 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800840 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800841 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700842 } else {
843 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000844 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700845 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 break;
847
848 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null) {
852 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800853 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700854 if (uiccPort == null) {
855 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
856 } else {
857 final int channelId = (Integer) request.argument;
858 uiccPort.onLogicalChannelClosed(channelId);
859 }
Chen Xu540470b2021-12-14 17:15:47 -0800860 } else {
861 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800862 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800863 if (ar.exception instanceof CommandException) {
864 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
865 CommandException.Error error =
866 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800867 if (error == CommandException.Error.INVALID_ARGUMENTS) {
868 // should only throw exceptions from the binder threads.
869 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800870 "iccCloseLogicalChannel: invalid argument ");
871 }
872 } else {
873 loge("iccCloseLogicalChannel: Unknown exception");
874 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800875 request.result = (exception != null) ? exception :
876 new IllegalStateException(
877 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800878 }
879 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800880 break;
881
882 case CMD_NV_READ_ITEM:
883 request = (MainThreadRequest) msg.obj;
884 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800885 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
886 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
889 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700894 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800895 request.result = "";
896 if (ar.result == null) {
897 loge("nvReadItem: Empty response");
898 } else if (ar.exception instanceof CommandException) {
899 loge("nvReadItem: CommandException: " +
900 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700901 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800902 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700903 }
904 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700905 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700906 break;
907
Jake Hambye994d462014-02-03 13:10:13 -0800908 case CMD_NV_WRITE_ITEM:
909 request = (MainThreadRequest) msg.obj;
910 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
911 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700913 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800914 break;
915
916 case EVENT_NV_WRITE_ITEM_DONE:
917 handleNullReturnEvent(msg, "nvWriteItem");
918 break;
919
920 case CMD_NV_WRITE_CDMA_PRL:
921 request = (MainThreadRequest) msg.obj;
922 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800923 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800924 break;
925
926 case EVENT_NV_WRITE_CDMA_PRL_DONE:
927 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
928 break;
929
chen xu6dac5ab2018-10-26 17:39:23 -0700930 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800931 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700932 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800933 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800934 break;
935
chen xu6dac5ab2018-10-26 17:39:23 -0700936 case EVENT_RESET_MODEM_CONFIG_DONE:
937 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800938 break;
939
Sooraj Sasindran37444802020-08-11 10:40:43 -0700940 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
943 request);
944 Phone phone = getPhoneFromRequest(request);
945 if (phone != null) {
946 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
947 } else {
948 loge("isNRDualConnectivityEnabled: No phone object");
949 request.result = false;
950 notifyRequester(request);
951 }
952 break;
953 }
954
955 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
956 ar = (AsyncResult) msg.obj;
957 request = (MainThreadRequest) ar.userObj;
958 if (ar.exception == null && ar.result != null) {
959 request.result = ar.result;
960 } else {
961 // request.result must be set to something non-null
962 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700963 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700964 request.result = ar.result;
965 } else {
966 request.result = false;
967 }
968 if (ar.result == null) {
969 loge("isNRDualConnectivityEnabled: Empty response");
970 } else if (ar.exception instanceof CommandException) {
971 loge("isNRDualConnectivityEnabled: CommandException: "
972 + ar.exception);
973 } else {
974 loge("isNRDualConnectivityEnabled: Unknown exception");
975 }
976 }
977 notifyRequester(request);
978 break;
979
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700980 case CMD_IS_VONR_ENABLED: {
981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
983 request);
984 Phone phone = getPhoneFromRequest(request);
985 if (phone != null) {
986 phone.isVoNrEnabled(onCompleted, request.workSource);
987 } else {
988 loge("isVoNrEnabled: No phone object");
989 request.result = false;
990 notifyRequester(request);
991 }
992 break;
993 }
994
995 case EVENT_IS_VONR_ENABLED_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 if (ar.exception == null && ar.result != null) {
999 request.result = ar.result;
1000 } else {
1001 // request.result must be set to something non-null
1002 // for the calling thread to unblock
1003 if (ar.result != null) {
1004 request.result = ar.result;
1005 } else {
1006 request.result = false;
1007 }
1008 if (ar.result == null) {
1009 loge("isVoNrEnabled: Empty response");
1010 } else if (ar.exception instanceof CommandException) {
1011 loge("isVoNrEnabled: CommandException: "
1012 + ar.exception);
1013 } else {
1014 loge("isVoNrEnabled: Unknown exception");
1015 }
1016 }
1017 notifyRequester(request);
1018 break;
1019
Sooraj Sasindran37444802020-08-11 10:40:43 -07001020 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1023 Phone phone = getPhoneFromRequest(request);
1024 if (phone != null) {
1025 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1026 request.workSource);
1027 } else {
1028 loge("enableNrDualConnectivity: No phone object");
1029 request.result =
1030 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1031 notifyRequester(request);
1032 }
1033 break;
1034 }
1035
1036 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 if (ar.exception == null) {
1040 request.result =
1041 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1042 } else {
1043 request.result =
1044 TelephonyManager
1045 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1046 if (ar.exception instanceof CommandException) {
1047 CommandException.Error error =
1048 ((CommandException) (ar.exception)).getCommandError();
1049 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1050 request.result =
1051 TelephonyManager
1052 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001053 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1054 request.result =
1055 TelephonyManager
1056 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001057 }
1058 loge("enableNrDualConnectivity" + ": CommandException: "
1059 + ar.exception);
1060 } else {
1061 loge("enableNrDualConnectivity" + ": Unknown exception");
1062 }
1063 }
1064 notifyRequester(request);
1065 break;
1066 }
1067
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001068 case CMD_ENABLE_VONR: {
1069 request = (MainThreadRequest) msg.obj;
1070 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1071 Phone phone = getPhoneFromRequest(request);
1072 if (phone != null) {
1073 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1074 request.workSource);
1075 } else {
1076 loge("setVoNrEnabled: No phone object");
1077 request.result =
1078 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1079 notifyRequester(request);
1080 }
1081 break;
1082 }
1083
1084 case EVENT_ENABLE_VONR_DONE: {
1085 ar = (AsyncResult) msg.obj;
1086 request = (MainThreadRequest) ar.userObj;
1087 if (ar.exception == null) {
1088 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1089 } else {
1090 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1091 if (ar.exception instanceof CommandException) {
1092 CommandException.Error error =
1093 ((CommandException) (ar.exception)).getCommandError();
1094 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1095 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1096 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1097 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1098 } else {
1099 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1100 }
1101 loge("setVoNrEnabled" + ": CommandException: "
1102 + ar.exception);
1103 } else {
1104 loge("setVoNrEnabled" + ": Unknown exception");
1105 }
1106 }
1107 notifyRequester(request);
1108 break;
1109 }
1110
SongFerngWang3ef3e072020-12-21 16:41:52 +08001111 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001112 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001113 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1114 request);
1115 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001116 break;
1117
SongFerngWang3ef3e072020-12-21 16:41:52 +08001118 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 ar = (AsyncResult) msg.obj;
1120 request = (MainThreadRequest) ar.userObj;
1121 if (ar.exception == null && ar.result != null) {
1122 request.result = ar.result; // Integer
1123 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301124 // request.result must be set to something non-null
1125 // for the calling thread to unblock
1126 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001128 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001129 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001130 loge("getAllowedNetworkTypesBitmask: CommandException: "
1131 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001132 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001133 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001134 }
1135 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001136 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 break;
1138
SongFerngWang3ef3e072020-12-21 16:41:52 +08001139 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001141 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1142 request);
1143 Pair<Integer, Long> reasonWithNetworkTypes =
1144 (Pair<Integer, Long>) request.argument;
1145 getPhoneFromRequest(request).setAllowedNetworkTypes(
1146 reasonWithNetworkTypes.first,
1147 reasonWithNetworkTypes.second,
1148 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001149 break;
1150
SongFerngWang3ef3e072020-12-21 16:41:52 +08001151 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1152 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 break;
1154
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001155 case CMD_SET_VOICEMAIL_NUMBER:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1158 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001159 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1160 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001161 break;
1162
1163 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1164 handleNullReturnEvent(msg, "setVoicemailNumber");
1165 break;
1166
Stuart Scott54788802015-03-30 13:18:01 -07001167 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1168 request = (MainThreadRequest) msg.obj;
1169 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1170 request);
1171 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1172 break;
1173
1174 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1175 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1176 break;
1177
Shishir Agrawal302c8692015-06-19 13:49:39 -07001178 case CMD_PERFORM_NETWORK_SCAN:
1179 request = (MainThreadRequest) msg.obj;
1180 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1181 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1182 break;
1183
Hall Liu27d24262020-09-18 19:04:59 -07001184 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001187 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1188 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1189 request.argument;
1190 int callForwardingReason = args.first;
1191 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001192 break;
Hall Liu27d24262020-09-18 19:04:59 -07001193 }
1194 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001197 TelephonyManager.CallForwardingInfoCallback callback =
1198 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1199 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001200 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001201 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1203 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1204 // Service Class is a bit mask per 3gpp 27.007. Search for
1205 // any service for voice call.
1206 if ((callForwardInfo.serviceClass
1207 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001208 callForwardingInfo = new CallForwardingInfo(
1209 callForwardInfo.status
1210 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001211 callForwardInfo.reason,
1212 callForwardInfo.number,
1213 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001214 break;
1215 }
1216 }
1217 // Didn't find a call forward info for voice call.
1218 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001219 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1220 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001221 }
Hall Liu27d24262020-09-18 19:04:59 -07001222 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001223 } else {
1224 if (ar.result == null) {
1225 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1226 }
1227 if (ar.exception != null) {
1228 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1229 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001230 int errorCode = TelephonyManager
1231 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 if (ar.exception instanceof CommandException) {
1233 CommandException.Error error =
1234 ((CommandException) (ar.exception)).getCommandError();
1235 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001236 errorCode = TelephonyManager
1237 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001238 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 errorCode = TelephonyManager
1240 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001241 }
1242 }
Hall Liu27d24262020-09-18 19:04:59 -07001243 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001244 }
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
Hall Liu27d24262020-09-18 19:04:59 -07001246 }
Shuo Qian4a594052020-01-23 11:59:30 -08001247
Hall Liu27d24262020-09-18 19:04:59 -07001248 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001249 request = (MainThreadRequest) msg.obj;
1250 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001251 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001252 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001253 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1254 request.argument).first;
1255 request.phone.setCallForwardingOption(
1256 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001257 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001258 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001259 callForwardingInfoToSet.getReason(),
1260 callForwardingInfoToSet.getNumber(),
1261 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1262 break;
Hall Liu27d24262020-09-18 19:04:59 -07001263 }
Shuo Qian4a594052020-01-23 11:59:30 -08001264
Hall Liu27d24262020-09-18 19:04:59 -07001265 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001268 Consumer<Integer> callback =
1269 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1270 request.argument).second;
1271 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001272 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001273 int errorCode = TelephonyManager.CallForwardingInfoCallback
1274 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001275 if (ar.exception instanceof CommandException) {
1276 CommandException.Error error =
1277 ((CommandException) (ar.exception)).getCommandError();
1278 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001279 errorCode = TelephonyManager.CallForwardingInfoCallback
1280 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001281 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001282 errorCode = TelephonyManager.CallForwardingInfoCallback
1283 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001284 }
1285 }
1286 callback.accept(errorCode);
1287 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001288 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001289 }
Shuo Qian4a594052020-01-23 11:59:30 -08001290 break;
Hall Liu27d24262020-09-18 19:04:59 -07001291 }
Shuo Qian4a594052020-01-23 11:59:30 -08001292
Hall Liu27d24262020-09-18 19:04:59 -07001293 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001294 request = (MainThreadRequest) msg.obj;
1295 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1296 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1297 break;
Hall Liu27d24262020-09-18 19:04:59 -07001298 }
Shuo Qian4a594052020-01-23 11:59:30 -08001299
Hall Liu27d24262020-09-18 19:04:59 -07001300 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 ar = (AsyncResult) msg.obj;
1302 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001303 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001304 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001305 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001306 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001307 // Service Class is a bit mask per 3gpp 27.007.
1308 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001309 if (callForwardResults.length > 1
1310 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001311 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001312 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001313 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1314 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001315 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001316 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001317 }
1318 } else {
1319 if (ar.result == null) {
1320 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1321 }
1322 if (ar.exception != null) {
1323 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1324 }
1325 if (ar.exception instanceof CommandException) {
1326 CommandException.Error error =
1327 ((CommandException) (ar.exception)).getCommandError();
1328 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001329 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001330 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001331 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1332 callWaitingStatus =
1333 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 }
1335 }
1336 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001337 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001338 break;
Hall Liu27d24262020-09-18 19:04:59 -07001339 }
Shuo Qian4a594052020-01-23 11:59:30 -08001340
Hall Liu27d24262020-09-18 19:04:59 -07001341 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001342 request = (MainThreadRequest) msg.obj;
1343 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001344 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1345 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001346 break;
Hall Liu27d24262020-09-18 19:04:59 -07001347 }
Shuo Qian4a594052020-01-23 11:59:30 -08001348
Hall Liu27d24262020-09-18 19:04:59 -07001349 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001350 ar = (AsyncResult) msg.obj;
1351 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001352 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1353 Consumer<Integer> callback =
1354 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1355 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001356 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001357 if (ar.exception instanceof CommandException) {
1358 CommandException.Error error =
1359 ((CommandException) (ar.exception)).getCommandError();
1360 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1361 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001362 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1363 callback.accept(
1364 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001365 } else {
1366 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1367 }
1368 } else {
1369 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1370 }
1371 } else {
1372 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1373 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001374 }
Shuo Qian4a594052020-01-23 11:59:30 -08001375 break;
Hall Liu27d24262020-09-18 19:04:59 -07001376 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001377 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1378 ar = (AsyncResult) msg.obj;
1379 request = (MainThreadRequest) ar.userObj;
1380 CellNetworkScanResult cellScanResult;
1381 if (ar.exception == null && ar.result != null) {
1382 cellScanResult = new CellNetworkScanResult(
1383 CellNetworkScanResult.STATUS_SUCCESS,
1384 (List<OperatorInfo>) ar.result);
1385 } else {
1386 if (ar.result == null) {
1387 loge("getCellNetworkScanResults: Empty response");
1388 }
1389 if (ar.exception != null) {
1390 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1391 }
1392 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1393 if (ar.exception instanceof CommandException) {
1394 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001395 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001396 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1397 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1398 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1399 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1400 }
1401 }
1402 cellScanResult = new CellNetworkScanResult(errorCode, null);
1403 }
1404 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001405 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001406 break;
1407
1408 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1409 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001410 ManualNetworkSelectionArgument selArg =
1411 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001412 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1413 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001414 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1415 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 break;
1417
1418 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception == null) {
1422 request.result = true;
1423 } else {
1424 request.result = false;
1425 loge("setNetworkSelectionModeManual " + ar.exception);
1426 }
1427 notifyRequester(request);
1428 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001429 break;
1430
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001431 case CMD_GET_MODEM_ACTIVITY_INFO:
1432 request = (MainThreadRequest) msg.obj;
1433 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001434 if (defaultPhone != null) {
1435 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001436 } else {
1437 ResultReceiver result = (ResultReceiver) request.argument;
1438 Bundle bundle = new Bundle();
1439 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001440 new ModemActivityInfo(0, 0, 0,
1441 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001442 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001443 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001444 break;
1445
Hall Liud0f208c2020-10-14 16:54:44 -07001446 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001449 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001450 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001451 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001452 if (mLastModemActivityInfo == null) {
1453 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1454 mLastModemActivitySpecificInfo[0] =
1455 new ActivityStatsTechSpecificInfo(
1456 0,
1457 0,
1458 new int[ModemActivityInfo.getNumTxPowerLevels()],
1459 0);
1460 mLastModemActivityInfo =
1461 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1462 }
1463
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001464 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 // Update the last modem activity info and the result of the request.
1466 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1467 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001468 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001469 } else {
1470 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 }
Kai Shi917fdc62022-11-28 14:01:02 -08001472 // This is needed to decouple ret from mLastModemActivityInfo
1473 // We don't want to return mLastModemActivityInfo which is updated
1474 // inside mergeModemActivityInfo()
1475 ret = new ModemActivityInfo(
1476 mLastModemActivityInfo.getTimestampMillis(),
1477 mLastModemActivityInfo.getSleepTimeMillis(),
1478 mLastModemActivityInfo.getIdleTimeMillis(),
1479 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001480
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001481 } else {
1482 if (ar.result == null) {
1483 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001484 error = TelephonyManager.ModemActivityInfoException
1485 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001486 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001487 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001488 error = TelephonyManager.ModemActivityInfoException
1489 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490 } else {
1491 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001492 error = TelephonyManager.ModemActivityInfoException
1493 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001494 }
1495 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001496 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001497 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001498 bundle.putParcelable(
1499 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001500 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001501 } else {
1502 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1503 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001504 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001505 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001507 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001508
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001509 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001510 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001511 CarrierRestrictionRules argument =
1512 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001513 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001514 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001516 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001517
1518 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1519 ar = (AsyncResult) msg.obj;
1520 request = (MainThreadRequest) ar.userObj;
1521 if (ar.exception == null && ar.result != null) {
1522 request.result = ar.result;
1523 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001524 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1525 if (ar.exception instanceof CommandException) {
1526 loge("setAllowedCarriers: CommandException: " + ar.exception);
1527 CommandException.Error error =
1528 ((CommandException) (ar.exception)).getCommandError();
1529 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1530 request.result =
1531 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1532 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001533 } else {
1534 loge("setAllowedCarriers: Unknown exception");
1535 }
1536 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001537 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001538 break;
1539
1540 case CMD_GET_ALLOWED_CARRIERS:
1541 request = (MainThreadRequest) msg.obj;
1542 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001543 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 break;
1545
1546 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1547 ar = (AsyncResult) msg.obj;
1548 request = (MainThreadRequest) ar.userObj;
1549 if (ar.exception == null && ar.result != null) {
1550 request.result = ar.result;
1551 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001552 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001553 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001554 if (ar.result == null) {
1555 loge("getAllowedCarriers: Empty response");
1556 } else if (ar.exception instanceof CommandException) {
1557 loge("getAllowedCarriers: CommandException: " +
1558 ar.exception);
1559 } else {
1560 loge("getAllowedCarriers: Unknown exception");
1561 }
1562 }
arunvoddud7401012022-12-15 16:08:12 +00001563 if (request.argument != null) {
1564 // This is for the implementation of carrierRestrictionStatus.
1565 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1566 Consumer<Integer> callback = callbackInfo.getConsumer();
1567 int callerCarrierId = callbackInfo.getCarrierId();
1568 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1569 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1570 CarrierRestrictionRules carrierRestrictionRules =
1571 (CarrierRestrictionRules) ar.result;
1572 int carrierId = -1;
1573 try {
1574 CarrierIdentifier carrierIdentifier =
1575 carrierRestrictionRules.getAllowedCarriers().get(0);
1576 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1577 carrierIdentifier);
1578 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1579 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1580 }
1581 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1582 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1583 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001584 lockStatus = TelephonyManager
1585 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001586 }
1587 } else {
1588 Rlog.e(LOG_TAG,
1589 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1590 }
1591 callback.accept(lockStatus);
1592 } else {
1593 // This is for the implementation of getAllowedCarriers.
1594 notifyRequester(request);
1595 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001596 break;
1597
Nathan Haroldb3014052017-01-25 15:57:32 -08001598 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 if (ar.exception == null && ar.result != null) {
1602 request.result = ar.result;
1603 } else {
1604 request.result = new IllegalArgumentException(
1605 "Failed to retrieve Forbidden Plmns");
1606 if (ar.result == null) {
1607 loge("getForbiddenPlmns: Empty response");
1608 } else {
1609 loge("getForbiddenPlmns: Unknown exception");
1610 }
1611 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001612 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001613 break;
1614
1615 case CMD_GET_FORBIDDEN_PLMNS:
1616 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001617 uiccPort = getUiccPortFromRequest(request);
1618 if (uiccPort == null) {
1619 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001620 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001621 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001622 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001623 break;
1624 }
1625 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001626 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001627 if (uiccApp == null) {
1628 loge("getForbiddenPlmns() no app with specified type -- "
1629 + appType);
1630 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001631 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001632 break;
1633 } else {
1634 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1635 + " specified type -- " + appType);
1636 }
1637 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1638 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001639 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001640 break;
1641
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001642 case CMD_SWITCH_SLOTS:
1643 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001644 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001645 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001646 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001647 break;
1648
1649 case EVENT_SWITCH_SLOTS_DONE:
1650 ar = (AsyncResult) msg.obj;
1651 request = (MainThreadRequest) ar.userObj;
1652 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 notifyRequester(request);
1654 break;
1655 case CMD_GET_NETWORK_SELECTION_MODE:
1656 request = (MainThreadRequest) msg.obj;
1657 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1658 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1659 break;
1660
1661 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 if (ar.exception != null) {
1665 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1666 } else {
1667 int mode = ((int[]) ar.result)[0];
1668 if (mode == 0) {
1669 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1670 } else {
1671 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1672 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001673 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001674 notifyRequester(request);
1675 break;
1676 case CMD_GET_CDMA_ROAMING_MODE:
1677 request = (MainThreadRequest) msg.obj;
1678 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1679 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1680 break;
1681 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 if (ar.exception != null) {
1685 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1686 } else {
1687 request.result = ((int[]) ar.result)[0];
1688 }
1689 notifyRequester(request);
1690 break;
1691 case CMD_SET_CDMA_ROAMING_MODE:
1692 request = (MainThreadRequest) msg.obj;
1693 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1694 int mode = (int) request.argument;
1695 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1696 break;
1697 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 request.result = ar.exception == null;
1701 notifyRequester(request);
1702 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001703 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1706 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1707 break;
1708 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception != null) {
1712 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1713 } else {
1714 request.result = ((int[]) ar.result)[0];
1715 }
1716 notifyRequester(request);
1717 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001718 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1719 request = (MainThreadRequest) msg.obj;
1720 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1721 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001722 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1723 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001724 break;
1725 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1726 ar = (AsyncResult) msg.obj;
1727 request = (MainThreadRequest) ar.userObj;
1728 request.result = ar.exception == null;
1729 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001730 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001731 case CMD_GET_ALL_CELL_INFO:
1732 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001733 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001734 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001735 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 case EVENT_GET_ALL_CELL_INFO_DONE:
1737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001739 // If a timeout occurs, the response will be null
1740 request.result = (ar.exception == null && ar.result != null)
1741 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001742 synchronized (request) {
1743 request.notifyAll();
1744 }
1745 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001746 case CMD_REQUEST_CELL_INFO_UPDATE:
1747 request = (MainThreadRequest) msg.obj;
1748 request.phone.requestCellInfoUpdate(request.workSource,
1749 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1750 break;
1751 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1755 try {
1756 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001757 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001758 cb.onError(
1759 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1760 ar.exception.getClass().getName(),
1761 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001762 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001763 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001764 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001765 } else {
1766 // use the result as returned
1767 cb.onCellInfo((List<CellInfo>) ar.result);
1768 }
1769 } catch (RemoteException re) {
1770 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1771 }
1772 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001773 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001774 request = (MainThreadRequest) msg.obj;
1775 WorkSource ws = (WorkSource) request.argument;
1776 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001777 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001778 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001779 }
1780 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001781 ar = (AsyncResult) msg.obj;
1782 request = (MainThreadRequest) ar.userObj;
1783 if (ar.exception == null) {
1784 request.result = ar.result;
1785 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001786 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001787 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001788 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001789 }
1790
1791 synchronized (request) {
1792 request.notifyAll();
1793 }
1794 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001795 }
chen xu6dac5ab2018-10-26 17:39:23 -07001796 case CMD_MODEM_REBOOT:
1797 request = (MainThreadRequest) msg.obj;
1798 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001799 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001800 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001801 case EVENT_CMD_MODEM_REBOOT_DONE:
1802 handleNullReturnEvent(msg, "rebootModem");
1803 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001804 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001805 request = (MainThreadRequest) msg.obj;
1806 boolean enable = (boolean) request.argument;
1807 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001808 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001809 PhoneConfigurationManager.getInstance()
1810 .enablePhone(request.phone, enable, onCompleted);
1811 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001812 }
Michele Berionne5e411512020-11-13 02:36:59 +00001813 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001817 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001818 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001819 if ((boolean) request.result) {
1820 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1821 updateModemStateMetrics();
1822 } else {
1823 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1824 + ar.exception);
1825 }
1826 notifyRequester(request);
1827 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001828 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001829 case CMD_GET_MODEM_STATUS:
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1832 PhoneConfigurationManager.getInstance()
1833 .getPhoneStatusFromModem(request.phone, onCompleted);
1834 break;
1835 case EVENT_GET_MODEM_STATUS_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 int id = request.phone.getPhoneId();
1839 if (ar.exception == null && ar.result != null) {
1840 request.result = ar.result;
1841 //update the cache as modem status has changed
1842 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1843 (boolean) request.result);
1844 } else {
1845 // Return true if modem status cannot be retrieved. For most cases,
1846 // modem status is on. And for older version modems, GET_MODEM_STATUS
1847 // and disable modem are not supported. Modem is always on.
1848 // TODO: this should be fixed in R to support a third
1849 // status UNKNOWN b/131631629
1850 request.result = true;
1851 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1852 + ar.exception);
1853 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001854 notifyRequester(request);
1855 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001856 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1857 request = (MainThreadRequest) msg.obj;
1858 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1859 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1860 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1861 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1862 break;
1863 }
1864 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1868 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1869 args.second.accept(ar.exception == null);
1870 notifyRequester(request);
1871 break;
1872 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001873 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1874 request = (MainThreadRequest) msg.obj;
1875 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1876 Phone phone = getPhoneFromRequest(request);
1877 if (phone != null) {
1878 phone.getSystemSelectionChannels(onCompleted);
1879 } else {
1880 loge("getSystemSelectionChannels: No phone object");
1881 request.result = new ArrayList<RadioAccessSpecifier>();
1882 notifyRequester(request);
1883 }
1884 break;
1885 }
1886 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1887 ar = (AsyncResult) msg.obj;
1888 request = (MainThreadRequest) ar.userObj;
1889 if (ar.exception == null && ar.result != null) {
1890 request.result = ar.result;
1891 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001892 request.result = new IllegalStateException(
1893 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001894 if (ar.result == null) {
1895 loge("getSystemSelectionChannels: Empty response");
1896 } else {
1897 loge("getSystemSelectionChannels: Unknown exception");
1898 }
1899 }
1900 notifyRequester(request);
1901 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001902 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1903 ar = (AsyncResult) msg.obj;
1904 request = (MainThreadRequest) ar.userObj;
1905 if (ar.exception == null && ar.result != null) {
1906 request.result = ar.result;
1907 } else {
1908 request.result = -1;
1909 loge("Failed to set Forbidden Plmns");
1910 if (ar.result == null) {
1911 loge("setForbidenPlmns: Empty response");
1912 } else if (ar.exception != null) {
1913 loge("setForbiddenPlmns: Exception: " + ar.exception);
1914 request.result = -1;
1915 } else {
1916 loge("setForbiddenPlmns: Unknown exception");
1917 }
1918 }
1919 notifyRequester(request);
1920 break;
1921 case CMD_SET_FORBIDDEN_PLMNS:
1922 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001923 uiccPort = getUiccPortFromRequest(request);
1924 if (uiccPort == null) {
1925 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001926 request.result = -1;
1927 notifyRequester(request);
1928 break;
1929 }
1930 Pair<Integer, List<String>> setFplmnsArgs =
1931 (Pair<Integer, List<String>>) request.argument;
1932 appType = setFplmnsArgs.first;
1933 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001934 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001935 if (uiccApp == null) {
1936 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1937 request.result = -1;
1938 loge("Failed to get UICC App");
1939 notifyRequester(request);
1940 } else {
1941 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1942 ((SIMRecords) uiccApp.getIccRecords())
1943 .setForbiddenPlmns(onCompleted, fplmns);
1944 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001945 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001946 case CMD_ERASE_MODEM_CONFIG:
1947 request = (MainThreadRequest) msg.obj;
1948 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1949 defaultPhone.eraseModemConfig(onCompleted);
1950 break;
1951 case EVENT_ERASE_MODEM_CONFIG_DONE:
1952 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001953 break;
zoey chene02881a2019-12-30 16:11:23 +08001954
Kai Shif70f46f2021-03-03 13:59:46 -08001955 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1956 request = (MainThreadRequest) msg.obj;
1957 request.result = defaultPhone.eraseDataInSharedPreferences();
1958 notifyRequester(request);
1959 break;
1960
zoey chene02881a2019-12-30 16:11:23 +08001961 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1962 request = (MainThreadRequest) msg.obj;
1963 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1964 Pair<String, String> changed = (Pair<String, String>) request.argument;
1965 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1966 changed.first, changed.second, onCompleted);
1967 break;
1968 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1969 ar = (AsyncResult) msg.obj;
1970 request = (MainThreadRequest) ar.userObj;
1971 if (ar.exception == null) {
1972 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001973 // If the operation is successful, update the PIN storage
1974 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1975 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001976 UiccController.getInstance().getPinStorage()
1977 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001978 } else {
1979 request.result = msg.arg1;
1980 }
1981 notifyRequester(request);
1982 break;
1983
Michele Berionne5e411512020-11-13 02:36:59 +00001984 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001985 request = (MainThreadRequest) msg.obj;
1986 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1987 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1988 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1989 enabled.first, enabled.second, onCompleted);
1990 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001991 }
zoey chene02881a2019-12-30 16:11:23 +08001992 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1993 ar = (AsyncResult) msg.obj;
1994 request = (MainThreadRequest) ar.userObj;
1995 if (ar.exception == null) {
1996 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001997 // If the operation is successful, update the PIN storage
1998 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1999 int phoneId = getPhoneFromRequest(request).getPhoneId();
2000 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002001 UiccController.getInstance().getPinStorage()
2002 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002003 } else {
2004 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2005 }
zoey chene02881a2019-12-30 16:11:23 +08002006 } else {
2007 request.result = msg.arg1;
2008 }
Michele Berionne5e411512020-11-13 02:36:59 +00002009
2010
zoey chene02881a2019-12-30 16:11:23 +08002011 notifyRequester(request);
2012 break;
2013
Peter Wangdafb9ac2020-01-15 14:13:38 -08002014 case MSG_NOTIFY_USER_ACTIVITY:
2015 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002016 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002017 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2018 getDefaultPhone().getContext().sendBroadcastAsUser(
2019 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2020 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002021
2022 case CMD_SET_DATA_THROTTLING: {
2023 request = (MainThreadRequest) msg.obj;
2024 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2025 DataThrottlingRequest dataThrottlingRequest =
2026 (DataThrottlingRequest) request.argument;
2027 Phone phone = getPhoneFromRequest(request);
2028 if (phone != null) {
2029 phone.setDataThrottling(onCompleted,
2030 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2031 dataThrottlingRequest.getCompletionDurationMillis());
2032 } else {
2033 loge("setDataThrottling: No phone object");
2034 request.result =
2035 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2036 notifyRequester(request);
2037 }
2038
2039 break;
2040 }
2041 case EVENT_SET_DATA_THROTTLING_DONE:
2042 ar = (AsyncResult) msg.obj;
2043 request = (MainThreadRequest) ar.userObj;
2044
2045 if (ar.exception == null) {
2046 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2047 } else if (ar.exception instanceof CommandException) {
2048 loge("setDataThrottling: CommandException: " + ar.exception);
2049 CommandException.Error error =
2050 ((CommandException) (ar.exception)).getCommandError();
2051
2052 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2053 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002054 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002055 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2056 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002057 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2058 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002059 } else {
2060 request.result =
2061 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2062 }
2063 } else {
2064 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2065 }
2066 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2067 notifyRequester(request);
2068 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002069
2070 case CMD_SET_SIM_POWER: {
2071 request = (MainThreadRequest) msg.obj;
2072 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2073 request = (MainThreadRequest) msg.obj;
2074 int stateToSet =
2075 ((Pair<Integer, IIntegerConsumer>)
2076 request.argument).first;
2077 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2078 break;
2079 }
2080 case EVENT_SET_SIM_POWER_DONE: {
2081 ar = (AsyncResult) msg.obj;
2082 request = (MainThreadRequest) ar.userObj;
2083 IIntegerConsumer callback =
2084 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2085 if (ar.exception != null) {
2086 loge("setSimPower exception: " + ar.exception);
2087 int errorCode = TelephonyManager.CallForwardingInfoCallback
2088 .RESULT_ERROR_UNKNOWN;
2089 if (ar.exception instanceof CommandException) {
2090 CommandException.Error error =
2091 ((CommandException) (ar.exception)).getCommandError();
2092 if (error == CommandException.Error.SIM_ERR) {
2093 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2094 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2095 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2096 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2097 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2098 } else {
2099 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2100 }
2101 }
2102 try {
2103 callback.accept(errorCode);
2104 } catch (RemoteException e) {
2105 // Ignore if the remote process is no longer available to call back.
2106 Log.w(LOG_TAG, "setSimPower: callback not available.");
2107 }
2108 } else {
2109 try {
2110 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2111 } catch (RemoteException e) {
2112 // Ignore if the remote process is no longer available to call back.
2113 Log.w(LOG_TAG, "setSimPower: callback not available.");
2114 }
2115 }
2116 break;
2117 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002118 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2119 request = (MainThreadRequest) msg.obj;
2120
2121 final Phone phone = getPhoneFromRequest(request);
2122 if (phone == null || phone.getServiceStateTracker() == null) {
2123 request.result = new IllegalStateException("Phone or SST is null");
2124 notifyRequester(request);
2125 break;
2126 }
2127
2128 Pair<Integer, SignalStrengthUpdateRequest> pair =
2129 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2130 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2131 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002132 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002133 request.subId, pair.first /*callingUid*/,
2134 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002135 break;
2136 }
2137 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2138 ar = (AsyncResult) msg.obj;
2139 request = (MainThreadRequest) ar.userObj;
2140 // request.result will be the exception of ar if present, true otherwise.
2141 // Be cautious not to leave result null which will wait() forever
2142 request.result = ar.exception != null ? ar.exception : true;
2143 notifyRequester(request);
2144 break;
2145 }
2146 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2147 request = (MainThreadRequest) msg.obj;
2148
2149 Phone phone = getPhoneFromRequest(request);
2150 if (phone == null || phone.getServiceStateTracker() == null) {
2151 request.result = new IllegalStateException("Phone or SST is null");
2152 notifyRequester(request);
2153 break;
2154 }
2155
2156 Pair<Integer, SignalStrengthUpdateRequest> pair =
2157 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2158 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2159 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002160 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002161 request.subId, pair.first /*callingUid*/,
2162 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002163 break;
2164 }
2165 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2166 ar = (AsyncResult) msg.obj;
2167 request = (MainThreadRequest) ar.userObj;
2168 request.result = ar.exception != null ? ar.exception : true;
2169 notifyRequester(request);
2170 break;
2171 }
Jordan Liu109698e2020-11-24 14:50:34 -08002172
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002173 case CMD_GET_SLICING_CONFIG: {
2174 request = (MainThreadRequest) msg.obj;
2175 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2176 request.phone.getSlicingConfig(onCompleted);
2177 break;
2178 }
2179 case EVENT_GET_SLICING_CONFIG_DONE: {
2180 ar = (AsyncResult) msg.obj;
2181 request = (MainThreadRequest) ar.userObj;
2182 ResultReceiver result = (ResultReceiver) request.argument;
2183
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002184 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002185 Bundle bundle = new Bundle();
2186 int resultCode = 0;
2187 if (ar.exception != null) {
2188 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2189 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002190 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002191 } else if (ar.result == null) {
2192 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002193 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002194 } else {
2195 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002196 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2197 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002198 }
2199
2200 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002201 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002202 }
2203 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2204 result.send(resultCode, bundle);
2205 notifyRequester(request);
2206 break;
2207 }
2208
Sarah Chin71b3a852022-09-28 15:54:19 -07002209 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002210 request = (MainThreadRequest) msg.obj;
2211 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002212 PurchasePremiumCapabilityArgument arg =
2213 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002214 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002215 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002216 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002217 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002218
Sarah Chin71b3a852022-09-28 15:54:19 -07002219 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002220 ar = (AsyncResult) msg.obj;
2221 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002222 PurchasePremiumCapabilityArgument arg =
2223 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002224 try {
2225 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002226 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002227 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002229 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002230 + TelephonyManager.convertPurchaseResultToString(result));
2231 } catch (RemoteException e) {
2232 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 + " failed: " + e;
2235 if (DBG) log(logStr);
2236 AnomalyReporter.reportAnomaly(
2237 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2238 }
2239 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241
Michele Berionne5e411512020-11-13 02:36:59 +00002242 case CMD_PREPARE_UNATTENDED_REBOOT:
2243 request = (MainThreadRequest) msg.obj;
2244 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002245 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002246 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002247 notifyRequester(request);
2248 break;
2249
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 default:
2251 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2252 break;
2253 }
2254 }
Jake Hambye994d462014-02-03 13:10:13 -08002255
Pengquan Menga1bb6272018-09-06 09:59:22 -07002256 private void notifyRequester(MainThreadRequest request) {
2257 synchronized (request) {
2258 request.notifyAll();
2259 }
2260 }
2261
Jake Hambye994d462014-02-03 13:10:13 -08002262 private void handleNullReturnEvent(Message msg, String command) {
2263 AsyncResult ar = (AsyncResult) msg.obj;
2264 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2265 if (ar.exception == null) {
2266 request.result = true;
2267 } else {
2268 request.result = false;
2269 if (ar.exception instanceof CommandException) {
2270 loge(command + ": CommandException: " + ar.exception);
2271 } else {
2272 loge(command + ": Unknown exception");
2273 }
2274 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002275 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
2279 /**
2280 * Posts the specified command to be executed on the main thread,
2281 * waits for the request to complete, and returns the result.
2282 * @see #sendRequestAsync
2283 */
2284 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002285 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2286 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002287 }
2288
2289 /**
2290 * Posts the specified command to be executed on the main thread,
2291 * waits for the request to complete, and returns the result.
2292 * @see #sendRequestAsync
2293 */
2294 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2295 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002296 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002297 }
2298
2299 /**
2300 * Posts the specified command to be executed on the main thread,
2301 * waits for the request to complete, and returns the result.
2302 * @see #sendRequestAsync
2303 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002304 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002305 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2306 }
2307
2308 /**
2309 * Posts the specified command to be executed on the main thread,
2310 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2311 * if not timeout or null otherwise.
2312 * @see #sendRequestAsync
2313 */
2314 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2315 long timeoutInMs) {
2316 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002317 }
2318
2319 /**
2320 * Posts the specified command to be executed on the main thread,
2321 * waits for the request to complete, and returns the result.
2322 * @see #sendRequestAsync
2323 */
Nathan Harold92bed182018-10-12 18:16:49 -07002324 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002325 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002326 }
2327
2328 /**
2329 * Posts the specified command to be executed on the main thread,
2330 * waits for the request to complete, and returns the result.
2331 * @see #sendRequestAsync
2332 */
2333 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002334 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2335 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002336 }
2337
2338 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002339 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2340 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2341 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002342 * @see #sendRequestAsync
2343 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002344 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2345 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2347 throw new RuntimeException("This method will deadlock if called from the main thread.");
2348 }
2349
Nathan Harold92bed182018-10-12 18:16:49 -07002350 MainThreadRequest request = null;
2351 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2352 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2353 } else if (phone != null) {
2354 request = new MainThreadRequest(argument, phone, workSource);
2355 } else {
2356 request = new MainThreadRequest(argument, subId, workSource);
2357 }
2358
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 Message msg = mMainThreadHandler.obtainMessage(command, request);
2360 msg.sendToTarget();
2361
Rambo Wang0f050d82021-02-12 11:43:36 -08002362
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002364 if (timeoutInMs >= 0) {
2365 // Wait for at least timeoutInMs before returning null request result
2366 long now = SystemClock.elapsedRealtime();
2367 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002368 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002369 try {
2370 request.wait(deadline - now);
2371 } catch (InterruptedException e) {
2372 // Do nothing, go back and check if request is completed or timeout
2373 } finally {
2374 now = SystemClock.elapsedRealtime();
2375 }
2376 }
2377 } else {
2378 // Wait for the request to complete
2379 while (request.result == null) {
2380 try {
2381 request.wait();
2382 } catch (InterruptedException e) {
2383 // Do nothing, go back and wait until the request is complete
2384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 }
2386 }
2387 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002388 if (request.result == null) {
2389 Log.wtf(LOG_TAG,
2390 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 return request.result;
2393 }
2394
2395 /**
2396 * Asynchronous ("fire and forget") version of sendRequest():
2397 * Posts the specified command to be executed on the main thread, and
2398 * returns immediately.
2399 * @see #sendRequest
2400 */
2401 private void sendRequestAsync(int command) {
2402 mMainThreadHandler.sendEmptyMessage(command);
2403 }
2404
2405 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002406 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002407 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002408 */
2409 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002410 sendRequestAsync(command, argument, null, null);
2411 }
2412
2413 /**
2414 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2415 * @see {@link #sendRequest(int,Object)}
2416 */
2417 private void sendRequestAsync(
2418 int command, Object argument, Phone phone, WorkSource workSource) {
2419 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002420 Message msg = mMainThreadHandler.obtainMessage(command, request);
2421 msg.sendToTarget();
2422 }
2423
2424 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 * Initialize the singleton PhoneInterfaceManager instance.
2426 * This is only done once, at startup, from PhoneApp.onCreate().
2427 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002428 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 synchronized (PhoneInterfaceManager.class) {
2430 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002431 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 } else {
2433 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2434 }
2435 return sInstance;
2436 }
2437 }
2438
2439 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002440 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002443 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002444 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002445 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2447 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002448 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002449 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002450 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002451 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002452 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002453 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 publish();
arunvoddud7401012022-12-15 16:08:12 +00002455 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 }
2457
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002458 @VisibleForTesting
2459 public SharedPreferences getSharedPreferences() {
2460 return mTelephonySharedPreferences;
2461 }
2462
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002463 /**
2464 * Get the default phone for this device.
2465 */
2466 @VisibleForTesting
2467 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002468 Phone thePhone = getPhone(getDefaultSubscription());
2469 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2470 }
2471
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 private void publish() {
2473 if (DBG) log("publish: " + this);
2474
Peter Wangc035ce42020-01-08 21:00:22 -08002475 TelephonyFrameworkInitializer
2476 .getTelephonyServiceManager()
2477 .getTelephonyServiceRegisterer()
2478 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 }
2480
Stuart Scott584921c2015-01-15 17:10:34 -08002481 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002482 if (request.phone != null) {
2483 return request.phone;
2484 } else {
2485 return getPhoneFromSubId(request.subId);
2486 }
2487 }
2488
2489 private Phone getPhoneFromSubId(int subId) {
2490 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2491 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002492 }
2493
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002494 /**
2495 * Get phone object associated with a subscription.
2496 * Return default phone if phone object associated with subscription is null
2497 * @param subId - subscriptionId
2498 * @return phone object associated with a subscription or default phone if null.
2499 */
Ling Mac28f0212023-03-24 16:07:15 -07002500 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002501 Phone phone = getPhoneFromSubId(subId);
2502 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002503 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002504 phone = getDefaultPhone();
2505 }
2506 return phone;
2507 }
2508
Rambo Wange53e07d2022-05-10 13:01:13 -07002509 @Nullable
2510 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002511 Phone phone = getPhoneFromRequest(request);
2512 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002513 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002514 }
2515
Ling Mac28f0212023-03-24 16:07:15 -07002516 /**
2517 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2518 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2519 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2520 * @return The Phone associated the sub Id
2521 */
2522 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002523 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525
Kai Shif70f46f2021-03-03 13:59:46 -08002526 private void sendEraseModemConfig(@NonNull Phone phone) {
2527 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2528 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2529 }
2530
2531 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2532 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2533 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002534 }
2535
Peter Wang44b186e2020-01-13 23:33:09 -08002536 private boolean isImsAvailableOnDevice() {
2537 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2538 if (pm == null) {
2539 // For some reason package manger is not available.. This will fail internally anyway,
2540 // so do not throw error and allow.
2541 return true;
2542 }
2543 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2544 }
2545
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002547 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002548 }
2549
Wink Savilleb564aae2014-10-23 10:18:09 -07002550 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 if (DBG) log("dial: " + number);
2552 // No permission check needed here: This is just a wrapper around the
2553 // ACTION_DIAL intent, which is available to any app since it puts up
2554 // the UI before it does anything.
2555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 String url = createTelUrl(number);
2559 if (url == null) {
2560 return;
2561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 // PENDING: should we just silently fail if phone is offhook or ringing?
2564 PhoneConstants.State state = mCM.getState(subId);
2565 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2566 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2567 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2568 mApp.startActivity(intent);
2569 }
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573 }
2574
2575 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002576 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002577 }
2578
Wink Savilleb564aae2014-10-23 10:18:09 -07002579 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 if (DBG) log("call: " + number);
2581
2582 // This is just a wrapper around the ACTION_CALL intent, but we still
2583 // need to do a permission check since we're calling startActivity()
2584 // from the context of the phone app.
2585 enforceCallPermission();
2586
Jordan Liu1617b712019-07-10 15:06:26 -07002587 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 != AppOpsManager.MODE_ALLOWED) {
2589 return;
2590 }
2591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 String url = createTelUrl(number);
2595 if (url == null) {
2596 return;
2597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 boolean isValid = false;
2600 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2601 if (slist != null) {
2602 for (SubscriptionInfo subInfoRecord : slist) {
2603 if (subInfoRecord.getSubscriptionId() == subId) {
2604 isValid = true;
2605 break;
2606 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002607 }
Wink Saville08874612014-08-31 19:19:58 -07002608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 if (!isValid) {
2610 return;
2611 }
Wink Saville08874612014-08-31 19:19:58 -07002612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2614 intent.putExtra(SUBSCRIPTION_KEY, subId);
2615 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2616 mApp.startActivity(intent);
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
2619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 }
2621
Wink Savilleb564aae2014-10-23 10:18:09 -07002622 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002623 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002624 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2625 }
2626
Wink Savilleb564aae2014-10-23 10:18:09 -07002627 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002628 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002629 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2630 }
2631
Wink Savilleb564aae2014-10-23 10:18:09 -07002632 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002637 Phone phone = getPhone(subId);
2638 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 checkSimPin.start();
2640 return checkSimPin.unlockSim(null, pin);
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 }
2645
Wink Savilleb564aae2014-10-23 10:18:09 -07002646 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002651 Phone phone = getPhone(subId);
2652 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 checkSimPuk.start();
2654 return checkSimPuk.unlockSim(puk, pin);
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
2660 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002661 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 * a synchronous one.
2663 */
2664 private static class UnlockSim extends Thread {
2665
2666 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002667 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668
2669 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002670 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2671 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672
2673 // For replies from SimCard interface
2674 private Handler mHandler;
2675
2676 // For async handler to identify request type
2677 private static final int SUPPLY_PIN_COMPLETE = 100;
2678
Michele Berionne5e411512020-11-13 02:36:59 +00002679 UnlockSim(int phoneId, IccCard simCard) {
2680 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 mSimCard = simCard;
2682 }
2683
2684 @Override
2685 public void run() {
2686 Looper.prepare();
2687 synchronized (UnlockSim.this) {
2688 mHandler = new Handler() {
2689 @Override
2690 public void handleMessage(Message msg) {
2691 AsyncResult ar = (AsyncResult) msg.obj;
2692 switch (msg.what) {
2693 case SUPPLY_PIN_COMPLETE:
2694 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2695 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002696 mRetryCount = msg.arg1;
2697 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002698 CommandException.Error error = null;
2699 if (ar.exception instanceof CommandException) {
2700 error = ((CommandException) (ar.exception))
2701 .getCommandError();
2702 }
2703 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002704 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002705 } else if (error == CommandException.Error.ABORTED) {
2706 /* When UiccCardApp dispose, handle message and return
2707 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002708 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002709 } else {
2710 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2711 }
2712 } else {
2713 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 mDone = true;
2716 UnlockSim.this.notifyAll();
2717 }
2718 break;
2719 }
2720 }
2721 };
2722 UnlockSim.this.notifyAll();
2723 }
2724 Looper.loop();
2725 }
2726
2727 /*
2728 * Use PIN or PUK to unlock SIM card
2729 *
2730 * If PUK is null, unlock SIM card with PIN
2731 *
2732 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302733 *
2734 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2735 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 */
Wink Saville9de0f752013-10-22 19:04:03 -07002737 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738
2739 while (mHandler == null) {
2740 try {
2741 wait();
2742 } catch (InterruptedException e) {
2743 Thread.currentThread().interrupt();
2744 }
2745 }
2746 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2747
2748 if (puk == null) {
2749 mSimCard.supplyPin(pin, callback);
2750 } else {
2751 mSimCard.supplyPuk(puk, pin, callback);
2752 }
2753
2754 while (!mDone) {
2755 try {
2756 Log.d(LOG_TAG, "wait for done");
2757 wait();
2758 } catch (InterruptedException e) {
2759 // Restore the interrupted status
2760 Thread.currentThread().interrupt();
2761 }
2762 }
2763 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002764 int[] resultArray = new int[2];
2765 resultArray[0] = mResult;
2766 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002767
2768 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002769 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002770 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302771 // This instance is no longer reused, so quit its thread's looper.
2772 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002773
Wink Saville9de0f752013-10-22 19:04:03 -07002774 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 }
2776 }
2777
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002778 /**
2779 * This method has been removed due to privacy and stability concerns.
2780 */
2781 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002783 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2784 return;
Wink Saville36469e72014-06-11 15:17:00 -07002785 }
2786
Nathan Harold1f889d82020-06-04 17:05:26 -07002787 @Override
2788 public void updateServiceLocationWithPackageName(String callingPackage) {
2789 mApp.getSystemService(AppOpsManager.class)
2790 .checkPackage(Binder.getCallingUid(), callingPackage);
2791
Nathan Haroldf096d982020-11-18 17:18:06 -08002792 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002793 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2794 // Callers targeting S have no business invoking this method.
2795 return;
2796 }
2797
2798 LocationAccessPolicy.LocationPermissionResult locationResult =
2799 LocationAccessPolicy.checkLocationPermission(mApp,
2800 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2801 .setCallingPackage(callingPackage)
2802 .setCallingFeatureId(null)
2803 .setCallingPid(Binder.getCallingPid())
2804 .setCallingUid(Binder.getCallingUid())
2805 .setMethod("updateServiceLocation")
2806 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2807 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2808 .build());
2809 // Apps that lack location permission have no business calling this method;
2810 // however, because no permission was declared in the public API, denials must
2811 // all be "soft".
2812 switch (locationResult) {
2813 case DENIED_HARD: /* fall through */
2814 case DENIED_SOFT:
2815 return;
2816 }
2817
2818 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 final long identity = Binder.clearCallingIdentity();
2820 try {
Ling Mac28f0212023-03-24 16:07:15 -07002821 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822 } finally {
2823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 }
2826
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002827 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002828 @Override
2829 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002830 return isRadioOnWithFeature(callingPackage, null);
2831 }
2832
2833
2834 @Override
2835 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2836 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2837 callingFeatureId);
2838 }
2839
2840 @Deprecated
2841 @Override
2842 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2843 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002844 }
2845
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002847 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2848 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002850 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002851 return false;
2852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 return isRadioOnForSubscriber(subId);
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
2859 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002860 }
2861
2862 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 final Phone phone = getPhone(subId);
2866 if (phone != null) {
2867 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2868 } else {
2869 return false;
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 }
2875
2876 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002877 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
Wink Saville36469e72014-06-11 15:17:00 -07002879
Wink Savilleb564aae2014-10-23 10:18:09 -07002880 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 final Phone phone = getPhone(subId);
2886 if (phone != null) {
2887 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2888 }
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002891 }
Wink Saville36469e72014-06-11 15:17:00 -07002892 }
2893
2894 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002895 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002896 }
2897
Wink Savilleb564aae2014-10-23 10:18:09 -07002898 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone == null) {
2905 return false;
2906 }
2907 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2908 toggleRadioOnOffForSubscriber(subId);
2909 }
2910 return true;
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 }
Wink Saville36469e72014-06-11 15:17:00 -07002915
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002916 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002917 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002918 /*
2919 * If any of the Radios are available, it will need to be
2920 * shutdown. So return true if any Radio is available.
2921 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2925 Phone phone = PhoneFactory.getPhone(i);
2926 if (phone != null && phone.isRadioAvailable()) return true;
2927 }
2928 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2929 return false;
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002932 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002933 }
2934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002936 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 enforceModifyPermission();
2938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2942 logv("Shutting down Phone " + i);
2943 shutdownRadioUsingPhoneId(i);
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002947 }
2948 }
2949
2950 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002951 Phone phone = PhoneFactory.getPhone(phoneId);
2952 if (phone != null && phone.isRadioAvailable()) {
2953 phone.shutdownRadio();
2954 }
2955 }
2956
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002958 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959
Ling Ma83dc5ea2023-01-12 15:06:04 -08002960 if (!turnOn) {
2961 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2962 }
2963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2967 if (defaultPhone != null) {
2968 defaultPhone.setRadioPower(turnOn);
2969 return true;
2970 } else {
2971 loge("There's no default phone.");
2972 return false;
2973 }
2974 } finally {
2975 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002976 }
Wink Saville36469e72014-06-11 15:17:00 -07002977 }
2978
Wink Savilleb564aae2014-10-23 10:18:09 -07002979 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981
Ling Ma83dc5ea2023-01-12 15:06:04 -08002982 if (!turnOn) {
2983 log("setRadioPowerForSubscriber off: subId=" + subId
2984 + ",callingPackage=" + getCurrentPackageName());
2985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 final Phone phone = getPhone(subId);
2989 if (phone != null) {
2990 phone.setRadioPower(turnOn);
2991 return true;
2992 } else {
2993 return false;
2994 }
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002998 }
2999
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003000 /**
3001 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3002 * no reason to power it off. When any of the voters want to power it off, it will be turned
3003 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3004 * powering it off, and these radio off votes will be cleared.
3005 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3006 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3007 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3008 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3009 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3010 * check its vote.
3011 *
3012 * @param subId The subscription ID.
3013 * @param reason The reason for powering off radio.
3014 * @return true on success and false on failure.
3015 */
3016 public boolean requestRadioPowerOffForReason(int subId,
3017 @TelephonyManager.RadioPowerReason int reason) {
3018 enforceModifyPermission();
3019
Ling Ma83dc5ea2023-01-12 15:06:04 -08003020 log("requestRadioPowerOffForReason: subId=" + subId
3021 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003022 final long identity = Binder.clearCallingIdentity();
3023 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003024 boolean result = false;
3025 for (Phone phone : PhoneFactory.getPhones()) {
3026 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003027 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003028 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003029 if (!result) {
3030 loge("requestRadioPowerOffForReason: no phone exists");
3031 }
3032 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
3036 }
3037
3038 /**
3039 * Remove the vote on powering off the radio for a reason, as requested by
3040 * {@link requestRadioPowerOffForReason}.
3041 *
3042 * @param subId The subscription ID.
3043 * @param reason The reason for powering off radio.
3044 * @return true on success and false on failure.
3045 */
3046 public boolean clearRadioPowerOffForReason(int subId,
3047 @TelephonyManager.RadioPowerReason int reason) {
3048 enforceModifyPermission();
3049
3050 final long identity = Binder.clearCallingIdentity();
3051 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003052 boolean result = false;
3053 for (Phone phone : PhoneFactory.getPhones()) {
3054 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003055 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003056 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003057 if (!result) {
3058 loge("clearRadioPowerOffForReason: no phone exists");
3059 }
3060 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
3064 }
3065
3066 /**
3067 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3068 *
3069 * @param subId The subscription ID.
3070 * @param callingPackage The package making the call.
3071 * @param callingFeatureId The feature in the package.
3072 * @return List of reasons for powering off radio.
3073 */
3074 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3075 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3076
3077 final long identity = Binder.clearCallingIdentity();
3078 List result = new ArrayList();
3079 try {
3080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3081 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3082 return result;
3083 }
3084
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003085 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003086 if (phone != null) {
3087 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003088 } else {
3089 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003090 }
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
3094 return result;
3095 }
3096
Wink Saville36469e72014-06-11 15:17:00 -07003097 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003098 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003099 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
Jack Yu285100e2022-12-02 22:48:35 -08003104 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 final Phone phone = getPhone(subId);
3106 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003107 phone.getDataSettingsManager().setDataEnabled(
3108 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109 return true;
3110 } else {
3111 return false;
3112 }
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 }
3117
Wink Saville36469e72014-06-11 15:17:00 -07003118 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003119 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003120 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
Jack Yu285100e2022-12-02 22:48:35 -08003125 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126 final Phone phone = getPhone(subId);
3127 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003128 phone.getDataSettingsManager().setDataEnabled(
3129 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130 return true;
3131 } else {
3132 return false;
3133 }
3134 } finally {
3135 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003137 }
3138
Sanket Padawe356d7632015-06-22 14:03:32 -07003139 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003140 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 final Phone phone = getPhone(subId);
3144 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003145 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 } else {
3147 return false;
3148 }
3149 } finally {
3150 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 }
3153
3154 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003155 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003156 }
3157
pkanwarae03a6b2016-11-06 20:37:09 -08003158 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003159 enforceCallPermission();
3160
3161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3164 return;
3165 }
3166 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3167 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
pkanwar32d516d2016-10-14 19:37:38 -07003171 };
3172
Wink Savilleb564aae2014-10-23 10:18:09 -07003173 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175
3176 final long identity = Binder.clearCallingIdentity();
3177 try {
3178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3179 return false;
3180 }
3181 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 }
3186
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003187 /**
3188 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3189 * tag on getCallState Binder call.
3190 */
3191 @Deprecated
3192 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003194 if (CompatChanges.isChangeEnabled(
3195 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3196 Binder.getCallingUid())) {
3197 // Do not allow this API to be called on API version 31+, it should only be
3198 // called on old apps using this Binder call directly.
3199 throw new SecurityException("This method can only be used for applications "
3200 + "targeting API version 30 or less.");
3201 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 final long identity = Binder.clearCallingIdentity();
3203 try {
Ling Mac28f0212023-03-24 16:07:15 -07003204 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3205 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003206 } finally {
3207 Binder.restoreCallingIdentity(identity);
3208 }
3209 }
3210
3211 @Override
3212 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3213 if (CompatChanges.isChangeEnabled(
3214 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3215 Binder.getCallingUid())) {
3216 // Check READ_PHONE_STATE for API version 31+
3217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3218 featureId, "getCallStateForSubscription")) {
3219 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3220 + "targeting API level 31+.");
3221 }
3222 }
3223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3227 PhoneConstantConversions.convertCallState(phone.getState());
3228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003231 }
3232
Sanket Padawe356d7632015-06-22 14:03:32 -07003233 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003234 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003235 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003236 }
3237
3238 @Override
3239 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 final long identity = Binder.clearCallingIdentity();
3241 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003242 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003244 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 } else {
3246 return PhoneConstantConversions.convertDataState(
3247 PhoneConstants.DataState.DISCONNECTED);
3248 }
3249 } finally {
3250 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003252 }
3253
Sanket Padawe356d7632015-06-22 14:03:32 -07003254 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003255 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003256 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003257 }
3258
3259 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003260 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261 final long identity = Binder.clearCallingIdentity();
3262 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003263 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003264 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003265 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266 } else {
3267 return TelephonyManager.DATA_ACTIVITY_NONE;
3268 }
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 }
3273
3274 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003275 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003276 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003277 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003278
3279 LocationAccessPolicy.LocationPermissionResult locationResult =
3280 LocationAccessPolicy.checkLocationPermission(mApp,
3281 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3282 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003283 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003284 .setCallingPid(Binder.getCallingPid())
3285 .setCallingUid(Binder.getCallingUid())
3286 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003287 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003288 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3289 .build());
3290 switch (locationResult) {
3291 case DENIED_HARD:
3292 throw new SecurityException("Not allowed to access cell location");
3293 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003294 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3295 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296 }
3297
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003298 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003302 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003303 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
Svetoslav64fad262015-04-14 14:35:21 -07003307 }
3308
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003309 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003310 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003311 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3312 // registered cell info, so return a NULL country instead.
3313 final long identity = Binder.clearCallingIdentity();
3314 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003315 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3316 // Get default phone in this case.
3317 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3318 }
Jack Yu285100e2022-12-02 22:48:35 -08003319 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003321 if (phone == null) return "";
3322 ServiceStateTracker sst = phone.getServiceStateTracker();
3323 if (sst == null) return "";
3324 LocaleTracker lt = sst.getLocaleTracker();
3325 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003326 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003327 } finally {
3328 Binder.restoreCallingIdentity(identity);
3329 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003330 }
3331
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003332 /**
3333 * This method was removed due to potential issues caused by performing partial
3334 * updates of service state, and lack of a credible use case.
3335 *
3336 * This has the ability to break the telephony implementation by disabling notification of
3337 * changes in device connectivity. DO NOT USE THIS!
3338 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003339 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003340 public void enableLocationUpdates() {
3341 mApp.enforceCallingOrSelfPermission(
3342 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003343 }
3344
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003345 /**
3346 * This method was removed due to potential issues caused by performing partial
3347 * updates of service state, and lack of a credible use case.
3348 *
3349 * This has the ability to break the telephony implementation by disabling notification of
3350 * changes in device connectivity. DO NOT USE THIS!
3351 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 @Override
3353 public void disableLocationUpdates() {
3354 mApp.enforceCallingOrSelfPermission(
3355 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003356 }
3357
3358 @Override
3359 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003360 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3361 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003362 try {
3363 mApp.getSystemService(AppOpsManager.class)
3364 .checkPackage(Binder.getCallingUid(), callingPackage);
3365 } catch (SecurityException e) {
3366 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3367 throw e;
3368 }
3369
Nathan Haroldf096d982020-11-18 17:18:06 -08003370 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003371 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3372 throw new SecurityException(
3373 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3374 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003375
Jordan Liu1617b712019-07-10 15:06:26 -07003376 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003377 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3378 return null;
3379 }
Svetoslav64fad262015-04-14 14:35:21 -07003380
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003381 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003382
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003383 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003384 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003385
Nathan Haroldf180aac2018-06-01 18:43:55 -07003386 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3387 for (CellInfo ci : info) {
3388 if (ci instanceof CellInfoGsm) {
3389 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3390 } else if (ci instanceof CellInfoWcdma) {
3391 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003394 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003395 }
3396
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003397 private List<CellInfo> getCachedCellInfo() {
3398 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3399 for (Phone phone : PhoneFactory.getPhones()) {
3400 List<CellInfo> info = phone.getAllCellInfo();
3401 if (info != null) cellInfos.addAll(info);
3402 }
3403 return cellInfos;
3404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405
3406 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003407 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003408 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003409 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003410
3411 LocationAccessPolicy.LocationPermissionResult locationResult =
3412 LocationAccessPolicy.checkLocationPermission(mApp,
3413 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3414 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003415 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003416 .setCallingPid(Binder.getCallingPid())
3417 .setCallingUid(Binder.getCallingUid())
3418 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003419 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003420 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3421 .build());
3422 switch (locationResult) {
3423 case DENIED_HARD:
3424 throw new SecurityException("Not allowed to access cell info");
3425 case DENIED_SOFT:
3426 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 }
3428
Nathan Haroldf096d982020-11-18 17:18:06 -08003429 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003430 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3431 return getCachedCellInfo();
3432 }
3433
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003434 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003435 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3439 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003440 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003441 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003442 if (info != null) cellInfos.addAll(info);
3443 }
3444 return cellInfos;
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 }
3448 }
3449
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003450 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003451 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3452 String callingFeatureId) {
3453 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3454 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003455 }
3456
3457 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003458 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3459 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003460 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003461 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003462 }
3463
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003464 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3465 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003466 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003467 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003468
3469 LocationAccessPolicy.LocationPermissionResult locationResult =
3470 LocationAccessPolicy.checkLocationPermission(mApp,
3471 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3472 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003473 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003474 .setCallingPid(Binder.getCallingPid())
3475 .setCallingUid(Binder.getCallingUid())
3476 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003477 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3478 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003479 .build());
3480 switch (locationResult) {
3481 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003482 if (TelephonyPermissions
3483 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003484 // Safetynet logging for b/154934934
3485 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3486 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003487 throw new SecurityException("Not allowed to access cell info");
3488 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003489 if (TelephonyPermissions
3490 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003491 // Safetynet logging for b/154934934
3492 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3493 }
Nathan Harold5320c422019-05-09 10:26:08 -07003494 try {
3495 cb.onCellInfo(new ArrayList<CellInfo>());
3496 } catch (RemoteException re) {
3497 // Drop without consequences
3498 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003499 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003500 }
3501
Nathan Harolda939a962019-05-09 10:13:47 -07003502
3503 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003504 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3505
3506 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3507 }
3508
3509 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003510 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003511 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003512 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003513
3514 final long identity = Binder.clearCallingIdentity();
3515 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003516 Phone phone = getPhone(subId);
3517 if (phone == null) {
3518 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3519 } else {
3520 phone.setCellInfoListRate(rateInMillis, workSource);
3521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 }
3526
Shishir Agrawala9f32182016-04-12 12:00:16 -07003527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003528 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003529 Phone phone = PhoneFactory.getPhone(slotIndex);
3530 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 return null;
3532 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003533 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003534 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003535 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003536 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 return null;
3538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539
3540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 return phone.getImei();
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003546 }
3547
3548 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003549 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3550 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3551 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3552 callingFeatureId, "getPrimaryImei")) {
3553 throw new SecurityException("Caller does not have permission");
3554 }
3555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 for (Phone phone : PhoneFactory.getPhones()) {
3558 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3559 return phone.getImei();
3560 }
3561 }
3562 throw new UnsupportedOperationException("Operation not supported");
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
3566 }
3567
3568 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003569 public String getTypeAllocationCodeForSlot(int slotIndex) {
3570 Phone phone = PhoneFactory.getPhone(slotIndex);
3571 String tac = null;
3572 if (phone != null) {
3573 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003574 try {
3575 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3576 } catch (IndexOutOfBoundsException e) {
3577 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3578 return null;
3579 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003580 }
3581 return tac;
3582 }
3583
3584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003585 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003586 try {
3587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3588 } catch (SecurityException se) {
3589 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3590 throw new SecurityException("Package " + callingPackage + " does not belong to "
3591 + Binder.getCallingUid());
3592 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003593 Phone phone = PhoneFactory.getPhone(slotIndex);
3594 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003595 return null;
3596 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003597
Jeff Davidson913390f2018-02-23 17:11:49 -08003598 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003599 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003600 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003601 return null;
3602 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 return phone.getMeid();
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
3609 }
Jack Yu2af8d712017-03-15 17:14:14 -07003610 }
3611
3612 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003613 public String getManufacturerCodeForSlot(int slotIndex) {
3614 Phone phone = PhoneFactory.getPhone(slotIndex);
3615 String manufacturerCode = null;
3616 if (phone != null) {
3617 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003618 try {
3619 manufacturerCode =
3620 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3621 } catch (IndexOutOfBoundsException e) {
3622 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3623 return null;
3624 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003625 }
3626 return manufacturerCode;
3627 }
3628
3629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003630 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3631 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003632 Phone phone = PhoneFactory.getPhone(slotIndex);
3633 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003634 return null;
3635 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003636 int subId = phone.getSubId();
3637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 mApp, subId, callingPackage, callingFeatureId,
3639 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 return null;
3641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642
3643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 return phone.getDeviceSvn();
3646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003649 }
3650
fionaxu43304da2017-11-27 22:51:16 -08003651 @Override
3652 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 final Phone phone = getPhone(subId);
3656 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
fionaxu43304da2017-11-27 22:51:16 -08003660 }
3661
3662 @Override
3663 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 final Phone phone = getPhone(subId);
3667 return phone == null ? null : phone.getCarrierName();
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
fionaxu43304da2017-11-27 22:51:16 -08003671 }
3672
calvinpanffe225e2018-11-01 19:43:06 +08003673 @Override
chen xu0026ca62019-03-06 15:28:50 -08003674 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 final Phone phone = getPhone(subId);
3678 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003679 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
chen xu0026ca62019-03-06 15:28:50 -08003686 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003690 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
3694 }
3695
chen xu651eec72018-11-11 19:03:44 -08003696 @Override
chen xu864e11c2018-12-06 22:10:03 -08003697 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3698 if (!isSubscriptionMccMnc) {
3699 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3700 }
chen xu651eec72018-11-11 19:03:44 -08003701 final Phone phone = PhoneFactory.getPhone(slotIndex);
3702 if (phone == null) {
3703 return TelephonyManager.UNKNOWN_CARRIER_ID;
3704 }
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 }
3712
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003713 //
3714 // Internal helper methods.
3715 //
3716
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003717 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003718 * Make sure the caller is the calling package itself
3719 *
3720 * @throws SecurityException if the caller is not the calling package
3721 */
3722 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3723 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003724 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3725 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003726 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003727 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003728 } catch (PackageManager.NameNotFoundException e) {
3729 // packageUid is -1
3730 }
3731 if (packageUid != callingUid) {
3732 throw new SecurityException(message + ": Package " + callingPackage
3733 + " does not belong to " + callingUid);
3734 }
3735 }
3736
3737 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003738 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3739 *
3740 * @throws SecurityException if the caller does not have the required permission
3741 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003742 @VisibleForTesting
3743 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003744 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3745 }
3746
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003747 /**
arunvoddud7401012022-12-15 16:08:12 +00003748 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003749 *
3750 * @throws SecurityException if the caller does not have the required permission
3751 */
3752 @VisibleForTesting
3753 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003754 enforceReadPermission(null);
3755 }
3756
3757 /**
3758 * Make sure the caller has the READ_PHONE_STATE permissions.
3759 *
3760 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3761 */
3762 @VisibleForTesting
3763 public void enforceReadPermission(String msg) {
3764 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003765 }
3766
Shuo Qian3b6ee772019-11-13 17:43:31 -08003767 private void enforceActiveEmergencySessionPermission() {
3768 mApp.enforceCallingOrSelfPermission(
3769 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3770 }
3771
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003772 /**
3773 * Make sure the caller has the CALL_PHONE permission.
3774 *
3775 * @throws SecurityException if the caller does not have the required permission
3776 */
3777 private void enforceCallPermission() {
3778 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3779 }
3780
paulhu5a773602019-08-23 19:17:33 +08003781 private void enforceSettingsPermission() {
3782 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003783 }
3784
Michele Berionne5e411512020-11-13 02:36:59 +00003785 private void enforceRebootPermission() {
3786 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3787 }
3788
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003789 /**
3790 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3791 * @param message - log message to print.
3792 * @throws SecurityException if the caller does not have the required permission
3793 */
3794 private void enforceSatelliteCommunicationPermission(String message) {
3795 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3796 }
3797
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003798 private String createTelUrl(String number) {
3799 if (TextUtils.isEmpty(number)) {
3800 return null;
3801 }
3802
Jake Hambye994d462014-02-03 13:10:13 -08003803 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003804 }
3805
Ihab Awadf9e92732013-12-05 18:02:52 -08003806 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003807 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003808 }
3809
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003810 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003811 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003812 }
3813
Ihab Awadf9e92732013-12-05 18:02:52 -08003814 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003815 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003818 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003819 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003820 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003821 }
3822
Sanket Padawe356d7632015-06-22 14:03:32 -07003823 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003824 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 final Phone phone = PhoneFactory.getPhone(slotIndex);
3828 if (phone == null) {
3829 return PhoneConstants.PHONE_TYPE_NONE;
3830 } else {
3831 return phone.getPhoneType();
3832 }
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003836 }
3837
3838 /**
3839 * Returns the CDMA ERI icon index to display
3840 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003842 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3843 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3844 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003845 }
3846
Sanket Padawe356d7632015-06-22 14:03:32 -07003847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003848 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3849 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003851 mApp, subId, callingPackage, callingFeatureId,
3852 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003853 return -1;
3854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855
3856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 final Phone phone = getPhone(subId);
3859 if (phone != null) {
3860 return phone.getCdmaEriIconIndex();
3861 } else {
3862 return -1;
3863 }
3864 } finally {
3865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003867 }
3868
3869 /**
3870 * Returns the CDMA ERI icon mode,
3871 * 0 - ON
3872 * 1 - FLASHING
3873 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003874 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003875 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3876 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3877 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003878 }
3879
Sanket Padawe356d7632015-06-22 14:03:32 -07003880 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003881 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3882 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003884 mApp, subId, callingPackage, callingFeatureId,
3885 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003886 return -1;
3887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888
3889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 final Phone phone = getPhone(subId);
3892 if (phone != null) {
3893 return phone.getCdmaEriIconMode();
3894 } else {
3895 return -1;
3896 }
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003900 }
3901
3902 /**
3903 * Returns the CDMA ERI text,
3904 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003905 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003906 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3907 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3908 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003909 }
3910
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003912 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3913 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003915 mApp, subId, callingPackage, callingFeatureId,
3916 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003917 return null;
3918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 final Phone phone = getPhone(subId);
3923 if (phone != null) {
3924 return phone.getCdmaEriText();
3925 } else {
3926 return null;
3927 }
3928 } finally {
3929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003931 }
3932
3933 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003934 * Returns the CDMA MDN.
3935 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003936 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003937 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3939 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940
3941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003944 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 return phone.getLine1Number();
3946 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003947 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948 return null;
3949 }
3950 } finally {
3951 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003952 }
3953 }
3954
3955 /**
3956 * Returns the CDMA MIN.
3957 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003958 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003959 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3961 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003962
3963 final long identity = Binder.clearCallingIdentity();
3964 try {
3965 final Phone phone = getPhone(subId);
3966 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3967 return phone.getCdmaMin();
3968 } else {
3969 return null;
3970 }
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003973 }
3974 }
3975
Hall Liud892bec2018-11-30 14:51:45 -08003976 @Override
3977 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3978 INumberVerificationCallback callback, String callingPackage) {
3979 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3980 != PERMISSION_GRANTED) {
3981 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3982 }
3983 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3984
3985 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3986 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003987 throw new SecurityException("Calling package must be configured in the device config: "
3988 + "calling package: " + callingPackage
3989 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003990 }
3991
3992 if (range == null) {
3993 throw new NullPointerException("Range must be non-null");
3994 }
3995
3996 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003997 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003998
3999 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4000 }
4001
Junda Liuca05d5d2014-08-14 22:36:34 -07004002 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004003 * Returns true if CDMA provisioning needs to run.
4004 */
4005 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004006 final long identity = Binder.clearCallingIdentity();
4007 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004008 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004012 }
4013
4014 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004015 * Sets the voice mail number of a given subId.
4016 */
4017 @Override
4018 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004019 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4020 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4025 new Pair<String, String>(alphaTag, number), new Integer(subId));
4026 return success;
4027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004030 }
4031
Ta-wei Yen87c49842016-05-13 21:19:52 -07004032 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004033 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004035 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4036 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004037 if (!TextUtils.equals(callingPackage, systemDialer)) {
4038 throw new SecurityException("caller must be system dialer");
4039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040
4041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4044 if (phoneAccountHandle == null) {
4045 return null;
4046 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004047 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 } finally {
4049 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004050 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004051 }
4052
4053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004054 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4055 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004058 mApp, subId, callingPackage, callingFeatureId,
4059 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004060 return null;
4061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004063 final long identity = Binder.clearCallingIdentity();
4064 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004065 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004066 } finally {
4067 Binder.restoreCallingIdentity(identity);
4068 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004069 }
4070
4071 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004072 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4073 VisualVoicemailSmsFilterSettings settings) {
4074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075
4076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004079 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004083 }
4084
4085 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004086 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4087 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088
4089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004092 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 } finally {
4094 Binder.restoreCallingIdentity(identity);
4095 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004096 }
4097
4098 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004099 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4100 String callingPackage, int subId) {
4101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102
4103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004106 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 } finally {
4108 Binder.restoreCallingIdentity(identity);
4109 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004110 }
4111
4112 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004113 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115
4116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004119 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 } finally {
4121 Binder.restoreCallingIdentity(identity);
4122 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004123 }
4124
4125 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004126 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4127 String callingAttributionTag, int subId, String number, int port, String text,
4128 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004130 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004131 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004132 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004133 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4134 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004135 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004136
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004137 /**
fionaxu0152e512016-11-14 13:36:14 -08004138 * Sets the voice activation state of a given subId.
4139 */
4140 @Override
4141 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4143 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144
4145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 final Phone phone = getPhone(subId);
4148 if (phone != null) {
4149 phone.setVoiceActivationState(activationState);
4150 } else {
4151 loge("setVoiceActivationState fails with invalid subId: " + subId);
4152 }
4153 } finally {
4154 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004155 }
4156 }
4157
4158 /**
4159 * Sets the data activation state of a given subId.
4160 */
4161 @Override
4162 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4164 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 final Phone phone = getPhone(subId);
4169 if (phone != null) {
4170 phone.setDataActivationState(activationState);
4171 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004172 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173 }
4174 } finally {
4175 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004176 }
4177 }
4178
4179 /**
4180 * Returns the voice activation state of a given subId.
4181 */
4182 @Override
4183 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185
fionaxu0152e512016-11-14 13:36:14 -08004186 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 if (phone != null) {
4190 return phone.getVoiceActivationState();
4191 } else {
4192 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4193 }
4194 } finally {
4195 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004196 }
4197 }
4198
4199 /**
4200 * Returns the data activation state of a given subId.
4201 */
4202 @Override
4203 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205
fionaxu0152e512016-11-14 13:36:14 -08004206 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004207 final long identity = Binder.clearCallingIdentity();
4208 try {
4209 if (phone != null) {
4210 return phone.getDataActivationState();
4211 } else {
4212 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4213 }
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004216 }
4217 }
4218
4219 /**
Wink Saville36469e72014-06-11 15:17:00 -07004220 * Returns the unread count of voicemails for a subId
4221 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004222 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004223 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4224 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004226 mApp, subId, callingPackage, callingFeatureId,
4227 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004228 return 0;
4229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 final Phone phone = getPhone(subId);
4233 if (phone != null) {
4234 return phone.getVoiceMessageCount();
4235 } else {
4236 return 0;
4237 }
4238 } finally {
4239 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004241 }
4242
4243 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004244 * returns true, if the device is in a state where both voice and data
4245 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004246 */
4247 @Override
4248 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 final long identity = Binder.clearCallingIdentity();
4250 try {
Ling Mac28f0212023-03-24 16:07:15 -07004251 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 } finally {
4253 Binder.restoreCallingIdentity(identity);
4254 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004255 }
4256
4257 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004258 * Send the dialer code if called from the current default dialer or the caller has
4259 * carrier privilege.
4260 * @param inputCode The dialer code to send
4261 */
4262 @Override
4263 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004264 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004266 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4267 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004268 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004269 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272
4273 final long identity = Binder.clearCallingIdentity();
4274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004275 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
fionaxu235cc5e2017-03-06 22:25:57 -08004279 }
4280
Pengquan Menga1bb6272018-09-06 09:59:22 -07004281 @Override
4282 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004283 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004284 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4285 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004286 final long identity = Binder.clearCallingIdentity();
4287 try {
4288 if (!isActiveSubscription(subId)) {
4289 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4290 }
4291 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4292 } finally {
4293 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004294 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004295 }
4296
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004298 public boolean isInEmergencySmsMode() {
4299 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 for (Phone phone : PhoneFactory.getPhones()) {
4303 if (phone.isInEmergencySmsMode()) {
4304 return true;
4305 }
4306 }
4307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
4310 return false;
4311 }
4312
shilu366312e2019-12-17 09:28:10 -08004313 /**
4314 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4315 * @param subId The subscription to use to check the configuration.
4316 * @param c The callback that will be used to send the result.
4317 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004318 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004319 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4320 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004321 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004322 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004323
4324 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4325 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4326 "IMS not available on device.");
4327 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 final long token = Binder.clearCallingIdentity();
4329 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004330 int slotId = getSlotIndexOrException(subId);
4331 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004332
4333 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4334 if (controller != null) {
4335 ImsManager imsManager = controller.getImsManager(subId);
4336 if (imsManager != null) {
4337 imsManager.addRegistrationCallbackForSubscription(c, subId);
4338 } else {
4339 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4340 }
4341 } else {
4342 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4343 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004344 } catch (ImsException e) {
4345 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 } finally {
4347 Binder.restoreCallingIdentity(token);
4348 }
4349 }
4350
shilu366312e2019-12-17 09:28:10 -08004351 /**
4352 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4353 * @param subId The subscription to use to check the configuration.
4354 * @param c The callback that will be used to send the result.
4355 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004357 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004358 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004359 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004360 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4361 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4362 }
Meng Wangafbc5852019-09-19 17:37:13 -07004363 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004364
Meng Wangafbc5852019-09-19 17:37:13 -07004365 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004366 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4367 if (controller != null) {
4368 ImsManager imsManager = controller.getImsManager(subId);
4369 if (imsManager != null) {
4370 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4371 } else {
4372 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4373 + "is inactive, ignoring unregister.");
4374 // If the ImsManager is not valid, just return, since the callback
4375 // will already have been removed internally.
4376 }
4377 }
Meng Wangafbc5852019-09-19 17:37:13 -07004378 } finally {
4379 Binder.restoreCallingIdentity(token);
4380 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 }
4382
Brad Ebingera34a6c22019-10-22 17:36:18 -07004383 /**
4384 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4385 */
4386 @Override
4387 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4388 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4389 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4390 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4391 "IMS not available on device.");
4392 }
4393 final long token = Binder.clearCallingIdentity();
4394 try {
4395 Phone phone = getPhone(subId);
4396 if (phone == null) {
4397 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4398 + subId + "'");
4399 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4400 }
4401 phone.getImsRegistrationState(regState -> {
4402 try {
4403 consumer.accept((regState == null)
4404 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4405 } catch (RemoteException e) {
4406 // Ignore if the remote process is no longer available to call back.
4407 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4408 }
4409 });
4410 } finally {
4411 Binder.restoreCallingIdentity(token);
4412 }
4413 }
4414
4415 /**
4416 * Get the transport type for the IMS service registration state.
4417 */
4418 @Override
4419 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004420 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004421 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004422 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4423 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4424 "IMS not available on device.");
4425 }
4426 final long token = Binder.clearCallingIdentity();
4427 try {
4428 Phone phone = getPhone(subId);
4429 if (phone == null) {
4430 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4431 + subId + "'");
4432 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4433 }
4434 phone.getImsRegistrationTech(regTech -> {
4435 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4436 int regTechConverted = (regTech == null)
4437 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4438 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4439 regTechConverted);
4440 try {
4441 consumer.accept(regTechConverted);
4442 } catch (RemoteException e) {
4443 // Ignore if the remote process is no longer available to call back.
4444 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4445 }
4446 });
4447 } finally {
4448 Binder.restoreCallingIdentity(token);
4449 }
4450 }
4451
shilu366312e2019-12-17 09:28:10 -08004452 /**
4453 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4454 * @param subId The subscription to use to check the configuration.
4455 * @param c The callback that will be used to send the result.
4456 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004457 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004458 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4459 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004460 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004461 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004462 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4463 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4464 "IMS not available on device.");
4465 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 final long token = Binder.clearCallingIdentity();
4467 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004468 int slotId = getSlotIndexOrException(subId);
4469 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004470
4471 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4472 if (controller != null) {
4473 ImsManager imsManager = controller.getImsManager(subId);
4474 if (imsManager != null) {
4475 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4476 } else {
4477 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4478 }
4479 } else {
4480 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4481 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 } finally {
4485 Binder.restoreCallingIdentity(token);
4486 }
4487 }
4488
shilu366312e2019-12-17 09:28:10 -08004489 /**
4490 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4491 * @param subId The subscription to use to check the configuration.
4492 * @param c The callback that will be used to send the result.
4493 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004495 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004496 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004497 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004498 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4499 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4500 }
Meng Wangafbc5852019-09-19 17:37:13 -07004501
4502 final long token = Binder.clearCallingIdentity();
4503 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004504 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4505 if (controller != null) {
4506 ImsManager imsManager = controller.getImsManager(subId);
4507 if (imsManager != null) {
4508 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4509 } else {
4510 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4511 + " is inactive, ignoring unregister.");
4512 // If the ImsManager is not valid, just return, since the callback
4513 // will already have been removed internally.
4514 }
4515 }
Meng Wangafbc5852019-09-19 17:37:13 -07004516 } finally {
4517 Binder.restoreCallingIdentity(token);
4518 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004519 }
4520
4521 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004522 public boolean isCapable(int subId, int capability, int regTech) {
4523 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 final long token = Binder.clearCallingIdentity();
4525 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004526 int slotId = getSlotIndexOrException(subId);
4527 verifyImsMmTelConfiguredOrThrow(slotId);
4528 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4529 } catch (com.android.ims.ImsException e) {
4530 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4531 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004532 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004533 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4534 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 } finally {
4536 Binder.restoreCallingIdentity(token);
4537 }
4538 }
4539
4540 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004541 public boolean isAvailable(int subId, int capability, int regTech) {
4542 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 final long token = Binder.clearCallingIdentity();
4544 try {
4545 Phone phone = getPhone(subId);
4546 if (phone == null) return false;
4547 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004548 } catch (com.android.ims.ImsException e) {
4549 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4550 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004551 } finally {
4552 Binder.restoreCallingIdentity(token);
4553 }
4554 }
4555
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004556 /**
4557 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4558 * subscription.
4559 * @param subId The subscription to use to check the configuration.
4560 * @param callback The callback that will be used to send the result.
4561 * @param capability The MmTelFeature capability that will be used to send the result.
4562 * @param transportType The transport type of the MmTelFeature capability.
4563 */
4564 @Override
4565 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4566 int transportType) {
4567 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004568 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4569 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4570 "IMS not available on device.");
4571 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004572 final long token = Binder.clearCallingIdentity();
4573 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004574 int slotId = getSlotIndex(subId);
4575 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4576 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4577 + subId + "'");
4578 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4579 }
4580 verifyImsMmTelConfiguredOrThrow(slotId);
4581 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4582 transportType, aBoolean -> {
4583 try {
4584 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4585 } catch (RemoteException e) {
4586 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4587 + "running. Ignore");
4588 }
4589 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004590 } catch (ImsException e) {
4591 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004592 } finally {
4593 Binder.restoreCallingIdentity(token);
4594 }
4595 }
4596
shilu366312e2019-12-17 09:28:10 -08004597 /**
4598 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4599 * @param subId The subscription to use to check the configuration.
4600 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004601 @Override
4602 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004603 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004604 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004605
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 final long token = Binder.clearCallingIdentity();
4607 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004608 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004609 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004610 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004611 } catch (ImsException e) {
4612 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 } finally {
4614 Binder.restoreCallingIdentity(token);
4615 }
4616 }
4617
4618 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004619 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004621 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004622 final long identity = Binder.clearCallingIdentity();
4623 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004624 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004625 // This setting doesn't require an active ImsService connection, so do not verify. The
4626 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004627 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004628 } catch (ImsException e) {
4629 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 } finally {
4631 Binder.restoreCallingIdentity(identity);
4632 }
4633 }
4634
shilu366312e2019-12-17 09:28:10 -08004635 /**
4636 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4637 * @param subId The subscription to use to check the configuration.
4638 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004639 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004640 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004641 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004642 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004643 final long identity = Binder.clearCallingIdentity();
4644 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004645 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004646 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004647 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004648 } catch (ImsException e) {
4649 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
4653 }
4654
4655 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004656 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004658 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 final long identity = Binder.clearCallingIdentity();
4660 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004661 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004662 // This setting doesn't require an active ImsService connection, so do not verify. The
4663 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004664 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004665 } catch (ImsException e) {
4666 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
4670 }
4671
shilu366312e2019-12-17 09:28:10 -08004672 /**
4673 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4674 * @param subId The subscription to use to check the configuration.
4675 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004676 @Override
4677 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004678 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004679 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004680 final long identity = Binder.clearCallingIdentity();
4681 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004682 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004683 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004684 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004685 } catch (ImsException e) {
4686 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004687 } finally {
4688 Binder.restoreCallingIdentity(identity);
4689 }
4690 }
4691
4692 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004693 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004695 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004696 final long identity = Binder.clearCallingIdentity();
4697 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004698 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004699 // This setting doesn't require an active ImsService connection, so do not verify. The
4700 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004701 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004702 } catch (ImsException e) {
4703 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004704 } finally {
4705 Binder.restoreCallingIdentity(identity);
4706 }
4707 }
4708
shilu366312e2019-12-17 09:28:10 -08004709 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004710 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4711 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4712 * @param subId The subscription to use to check the configuration.
4713 */
4714 @Override
4715 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004716 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004717 mApp, subId, "isCrossSimCallingEnabledByUser");
4718 final long identity = Binder.clearCallingIdentity();
4719 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004720 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004721 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004722 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004723 } catch (ImsException e) {
4724 throw new ServiceSpecificException(e.getCode());
4725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
4730 /**
4731 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4732 * Requires MODIFY_PHONE_STATE permission.
4733 * @param subId The subscription to use to check the configuration.
4734 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4735 * false otherwise
4736 */
4737 @Override
4738 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4740 "setCrossSimCallingEnabled");
4741 final long identity = Binder.clearCallingIdentity();
4742 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004743 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004744 // This setting doesn't require an active ImsService connection, so do not verify. The
4745 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004746 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004747 } catch (ImsException e) {
4748 throw new ServiceSpecificException(e.getCode());
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
4754 /**
shilu366312e2019-12-17 09:28:10 -08004755 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4756 * @param subId The subscription to use to check the configuration.
4757 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004758 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004759
Brad Ebinger35c841c2018-10-01 10:40:55 -07004760 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004761 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004762 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004763 final long identity = Binder.clearCallingIdentity();
4764 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004765 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004766 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004767 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004768 } catch (ImsException e) {
4769 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
4772 }
4773 }
4774
4775 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004776 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004778 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004779 final long identity = Binder.clearCallingIdentity();
4780 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004781 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004782 // This setting doesn't require an active ImsService connection, so do not verify. The
4783 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004784 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004785 } catch (ImsException e) {
4786 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
4790 }
4791
4792 @Override
4793 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4795 "setVoWiFiNonPersistent");
4796 final long identity = Binder.clearCallingIdentity();
4797 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004798 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004799 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004800 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004801 } catch (ImsException e) {
4802 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
4806 }
4807
shilu366312e2019-12-17 09:28:10 -08004808 /**
4809 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4810 * @param subId The subscription to use to check the configuration.
4811 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004812 @Override
4813 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004814 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004815 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004816 final long identity = Binder.clearCallingIdentity();
4817 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004818 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004819 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004820 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004821 } catch (ImsException e) {
4822 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004823 } finally {
4824 Binder.restoreCallingIdentity(identity);
4825 }
4826 }
4827
4828 @Override
4829 public void setVoWiFiModeSetting(int subId, int mode) {
4830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4831 "setVoWiFiModeSetting");
4832 final long identity = Binder.clearCallingIdentity();
4833 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004834 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004835 // This setting doesn't require an active ImsService connection, so do not verify. The
4836 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004837 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004838 } catch (ImsException e) {
4839 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 } finally {
4841 Binder.restoreCallingIdentity(identity);
4842 }
4843 }
4844
4845 @Override
4846 public int getVoWiFiRoamingModeSetting(int subId) {
4847 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4848 final long identity = Binder.clearCallingIdentity();
4849 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004850 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004851 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004852 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004853 } catch (ImsException e) {
4854 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004855 } finally {
4856 Binder.restoreCallingIdentity(identity);
4857 }
4858 }
4859
4860 @Override
4861 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4863 "setVoWiFiRoamingModeSetting");
4864 final long identity = Binder.clearCallingIdentity();
4865 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004866 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004867 // This setting doesn't require an active ImsService connection, so do not verify. The
4868 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004869 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004870 } catch (ImsException e) {
4871 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
4875 }
4876
4877 @Override
4878 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4880 "setRttCapabilityEnabled");
4881 final long identity = Binder.clearCallingIdentity();
4882 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004883 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004884 // This setting doesn't require an active ImsService connection, so do not verify. The
4885 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004886 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004887 } catch (ImsException e) {
4888 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004889 } finally {
4890 Binder.restoreCallingIdentity(identity);
4891 }
4892 }
4893
shilu366312e2019-12-17 09:28:10 -08004894 /**
4895 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4896 * @param subId The subscription to use to check the configuration.
4897 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004898 @Override
4899 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004900 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004901 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 final long identity = Binder.clearCallingIdentity();
4903 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004904 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004905 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004906 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004907 } catch (ImsException e) {
4908 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
4912 }
4913
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004914 @Override
4915 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4916 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004917
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004918 final long identity = Binder.clearCallingIdentity();
4919 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004920 if (!isImsAvailableOnDevice()) {
4921 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4922 "IMS not available on device.");
4923 }
4924 int slotId = getSlotIndexOrException(subId);
4925 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004926
4927 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4928 if (controller != null) {
4929 ImsManager imsManager = controller.getImsManager(subId);
4930 if (imsManager != null) {
4931 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4932 } else {
4933 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4934 }
4935 } else {
4936 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4937 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004938 } catch (ImsException e) {
4939 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
4943 }
4944
4945 @Override
4946 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4947 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004948
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004949 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004950 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4951 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4952 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004953 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004954 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4955 if (controller != null) {
4956 ImsManager imsManager = controller.getImsManager(subId);
4957 if (imsManager != null) {
4958 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4959 } else {
4960 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4961 + " is inactive, ignoring unregister.");
4962 // If the ImsManager is not valid, just return, since the callback will already
4963 // have been removed internally.
4964 }
4965 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
4969 }
4970
joonhunshincffb7fc2021-11-28 07:32:01 +00004971 @Override
4972 public void registerFeatureProvisioningChangedCallback(int subId,
4973 IFeatureProvisioningCallback callback) {
4974 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4975 mApp, subId, "registerFeatureProvisioningChangedCallback");
4976
4977 final long identity = Binder.clearCallingIdentity();
4978 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4979 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4980 }
4981
joonhunshin91bc1952022-04-29 08:47:15 +00004982 try {
4983 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4984 if (controller == null) {
4985 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4986 "Device does not support IMS");
4987 }
4988 controller.addFeatureProvisioningChangedCallback(subId, callback);
4989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004992 }
4993
4994 @Override
4995 public void unregisterFeatureProvisioningChangedCallback(int subId,
4996 IFeatureProvisioningCallback callback) {
4997 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4998 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4999
5000 final long identity = Binder.clearCallingIdentity();
5001 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5002 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5003 }
5004
joonhunshin91bc1952022-04-29 08:47:15 +00005005 try {
5006 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5007 if (controller == null) {
5008 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5009 return;
5010 }
5011 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005015 }
allenwtsu99c623b2020-01-03 18:24:23 +08005016
5017 private void checkModifyPhoneStatePermission(int subId, String message) {
5018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5019 message);
5020 }
5021
allenwtsu99c623b2020-01-03 18:24:23 +08005022 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005023 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005024 boolean isProvisioned) {
5025 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5026
5027 final long identity = Binder.clearCallingIdentity();
5028 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005029 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5030 if (controller == null) {
5031 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5032 return;
5033 }
5034 controller.setRcsProvisioningStatusForCapability(
5035 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
allenwtsu99c623b2020-01-03 18:24:23 +08005039 }
5040
5041
5042 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005043 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5044 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5045 mApp, subId, "getRcsProvisioningStatusForCapability");
5046
allenwtsu99c623b2020-01-03 18:24:23 +08005047 final long identity = Binder.clearCallingIdentity();
5048 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005049 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5050 if (controller == null) {
5051 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5052
5053 // device does not support IMS, this method will return true always.
5054 return true;
5055 }
5056 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005057 } finally {
5058 Binder.restoreCallingIdentity(identity);
5059 }
5060 }
5061
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005062 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005063 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5064 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005065 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005066
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005069 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5070 if (controller == null) {
5071 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5072 return;
5073 }
5074 controller.setImsProvisioningStatusForCapability(
5075 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005076 } finally {
5077 Binder.restoreCallingIdentity(identity);
5078 }
5079 }
5080
5081 @Override
5082 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005083 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5084 mApp, subId, "getProvisioningStatusForCapability");
5085
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005086 final long identity = Binder.clearCallingIdentity();
5087 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005088 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5089 if (controller == null) {
5090 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005091
joonhunshin91bc1952022-04-29 08:47:15 +00005092 // device does not support IMS, this method will return true always.
5093 return true;
5094 }
5095 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005096 } finally {
5097 Binder.restoreCallingIdentity(identity);
5098 }
5099 }
5100
5101 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005102 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5103 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5104 mApp, subId, "isProvisioningRequiredForCapability");
5105
5106 final long identity = Binder.clearCallingIdentity();
5107 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005108 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5109 if (controller == null) {
5110 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5111
5112 // device does not support IMS, this method will return false
5113 return false;
5114 }
5115 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005116 } finally {
5117 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005118 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005119 }
5120
5121 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005122 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5123 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5124 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005125
joonhunshincffb7fc2021-11-28 07:32:01 +00005126 final long identity = Binder.clearCallingIdentity();
5127 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005128 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5129 if (controller == null) {
5130 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5131
5132 // device does not support IMS, this method will return false
5133 return false;
5134 }
5135 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005139 }
5140
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005141 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005142 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005143 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5144 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5145 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005146 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5147 mApp, subId, "getImsProvisioningInt");
5148
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005149 final long identity = Binder.clearCallingIdentity();
5150 try {
5151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005152 int slotId = getSlotIndex(subId);
5153 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5154 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5155 + subId + "' for key:" + key);
5156 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5157 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005158
joonhunshin91bc1952022-04-29 08:47:15 +00005159 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5160 if (controller == null) {
5161 loge("getImsProvisioningInt: Device does not support IMS");
5162
5163 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5164 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5165 }
5166 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005167 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5168 return retVal;
5169 }
5170
calvinpanb5a34062021-02-08 19:59:36 +08005171 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005172 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005173 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5174 + subId + "' for key:" + key);
5175 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
5181 @Override
5182 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005183 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5184 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5185 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005186 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5187 mApp, subId, "getImsProvisioningString");
5188
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005189 final long identity = Binder.clearCallingIdentity();
5190 try {
5191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005192 int slotId = getSlotIndex(subId);
5193 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5194 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5195 + subId + "' for key:" + key);
5196 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5197 }
calvinpanb5a34062021-02-08 19:59:36 +08005198 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005199 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005200 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5201 + subId + "' for key:" + key);
5202 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
5206 }
5207
5208 @Override
5209 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005210 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5211 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5212 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5214 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005215
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005219 int slotId = getSlotIndex(subId);
5220 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5221 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5222 + subId + "' for key:" + key);
5223 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5224 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005225
joonhunshin91bc1952022-04-29 08:47:15 +00005226 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5227 if (controller == null) {
5228 loge("setImsProvisioningInt: Device does not support IMS");
5229
5230 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5231 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5232 }
5233 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005234 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5235 return retVal;
5236 }
5237
calvinpanb5a34062021-02-08 19:59:36 +08005238 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5239 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005240 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005241 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005242 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005243 } finally {
5244 Binder.restoreCallingIdentity(identity);
5245 }
5246 }
5247
5248 @Override
5249 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005250 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5251 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5252 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5254 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005258 int slotId = getSlotIndex(subId);
5259 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5260 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5261 + subId + "' for key:" + key);
5262 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5263 }
calvinpanb5a34062021-02-08 19:59:36 +08005264 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5265 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005266 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005267 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005268 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
5272 }
5273
Brad Ebinger919631e2021-06-02 17:46:35 -07005274 /**
5275 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5276 * for the given slot ID or no ImsResolver instance has been created.
5277 * @param slotId The slot ID that the IMS service is created for.
5278 * @throws ImsException If there is no ImsService configured for this slot.
5279 */
5280 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5281 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5282 ImsFeature.FEATURE_MMTEL)) {
5283 throw new ImsException("This subscription does not support MMTEL over IMS",
5284 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5285 }
5286 }
5287
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005288 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005289 int slotId = SubscriptionManager.getSlotIndex(subId);
5290 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005291 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5292 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005293 }
5294 return slotId;
5295 }
5296
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005297 private int getSlotIndex(int subId) {
5298 int slotId = SubscriptionManager.getSlotIndex(subId);
5299 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5300 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5301 }
5302 return slotId;
5303 }
5304
Wink Saville36469e72014-06-11 15:17:00 -07005305 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005306 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005307 */
5308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005309 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5310 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005311 try {
5312 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5313 } catch (SecurityException se) {
5314 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5315 throw new SecurityException("Package " + callingPackage + " does not belong to "
5316 + Binder.getCallingUid());
5317 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005318 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005319 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005320 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005321 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005322 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005323 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005324 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005325 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5326 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 final long identity = Binder.clearCallingIdentity();
5329 try {
5330 final Phone phone = getPhone(subId);
5331 if (phone != null) {
5332 return phone.getServiceState().getDataNetworkType();
5333 } else {
5334 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5335 }
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005339 }
5340
5341 /**
5342 * Returns the data network type
5343 */
5344 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005345 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005346 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005347 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005348 }
5349
5350 /**
5351 * Returns the data network type for a subId
5352 */
5353 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005354 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5355 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005356 String functionName = "getDataNetworkTypeForSubscriber";
5357 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5358 mApp, functionName)) {
5359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5360 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5361 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5362 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005363 }
5364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 final Phone phone = getPhone(subId);
5368 if (phone != null) {
5369 return phone.getServiceState().getDataNetworkType();
5370 } else {
5371 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5372 }
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005375 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005376 }
5377
5378 /**
Wink Saville36469e72014-06-11 15:17:00 -07005379 * Returns the Voice network type for a subId
5380 */
5381 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005382 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5383 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005384 String functionName = "getVoiceNetworkTypeForSubscriber";
5385 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5386 mApp, functionName)) {
5387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5388 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5389 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5390 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005391 }
5392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 final Phone phone = getPhone(subId);
5396 if (phone != null) {
5397 return phone.getServiceState().getVoiceNetworkType();
5398 } else {
5399 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5400 }
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005404 }
5405
5406 /**
5407 * @return true if a ICC card is present
5408 */
5409 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005410 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005411 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005412 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005413 }
5414
5415 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005416 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005417 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005418 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005419 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005420 final long identity = Binder.clearCallingIdentity();
5421 try {
5422 final Phone phone = PhoneFactory.getPhone(slotIndex);
5423 if (phone != null) {
5424 return phone.getIccCard().hasIccCard();
5425 } else {
5426 return false;
5427 }
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005431 }
5432
5433 /**
5434 * Return if the current radio is LTE on CDMA. This
5435 * is a tri-state return value as for a period of time
5436 * the mode may be unknown.
5437 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005438 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005439 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005440 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005441 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005443 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5444 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5445 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005446 }
5447
Sanket Padawe356d7632015-06-22 14:03:32 -07005448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005449 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5450 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005451 try {
5452 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5453 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005454 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5455 }
5456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 final long identity = Binder.clearCallingIdentity();
5458 try {
5459 final Phone phone = getPhone(subId);
5460 if (phone == null) {
5461 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5462 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005463 return TelephonyProperties.lte_on_cdma_device()
5464 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 }
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005468 }
Wink Saville36469e72014-06-11 15:17:00 -07005469 }
5470
Wink Saville36469e72014-06-11 15:17:00 -07005471 /**
5472 * {@hide}
5473 * Returns Default subId, 0 in the case of single standby.
5474 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005475 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005476 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005477 }
5478
Shishir Agrawala9f32182016-04-12 12:00:16 -07005479 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005480 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005481 }
5482
Wink Savilleb564aae2014-10-23 10:18:09 -07005483 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005484 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005485 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005486
Pengquan Menge92a50d2018-09-21 15:54:48 -07005487 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005488 return getSubscriptionManagerService().isActiveSubId(subId,
5489 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005490 }
5491
Ihab Awadf2177b72013-11-25 13:33:23 -08005492 /**
5493 * @see android.telephony.TelephonyManager.WifiCallingChoices
5494 */
5495 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 final long identity = Binder.clearCallingIdentity();
5497 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005498 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5500 getWhenToMakeWifiCallsDefaultPreference());
5501 } finally {
5502 Binder.restoreCallingIdentity(identity);
5503 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005504 }
5505
5506 /**
5507 * @see android.telephony.TelephonyManager.WifiCallingChoices
5508 */
5509 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005513 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005518 }
5519
Sailesh Nepald1e68152013-12-12 19:08:02 -08005520 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005521 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005522 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005523 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005524
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005525 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5526 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5527 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005528 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005529 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005530 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005531 }
5532 return PhoneFactory.getPhone(phoneId);
5533 }
5534
Shishir Agrawal566b7612013-10-28 14:41:00 -07005535 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005536 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005537 @NonNull IccLogicalChannelRequest request) {
5538 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5539 /*message=*/ "iccOpenLogicalChannel");
5540
5541 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5542 // Verify that the callingPackage in the request belongs to the calling UID
5543 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5544
5545 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005546 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005547
Rambo Wanga1782702021-11-10 20:15:19 -08005548 private Phone getPhoneFromValidIccLogicalChannelRequest(
5549 @NonNull IccLogicalChannelRequest request, String message) {
5550 Phone phone;
5551 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, request.subId, message);
5554 phone = getPhoneFromSubId(request.subId);
5555 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5556 enforceModifyPermission();
5557 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5558 } else {
5559 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005560 }
Rambo Wanga1782702021-11-10 20:15:19 -08005561 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005562 }
5563
5564 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005565 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 final long identity = Binder.clearCallingIdentity();
5567 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005568 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005570 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5571 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005572 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5573 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 loge("The calling package is not allowed to access ISD-R.");
5575 throw new SecurityException(
5576 "The calling package is not allowed to access ISD-R.");
5577 }
Derek Tan740e1672017-06-27 14:56:27 -07005578 }
Derek Tan740e1672017-06-27 14:56:27 -07005579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005581 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5582 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 return response;
5584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005587 }
5588
5589 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005590 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5591 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5592 /*message=*/"iccCloseLogicalChannel");
5593
5594 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5595
5596 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005597 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005598
Rambo Wanga1782702021-11-10 20:15:19 -08005599 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5600 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005601 // before this feature is enabled, this API should only return false if
5602 // the operation fails instead of throwing runtime exception for
5603 // backward-compatibility.
5604 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5605 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 final long identity = Binder.clearCallingIdentity();
5607 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005608 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005609 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 }
Chen Xue9d737e2022-01-01 23:41:31 -08005611 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005612 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005613 Boolean success = false;
5614 if (result instanceof RuntimeException) {
5615 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005616 if (shouldThrowExceptionOnFailure) {
5617 throw (RuntimeException) result;
5618 } else {
5619 return false;
5620 }
Chen Xue9d737e2022-01-01 23:41:31 -08005621 } else if (result instanceof Boolean) {
5622 success = (Boolean) result;
5623 } else {
5624 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5625 }
Rambo Wanga1782702021-11-10 20:15:19 -08005626 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627 return success;
5628 } finally {
5629 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005630 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005631 }
5632
5633 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005634 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005635 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5637 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005638 if (DBG) {
5639 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5640 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5641 + p3 + " data=" + data);
5642 }
5643 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5644 command, p1, p2, p3, data);
5645 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005646
Jordan Liu4c733742019-02-28 12:03:40 -08005647 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005648 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005649 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005650 enforceModifyPermission();
5651 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005652 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005653 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5654 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005655 }
5656 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005657 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5658 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005659 }
5660
5661 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5662 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 final long identity = Binder.clearCallingIdentity();
5664 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005665 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 return "";
5667 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005670 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5671 null /* workSource */);
5672 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 // Append the returned status code to the end of the response payload.
5675 String s = Integer.toHexString(
5676 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5677 if (response.payload != null) {
5678 s = IccUtils.bytesToHexString(response.payload) + s;
5679 }
5680 return s;
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005683 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005684 }
Jake Hambye994d462014-02-03 13:10:13 -08005685
Evan Charltonc66da362014-05-16 14:06:40 -07005686 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005687 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5688 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5690 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005692 if (DBG) {
5693 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5694 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5695 }
5696 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5697 cla, command, p1, p2, p3, data);
5698 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005699
Jordan Liu4c733742019-02-28 12:03:40 -08005700 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005701 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005702 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005703 enforceModifyPermission();
5704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5705 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005706 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005707 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5708 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005709 }
5710
5711 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005712 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5713 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005714 }
5715
5716 // open APDU basic channel assuming the caller has sufficient permissions
5717 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5718 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5722 && TextUtils.equals(ISDR_AID, data)) {
5723 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005724 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5725 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 if (bestComponent == null
5727 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5728 loge("The calling package is not allowed to select ISD-R.");
5729 throw new SecurityException(
5730 "The calling package is not allowed to select ISD-R.");
5731 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005732 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005735 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5736 null /* workSource */);
5737 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 // Append the returned status code to the end of the response payload.
5740 String s = Integer.toHexString(
5741 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5742 if (response.payload != null) {
5743 s = IccUtils.bytesToHexString(response.payload) + s;
5744 }
5745 return s;
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005748 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005749 }
5750
5751 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005752 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005753 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5755 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 if (DBG) {
5760 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5761 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5762 }
5763
5764 IccIoResult response =
5765 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5766 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5767 subId);
5768
5769 if (DBG) {
5770 log("Exchange SIM_IO [R]" + response);
5771 }
5772
5773 byte[] result = null;
5774 int length = 2;
5775 if (response.payload != null) {
5776 length = 2 + response.payload.length;
5777 result = new byte[length];
5778 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5779 } else {
5780 result = new byte[length];
5781 }
5782
5783 result[length - 1] = (byte) response.sw2;
5784 result[length - 2] = (byte) response.sw1;
5785 return result;
5786 } finally {
5787 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005788 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005789 }
5790
Nathan Haroldb3014052017-01-25 15:57:32 -08005791 /**
5792 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5793 * on a particular subscription
5794 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005795 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5796 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005798 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005799 return null;
5800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 if (appType != TelephonyManager.APPTYPE_USIM
5805 && appType != TelephonyManager.APPTYPE_SIM) {
5806 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5807 return null;
5808 }
5809 Object response = sendRequest(
5810 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5811 if (response instanceof String[]) {
5812 return (String[]) response;
5813 }
yincheng zhao2737e882019-09-06 17:06:54 -07005814 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005816 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005819 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005820 }
5821
yincheng zhao2737e882019-09-06 17:06:54 -07005822 /**
5823 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5824 * subscription.
5825 *
5826 * @param subId the id of the subscription.
5827 * @param appType the uicc app type, must be USIM or SIM.
5828 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5829 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005830 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005831 * @return number of fplmns that is successfully written to the SIM.
5832 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005833 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5834 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5836 mApp, subId, "setForbiddenPlmns");
5837
yincheng zhao2737e882019-09-06 17:06:54 -07005838 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5839 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5840 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5841 }
5842 if (fplmns == null) {
5843 throw new IllegalArgumentException("Fplmn List provided is null");
5844 }
5845 for (String fplmn : fplmns) {
5846 if (!CellIdentity.isValidPlmn(fplmn)) {
5847 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5848 }
5849 }
5850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 Object response = sendRequest(
5853 CMD_SET_FORBIDDEN_PLMNS,
5854 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5855 subId);
5856 return (int) response;
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005862 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005863 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5865 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005867 final long identity = Binder.clearCallingIdentity();
5868 try {
5869 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5870 if (response.payload == null) {
5871 return "";
5872 }
Evan Charltonc66da362014-05-16 14:06:40 -07005873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 // Append the returned status code to the end of the response payload.
5875 String s = Integer.toHexString(
5876 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5877 s = IccUtils.bytesToHexString(response.payload) + s;
5878 return s;
5879 } finally {
5880 Binder.restoreCallingIdentity(identity);
5881 }
Evan Charltonc66da362014-05-16 14:06:40 -07005882 }
5883
Jake Hambye994d462014-02-03 13:10:13 -08005884 /**
5885 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5886 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5887 *
5888 * @param itemID the ID of the item to read
5889 * @return the NV item as a String, or null on error.
5890 */
5891 @Override
5892 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005893 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5895 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896
5897 final long identity = Binder.clearCallingIdentity();
5898 try {
5899 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005900 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5902 return value;
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Jake Hambye994d462014-02-03 13:10:13 -08005906 }
5907
5908 /**
5909 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5910 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5911 *
5912 * @param itemID the ID of the item to read
5913 * @param itemValue the value to write, as a String
5914 * @return true on success; false on any failure
5915 */
5916 @Override
5917 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005918 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5920 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921
5922 final long identity = Binder.clearCallingIdentity();
5923 try {
5924 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5925 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005926 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5928 return success;
5929 } finally {
5930 Binder.restoreCallingIdentity(identity);
5931 }
Jake Hambye994d462014-02-03 13:10:13 -08005932 }
5933
5934 /**
5935 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5936 * Used for device configuration by some CDMA operators.
5937 *
5938 * @param preferredRoamingList byte array containing the new PRL
5939 * @return true on success; false on any failure
5940 */
5941 @Override
5942 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5944 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945
5946 final long identity = Binder.clearCallingIdentity();
5947 try {
5948 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5949 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5950 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5951 return success;
5952 } finally {
5953 Binder.restoreCallingIdentity(identity);
5954 }
Jake Hambye994d462014-02-03 13:10:13 -08005955 }
5956
5957 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005958 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005959 * Used for device configuration by some CDMA operators.
5960 *
chen xu6dac5ab2018-10-26 17:39:23 -07005961 * @param slotIndex - device slot.
5962 *
Jake Hambye994d462014-02-03 13:10:13 -08005963 * @return true on success; false on any failure
5964 */
5965 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005966 public boolean resetModemConfig(int slotIndex) {
5967 Phone phone = PhoneFactory.getPhone(slotIndex);
5968 if (phone != null) {
5969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5970 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971
chen xu6dac5ab2018-10-26 17:39:23 -07005972 final long identity = Binder.clearCallingIdentity();
5973 try {
5974 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5975 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5976 return success;
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 }
chen xu6dac5ab2018-10-26 17:39:23 -07005981 return false;
5982 }
5983
5984 /**
5985 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5986 *
5987 * @param slotIndex - device slot.
5988 *
5989 * @return true on success; false on any failure
5990 */
5991 @Override
5992 public boolean rebootModem(int slotIndex) {
5993 Phone phone = PhoneFactory.getPhone(slotIndex);
5994 if (phone != null) {
5995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5996 mApp, phone.getSubId(), "rebootModem");
5997
5998 final long identity = Binder.clearCallingIdentity();
5999 try {
6000 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6001 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6002 return success;
6003 } finally {
6004 Binder.restoreCallingIdentity(identity);
6005 }
6006 }
6007 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006008 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006009
Brad Ebinger51f743a2017-01-23 13:50:20 -08006010 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006011 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6012 * {@link #disableIms(int)}.
6013 * @param slotIndex device slot.
6014 */
6015 public void resetIms(int slotIndex) {
6016 enforceModifyPermission();
6017
6018 final long identity = Binder.clearCallingIdentity();
6019 try {
6020 if (mImsResolver == null) {
6021 // may happen if the does not support IMS.
6022 return;
6023 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006024 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006025 } finally {
6026 Binder.restoreCallingIdentity(identity);
6027 }
6028 }
6029
6030 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006031 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6032 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006033 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006034 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036
6037 final long identity = Binder.clearCallingIdentity();
6038 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006040 // may happen if the device does not support IMS.
6041 return;
6042 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006043 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 } finally {
6045 Binder.restoreCallingIdentity(identity);
6046 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006047 }
6048
6049 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006050 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6051 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006052 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006053 public void disableIms(int slotId) {
6054 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055
6056 final long identity = Binder.clearCallingIdentity();
6057 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006058 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006059 // may happen if the device does not support IMS.
6060 return;
6061 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006062 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 } finally {
6064 Binder.restoreCallingIdentity(identity);
6065 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006066 }
6067
6068 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006069 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6070 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006071 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006072 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006073 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006074 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075
6076 final long identity = Binder.clearCallingIdentity();
6077 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006078 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006079 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6080 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006081 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006082 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 } finally {
6084 Binder.restoreCallingIdentity(identity);
6085 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006086 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006087 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006088 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6089 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006090 @Override
6091 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006092 enforceModifyPermission();
6093
6094 final long identity = Binder.clearCallingIdentity();
6095 try {
6096 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006097 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006098 } finally {
6099 Binder.restoreCallingIdentity(identity);
6100 }
6101 }
6102
6103 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006104 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006105 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006106 */
6107 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6108 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109
6110 final long identity = Binder.clearCallingIdentity();
6111 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006112 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006113 // may happen if the device does not support IMS.
6114 return null;
6115 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006116 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 } finally {
6118 Binder.restoreCallingIdentity(identity);
6119 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006120 }
6121
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006122 /**
6123 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006124 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006125 */
6126 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6127 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128
6129 final long identity = Binder.clearCallingIdentity();
6130 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006131 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006132 // may happen if the device does not support IMS.
6133 return null;
6134 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006135 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006139 }
6140
Brad Ebinger884c07b2018-02-15 16:17:40 -08006141 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006142 * Sets the ImsService Package Name that Telephony will bind to.
6143 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006144 * @param slotIndex the slot ID that the ImsService should bind for.
6145 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006146 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006147 * @param featureTypes An integer array of feature types associated with a packageName.
6148 * @param packageName The name of the package that the current configuration will be replaced
6149 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006150 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006151 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006152 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6153 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006156 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 final long identity = Binder.clearCallingIdentity();
6159 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006160 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006161 // may happen if the device does not support IMS.
6162 return false;
6163 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006164 Map<Integer, String> featureConfig = new HashMap<>();
6165 for (int featureType : featureTypes) {
6166 featureConfig.put(featureType, packageName);
6167 }
6168 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6169 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006173 }
6174
6175 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006176 * Clears any carrier ImsService overrides for the slot index specified that were previously
6177 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6178 *
6179 * This should only be used for testing.
6180 *
6181 * @param slotIndex the slot ID that the ImsService should bind for.
6182 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6183 */
6184 @Override
6185 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006186 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6187 "clearCarrierImsServiceOverride");
6188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006189 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006190
6191 final long identity = Binder.clearCallingIdentity();
6192 try {
6193 if (mImsResolver == null) {
6194 // may happen if the device does not support IMS.
6195 return false;
6196 }
6197 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
6200 }
6201 }
6202
6203 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006204 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006205 *
6206 * @param slotId The slot that the ImsService is associated with.
6207 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6208 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006209 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006210 * @return the package name of the ImsService configuration.
6211 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006212 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6213 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006214 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006215 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6216 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218 final long identity = Binder.clearCallingIdentity();
6219 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006220 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006221 // may happen if the device does not support IMS.
6222 return "";
6223 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006224 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006225 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6226 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 } finally {
6228 Binder.restoreCallingIdentity(identity);
6229 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006230 }
6231
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006232 /**
6233 * Get the MmTelFeature state associated with the requested subscription id.
6234 * @param subId The subscription that the MmTelFeature is associated with.
6235 * @param callback A callback with an integer containing the
6236 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6237 */
6238 @Override
6239 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6240 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6243 "IMS not available on device.");
6244 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006245 final long token = Binder.clearCallingIdentity();
6246 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006247 int slotId = getSlotIndex(subId);
6248 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6249 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6250 + subId + "'");
6251 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6252 }
6253 verifyImsMmTelConfiguredOrThrow(slotId);
6254 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6255 try {
6256 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6257 } catch (RemoteException e) {
6258 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6259 + "Ignore");
6260 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006261 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006262 } catch (ImsException e) {
6263 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006264 } finally {
6265 Binder.restoreCallingIdentity(token);
6266 }
6267 }
6268
Daniel Brightbb5840b2021-01-12 15:48:18 -08006269 /**
6270 * Sets the ims registration state on all valid {@link Phone}s.
6271 */
6272 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274
6275 final long identity = Binder.clearCallingIdentity();
6276 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006277 // NOTE: Before S, this method only set the default phone.
6278 for (final Phone phone : PhoneFactory.getPhones()) {
6279 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6280 phone.setImsRegistrationState(registered);
6281 }
6282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 } finally {
6284 Binder.restoreCallingIdentity(identity);
6285 }
Wink Saville36469e72014-06-11 15:17:00 -07006286 }
6287
6288 /**
Stuart Scott54788802015-03-30 13:18:01 -07006289 * Set the network selection mode to automatic.
6290 *
6291 */
6292 @Override
6293 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6295 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296
6297 final long identity = Binder.clearCallingIdentity();
6298 try {
shilufc958392020-01-20 11:36:01 -08006299 if (!isActiveSubscription(subId)) {
6300 return;
6301 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006303 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6304 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 } finally {
6306 Binder.restoreCallingIdentity(identity);
6307 }
Stuart Scott54788802015-03-30 13:18:01 -07006308 }
6309
Jack Yud10cdd42020-09-28 20:28:01 -07006310 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006311 * Ask the radio to connect to the input network and change selection mode to manual.
6312 *
6313 * @param subId the id of the subscription.
6314 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6315 * the operator to attach to.
6316 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6317 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6318 * normal network selection next time.
6319 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006320 */
6321 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006322 public boolean setNetworkSelectionModeManual(
6323 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6325 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006326
Jack Yu285100e2022-12-02 22:48:35 -08006327 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006328 if (!isActiveSubscription(subId)) {
6329 return false;
6330 }
6331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006333 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006335 if (DBG) {
6336 log("setNetworkSelectionModeManual: subId: " + subId
6337 + " operator: " + operatorInfo);
6338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
6342 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006343 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006344 /**
shilu84f6e8b2019-12-19 13:58:01 -08006345 * Get the manual network selection
6346 *
6347 * @param subId the id of the subscription.
6348 *
6349 * @return the previously saved user selected PLMN
6350 */
6351 @Override
6352 public String getManualNetworkSelectionPlmn(int subId) {
6353 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006354 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6355 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006356
6357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006360 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006361 }
6362
6363 final Phone phone = getPhone(subId);
6364 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006365 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006366 }
6367 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6368 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006369 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
6373 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006374
6375 /**
6376 * Scans for available networks.
6377 */
6378 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006379 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6380 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6382 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006383 LocationAccessPolicy.LocationPermissionResult locationResult =
6384 LocationAccessPolicy.checkLocationPermission(mApp,
6385 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6386 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006387 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006388 .setCallingPid(Binder.getCallingPid())
6389 .setCallingUid(Binder.getCallingUid())
6390 .setMethod("getCellNetworkScanResults")
6391 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006392 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6393 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006394 .build());
6395 switch (locationResult) {
6396 case DENIED_HARD:
6397 throw new SecurityException("Not allowed to access scan results -- location");
6398 case DENIED_SOFT:
6399 return null;
6400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401
Pengquan Menga1bb6272018-09-06 09:59:22 -07006402 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 try {
6404 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006405 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 } finally {
6408 Binder.restoreCallingIdentity(identity);
6409 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006410 }
6411
6412 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006413 * Get the call forwarding info, given the call forwarding reason.
6414 */
6415 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006416 public void getCallForwarding(int subId, int callForwardingReason,
6417 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006418 enforceReadPrivilegedPermission("getCallForwarding");
6419 long identity = Binder.clearCallingIdentity();
6420 try {
6421 if (DBG) {
6422 log("getCallForwarding: subId " + subId
6423 + " callForwardingReason" + callForwardingReason);
6424 }
Hall Liu27d24262020-09-18 19:04:59 -07006425
6426 Phone phone = getPhone(subId);
6427 if (phone == null) {
6428 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006429 callback.onError(
6430 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006431 } catch (RemoteException e) {
6432 // ignore
6433 }
6434 return;
6435 }
6436
6437 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6438 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6439 @Override
6440 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6441 try {
6442 callback.onCallForwardingInfoAvailable(info);
6443 } catch (RemoteException e) {
6444 // ignore
6445 }
6446 }
6447
6448 @Override
6449 public void onError(int error) {
6450 try {
6451 callback.onError(error);
6452 } catch (RemoteException e) {
6453 // ignore
6454 }
6455 }
6456 });
6457 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
6461 }
6462
6463 /**
6464 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6465 * reason, the number to forward, and the timeout before the forwarding is attempted.
6466 */
6467 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006468 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6469 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006470 enforceModifyPermission();
6471 long identity = Binder.clearCallingIdentity();
6472 try {
6473 if (DBG) {
6474 log("setCallForwarding: subId " + subId
6475 + " callForwardingInfo" + callForwardingInfo);
6476 }
Hall Liu27d24262020-09-18 19:04:59 -07006477
6478 Phone phone = getPhone(subId);
6479 if (phone == null) {
6480 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006481 callback.accept(
6482 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006483 } catch (RemoteException e) {
6484 // ignore
6485 }
6486 return;
6487 }
6488
6489 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6490 FunctionalUtils.ignoreRemoteException(callback::accept));
6491
6492 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006493 } finally {
6494 Binder.restoreCallingIdentity(identity);
6495 }
6496 }
6497
6498 /**
Hall Liu27d24262020-09-18 19:04:59 -07006499 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006500 */
6501 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006502 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006503 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006504 long identity = Binder.clearCallingIdentity();
6505 try {
Hall Liu27d24262020-09-18 19:04:59 -07006506 Phone phone = getPhone(subId);
6507 if (phone == null) {
6508 try {
6509 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6510 } catch (RemoteException e) {
6511 // ignore
6512 }
6513 return;
6514 }
SongFerngWang0e767992021-03-31 22:08:45 +08006515 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6516 PersistableBundle c = configManager.getConfigForSubId(subId);
6517 boolean requireUssd = c.getBoolean(
6518 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006519
Shuo Qian4a594052020-01-23 11:59:30 -08006520 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006521 if (requireUssd) {
6522 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6523 getSubscriptionCarrierId(subId));
6524 String newUssdCommand = "";
6525 try {
6526 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006527 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006528 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6529 } catch (NullPointerException e) {
6530 loge("Failed to generate USSD number" + e);
6531 }
6532 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6533 mMainThreadHandler, callback, carrierXmlParser,
6534 CarrierXmlParser.SsEntry.SSAction.QUERY);
6535 final String ussdCommand = newUssdCommand;
6536 Executors.newSingleThreadExecutor().execute(() -> {
6537 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6538 });
6539 } else {
6540 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6541 callback::accept);
6542 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6543 }
Shuo Qian4a594052020-01-23 11:59:30 -08006544 } finally {
6545 Binder.restoreCallingIdentity(identity);
6546 }
6547 }
6548
6549 /**
Hall Liu27d24262020-09-18 19:04:59 -07006550 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006551 */
6552 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006553 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006554 enforceModifyPermission();
6555 long identity = Binder.clearCallingIdentity();
6556 try {
Hall Liu27d24262020-09-18 19:04:59 -07006557 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6558
6559 Phone phone = getPhone(subId);
6560 if (phone == null) {
6561 try {
6562 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6563 } catch (RemoteException e) {
6564 // ignore
6565 }
6566 return;
6567 }
6568
SongFerngWang0e767992021-03-31 22:08:45 +08006569 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6570 PersistableBundle c = configManager.getConfigForSubId(subId);
6571 boolean requireUssd = c.getBoolean(
6572 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006573
SongFerngWang0e767992021-03-31 22:08:45 +08006574 if (DBG) log("getCallWaitingStatus: subId " + subId);
6575 if (requireUssd) {
6576 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6577 getSubscriptionCarrierId(subId));
6578 CarrierXmlParser.SsEntry.SSAction ssAction =
6579 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6580 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6581 String newUssdCommand = "";
6582 try {
6583 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006584 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006585 .makeCommand(ssAction, null);
6586 } catch (NullPointerException e) {
6587 loge("Failed to generate USSD number" + e);
6588 }
6589 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6590 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6591 final String ussdCommand = newUssdCommand;
6592 Executors.newSingleThreadExecutor().execute(() -> {
6593 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6594 });
6595 } else {
6596 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6597 FunctionalUtils.ignoreRemoteException(callback::accept));
6598
6599 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6600 }
Shuo Qian4a594052020-01-23 11:59:30 -08006601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
6604 }
6605
6606 /**
yinxub1bed742017-04-17 11:45:04 -07006607 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006608 *
yinxub1bed742017-04-17 11:45:04 -07006609 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006610 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6611 * location related information which will be sent if the caller already possess
6612 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006613 * @param request contains the radio access networks with bands/channels to scan
6614 * @param messenger callback messenger for scan results or errors
6615 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006616 * @return the id of the requested scan which can be used to stop the scan.
6617 */
6618 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006619 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6620 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006621 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6623 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006624 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006625 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6626 if (!renounceFineLocationAccess) {
6627 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006628 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6629 .setCallingPackage(callingPackage)
6630 .setCallingFeatureId(callingFeatureId)
6631 .setCallingPid(Binder.getCallingPid())
6632 .setCallingUid(Binder.getCallingUid())
6633 .setMethod("requestNetworkScan")
6634 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6635 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6636 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6637 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006638 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006639 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006640 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6641 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006642 if (e != null) {
6643 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6644 throw e;
6645 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006646 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006647 return TelephonyScanManager.INVALID_SCAN_ID;
6648 }
6649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 }
Hall Liu912dfd32019-04-25 14:02:26 -07006651 int callingUid = Binder.getCallingUid();
6652 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006653 final long identity = Binder.clearCallingIdentity();
6654 try {
6655 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006656 renounceFineLocationAccess, request, messenger, binder,
6657 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006658 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006659 } finally {
6660 Binder.restoreCallingIdentity(identity);
6661 }
yinxu504e1392017-04-12 16:03:22 -07006662 }
6663
Hall Liub2ac8ef2019-02-28 15:56:23 -08006664 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006665 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006666 boolean hasCarrierPriv;
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
6669 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6670 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
6673 }
Hall Liu558027f2019-05-15 19:14:05 -07006674 boolean hasNetworkScanPermission =
6675 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006676 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006677
6678 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6679 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6680 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006681 }
6682
6683 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6684 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006685 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6686 return new SecurityException("Specific channels must not be"
6687 + " scanned without location access.");
6688 }
6689 }
6690 }
6691
Hall Liub2ac8ef2019-02-28 15:56:23 -08006692 return null;
6693 }
6694
yinxu504e1392017-04-12 16:03:22 -07006695 /**
6696 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006697 *
6698 * @param subId id of the subscription
6699 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006700 */
6701 @Override
6702 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6704 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705
Hall Liu912dfd32019-04-25 14:02:26 -07006706 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 final long identity = Binder.clearCallingIdentity();
6708 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006709 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 } finally {
6711 Binder.restoreCallingIdentity(identity);
6712 }
yinxu504e1392017-04-12 16:03:22 -07006713 }
6714
6715 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006716 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006717 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006718 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006719 */
6720 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006721 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006722 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006723 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006724 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725
6726 final long identity = Binder.clearCallingIdentity();
6727 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006728 if (DBG) log("getAllowedNetworkTypesBitmask");
6729 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6730 int networkTypesBitmask = (result != null ? result[0] : -1);
6731 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6732 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006736 }
6737
6738 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006739 * Get the allowed network types for certain reason.
6740 *
6741 * @param subId the id of the subscription.
6742 * @param reason the reason the allowed network type change is taking place
6743 * @return the allowed network types.
6744 */
6745 @Override
6746 public long getAllowedNetworkTypesForReason(int subId,
6747 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006748 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006749 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006750 final long identity = Binder.clearCallingIdentity();
6751 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006752 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006753 } finally {
6754 Binder.restoreCallingIdentity(identity);
6755 }
6756 }
6757
6758 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006759 * Enable/Disable E-UTRA-NR Dual Connectivity
6760 * @param subId subscription id of the sim card
6761 * @param nrDualConnectivityState expected NR dual connectivity state
6762 * This can be passed following states
6763 * <ol>
6764 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6765 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6766 * <li>Disable NR dual connectivity and force secondary cell to be released
6767 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6768 * </ol>
6769 * @return operation result.
6770 */
6771 @Override
6772 public int setNrDualConnectivityState(int subId,
6773 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6775 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006776 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006777 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6778 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6779 }
6780
Sooraj Sasindran37444802020-08-11 10:40:43 -07006781 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6782 final long identity = Binder.clearCallingIdentity();
6783 try {
6784 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6785 nrDualConnectivityState, subId,
6786 workSource);
6787 if (DBG) log("enableNRDualConnectivity result: " + result);
6788 return result;
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
6792 }
6793
6794 /**
6795 * Is E-UTRA-NR Dual Connectivity enabled
6796 * @return true if dual connectivity is enabled else false
6797 */
6798 @Override
6799 public boolean isNrDualConnectivityEnabled(int subId) {
6800 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006801 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006802 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006803 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006804 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6805 return false;
6806 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006807 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
6810 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6811 null, subId, workSource);
6812 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6813 return isEnabled;
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
6816 }
6817 }
6818
6819 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006820 * Set the allowed network types of the device and
6821 * provide the reason triggering the allowed network change.
6822 *
6823 * @param subId the id of the subscription.
6824 * @param reason the reason the allowed network type change is taking place
6825 * @param allowedNetworkTypes the allowed network types.
6826 * @return true on success; false on any failure.
6827 */
6828 @Override
6829 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006830 @TelephonyManager.AllowedNetworkTypesReason int reason,
6831 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6833 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006834 // If the caller only has carrier privileges, then they should not be able to override
6835 // any network types which were set for security reasons.
6836 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6837 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006838 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006839 throw new SecurityException(
6840 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006841 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006842 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006843 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006844 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006845 return false;
6846 }
6847 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6848 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006849 return false;
6850 }
6851
Jack Yu5b494332023-01-23 18:18:04 +00006852 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6853 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006854
Jack Yue37dd262022-12-16 11:53:37 -08006855 Phone phone = getPhone(subId);
6856 if (phone == null) {
6857 return false;
6858 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006859
Jack Yue37dd262022-12-16 11:53:37 -08006860 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006861 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006862 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006863 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006864
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006865 final long identity = Binder.clearCallingIdentity();
6866 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006867 Boolean success = (Boolean) sendRequest(
6868 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6869 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6870
6871 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6872 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006873 } finally {
6874 Binder.restoreCallingIdentity(identity);
6875 }
6876 }
6877
6878 /**
Miaoa84611c2019-03-15 09:21:10 +08006879 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006880 *
Miaoa84611c2019-03-15 09:21:10 +08006881 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006882 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006883 * @hide
6884 */
6885 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006886 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006887 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006889 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 try {
Miaoa84611c2019-03-15 09:21:10 +08006891 if (phone != null) {
6892 return phone.hasMatchedTetherApnSetting();
6893 } else {
6894 return false;
6895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 } finally {
6897 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006898 }
Junda Liu475951f2014-11-07 16:45:03 -08006899 }
6900
6901 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006902 * Get the user enabled state of Mobile Data.
6903 *
6904 * TODO: remove and use isUserDataEnabled.
6905 * This can't be removed now because some vendor codes
6906 * calls through ITelephony directly while they should
6907 * use TelephonyManager.
6908 *
6909 * @return true on enabled
6910 */
6911 @Override
6912 public boolean getDataEnabled(int subId) {
6913 return isUserDataEnabled(subId);
6914 }
6915
6916 /**
6917 * Get whether mobile data is enabled per user setting.
6918 *
6919 * There are other factors deciding whether mobile data is actually enabled, but they are
6920 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006921 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006922 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6923 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006924 *
6925 * @return {@code true} if data is enabled else {@code false}
6926 */
6927 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006928 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006929 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006930 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006931 try {
6932 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6933 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006934 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006935 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6936 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006937 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006939 mApp, subId, functionName);
6940
Robert Greenwalt646120a2014-05-23 11:54:03 -07006941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942
6943 final long identity = Binder.clearCallingIdentity();
6944 try {
Jack Yu285100e2022-12-02 22:48:35 -08006945 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6947 Phone phone = PhoneFactory.getPhone(phoneId);
6948 if (phone != null) {
6949 boolean retVal = phone.isUserDataEnabled();
6950 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6951 return retVal;
6952 } else {
6953 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6954 return false;
6955 }
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006958 }
6959 }
6960
6961 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006962 * Checks if the device is capable of mobile data by considering whether whether the
6963 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6964 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006965 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006966 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006967 */
6968 @Override
6969 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006970 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006971 try {
6972 try {
6973 mApp.enforceCallingOrSelfPermission(
6974 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006975 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006976 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006977 try {
6978 mApp.enforceCallingOrSelfPermission(
6979 android.Manifest.permission.READ_PHONE_STATE,
6980 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006981 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006982 mApp.enforceCallingOrSelfPermission(
6983 permission.READ_BASIC_PHONE_STATE, functionName);
6984 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006985 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006986 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006987 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006989
6990 final long identity = Binder.clearCallingIdentity();
6991 try {
Jack Yu285100e2022-12-02 22:48:35 -08006992 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 Phone phone = PhoneFactory.getPhone(phoneId);
6994 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006995 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006996 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 return retVal;
6998 } else {
6999 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7000 return false;
7001 }
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007004 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007005 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007006
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007007 /**
7008 * Check if data is enabled for a specific reason
7009 * @param subId Subscription index
7010 * @param reason the reason the data enable change is taking place
7011 * @return {@code true} if the overall data is enabled; {@code false} if not.
7012 */
7013 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007014 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007015 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007016 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007017 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007018 try {
7019 mApp.enforceCallingOrSelfPermission(
7020 android.Manifest.permission.ACCESS_NETWORK_STATE,
7021 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007022 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007023 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7024 functionName);
7025 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007026 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007027 try {
7028 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007029 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007030 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007032 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007033 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007034 }
7035
7036
7037 final long identity = Binder.clearCallingIdentity();
7038 try {
Jack Yu285100e2022-12-02 22:48:35 -08007039 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007040 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007041 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007042 + " reason=" + reason);
7043 }
7044 Phone phone = PhoneFactory.getPhone(phoneId);
7045 if (phone != null) {
7046 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007047 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007048 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007049 return retVal;
7050 } else {
7051 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007052 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007053 + subId + " retVal=false");
7054 }
7055 return false;
7056 }
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
7059 }
7060 }
7061
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007062 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007063 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007064 // No permission needed; this only lets the caller inspect their own status.
7065 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007066 }
Junda Liu29340342014-07-10 15:23:27 -07007067
7068 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007070 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007071 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7072 }
7073
7074 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7075 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007076 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007077 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007078 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7079 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007080 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7081 if (cpt == null) {
7082 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007083 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7084 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007085 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007086 }
7087
7088 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007089 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007090 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007091 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007092 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007093 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007094 Phone phone = getPhone(subId);
7095 if (phone == null) {
7096 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7097 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7098 }
7099 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7100 if (cpt == null) {
7101 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007102 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7103 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007104 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007105 }
7106
7107 @Override
7108 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007109 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007110 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7111 }
7112
7113 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007114 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007115 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007116 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007117 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007118 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7119 Phone phone = PhoneFactory.getPhone(phoneId);
7120 if (phone == null) {
7121 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007122 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007123 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7124 if (cpt == null) {
7125 continue;
7126 }
7127 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007128 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7129 break;
7130 }
7131 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007132 return result;
Junda Liu29340342014-07-10 15:23:27 -07007133 }
Derek Tan89e89d42014-07-08 17:00:10 -07007134
7135 @Override
Junda Liue64de782015-04-16 17:19:16 -07007136 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007137 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007138 Phone phone = PhoneFactory.getPhone(phoneId);
7139 if (phone == null) {
7140 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007141 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007142 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7143 if (cpt == null) {
7144 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007145 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007146 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007147 }
7148
Amith Yamasani6e118872016-02-19 12:53:51 -08007149 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007150 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007151 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007152 Phone phone = PhoneFactory.getPhone(phoneId);
7153 if (phone == null) {
7154 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007155 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007156 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7157 if (cpt == null) {
7158 return Collections.emptyList();
7159 }
7160 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007161 }
7162
chen xuf7e9fe82019-05-09 19:31:02 -07007163 @Override
7164 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007165 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007166 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007167 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007168 try {
7169 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7170 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7171 }
7172 } finally {
7173 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007174 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007175 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007176 }
7177
Rambo Wang6812ffb2022-03-15 16:54:17 -07007178 @Override
7179 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7180 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7181
7182 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7183 if (phone == null) {
7184 return null;
7185 }
7186 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7187 if (cpt == null) {
7188 return null;
7189 }
7190 return cpt.getCarrierServicePackageName();
7191 }
7192
Wink Savilleb564aae2014-10-23 10:18:09 -07007193 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007194 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007195 UiccPort port = phone == null ? null : phone.getUiccPort();
7196 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007197 return null;
7198 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007199 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007200 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007201 return null;
7202 }
7203 return iccId;
7204 }
7205
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007206 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007207 public void setCallComposerStatus(int subId, int status) {
7208 enforceModifyPermission();
7209
7210 final long identity = Binder.clearCallingIdentity();
7211 try {
7212 Phone phone = getPhone(subId);
7213 if (phone != null) {
7214 Phone defaultPhone = phone.getImsPhone();
7215 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7216 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7217 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007218 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7219 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007220 }
7221 }
Shuo Qian284ae752020-12-22 19:10:14 -08007222 } catch (ImsException e) {
7223 throw new ServiceSpecificException(e.getCode());
7224 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007225 Binder.restoreCallingIdentity(identity);
7226 }
7227 }
7228
7229 @Override
7230 public int getCallComposerStatus(int subId) {
7231 enforceReadPrivilegedPermission("getCallComposerStatus");
7232
7233 final long identity = Binder.clearCallingIdentity();
7234 try {
7235 Phone phone = getPhone(subId);
7236 if (phone != null) {
7237 Phone defaultPhone = phone.getImsPhone();
7238 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7239 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7240 return imsPhone.getCallComposerStatus();
7241 }
7242 }
7243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
7246 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7247 }
7248
7249 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007250 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7251 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007252 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007253 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 final long identity = Binder.clearCallingIdentity();
7256 try {
7257 final String iccId = getIccId(subId);
7258 final Phone phone = getPhone(subId);
7259 if (phone == null) {
7260 return false;
7261 }
7262 final String subscriberId = phone.getSubscriberId();
7263
7264 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007265 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 + subscriberId + " to " + number);
7267 }
7268
7269 if (TextUtils.isEmpty(iccId)) {
7270 return false;
7271 }
7272
7273 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7274
7275 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7276 if (alphaTag == null) {
7277 editor.remove(alphaTagPrefKey);
7278 } else {
7279 editor.putString(alphaTagPrefKey, alphaTag);
7280 }
7281
7282 // Record both the line number and IMSI for this ICCID, since we need to
7283 // track all merged IMSIs based on line number
7284 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7285 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7286 if (number == null) {
7287 editor.remove(numberPrefKey);
7288 editor.remove(subscriberPrefKey);
7289 } else {
7290 editor.putString(numberPrefKey, number);
7291 editor.putString(subscriberPrefKey, subscriberId);
7292 }
7293
7294 editor.commit();
7295 return true;
7296 } finally {
7297 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007298 }
Derek Tan7226c842014-07-02 17:42:23 -07007299 }
7300
7301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007302 public String getLine1NumberForDisplay(int subId, String callingPackage,
7303 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007304 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007306 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007307 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007308 return null;
7309 }
Derek Tan97ebb422014-09-05 16:55:38 -07007310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 String iccId = getIccId(subId);
7314 if (iccId != null) {
7315 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7316 if (DBG_MERGE) {
7317 log("getLine1NumberForDisplay returning "
7318 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7319 }
7320 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7323 return null;
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007326 }
Derek Tan7226c842014-07-02 17:42:23 -07007327 }
7328
7329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007330 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7331 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007333 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007334 return null;
7335 }
Derek Tan97ebb422014-09-05 16:55:38 -07007336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 final long identity = Binder.clearCallingIdentity();
7338 try {
7339 String iccId = getIccId(subId);
7340 if (iccId != null) {
7341 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7342 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7343 }
7344 return null;
7345 } finally {
7346 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007347 }
Derek Tan7226c842014-07-02 17:42:23 -07007348 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007349
7350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007351 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7352 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007353 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7354 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007356 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007357 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007358 return null;
7359 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007360
Jordan Liub49b04b2019-05-06 14:45:15 -07007361 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7362 // the process, where TelephonyManager was instantiated.
7363 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007364 final long identity = Binder.clearCallingIdentity();
7365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007366 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 final TelephonyManager tele = TelephonyManager.from(context);
7368 final SubscriptionManager sub = SubscriptionManager.from(context);
7369
7370 // Figure out what subscribers are currently active
7371 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372
Jordan Liub49b04b2019-05-06 14:45:15 -07007373 // Only consider subs which match the current subId
7374 // This logic can be simplified. See b/131189269 for progress.
7375 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007376 activeSubscriberIds.add(tele.getSubscriberId(subId));
7377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378
7379 // First pass, find a number override for an active subscriber
7380 String mergeNumber = null;
7381 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7382 for (String key : prefs.keySet()) {
7383 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7384 final String subscriberId = (String) prefs.get(key);
7385 if (activeSubscriberIds.contains(subscriberId)) {
7386 final String iccId = key.substring(
7387 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7388 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7389 mergeNumber = (String) prefs.get(numberKey);
7390 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007391 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 + " for active subscriber " + subscriberId);
7393 }
7394 if (!TextUtils.isEmpty(mergeNumber)) {
7395 break;
7396 }
7397 }
7398 }
7399 }
7400
7401 // Shortcut when no active merged subscribers
7402 if (TextUtils.isEmpty(mergeNumber)) {
7403 return null;
7404 }
7405
7406 // Second pass, find all subscribers under that line override
7407 final ArraySet<String> result = new ArraySet<>();
7408 for (String key : prefs.keySet()) {
7409 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7410 final String number = (String) prefs.get(key);
7411 if (mergeNumber.equals(number)) {
7412 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7413 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7414 final String subscriberId = (String) prefs.get(subscriberKey);
7415 if (!TextUtils.isEmpty(subscriberId)) {
7416 result.add(subscriberId);
7417 }
7418 }
7419 }
7420 }
7421
7422 final String[] resultArray = result.toArray(new String[result.size()]);
7423 Arrays.sort(resultArray);
7424 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007425 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7427 }
7428 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007429 } finally {
7430 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007431 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007432 }
7433
7434 @Override
zoey chen38003472019-12-13 17:16:31 +08007435 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7436 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007437
7438 final long identity = Binder.clearCallingIdentity();
7439 try {
7440 final TelephonyManager telephonyManager = mApp.getSystemService(
7441 TelephonyManager.class);
7442 String subscriberId = telephonyManager.getSubscriberId(subId);
7443 if (subscriberId == null) {
7444 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007445 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007446 + subId);
7447 }
7448 return null;
7449 }
7450
Jack Yu3beaf9d2023-04-14 09:17:27 -07007451 final SubscriptionInfo info = getSubscriptionManagerService()
7452 .getSubscriptionInfo(subId);
7453 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007454 // If it doesn't belong to any group, return just subscriberId of itself.
7455 if (groupUuid == null) {
7456 return new String[]{subscriberId};
7457 }
7458
7459 // Get all subscriberIds from the group.
7460 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007461 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7462 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7463 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007464 for (SubscriptionInfo subInfo : groupInfos) {
7465 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7466 if (subscriberId != null) {
7467 mergedSubscriberIds.add(subscriberId);
7468 }
7469 }
7470
7471 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474
7475 }
7476 }
7477
7478 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007479 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007480 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007481 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482
7483 final long identity = Binder.clearCallingIdentity();
7484 try {
7485 final Phone phone = getPhone(subId);
7486 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007490 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007491
7492 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007493 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007494 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7495 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007496 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7497 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498
7499 final long identity = Binder.clearCallingIdentity();
7500 try {
7501 final Phone phone = getPhone(subId);
7502 if (phone == null) {
7503 return false;
7504 }
7505 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7506 cdmaNonRoamingList);
7507 } finally {
7508 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007509 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007510 }
7511
7512 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007513 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007514 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007515 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007516 if (phone == null) {
7517 return raf;
7518 }
7519
Shuo Qiandee53402020-05-29 14:08:15 -07007520 try {
7521 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007522 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007523 mApp, phone.getSubId(), "getRadioAccessFamily");
7524 } catch (SecurityException e) {
7525 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7526 throw e;
7527 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 final long identity = Binder.clearCallingIdentity();
7530 try {
chen xub97461a2018-10-26 14:17:57 -07007531 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
chen xub97461a2018-10-26 14:17:57 -07007535 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007536 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007537
7538 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007539 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007540 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007541 try {
7542 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7543 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007544 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007545 }
7546 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007547 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007548 }
7549 RoleManager rm = mApp.getSystemService(RoleManager.class);
7550 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7551 if (!dialerRoleHolders.contains(callingPackage)) {
7552 throw new SecurityException("App must be the dialer role holder to"
7553 + " upload a call composer pic");
7554 }
7555
7556 Executors.newSingleThreadExecutor().execute(() -> {
7557 ByteArrayOutputStream output = new ByteArrayOutputStream(
7558 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7559 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7560 boolean readUntilEnd = false;
7561 int totalBytesRead = 0;
7562 byte[] buffer = new byte[16 * 1024];
7563 while (true) {
7564 int numRead;
7565 try {
7566 numRead = input.read(buffer);
7567 } catch (IOException e) {
7568 try {
7569 fd.checkError();
7570 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7571 null);
7572 } catch (IOException e1) {
7573 // This means that the other side closed explicitly with an error. If this
7574 // happens, log and ignore.
7575 loge("Remote end of call composer picture pipe closed: " + e1);
7576 }
7577 break;
7578 }
7579 if (numRead == -1) {
7580 readUntilEnd = true;
7581 break;
7582 }
7583 totalBytesRead += numRead;
7584 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7585 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7586 try {
7587 input.close();
7588 } catch (IOException e) {
7589 // ignore
7590 }
7591 break;
7592 }
7593 output.write(buffer, 0, numRead);
7594 }
7595 // Generally, the remote end will close the file descriptors. The only case where we
7596 // close is above, where the picture size is too big.
7597
7598 try {
7599 fd.checkError();
7600 } catch (IOException e) {
7601 loge("Remote end for call composer closed with an error: " + e);
7602 return;
7603 }
7604
Hall Liuaa4211e2021-01-20 15:43:39 -08007605 if (!readUntilEnd) {
7606 loge("Did not finish reading entire image; aborting");
7607 return;
7608 }
Hall Liu82694d52020-12-11 18:22:04 -08007609
Hall Liuaa4211e2021-01-20 15:43:39 -08007610 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7611 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7612 new CallComposerPictureTransfer.Factory() {},
7613 imageData,
7614 (result) -> {
7615 if (result.first != null) {
7616 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7617 Bundle outputResult = new Bundle();
7618 outputResult.putParcelable(
7619 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7620 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7621 outputResult);
7622 } else {
7623 callback.send(result.second, null);
7624 }
7625 }
7626 );
Hall Liu82694d52020-12-11 18:22:04 -08007627 });
7628 }
7629
7630 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007631 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007632 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007633 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634
7635 final long identity = Binder.clearCallingIdentity();
7636 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007637 ImsManager.getInstance(defaultPhone.getContext(),
7638 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639 } finally {
7640 Binder.restoreCallingIdentity(identity);
7641 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007642 }
7643
7644 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007645 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007646 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7648 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007649 return false;
7650 }
Svet Ganovb320e182015-04-16 12:30:10 -07007651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 // Check the user preference and the system-level IMS setting. Even if the user has
7655 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7656 // In the long run, we may instead need to check if there exists a connection service
7657 // which can support video calling.
7658 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007659 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 return imsManager.isVtEnabledByPlatform()
7661 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7662 && imsManager.isVtEnabledByUser();
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007666 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007667
Andrew Leea1239f22015-03-02 17:44:07 -08007668 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007669 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7670 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007672 mApp, subId, callingPackage, callingFeatureId,
7673 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 return false;
7675 }
7676
7677 final long identity = Binder.clearCallingIdentity();
7678 try {
7679 CarrierConfigManager configManager =
7680 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007681 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
Andrew Leea1239f22015-03-02 17:44:07 -08007686 }
7687
7688 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007689 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007691 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 return false;
7693 }
7694
7695 final long identity = Binder.clearCallingIdentity();
7696 try {
7697 CarrierConfigManager configManager =
7698 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007699 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
7703 }
Andrew Leea1239f22015-03-02 17:44:07 -08007704 }
7705
Andrew Lee9431b832015-03-09 18:46:45 -07007706 @Override
7707 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007708 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007709 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007710 }
7711
7712 @Override
7713 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714 final long identity = Binder.clearCallingIdentity();
7715 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007716 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 } finally {
7718 Binder.restoreCallingIdentity(identity);
7719 }
Andrew Lee9431b832015-03-09 18:46:45 -07007720 }
7721
Hall Liuf6668912018-10-31 17:05:23 -07007722 /**
7723 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7724 * support for the feature and device firmware support.
7725 *
7726 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7727 */
7728 @Override
7729 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007731 final Phone phone = getPhone(subscriptionId);
7732 if (phone == null) {
7733 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7734 return false;
7735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007737 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7739 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007740 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 return isCarrierSupported && isDeviceSupported;
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
7744 }
Hall Liu98187582018-01-22 19:15:32 -08007745 }
7746
Hall Liuf6668912018-10-31 17:05:23 -07007747 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007748 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7749 * RTT setting, will return true if the device and carrier both support RTT.
7750 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007751 */
7752 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 final long identity = Binder.clearCallingIdentity();
7754 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007755 boolean isRttSupported = isRttSupported(subscriptionId);
7756 boolean isUserRttSettingOn = Settings.Secure.getInt(
7757 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7758 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7759 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7760 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007764 }
7765
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007766 @Deprecated
7767 @Override
7768 public String getDeviceId(String callingPackage) {
7769 return getDeviceIdWithFeature(callingPackage, null);
7770 }
7771
Sanket Padawe7310cc72015-01-14 09:53:20 -08007772 /**
7773 * Returns the unique device ID of phone, for example, the IMEI for
7774 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7775 *
7776 * <p>Requires Permission:
7777 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7778 */
7779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007780 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007781 try {
7782 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7783 } catch (SecurityException se) {
7784 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7785 throw new SecurityException("Package " + callingPackage + " does not belong to "
7786 + Binder.getCallingUid());
7787 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007788 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007789 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007790 return null;
7791 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007792 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007793 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007794 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007795 return null;
7796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797
7798 final long identity = Binder.clearCallingIdentity();
7799 try {
7800 return phone.getDeviceId();
7801 } finally {
7802 Binder.restoreCallingIdentity(identity);
7803 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007804 }
7805
Ping Sunc67b7c22016-03-02 19:16:45 +08007806 /**
7807 * {@hide}
7808 * Returns the IMS Registration Status on a particular subid
7809 *
7810 * @param subId
7811 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007812 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007813 Phone phone = getPhone(subId);
7814 if (phone != null) {
7815 return phone.isImsRegistered();
7816 } else {
7817 return false;
7818 }
7819 }
7820
Santos Cordon7a1885b2015-02-03 11:15:19 -08007821 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007822 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007825 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007826 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7827 }
7828 final long identity = Binder.clearCallingIdentity();
7829 try {
7830 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7831 } finally {
7832 Binder.restoreCallingIdentity(identity);
7833 }
7834 }
7835
7836 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007837 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007838 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007839 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007840 mApp,
7841 subscriptionId,
7842 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7843 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007844 final long identity = Binder.clearCallingIdentity();
7845 try {
7846 Phone phone = getPhone(subscriptionId);
7847 if (phone == null) {
7848 return null;
7849 }
7850 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
7854 }
7855
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007856 /**
7857 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007858 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007859 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 final long identity = Binder.clearCallingIdentity();
7861 try {
7862 Phone phone = getPhone(subId);
7863 if (phone != null) {
7864 return phone.isWifiCallingEnabled();
7865 } else {
7866 return false;
7867 }
7868 } finally {
7869 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007870 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007871 }
7872
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007873 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007874 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007875 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007876 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877 final long identity = Binder.clearCallingIdentity();
7878 try {
7879 Phone phone = getPhone(subId);
7880 if (phone != null) {
7881 return phone.isVideoEnabled();
7882 } else {
7883 return false;
7884 }
7885 } finally {
7886 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007887 }
7888 }
7889
7890 /**
7891 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7892 * defined in {@link ImsRegistrationImplBase}.
7893 */
7894 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895 final long identity = Binder.clearCallingIdentity();
7896 try {
7897 Phone phone = getPhone(subId);
7898 if (phone != null) {
7899 return phone.getImsRegistrationTech();
7900 } else {
7901 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7902 }
7903 } finally {
7904 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007905 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007906 }
7907
Stuart Scott8eef64f2015-04-08 15:13:54 -07007908 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007909 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007910 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007911 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7912 return;
7913 }
Kai Shif70f46f2021-03-03 13:59:46 -08007914 Phone defaultPhone = getDefaultPhone();
7915 if (defaultPhone != null) {
7916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7917 mApp, getDefaultPhone().getSubId(), "factoryReset");
7918 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007919 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007920
Svet Ganovcc087f82015-05-12 20:35:54 -07007921 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007922 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7923 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007924 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007925 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007926 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007927 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007928 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007929 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007930 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007931 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007932 // There has been issues when Sms raw table somehow stores orphan
7933 // fragments. They lead to garbled message when new fragments come
7934 // in and combined with those stale ones. In case this happens again,
7935 // user can reset all network settings which will clean up this table.
7936 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007937 // Clean up IMS settings as well here.
7938 int slotId = getSlotIndex(subId);
7939 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7940 ImsManager.getInstance(mApp, slotId).factoryReset();
7941 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007942
Kai Shif70f46f2021-03-03 13:59:46 -08007943 if (defaultPhone == null) {
7944 return;
7945 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007946 // Erase modem config if erase modem on network setting is enabled.
7947 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7948 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7949 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007950 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007951 }
Kai Shif70f46f2021-03-03 13:59:46 -08007952
7953 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007954 } finally {
7955 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007956 }
7957 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007958
SongFerngWangfd89b102021-05-27 22:44:54 +08007959 @VisibleForTesting
7960 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7961 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7962 return;
7963 }
7964 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7965 RILConstants.PREFERRED_NETWORK_MODE);
7966 SubscriptionManager.setSubscriptionProperty(subId,
7967 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7968 "user=" + defaultNetworkType);
7969 phone.loadAllowedNetworksFromSubscriptionDatabase();
7970 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7971 defaultNetworkType, null);
7972 }
7973
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007974 private void cleanUpSmsRawTable(Context context) {
7975 ContentResolver resolver = context.getContentResolver();
7976 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7977 resolver.delete(uri, null, null);
7978 }
7979
Narayan Kamath1c496c22015-04-16 14:40:19 +01007980 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007981 public String getSimLocaleForSubscriber(int subId) {
7982 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7983 final Phone phone = getPhone(subId);
7984 if (phone == null) {
7985 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007986 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 final long identity = Binder.clearCallingIdentity();
7989 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07007990 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
7991 phone.getContext().getOpPackageName(),
7992 phone.getContext().getAttributionTag());
7993 if (info == null) {
7994 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7995 return null;
chen xu6291c472019-02-04 12:55:53 -08007996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 // Try and fetch the locale from the carrier properties or from the SIM language
7998 // preferences (EF-PL and EF-LI)...
7999 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008001 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8002 if (localeFromDefaultSim != null) {
8003 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8004 if (DBG) log("Using locale from subId: " + subId + " locale: "
8005 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008006 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008007 } else {
8008 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 }
8010 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 // The SIM language preferences only store a language (e.g. fr = French), not an
8013 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8014 // the SIM and carrier preferences does not include a country we add the country
8015 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008016 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008018 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008019 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 }
8021
8022 if (DBG) log("No locale found - returning null");
8023 return null;
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
8026 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008027 }
8028
tom hsu0b59d292022-09-29 23:49:21 +08008029 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008030 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008031 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008032 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008033 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008034 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8035 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008036 Locale.forLanguageTag(localeTag).getCountry())) {
8037 return localeTag;
8038 }
8039 }
8040 return inputLocale.toLanguageTag();
8041 }
8042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 /**
8044 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8045 */
8046 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008047 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
8048 mApp.getOpPackageName(), mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008049 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008050
Gary Jian3aa9a762022-01-24 16:41:19 +08008051 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8052 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008053
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008054 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008055 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8056 * representing the state of the modem.
8057 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008058 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8059 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008060 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008061 */
8062 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008063 public void requestModemActivityInfo(ResultReceiver result) {
8064 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008065 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066
8067 final long identity = Binder.clearCallingIdentity();
8068 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008069 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 } finally {
8071 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008072 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008073 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008074
Gary Jian76280a42022-12-07 16:18:33 +08008075 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008076 // less than total activity duration.
8077 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8078 if (info == null) {
8079 return false;
8080 }
8081 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008082 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008083 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8084
Hall Liu49656c02020-10-09 19:00:11 -07008085 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8086
Siddharth Rayb8114062018-06-17 15:02:38 -07008087 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008088 && (info.getSleepTimeMillis() <= activityDurationMs)
8089 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008090 }
8091
Gary Jian3aa9a762022-01-24 16:41:19 +08008092 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8093 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8094 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8095 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8096
8097 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8098 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8099 }
8100
8101 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8102 mLastModemActivityInfo.setReceiveTimeMillis(
8103 rat,
8104 freq,
8105 info.getReceiveTimeMillis(rat, freq)
8106 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8107 }
8108
8109 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8110 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8111 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8112 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8113
8114 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8115 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8116 }
8117 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8118 mLastModemActivityInfo.setReceiveTimeMillis(
8119 rat,
8120 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8121 }
8122
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008123 /**
8124 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8125 * @param info recent ModemActivityInfo
8126 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008127 private void mergeModemActivityInfo(ModemActivityInfo info) {
8128 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008129 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008130 boolean matched;
8131 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8132 matched = false;
8133 int rat = info.getSpecificInfoRat(i);
8134 int freq = info.getSpecificInfoFrequencyRange(i);
8135 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8136 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8137 //if it already exists
8138 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8139 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8140 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8141 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8142 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8143 updateLastModemActivityInfo(info, rat, freq);
8144 matched = true;
8145 }
8146 } else {
8147 updateLastModemActivityInfo(info, rat);
8148 matched = true;
8149 }
8150 }
8151 }
8152
8153 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008154 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008155 new ActivityStatsTechSpecificInfo(
8156 rat,
8157 freq,
8158 info.getTransmitTimeMillis(rat, freq),
8159 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008160 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008161 }
8162 }
8163 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8164 mLastModemActivitySpecificInfo =
8165 new ActivityStatsTechSpecificInfo[merged.size()];
8166 merged.toArray(mLastModemActivitySpecificInfo);
8167
8168 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8169 mLastModemActivityInfo.setSleepTimeMillis(
8170 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008171 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008172 mLastModemActivityInfo.setIdleTimeMillis(
8173 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008174 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008175
8176 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008177 new ModemActivityInfo(
8178 mLastModemActivityInfo.getTimestampMillis(),
8179 mLastModemActivityInfo.getSleepTimeMillis(),
8180 mLastModemActivityInfo.getIdleTimeMillis(),
8181 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008182 }
8183
8184 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8185 ActivityStatsTechSpecificInfo[] info) {
8186 int infoSize = info.length;
8187 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8188 for (int i = 0; i < infoSize; i++) {
8189 ret[i] = new ActivityStatsTechSpecificInfo(
8190 info[i].getRat(), info[i].getFrequencyRange(),
8191 info[i].getTransmitTimeMillis(),
8192 (int) info[i].getReceiveTimeMillis());
8193 }
8194 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008195 }
8196
Jack Yu85bd38a2015-11-09 11:34:32 -08008197 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008198 * Returns the service state information on specified subscription.
8199 */
8200 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008201 public ServiceState getServiceStateForSubscriber(int subId,
8202 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8203 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008204 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008205 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008206 return null;
8207 }
8208
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008209 boolean hasFinePermission = false;
8210 boolean hasCoarsePermission = false;
8211 if (!renounceFineLocationAccess) {
8212 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8213 LocationAccessPolicy.checkLocationPermission(mApp,
8214 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8215 .setCallingPackage(callingPackage)
8216 .setCallingFeatureId(callingFeatureId)
8217 .setCallingPid(Binder.getCallingPid())
8218 .setCallingUid(Binder.getCallingUid())
8219 .setMethod("getServiceStateForSubscriber")
8220 .setLogAsInfo(true)
8221 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8222 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8223 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8224 .build());
8225 hasFinePermission =
8226 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8227 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008228
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008229 if (!renounceCoarseLocationAccess) {
8230 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8231 LocationAccessPolicy.checkLocationPermission(mApp,
8232 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8233 .setCallingPackage(callingPackage)
8234 .setCallingFeatureId(callingFeatureId)
8235 .setCallingPid(Binder.getCallingPid())
8236 .setCallingUid(Binder.getCallingUid())
8237 .setMethod("getServiceStateForSubscriber")
8238 .setLogAsInfo(true)
8239 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8240 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8241 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8242 .build());
8243 hasCoarsePermission =
8244 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8245 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008246
Jack Yu479f40e2020-10-27 21:29:25 -07008247 final Phone phone = getPhone(subId);
8248 if (phone == null) {
8249 return null;
8250 }
8251
Jordan Liu0f2bc442020-11-18 16:47:37 -08008252 final long identity = Binder.clearCallingIdentity();
8253
Jack Yu479f40e2020-10-27 21:29:25 -07008254 boolean isCallingPackageDataService = phone.getDataServicePackages()
8255 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008257 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008258 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8259 .getSubscriptionInfoInternal(subId);
8260 if (subInfo == null || !subInfo.isActive()) {
8261 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8262 + "subId=" + subId);
8263 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008264 }
8265
Hall Liuf19c44f2018-11-27 14:38:17 -08008266 ServiceState ss = phone.getServiceState();
8267
8268 // Scrub out the location info in ServiceState depending on what level of access
8269 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008270 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008271 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8272 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 } finally {
8274 Binder.restoreCallingIdentity(identity);
8275 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008276 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008277
8278 /**
8279 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8280 *
8281 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8282 * voicemail ringtone.
8283 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8284 * PhoneAccount.
8285 */
8286 @Override
8287 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 final long identity = Binder.clearCallingIdentity();
8289 try {
8290 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8291 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008292 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008299 }
8300
8301 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008302 * Sets the per-account voicemail ringtone.
8303 *
8304 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8305 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8306 *
8307 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8308 * voicemail ringtone.
8309 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8310 * PhoneAccount.
8311 */
8312 @Override
8313 public void setVoicemailRingtoneUri(String callingPackage,
8314 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008315 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008317 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8318 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8320 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8321 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323
8324 final long identity = Binder.clearCallingIdentity();
8325 try {
8326 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8327 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008328 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 }
8330 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008333 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008334 }
8335
8336 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008337 * Returns whether vibration is set for voicemail notification in Phone settings.
8338 *
8339 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8340 * voicemail vibration setting.
8341 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8342 */
8343 @Override
8344 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 final long identity = Binder.clearCallingIdentity();
8346 try {
8347 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8348 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008349 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008352 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
8355 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008356 }
8357
Youhan Wange64578a2016-05-02 15:32:42 -07008358 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008359 * Sets the per-account voicemail vibration.
8360 *
8361 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8362 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8363 *
8364 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8365 * voicemail vibration setting.
8366 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8367 * specific PhoneAccount.
8368 */
8369 @Override
8370 public void setVoicemailVibrationEnabled(String callingPackage,
8371 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008372 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008374 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8375 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8377 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8378 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008379 }
8380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8384 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008385 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 }
8387 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8388 } finally {
8389 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008390 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008391 }
8392
8393 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008394 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8395 *
8396 * @throws SecurityException if the caller does not have the required permission
8397 */
arunvoddud7401012022-12-15 16:08:12 +00008398 @VisibleForTesting
8399 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008401 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008402 }
8403
8404 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008405 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8406 * permission.
8407 *
8408 * @throws SecurityException if the caller does not have the required permission
8409 */
8410 private void enforceSendSmsPermission() {
8411 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8412 }
8413
8414 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008415 * Make sure either called from same process as self (phone) or IPC caller has interact across
8416 * users permission.
8417 *
8418 * @throws SecurityException if the caller does not have the required permission
8419 */
8420 private void enforceInteractAcrossUsersPermission(String message) {
8421 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8422 }
8423
8424 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008425 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008426 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008427 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008428 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008429 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 final long identity = Binder.clearCallingIdentity();
8431 try {
8432 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008433 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 if (componentName == null) {
8435 throw new SecurityException(
8436 "Caller not current active visual voicemail package[null]");
8437 }
8438 String vvmPackage = componentName.getPackageName();
8439 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008440 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441 }
8442 } finally {
8443 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008444 }
8445 }
8446
8447 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008448 * Return the application ID for the app type.
8449 *
8450 * @param subId the subscription ID that this request applies to.
8451 * @param appType the uicc app type.
8452 * @return Application ID for specificied app type, or null if no uicc.
8453 */
8454 @Override
8455 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008456 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008457 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458
8459 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008460 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 if (phone == null) {
8462 return null;
8463 }
8464 String aid = null;
8465 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008466 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467 .getApplicationByType(appType).getAid();
8468 } catch (Exception e) {
8469 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8470 }
8471 return aid;
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008474 }
Youhan Wange64578a2016-05-02 15:32:42 -07008475 }
8476
Youhan Wang4001d252016-05-11 10:29:41 -07008477 /**
8478 * Return the Electronic Serial Number.
8479 *
8480 * @param subId the subscription ID that this request applies to.
8481 * @return ESN or null if error.
8482 */
8483 @Override
8484 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008485 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008486 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008487
8488 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008489 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 if (phone == null) {
8491 return null;
8492 }
8493 String esn = null;
8494 try {
8495 esn = phone.getEsn();
8496 } catch (Exception e) {
8497 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8498 }
8499 return esn;
8500 } finally {
8501 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008502 }
Youhan Wang4001d252016-05-11 10:29:41 -07008503 }
8504
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008505 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008506 * Return the Preferred Roaming List Version.
8507 *
8508 * @param subId the subscription ID that this request applies to.
8509 * @return PRLVersion or null if error.
8510 */
8511 @Override
8512 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008513 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008514 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008515
8516 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008517 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008518 if (phone == null) {
8519 return null;
8520 }
8521 String cdmaPrlVersion = null;
8522 try {
8523 cdmaPrlVersion = phone.getCdmaPrlVersion();
8524 } catch (Exception e) {
8525 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8526 }
8527 return cdmaPrlVersion;
8528 } finally {
8529 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008530 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008531 }
8532
8533 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008534 * Get snapshot of Telephony histograms
8535 * @return List of Telephony histograms
8536 * @hide
8537 */
8538 @Override
8539 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8541 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 return RIL.getTelephonyRILTimingHistograms();
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008549 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008550
8551 /**
8552 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008553 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8554 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008555 * Require system privileges. In the future we may add this to carrier APIs.
8556 *
Michele Berionne482f8202018-11-27 18:57:59 -08008557 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008558 */
8559 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008560 @TelephonyManager.SetCarrierRestrictionResult
8561 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008562 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008563 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008564
Michele Berionne482f8202018-11-27 18:57:59 -08008565 if (carrierRestrictionRules == null) {
8566 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008567 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569 final long identity = Binder.clearCallingIdentity();
8570 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008571 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008572 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008573 } finally {
8574 Binder.restoreCallingIdentity(identity);
8575 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008576 }
8577
8578 /**
8579 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008580 * Get the allowed carrier list and the excluded carrier list, including the priority between
8581 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008582 * Require system privileges. In the future we may add this to carrier APIs.
8583 *
Michele Berionne482f8202018-11-27 18:57:59 -08008584 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008585 */
8586 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008587 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008588 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008589 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008593 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8594 if (response instanceof CarrierRestrictionRules) {
8595 return (CarrierRestrictionRules) response;
8596 }
8597 // Response is an Exception of some kind,
8598 // which is signalled to the user as a NULL retval
8599 return null;
8600 } catch (Exception e) {
8601 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8602 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 } finally {
8604 Binder.restoreCallingIdentity(identity);
8605 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008606 }
8607
fionaxu59545b42016-05-25 15:53:37 -07008608 /**
arunvoddud7401012022-12-15 16:08:12 +00008609 * Fetches the carrier restriction status of the device and sends the status to the caller
8610 * through the callback.
8611 *
8612 * @param callback The callback that will be used to send the result.
8613 * @throws SecurityException if the caller does not have the required permission/privileges or
8614 * the caller is not allowlisted.
8615 */
8616 @Override
8617 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8618 enforceReadPermission("getCarrierRestrictionStatus");
8619 int carrierId = validateCallerAndGetCarrierId(packageName);
8620 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8621 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8622 throw new SecurityException("Not an authorized caller");
8623 }
8624 final long identity = Binder.clearCallingIdentity();
8625 try {
8626 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8627 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8628 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8629 } finally {
8630 Binder.restoreCallingIdentity(identity);
8631 }
8632 }
8633
arunvoddu567f2b42023-04-25 17:22:00 +00008634 @Override
8635 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8636 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8637 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8638 return allowListInfo.getShaIdList(pkgName, carrierId);
8639 }
8640
arunvoddud7401012022-12-15 16:08:12 +00008641 @VisibleForTesting
8642 public int validateCallerAndGetCarrierId(String packageName) {
8643 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8644 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8645 }
8646
8647 /**
fionaxu59545b42016-05-25 15:53:37 -07008648 * Action set from carrier signalling broadcast receivers to enable/disable radio
8649 * @param subId the subscription ID that this action applies to.
8650 * @param enabled control enable or disable radio.
8651 * {@hide}
8652 */
8653 @Override
8654 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8655 enforceModifyPermission();
8656 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008657
8658 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008659 if (phone == null) {
8660 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8661 return;
8662 }
8663 try {
8664 phone.carrierActionSetRadioEnabled(enabled);
8665 } catch (Exception e) {
8666 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667 } finally {
8668 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008669 }
8670 }
8671
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008672 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008673 * Enable or disable Voice over NR (VoNR)
8674 * @param subId the subscription ID that this action applies to.
8675 * @param enabled enable or disable VoNR.
8676 * @return operation result.
8677 */
8678 @Override
8679 public int setVoNrEnabled(int subId, boolean enabled) {
8680 enforceModifyPermission();
8681 final Phone phone = getPhone(subId);
8682
8683 final long identity = Binder.clearCallingIdentity();
8684 if (phone == null) {
8685 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8686 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8687 }
8688
8689 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8690 try {
8691 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8692 workSource);
8693 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008694
8695 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8696 if (DBG) {
8697 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8698 }
8699 SubscriptionManager.setSubscriptionProperty(
8700 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8701 (enabled ? "1" : "0"));
8702 }
8703
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008704 return result;
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
8708 }
8709
8710 /**
8711 * Is voice over NR enabled
8712 * @return true if VoNR is enabled else false
8713 */
8714 @Override
8715 public boolean isVoNrEnabled(int subId) {
8716 enforceReadPrivilegedPermission("isVoNrEnabled");
8717 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8718 final long identity = Binder.clearCallingIdentity();
8719 try {
8720 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8721 null, subId, workSource);
8722 if (DBG) log("isVoNrEnabled: " + isEnabled);
8723 return isEnabled;
8724 } finally {
8725 Binder.restoreCallingIdentity(identity);
8726 }
8727 }
8728
8729 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008730 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8731 * network status based on which carrier apps could apply actions accordingly,
8732 * enable/disable default url handler for example.
8733 *
8734 * @param subId the subscription ID that this action applies to.
8735 * @param report control start/stop reporting the default network status.
8736 * {@hide}
8737 */
8738 @Override
8739 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8740 enforceModifyPermission();
8741 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008742
8743 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008744 if (phone == null) {
8745 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8746 return;
8747 }
8748 try {
8749 phone.carrierActionReportDefaultNetworkStatus(report);
8750 } catch (Exception e) {
8751 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008752 } finally {
8753 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008754 }
8755 }
8756
8757 /**
fionaxud9622282017-07-17 17:51:30 -07008758 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8759 * @param subId the subscription ID that this action applies to.
8760 * {@hide}
8761 */
8762 @Override
8763 public void carrierActionResetAll(int subId) {
8764 enforceModifyPermission();
8765 final Phone phone = getPhone(subId);
8766 if (phone == null) {
8767 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8768 return;
8769 }
8770 try {
8771 phone.carrierActionResetAll();
8772 } catch (Exception e) {
8773 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8774 }
8775 }
8776
8777 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008778 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8779 * bug report is being generated.
8780 */
8781 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008782 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008783 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8784 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008785 writer.println("Permission Denial: can't dump Phone from pid="
8786 + Binder.getCallingPid()
8787 + ", uid=" + Binder.getCallingUid()
8788 + "without permission "
8789 + android.Manifest.permission.DUMP);
8790 return;
8791 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008792 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008793 }
Jack Yueb89b242016-06-22 13:27:47 -07008794
Brad Ebingerdac2f002018-04-03 15:17:52 -07008795 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008796 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8797 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8798 @NonNull String[] args) {
8799 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8800 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008801 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008802 }
8803
Jack Yueb89b242016-06-22 13:27:47 -07008804 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008805 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008806 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008807 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008808 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008809 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008810 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008811 */
8812 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008813 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008814 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008815 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8816 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8817 try {
8818 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008819 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008820 } catch (SecurityException se) {
8821 enforceModifyPermission();
8822 }
8823 } else {
8824 enforceModifyPermission();
8825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008826
8827 final long identity = Binder.clearCallingIdentity();
8828 try {
8829 Phone phone = getPhone(subId);
8830 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008831 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8832 phone.carrierActionSetMeteredApnsEnabled(enabled);
8833 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008834 phone.getDataSettingsManager().setDataEnabled(
8835 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008837 }
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008840 }
8841 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008842
8843 /**
8844 * Get Client request stats
8845 * @return List of Client Request Stats
8846 * @hide
8847 */
8848 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008849 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8850 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008852 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008853 return null;
8854 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008855 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857 final long identity = Binder.clearCallingIdentity();
8858 try {
8859 if (phone != null) {
8860 return phone.getClientRequestStats();
8861 }
8862
8863 return null;
8864 } finally {
8865 Binder.restoreCallingIdentity(identity);
8866 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008867 }
8868
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008869 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008870 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008871 if (uid == Process.ROOT_UID && packageName == null) {
8872 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8873 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8874 // exception. ROOT_UID seems not to have a valid package name returned by
8875 // PackageManager, so just fake it here to avoid issues when running telephony shell
8876 // commands that plumb through the RIL as root, like so:
8877 // $ adb root
8878 // $ adb shell cmd phone ...
8879 packageName = "root";
8880 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008881 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008882 }
Jack Yueb4124c2017-02-16 15:32:43 -08008883
8884 /**
Grace Chen70990072017-03-24 17:21:30 -07008885 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008886 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008887 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008888 * @param state State of SIM (power down, power up, pass through)
8889 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8890 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8891 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008892 *
8893 **/
8894 @Override
Grace Chen70990072017-03-24 17:21:30 -07008895 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008896 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008897 Phone phone = PhoneFactory.getPhone(slotIndex);
8898
vagdeviaf9a5b92018-08-15 16:01:53 -07008899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008901 final long identity = Binder.clearCallingIdentity();
8902 try {
8903 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008904 phone.setSimPowerState(state, null, workSource);
8905 }
8906 } finally {
8907 Binder.restoreCallingIdentity(identity);
8908 }
8909 }
8910
8911 /**
8912 * Set SIM card power state.
8913 *
8914 * @param slotIndex SIM slot id.
8915 * @param state State of SIM (power down, power up, pass through)
8916 * @param callback callback to trigger after success or failure
8917 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8918 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8919 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8920 *
8921 **/
8922 @Override
8923 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8924 IIntegerConsumer callback) {
8925 enforceModifyPermission();
8926 Phone phone = PhoneFactory.getPhone(slotIndex);
8927
8928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8929
8930 final long identity = Binder.clearCallingIdentity();
8931 try {
8932 if (phone != null) {
8933 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8934 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 }
8936 } finally {
8937 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008938 }
8939 }
Shuo Qiandd210312017-04-12 22:11:33 +00008940
Tyler Gunn65d45c22017-06-05 11:22:26 -07008941 private boolean isUssdApiAllowed(int subId) {
8942 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008943 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008944 if (configManager == null) {
8945 return false;
8946 }
8947 PersistableBundle pb = configManager.getConfigForSubId(subId);
8948 if (pb == null) {
8949 return false;
8950 }
8951 return pb.getBoolean(
8952 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8953 }
8954
Shuo Qiandd210312017-04-12 22:11:33 +00008955 /**
Ling Mac28f0212023-03-24 16:07:15 -07008956 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008957 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008958 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008959 */
goneil9c5f4872017-12-05 14:07:56 -08008960 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008961 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008962 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008963 final long identity = Binder.clearCallingIdentity();
8964 try {
Ling Mac28f0212023-03-24 16:07:15 -07008965 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008966 } finally {
8967 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008968 }
8969 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008970
8971 /**
8972 * Get the current signal strength information for the given subscription.
8973 * Because this information is not updated when the device is in a low power state
8974 * it should not be relied-upon to be current.
8975 * @param subId Subscription index
8976 * @return the most recent cached signal strength info from the modem
8977 */
8978 @Override
8979 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 final long identity = Binder.clearCallingIdentity();
8981 try {
8982 Phone p = getPhone(subId);
8983 if (p == null) {
8984 return null;
8985 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 return p.getSignalStrength();
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
8990 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008991 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008992
Pengquan Meng77b7f132018-08-22 14:49:57 -07008993 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008994 * Get the current modem radio state for the given slot.
8995 * @param slotIndex slot index.
8996 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008997 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008998 * @return the current radio power state from the modem
8999 */
9000 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009001 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009002 Phone phone = PhoneFactory.getPhone(slotIndex);
9003 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9005 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009006 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9007 }
9008
9009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 return phone.getRadioPowerState();
9012 } finally {
9013 Binder.restoreCallingIdentity(identity);
9014 }
9015 }
9016 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9017 }
9018
9019 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009020 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9021 *
9022 * <p>Requires one of the following permissions:
9023 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009024 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009025 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9026 * privileges.
9027 *
9028 * @param subId subscription id
9029 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9030 * {@code false}.
9031 */
9032 @Override
9033 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009034 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009035 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009036 try {
9037 mApp.enforceCallingOrSelfPermission(
9038 android.Manifest.permission.ACCESS_NETWORK_STATE,
9039 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009040 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009041 mApp.enforceCallingOrSelfPermission(
9042 permission.READ_BASIC_PHONE_STATE, functionName);
9043 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009044 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009045 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009046 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009047 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009048
Pengquan Menga1bb6272018-09-06 09:59:22 -07009049 boolean isEnabled = false;
9050 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009051 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009052 Phone phone = getPhone(subId);
9053 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009054 } finally {
9055 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009056 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009057 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009058 }
9059
9060
9061 /**
9062 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9063 *
9064 * <p> Requires permission:
9065 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9066 * privileges.
9067 *
9068 * @param subId subscription id
9069 * @param isEnabled {@code true} means enable, {@code false} means disable.
9070 */
9071 @Override
9072 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9074 mApp, subId, "setDataRoamingEnabled");
9075
Pengquan Menga1bb6272018-09-06 09:59:22 -07009076 final long identity = Binder.clearCallingIdentity();
9077 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009078 Phone phone = getPhone(subId);
9079 if (phone != null) {
9080 phone.setDataRoamingEnabled(isEnabled);
9081 }
9082 } finally {
9083 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009084 }
9085 }
9086
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009087 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009088 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009089 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009090 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009091 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009092
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009093 boolean isAllowed = true;
9094 final long identity = Binder.clearCallingIdentity();
9095 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009096 Phone phone = getPhone(subId);
9097 if (phone != null) {
9098 isAllowed = phone.isCspPlmnEnabled();
9099 }
9100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
9103 return isAllowed;
9104 }
9105
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009106 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9107 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009108 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009109 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009110 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009111 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9112 if (phone == null) {
9113 return false;
9114 }
9115 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9116 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9117 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009118 }
9119
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009120 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009121 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009122 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009123 mApp.getSystemService(AppOpsManager.class)
9124 .checkPackage(Binder.getCallingUid(), callingPackage);
9125
Jordan Liu1e142fc2019-04-22 15:10:43 -07009126 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009127 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009128 try {
9129 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009130 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009131 } catch (SecurityException e) {
9132 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9133 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009134 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009135 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009136 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009137 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009138 }
sandeepjsb6c87872021-09-27 15:34:44 +00009139 // checking compatibility, if calling app's target SDK is T and beyond.
9140 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9141 Binder.getCallingUid())) {
9142 isIccIdAccessRestricted = true;
9143 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009144 final long identity = Binder.clearCallingIdentity();
9145 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009146 UiccController uiccController = UiccController.getInstance();
9147 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009148 if (hasReadPermission) {
9149 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009150 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009151
9152 // Remove private info if the caller doesn't have access
9153 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9154 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009155 //setting the value after compatibility check
9156 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009157 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9158 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009159 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009160 if (card == null) {
9161 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009162 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009163 continue;
9164 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009165 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9166 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009167 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009168 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009169 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009170 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9171 for (UiccPortInfo portInfo : portInfos) {
9172 UiccPort port = uiccController.getUiccPortForSlot(
9173 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9174 if (port == null) {
9175 // assume no access if port is null
9176 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9177 continue;
9178 }
9179 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9180 uiccPortInfos.add(portInfo);
9181 } else {
9182 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9183 }
9184 }
9185 filteredInfos.add(new UiccCardInfo(
9186 cardInfo.isEuicc(),
9187 cardInfo.getCardId(),
9188 null,
9189 cardInfo.getPhysicalSlotIndex(),
9190 cardInfo.isRemovable(),
9191 cardInfo.isMultipleEnabledProfilesSupported(),
9192 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009193 }
9194 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
sandeepjsb6c87872021-09-27 15:34:44 +00009200 /**
9201 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9202 * generally private and require carrier privileges to view.
9203 *
9204 * @hide
9205 */
9206 @NonNull
9207 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9208 List<UiccPortInfo> portinfo = new ArrayList<>();
9209 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9210 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9211 }
9212 return new UiccCardInfo(
9213 cardInfo.isEuicc(),
9214 cardInfo.getCardId(),
9215 null,
9216 cardInfo.getPhysicalSlotIndex(),
9217 cardInfo.isRemovable(),
9218 cardInfo.isMultipleEnabledProfilesSupported(),
9219 portinfo
9220 );
9221 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009222
sandeepjsb6c87872021-09-27 15:34:44 +00009223 /**
9224 * @hide
9225 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9226 * These values are generally private and require carrier privileges to view.
9227 */
9228 @NonNull
9229 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9230 return new UiccPortInfo(
9231 UiccPortInfo.ICCID_REDACTED,
9232 portInfo.getPortIndex(),
9233 portInfo.getLogicalSlotIndex(),
9234 portInfo.isActive()
9235 );
9236 }
9237 @Override
9238 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009239 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009240 mApp.getSystemService(AppOpsManager.class)
9241 .checkPackage(Binder.getCallingUid(), callingPackage);
9242
sandeepjsb6c87872021-09-27 15:34:44 +00009243 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009244
Aman Guptaf3c90b32022-03-17 04:54:16 +00009245 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9246 // we are reading iccId which is PII data.
9247 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009248
9249 // checking compatibility, if calling app's target SDK is T and beyond.
9250 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9251 Binder.getCallingUid())) {
9252 isLogicalSlotAccessRestricted = true;
9253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009254 final long identity = Binder.clearCallingIdentity();
9255 try {
9256 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009257 if (slots == null || slots.length == 0) {
9258 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009259 return null;
9260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009261 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9262 for (int i = 0; i < slots.length; i++) {
9263 UiccSlot slot = slots[i];
9264 if (slot == null) {
9265 continue;
9266 }
9267
Jordan Liu7be7e652019-05-06 18:55:02 +00009268 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009269 UiccCard card = slot.getUiccCard();
9270 if (card != null) {
9271 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009272 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009273 cardId = slot.getEid();
9274 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009275 // If cardId is null, use iccId of default port as cardId.
9276 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009277 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009278 }
9279
Jordan Liu857451f2019-05-09 16:35:35 -07009280 if (cardId != null) {
9281 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9282 // if cardId is an EID, it's all digits so this is fine
9283 cardId = IccUtils.stripTrailingFs(cardId);
9284 }
9285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009286 int cardState = 0;
9287 switch (slot.getCardState()) {
9288 case CARDSTATE_ABSENT:
9289 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9290 break;
9291 case CARDSTATE_PRESENT:
9292 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9293 break;
9294 case CARDSTATE_ERROR:
9295 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9296 break;
9297 case CARDSTATE_RESTRICTED:
9298 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9299 break;
9300 default:
9301 break;
9302
9303 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009304 List<UiccPortInfo> portInfos = new ArrayList<>();
9305 int[] portIndexes = slot.getPortList();
9306 for (int portIdx : portIndexes) {
9307 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009308 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009309 portInfos.add(new UiccPortInfo(iccId, portIdx,
9310 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009312 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009313 slot.isEuicc(),
9314 cardId,
9315 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009316 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009317 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009318 //setting the value after compatibility check
9319 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009320 }
9321 return infos;
9322 } finally {
9323 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009324 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009325 }
9326
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009327 /* Returns null if doesn't have read permission or carrier privilege access. */
9328 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9329 boolean hasReadPermission) {
9330 String iccId = slot.getIccId(portIndex);
9331 if (hasReadPermission) { // if has read permission
9332 return iccId;
9333 } else {
9334 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9335 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9336 // if no read permission, checking carrier privilege access
9337 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9338 return iccId;
9339 }
9340 }
9341 }
9342 // No read permission or carrier privilege access.
9343 return UiccPortInfo.ICCID_REDACTED;
9344 }
9345
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009346 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009347 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009348 public boolean switchSlots(int[] physicalSlots) {
9349 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009350
9351 final long identity = Binder.clearCallingIdentity();
9352 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009353 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9354 for (int i = 0; i < physicalSlots.length; i++) {
9355 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9356 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9357 physicalSlots[i], i));
9358 }
9359 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009363 }
Jack Yu4c988042018-02-27 15:30:01 -08009364
9365 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009366 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9367 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9368 enforceModifyPermission();
9369
9370 final long identity = Binder.clearCallingIdentity();
9371 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009372 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009373 } finally {
9374 Binder.restoreCallingIdentity(identity);
9375 }
9376 }
9377
9378 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009379 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009380 final long identity = Binder.clearCallingIdentity();
9381 try {
9382 return UiccController.getInstance().getCardIdForDefaultEuicc();
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
Pengquan Meng85728fb2018-03-12 16:31:21 -07009388 /**
goneil47ffb6e2018-04-06 15:40:58 -07009389 * A test API to reload the UICC profile.
9390 *
9391 * <p>Requires that the calling app has permission
9392 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9393 * @hide
9394 */
9395 @Override
9396 public void refreshUiccProfile(int subId) {
9397 enforceModifyPermission();
9398
9399 final long identity = Binder.clearCallingIdentity();
9400 try {
9401 Phone phone = getPhone(subId);
9402 if (phone == null) {
9403 return;
9404 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009405 UiccPort uiccPort = phone.getUiccPort();
9406 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009407 return;
9408 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009409 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009410 if (uiccProfile == null) {
9411 return;
9412 }
9413 uiccProfile.refresh();
9414 } finally {
9415 Binder.restoreCallingIdentity(identity);
9416 }
9417 }
9418
9419 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009420 * Returns false if the mobile data is disabled by default, otherwise return true.
9421 */
9422 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009423 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009424 }
9425
9426 /**
9427 * Returns true if the data roaming is enabled by default, i.e the system property
9428 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9429 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9430 */
9431 private boolean getDefaultDataRoamingEnabled(int subId) {
9432 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009433 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009434 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009435 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9436 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9437 return isDataRoamingEnabled;
9438 }
9439
9440 /**
9441 * Returns the default network type for the given {@code subId}, if the default network type is
9442 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9443 */
9444 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009445 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009446 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009447 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9448 return list.get(phoneId);
9449 }
9450 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009451 }
fionaxua13278b2018-03-21 00:08:13 -07009452
9453 @Override
9454 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009455 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 final Phone phone = getPhone(subId);
9461 if (phone == null) {
9462 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9463 return;
9464 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009465 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9466 if (cpt != null) {
9467 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9468 }
9469 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009470 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9471 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009472 if (carrierPrivilegeRules == null) {
9473 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9474 } else {
9475 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009477 } finally {
9478 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009479 }
fionaxua13278b2018-03-21 00:08:13 -07009480 }
9481
9482 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009483 public void setCarrierServicePackageOverride(
9484 int subId, String carrierServicePackage, String callingPackage) {
9485 TelephonyPermissions.enforceShellOnly(
9486 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9487
Benedict Wong66477622023-02-03 23:30:57 +00009488 final long identity = Binder.clearCallingIdentity();
9489 try {
9490 final Phone phone = getPhone(subId);
9491 if (phone == null || phone.getSubId() != subId) {
9492 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9493 throw new IllegalArgumentException("No phone for subid");
9494 }
9495 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9496 if (cpt == null) {
9497 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9498 throw new IllegalStateException("No CPT for phone");
9499 }
9500 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9501 } finally {
9502 Binder.restoreCallingIdentity(identity);
9503 }
9504 }
9505
9506 @Override
fionaxua13278b2018-03-21 00:08:13 -07009507 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009508 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009509
9510 final long identity = Binder.clearCallingIdentity();
9511 try {
9512 final Phone phone = getPhone(subId);
9513 if (phone == null) {
9514 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9515 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9516 }
9517 return phone.getCarrierIdListVersion();
9518 } finally {
9519 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009520 }
fionaxua13278b2018-03-21 00:08:13 -07009521 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009522
9523 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009524 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9525 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009527 mApp, subId, callingPackage, callingFeatureId,
9528 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009529 return -1;
9530 }
9531
9532 final long identity = Binder.clearCallingIdentity();
9533 try {
9534 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9535 } finally {
9536 Binder.restoreCallingIdentity(identity);
9537 }
9538 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009539
9540 @Override
9541 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009542 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009543 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009544 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009545
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
9548 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9549 } finally {
9550 Binder.restoreCallingIdentity(identity);
9551 }
9552 }
9553
9554 @Override
9555 public boolean setCdmaRoamingMode(int subId, int mode) {
9556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9557 mApp, subId, "setCdmaRoamingMode");
9558
9559 final long identity = Binder.clearCallingIdentity();
9560 try {
9561 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9562 } finally {
9563 Binder.restoreCallingIdentity(identity);
9564 }
9565 }
9566
9567 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009568 public int getCdmaSubscriptionMode(int subId) {
9569 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009570 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009571 mApp, subId, "getCdmaSubscriptionMode");
9572
9573 final long identity = Binder.clearCallingIdentity();
9574 try {
9575 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9576 } finally {
9577 Binder.restoreCallingIdentity(identity);
9578 }
9579 }
9580
9581 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009582 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9584 mApp, subId, "setCdmaSubscriptionMode");
9585
9586 final long identity = Binder.clearCallingIdentity();
9587 try {
9588 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9589 } finally {
9590 Binder.restoreCallingIdentity(identity);
9591 }
9592 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009593
sqianc5eccab2018-10-19 18:46:41 -07009594 @Override
sqian8c685422019-02-22 15:55:18 -08009595 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009596 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009598 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9599 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009600 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9601 }
9602 final long identity = Binder.clearCallingIdentity();
9603 try {
sqian854d44b2018-12-12 16:48:18 -08009604 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9605 for (Phone phone: PhoneFactory.getPhones()) {
9606 if (phone.getEmergencyNumberTracker() != null
9607 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9608 emergencyNumberListInternal.put(
9609 phone.getSubId(),
9610 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9611 }
sqian11b7a0e2018-12-05 18:48:28 -08009612 }
sqian854d44b2018-12-12 16:48:18 -08009613 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
sqianc5eccab2018-10-19 18:46:41 -07009617 }
9618
9619 @Override
sqian8c685422019-02-22 15:55:18 -08009620 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009621 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009622 if (!exactMatch) {
9623 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009624 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009625 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009626 }
9627 final long identity = Binder.clearCallingIdentity();
9628 try {
sqian854d44b2018-12-12 16:48:18 -08009629 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009630 //Note: we ignore passed in param exactMatch. We can remove it once
9631 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009632 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009633 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009634 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009635 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009636 }
sqian11b7a0e2018-12-05 18:48:28 -08009637 }
9638 return false;
9639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
9643
sqianf4ca7ed2019-01-15 18:32:07 -08009644 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009645 * Start emergency callback mode for GsmCdmaPhone for testing.
9646 */
9647 @Override
9648 public void startEmergencyCallbackMode() {
9649 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9650 "startEmergencyCallbackMode");
9651 enforceModifyPermission();
9652 final long identity = Binder.clearCallingIdentity();
9653 try {
9654 for (Phone phone : PhoneFactory.getPhones()) {
9655 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9656 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9657 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9658 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9659 gsmCdmaPhone.obtainMessage(
9660 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9661 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9662 }
9663 }
9664 } finally {
9665 Binder.restoreCallingIdentity(identity);
9666 }
9667 }
9668
9669 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009670 * Update emergency number list for test mode.
9671 */
9672 @Override
9673 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9675 "updateEmergencyNumberListTestMode");
9676
9677 final long identity = Binder.clearCallingIdentity();
9678 try {
9679 for (Phone phone: PhoneFactory.getPhones()) {
9680 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9681 if (tracker != null) {
9682 tracker.executeEmergencyNumberTestModeCommand(action, num);
9683 }
9684 }
9685 } finally {
9686 Binder.restoreCallingIdentity(identity);
9687 }
9688 }
9689
9690 /**
9691 * Get the full emergency number list for test mode.
9692 */
9693 @Override
9694 public List<String> getEmergencyNumberListTestMode() {
9695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9696 "getEmergencyNumberListTestMode");
9697
9698 final long identity = Binder.clearCallingIdentity();
9699 try {
9700 Set<String> emergencyNumbers = new HashSet<>();
9701 for (Phone phone: PhoneFactory.getPhones()) {
9702 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9703 if (tracker != null) {
9704 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9705 emergencyNumbers.add(num.getNumber());
9706 }
9707 }
9708 }
9709 return new ArrayList<>(emergencyNumbers);
9710 } finally {
9711 Binder.restoreCallingIdentity(identity);
9712 }
9713 }
9714
chen xud6b45bd2018-10-30 22:27:10 -07009715 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009716 public int getEmergencyNumberDbVersion(int subId) {
9717 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9718
9719 final long identity = Binder.clearCallingIdentity();
9720 try {
9721 final Phone phone = getPhone(subId);
9722 if (phone == null) {
9723 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9724 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9725 }
9726 return phone.getEmergencyNumberDbVersion();
9727 } finally {
9728 Binder.restoreCallingIdentity(identity);
9729 }
9730 }
9731
9732 @Override
9733 public void notifyOtaEmergencyNumberDbInstalled() {
9734 enforceModifyPermission();
9735
9736 final long identity = Binder.clearCallingIdentity();
9737 try {
9738 for (Phone phone: PhoneFactory.getPhones()) {
9739 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9740 if (tracker != null) {
9741 tracker.updateOtaEmergencyNumberDatabase();
9742 }
9743 }
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748
9749 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009750 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009751 enforceActiveEmergencySessionPermission();
9752
9753 final long identity = Binder.clearCallingIdentity();
9754 try {
9755 for (Phone phone: PhoneFactory.getPhones()) {
9756 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9757 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009758 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9759 }
9760 }
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
9763 }
9764 }
9765
9766 @Override
9767 public void resetOtaEmergencyNumberDbFilePath() {
9768 enforceActiveEmergencySessionPermission();
9769
9770 final long identity = Binder.clearCallingIdentity();
9771 try {
9772 for (Phone phone: PhoneFactory.getPhones()) {
9773 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9774 if (tracker != null) {
9775 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009776 }
9777 }
9778 } finally {
9779 Binder.restoreCallingIdentity(identity);
9780 }
9781 }
9782
9783 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009784 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9785 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9786 Phone phone = getPhone(subId);
9787 if (phone == null) {
9788 return null;
9789 }
9790 final long identity = Binder.clearCallingIdentity();
9791 try {
9792 UiccProfile profile = UiccController.getInstance()
9793 .getUiccProfileForPhone(phone.getPhoneId());
9794 if (profile != null) {
9795 return profile.getCertsFromCarrierPrivilegeAccessRules();
9796 }
9797 } finally {
9798 Binder.restoreCallingIdentity(identity);
9799 }
9800 return null;
9801 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009802
9803 /**
9804 * Enable or disable a modem stack.
9805 */
9806 @Override
9807 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9808 enforceModifyPermission();
9809
9810 final long identity = Binder.clearCallingIdentity();
9811 try {
9812 Phone phone = PhoneFactory.getPhone(slotIndex);
9813 if (phone == null) {
9814 return false;
9815 } else {
9816 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9817 }
9818 } finally {
9819 Binder.restoreCallingIdentity(identity);
9820 }
9821 }
Michelecea4cf22018-12-21 15:00:11 -08009822
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009823 /**
9824 * Whether a modem stack is enabled or not.
9825 */
9826 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009827 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9828 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009829 Phone phone = PhoneFactory.getPhone(slotIndex);
9830 if (phone == null) return false;
9831
9832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009833 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9834 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009835 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9836 }
9837
9838 final long identity = Binder.clearCallingIdentity();
9839 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009840 try {
9841 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9842 } catch (NoSuchElementException ex) {
9843 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9844 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
9849
Michelecea4cf22018-12-21 15:00:11 -08009850 @Override
Michele0ea7d782019-03-19 14:58:42 -07009851 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009852 enforceModifyPermission();
9853
9854 final long identity = Binder.clearCallingIdentity();
9855 try {
9856 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009857 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009858 .commit();
9859 } finally {
9860 Binder.restoreCallingIdentity(identity);
9861 }
9862 }
9863
9864 @Override
Michele0ea7d782019-03-19 14:58:42 -07009865 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009866 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009867 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009868 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9869 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009870 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009871 }
Michelecea4cf22018-12-21 15:00:11 -08009872
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
Michele0ea7d782019-03-19 14:58:42 -07009875 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009880
Michele0ea7d782019-03-19 14:58:42 -07009881 @TelephonyManager.IsMultiSimSupportedResult
9882 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009883 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9884 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9885 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009886 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9887 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009888 }
9889 // Check if the hardware supports multisim functionality. If usage of multisim is not
9890 // supported by the modem, indicate that it is restricted.
9891 PhoneCapability staticCapability =
9892 mPhoneConfigurationManager.getStaticPhoneCapability();
9893 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009894 loge("isMultiSimSupportedInternal: no static configuration available");
9895 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009896 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009897 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009898 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9899 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009900 }
9901 // Check if support of multiple SIMs is restricted by carrier
9902 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009903 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009904 }
9905
Michele0ea7d782019-03-19 14:58:42 -07009906 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009907 }
9908
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009909 /**
9910 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009911 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9912 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9913 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009914 * @param numOfSims number of active sims we want to switch to
9915 */
9916 @Override
9917 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009918 if (numOfSims == 1) {
9919 enforceModifyPermission();
9920 } else {
9921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9922 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9923 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009924 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009925
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009926 try {
Michele30b57b22019-03-01 12:01:14 -08009927 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009928 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009929 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9930 return;
9931 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009932 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9933 } finally {
9934 Binder.restoreCallingIdentity(identity);
9935 }
9936 }
9937
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009938 @Override
9939 public boolean isApplicationOnUicc(int subId, int appType) {
9940 enforceReadPrivilegedPermission("isApplicationOnUicc");
9941 Phone phone = getPhone(subId);
9942 if (phone == null) {
9943 return false;
9944 }
9945 final long identity = Binder.clearCallingIdentity();
9946 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009947 UiccPort uiccPort = phone.getUiccPort();
9948 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009949 return false;
9950 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009951 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009952 if (uiccProfile == null) {
9953 return false;
9954 }
9955 if (TelephonyManager.APPTYPE_SIM <= appType
9956 && appType <= TelephonyManager.APPTYPE_ISIM) {
9957 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9958 }
9959 return false;
9960 } finally {
9961 Binder.restoreCallingIdentity(identity);
9962 }
9963 }
9964
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009965 /**
chen xub4baa772019-04-03 10:23:41 -07009966 * Get whether making changes to modem configurations will trigger reboot.
9967 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009968 */
9969 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009970 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9971 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009973 mApp, subId, callingPackage, callingFeatureId,
9974 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009975 return false;
9976 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009977 final long identity = Binder.clearCallingIdentity();
9978 try {
9979 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9980 } finally {
9981 Binder.restoreCallingIdentity(identity);
9982 }
9983 }
9984
Nathan Harold29f5f052019-02-15 13:41:57 -08009985 private void updateModemStateMetrics() {
9986 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9987 // TODO: check the state for each modem if the api is ready.
9988 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9989 }
9990
Pengquan Meng3889a572019-01-23 11:16:29 -08009991 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009992 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009993 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009994 // Verify that the callingPackage belongs to the calling UID
9995 mApp.getSystemService(AppOpsManager.class)
9996 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009997 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009998 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009999 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010000 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10001 if (slotInfos != null) {
10002 for (int i = 0; i < slotInfos.length; i++) {
10003 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10004 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10005 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10006 portInfo.getLogicalSlotIndex()));
10007 }
10008 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010009 }
10010 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010011 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010012 } finally {
10013 Binder.restoreCallingIdentity(identity);
10014 }
10015 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010016
10017 /**
10018 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010019 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010020 */
jimsunf9ec1622022-09-13 21:18:43 +080010021 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010022 @Override
10023 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010024 return getHalVersion(HAL_SERVICE_RADIO);
10025 }
10026
10027 /**
10028 * Get the HAL Version of a specific service
10029 */
10030 @Override
10031 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010032 Phone phone = getDefaultPhone();
10033 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010034 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010035 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10036 return hv.major * 100 + hv.minor;
10037 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010038
10039 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010040 * Get the current calling package name.
10041 * @return the current calling package name
10042 */
10043 @Override
10044 public String getCurrentPackageName() {
10045 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10046 }
10047
10048 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010049 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10050 * corresponding network requests on a subId.
10051 *
10052 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010053 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010054 * 2) APN is un-metered for this subscription, or
10055 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010056 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010057 *
10058 * @return whether data is allowed for a apn type.
10059 *
10060 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010061 */
10062 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010063 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010064 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10065 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010066
10067 // Now that all security checks passes, perform the operation as ourselves.
10068 final long identity = Binder.clearCallingIdentity();
10069 try {
10070 Phone phone = getPhone(subId);
10071 if (phone == null) return false;
10072
Jack Yu27422a52022-03-21 10:38:05 -070010073 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010074 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010075 isMetered = phone.getDataNetworkController().getDataConfigManager()
10076 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10077 phone.getServiceState().getDataRoaming());
10078 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010079 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010080 } finally {
10081 Binder.restoreCallingIdentity(identity);
10082 }
10083 }
10084
10085 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010086 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010087 enforceReadPrivilegedPermission("isApnMetered");
10088
10089 // Now that all security checks passes, perform the operation as ourselves.
10090 final long identity = Binder.clearCallingIdentity();
10091 try {
10092 Phone phone = getPhone(subId);
10093 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010094 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10095 DataUtils.apnTypeToNetworkCapability(apnType),
10096 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010097 } finally {
10098 Binder.restoreCallingIdentity(identity);
10099 }
10100 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010101
10102 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010103 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10104 int subscriptionId, IBooleanConsumer resultCallback) {
10105 enforceModifyPermission();
10106 long token = Binder.clearCallingIdentity();
10107 try {
10108 Phone phone = getPhone(subscriptionId);
10109 if (phone == null) {
10110 try {
10111 if (resultCallback != null) {
10112 resultCallback.accept(false);
10113 }
10114 } catch (RemoteException e) {
10115 // ignore
10116 }
10117 return;
10118 }
10119 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10120 Pair.create(specifiers, (x) -> {
10121 try {
10122 if (resultCallback != null) {
10123 resultCallback.accept(x);
10124 }
10125 } catch (RemoteException e) {
10126 // ignore
10127 }
10128 });
10129 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10130 } finally {
10131 Binder.restoreCallingIdentity(token);
10132 }
10133 }
10134
10135 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010136 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10137 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010138 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010139 mApp, subId, "getSystemSelectionChannels");
10140 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10141 final long identity = Binder.clearCallingIdentity();
10142 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010143 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10144 if (result instanceof IllegalStateException) {
10145 throw (IllegalStateException) result;
10146 }
10147 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010148 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10149 return specifiers;
10150 } finally {
10151 Binder.restoreCallingIdentity(identity);
10152 }
10153 }
10154
10155 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010156 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010157 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010158 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010159 }
10160
10161 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010162 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10163 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010164 if (callingPackage == null) {
10165 callingPackage = getCurrentPackageName();
10166 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010167 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10168 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010169 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10170 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010171 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10172 }
10173 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10174 Intent intent = new Intent();
10175 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10176 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10177 // Bring up choose default SMS subscription dialog right now
10178 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10179 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10180 mApp.startActivity(intent);
10181 }
chen xud5ca2d52019-05-28 15:20:57 -070010182
10183 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010184 public void showSwitchToManagedProfileDialog() {
10185 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010186 try {
10187 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10188 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10189 // for work telephony.
10190 Intent intent = new Intent(Intent.ACTION_SENDTO);
10191 intent.setData(Uri.parse("smsto:"));
10192 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10193 mApp.startActivity(intent);
10194 } catch (ActivityNotFoundException e) {
10195 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10196 Intent intent = new Intent();
10197 intent.setClass(mApp, ErrorDialogActivity.class);
10198 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10199 mApp.startActivity(intent);
10200 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010201 }
10202
10203 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010204 public String getMmsUAProfUrl(int subId) {
10205 //TODO investigate if this API should require proper permission check in R b/133791609
10206 final long identity = Binder.clearCallingIdentity();
10207 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010208 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10209 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10210 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10211 return carrierUAProfUrl;
10212 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010213 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10214 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010215 } finally {
10216 Binder.restoreCallingIdentity(identity);
10217 }
10218 }
10219
10220 @Override
10221 public String getMmsUserAgent(int subId) {
10222 //TODO investigate if this API should require proper permission check in R b/133791609
10223 final long identity = Binder.clearCallingIdentity();
10224 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010225 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10226 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10227 if (!TextUtils.isEmpty(carrierUserAgent)) {
10228 return carrierUserAgent;
10229 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010230 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10231 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
Jack Yub07d4972019-05-28 16:12:25 -070010236
10237 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010238 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10239 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010240
Jack Yub07d4972019-05-28 16:12:25 -070010241 final long identity = Binder.clearCallingIdentity();
10242 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010243 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010244 if (phone == null) return false;
10245
Ling Maf188d502022-09-16 15:22:36 -070010246 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010247 } finally {
10248 Binder.restoreCallingIdentity(identity);
10249 }
10250 }
10251
10252 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010253 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010254 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010255 enforceModifyPermission();
10256
changbettyd5c246e2019-12-24 15:40:37 +080010257 final long identity = Binder.clearCallingIdentity();
10258 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010259 Phone phone = getPhone(subscriptionId);
10260 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010261
Ling Maf188d502022-09-16 15:22:36 -070010262 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010263 } finally {
10264 Binder.restoreCallingIdentity(identity);
10265 }
10266 }
10267
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010268 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010269 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010270 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10271 * otherwise.
10272 */
10273 @Override
10274 public void setCepEnabled(boolean isCepEnabled) {
10275 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10276
10277 final long identity = Binder.clearCallingIdentity();
10278 try {
10279 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10280 for (Phone phone : PhoneFactory.getPhones()) {
10281 Phone defaultPhone = phone.getImsPhone();
10282 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10283 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10284 ImsPhoneCallTracker imsPhoneCallTracker =
10285 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10286 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10287 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10288 + imsPhone.getMsisdn());
10289 }
10290 }
10291 } finally {
10292 Binder.restoreCallingIdentity(identity);
10293 }
10294 }
allenwtsu46dcc572020-01-08 18:24:03 +080010295
10296 /**
10297 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10298 *
10299 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10300 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10301 * before being read.
10302 */
10303 @Override
10304 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10305 isCompressed) {
10306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10307 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010308 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10309 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10310 }
10311 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010312 // ProvisioningManager can not handle ServiceSpecificException.
10313 // Throw the IllegalStateException and annotate ProvisioningManager.
10314 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010315 }
10316
10317 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010318 try {
Hui Wang761a6682020-10-31 05:12:53 +000010319 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10320 } finally {
10321 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010322 }
10323 }
zoey chene02881a2019-12-30 16:11:23 +080010324
10325 @Override
10326 public boolean isIccLockEnabled(int subId) {
10327 enforceReadPrivilegedPermission("isIccLockEnabled");
10328
10329 // Now that all security checks passes, perform the operation as ourselves.
10330 final long identity = Binder.clearCallingIdentity();
10331 try {
10332 Phone phone = getPhone(subId);
10333 if (phone != null && phone.getIccCard() != null) {
10334 return phone.getIccCard().getIccLockEnabled();
10335 } else {
10336 return false;
10337 }
10338 } finally {
10339 Binder.restoreCallingIdentity(identity);
10340 }
10341 }
10342
10343 /**
10344 * Set the ICC pin lock enabled or disabled.
10345 *
10346 * @return an integer representing the status of IccLock enabled or disabled in the following
10347 * three cases:
10348 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10349 * successfully.
10350 * - Positive number and zero for remaining password attempts.
10351 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10352 *
10353 */
10354 @Override
10355 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10356 enforceModifyPermission();
10357
10358 Phone phone = getPhone(subId);
10359 if (phone == null) {
10360 return 0;
10361 }
10362 // Now that all security checks passes, perform the operation as ourselves.
10363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10366 new Pair<Boolean, String>(enabled, password), phone, null);
10367 return attemptsRemaining;
10368
10369 } catch (Exception e) {
10370 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10371 } finally {
10372 Binder.restoreCallingIdentity(identity);
10373 }
10374 return 0;
10375 }
10376
10377 /**
10378 * Change the ICC password used in ICC pin lock.
10379 *
10380 * @return an integer representing the status of IccLock changed in the following three cases:
10381 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10382 * - Positive number and zero for remaining password attempts.
10383 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10384 *
10385 */
10386 @Override
10387 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10388 enforceModifyPermission();
10389
10390 Phone phone = getPhone(subId);
10391 if (phone == null) {
10392 return 0;
10393 }
10394 // Now that all security checks passes, perform the operation as ourselves.
10395 final long identity = Binder.clearCallingIdentity();
10396 try {
10397 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10398 new Pair<String, String>(oldPassword, newPassword), phone, null);
10399 return attemptsRemaining;
10400
10401 } catch (Exception e) {
10402 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10403 } finally {
10404 Binder.restoreCallingIdentity(identity);
10405 }
10406 return 0;
10407 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010408
10409 /**
10410 * Request for receiving user activity notification
10411 */
10412 @Override
10413 public void requestUserActivityNotification() {
10414 if (!mNotifyUserActivity.get()
10415 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10416 mNotifyUserActivity.set(true);
10417 }
10418 }
10419
10420 /**
10421 * Called when userActivity is signalled in the power manager.
10422 * This is safe to call from any thread, with any window manager locks held or not.
10423 */
10424 @Override
10425 public void userActivity() {
10426 // ***************************************
10427 // * Inherited from PhoneWindowManager *
10428 // ***************************************
10429 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10430 // WITH ITS LOCKS HELD.
10431 //
10432 // This code must be VERY careful about the locks
10433 // it acquires.
10434 // In fact, the current code acquires way too many,
10435 // and probably has lurking deadlocks.
10436
10437 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10438 throw new SecurityException("Only the OS may call notifyUserActivity()");
10439 }
10440
10441 if (mNotifyUserActivity.getAndSet(false)) {
10442 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10443 USER_ACTIVITY_NOTIFICATION_DELAY);
10444 }
10445 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010446
10447 @Override
10448 public boolean canConnectTo5GInDsdsMode() {
10449 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10450 }
Jack Yud10cdd42020-09-28 20:28:01 -070010451
10452 @Override
10453 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10454 String callingFeatureId) {
10455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10456 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10457 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10458 }
10459
10460 Phone phone = getPhone(subId);
10461 if (phone == null) {
10462 throw new RuntimeException("phone is not available");
10463 }
10464 // Now that all security checks passes, perform the operation as ourselves.
10465 final long identity = Binder.clearCallingIdentity();
10466 try {
10467 return phone.getEquivalentHomePlmns();
10468 } finally {
10469 Binder.restoreCallingIdentity(identity);
10470 }
10471 }
Daniel Bright59e67312020-11-13 11:49:37 -080010472
10473 @Override
10474 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010475 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10476 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010477 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010478 if (radioInterfaceCapabilities == null) {
10479 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010480 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010481 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010482 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010483
Hui Wang641e81c2020-10-12 12:14:23 -070010484 @Override
10485 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10486 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010487 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10488 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10489 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10490 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10491 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010492 if (DBG) {
10493 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10494 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10495 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10496 }
10497
10498 if (!SubscriptionManager.isValidSubscriptionId(subId)
10499 || appType < TelephonyManager.APPTYPE_UNKNOWN
10500 || appType > TelephonyManager.APPTYPE_ISIM
10501 || nafUrl == null || securityProtocol == null || callback == null) {
10502 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10503 if (callback != null) {
10504 try {
10505 callback.onAuthenticationFailure(
10506 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10507 } catch (RemoteException exception) {
10508 log("Fail to notify onAuthenticationFailure due to " + exception);
10509 }
10510 return;
10511 }
10512 }
10513
10514 final long token = Binder.clearCallingIdentity();
10515 try {
10516 getGbaManager(subId).bootstrapAuthenticationRequest(
10517 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010518 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010519 } finally {
10520 Binder.restoreCallingIdentity(token);
10521 }
10522 }
10523
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010524 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010525 * Attempts to set the radio power state for all phones for thermal reason.
10526 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010527 * requested radio power state will actually be set. See {@link
10528 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10529 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010530 * @param enable {@code true} if trying to turn radio on.
10531 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10532 * false}.
10533 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010534 private boolean setRadioPowerForThermal(boolean enable) {
10535 boolean isPhoneAvailable = false;
10536 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10537 Phone phone = PhoneFactory.getPhone(i);
10538 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010539 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010540 isPhoneAvailable = true;
10541 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010542 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010543
10544 // return true if successfully informed the phone object about the thermal radio power
10545 // request.
10546 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010547 }
10548
10549 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010550 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010551 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10552 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10553 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10554 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10555 throw new IllegalArgumentException("modem does not support data throttling");
10556 }
10557
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010558 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10559 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010560 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010561 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10562 }
10563
Sarah Chinecc78c42022-03-31 21:16:48 -070010564 setDataEnabledForReason(
10565 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010566
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010567 if (isDataThrottlingSupported) {
10568 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010569 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010570 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10571 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10572 } else if (thermalMitigationResult
10573 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010574 log("Modem likely does not support data throttling on secondary carrier. Data " +
10575 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10576 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010577 }
10578 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010579 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010580
10581 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010582 }
10583
Jack Nudelman644b91a2021-03-12 14:09:48 -080010584 private static List<String> getThermalMitigationAllowlist(Context context) {
10585 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10586 for (String pckg : context.getResources()
10587 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10588 sThermalMitigationAllowlistedPackages.add(pckg);
10589 }
10590 }
10591
10592 return sThermalMitigationAllowlistedPackages;
10593 }
10594
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010595 private boolean isAnyPhoneInEmergencyState() {
10596 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10597 if (tm.isInEmergencyCall()) {
10598 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10599 return true;
10600 }
10601 for (Phone phone : PhoneFactory.getPhones()) {
10602 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10603 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010604 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10605 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010606 return true;
10607 }
10608 }
10609
10610 return false;
10611 }
10612
Jack Nudelman644b91a2021-03-12 14:09:48 -080010613 /**
10614 * Used by shell commands to add an authorized package name for thermal mitigation.
10615 * @param packageName name of package to be allowlisted
10616 * @param context
10617 */
10618 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10619 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10620 sThermalMitigationAllowlistedPackages.add(packageName);
10621 }
10622
10623 /**
10624 * Used by shell commands to remove an authorized package name for thermal mitigation.
10625 * @param packageName name of package to remove from allowlist
10626 * @param context
10627 */
10628 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10629 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10630 sThermalMitigationAllowlistedPackages.remove(packageName);
10631 }
10632
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010633 /**
10634 * Thermal mitigation request to control functionalities at modem.
10635 *
10636 * @param subId the id of the subscription.
10637 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010638 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010639 *
10640 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10641 */
10642 @Override
10643 @ThermalMitigationResult
10644 public int sendThermalMitigationRequest(
10645 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010646 ThermalMitigationRequest thermalMitigationRequest,
10647 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010648 enforceModifyPermission();
10649
Jack Nudelman644b91a2021-03-12 14:09:48 -080010650 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10651 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10652 .contains(callingPackage)) {
10653 throw new SecurityException("Calling package must be configured in the device config. "
10654 + "calling package: " + callingPackage);
10655 }
10656
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010657 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10658 final long identity = Binder.clearCallingIdentity();
10659
10660 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10661 try {
10662 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10663 switch (thermalMitigationAction) {
10664 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10665 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010666 handleDataThrottlingRequest(subId,
10667 thermalMitigationRequest.getDataThrottlingRequest(),
10668 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010669 break;
10670 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10671 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10672 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10673 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10674 }
10675
10676 // Ensure that radio is on. If not able to power on due to phone being
10677 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010678 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010679 thermalMitigationResult =
10680 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10681 break;
10682 }
10683
10684 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010685 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010686 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10687 break;
10688 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10689 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10690 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10691 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10692 }
10693
10694 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10695 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010696 Phone phone = getPhone(subId);
10697 if (phone == null) {
10698 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010699 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010700 break;
10701 }
10702
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010703 TelephonyConnectionService service =
10704 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010705 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010706 Log.e(LOG_TAG, "An emergency call is pending");
10707 thermalMitigationResult =
10708 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10709 break;
10710 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010711 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010712 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010713 break;
10714 }
10715 } else {
10716 thermalMitigationResult =
10717 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10718 break;
10719 }
10720
10721 // Turn radio off. If not able to power off due to phone being unavailable,
10722 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010723 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010724 thermalMitigationResult =
10725 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10726 break;
10727 }
10728 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010729 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010730 break;
10731 default:
10732 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10733 + "not exist. Requested action: " + thermalMitigationAction);
10734 }
10735 } catch (IllegalArgumentException e) {
10736 throw e;
10737 } catch (Exception e) {
10738 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10739 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10740 } finally {
10741 Binder.restoreCallingIdentity(identity);
10742 }
10743
10744 if (DBG) {
10745 log("thermalMitigationRequest returning with thermalMitigationResult: "
10746 + thermalMitigationResult);
10747 }
10748
10749 return thermalMitigationResult;
10750 }
Hui Wang641e81c2020-10-12 12:14:23 -070010751
10752 /**
10753 * Set the GbaService Package Name that Telephony will bind to.
10754 *
10755 * @param subId The sim that the GbaService is associated with.
10756 * @param packageName The name of the package to be replaced with.
10757 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10758 */
10759 @Override
10760 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10761 enforceModifyPermission();
10762
10763 final long identity = Binder.clearCallingIdentity();
10764 try {
10765 return getGbaManager(subId).overrideServicePackage(packageName);
10766 } finally {
10767 Binder.restoreCallingIdentity(identity);
10768 }
10769 }
10770
10771 /**
10772 * Return the package name of the currently bound GbaService.
10773 *
10774 * @param subId The sim that the GbaService is associated with.
10775 * @return the package name of the GbaService configuration, null if GBA is not supported.
10776 */
10777 @Override
10778 public String getBoundGbaService(int subId) {
10779 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10780
10781 final long identity = Binder.clearCallingIdentity();
10782 try {
10783 return getGbaManager(subId).getServicePackage();
10784 } finally {
10785 Binder.restoreCallingIdentity(identity);
10786 }
10787 }
10788
10789 /**
10790 * Set the release time for telephony to unbind GbaService.
10791 *
10792 * @param subId The sim that the GbaService is associated with.
10793 * @param interval The release time to unbind GbaService by millisecond.
10794 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10795 */
10796 @Override
10797 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10798 enforceModifyPermission();
10799
10800 final long identity = Binder.clearCallingIdentity();
10801 try {
10802 return getGbaManager(subId).overrideReleaseTime(interval);
10803 } finally {
10804 Binder.restoreCallingIdentity(identity);
10805 }
10806 }
10807
10808 /**
10809 * Return the release time for telephony to unbind GbaService.
10810 *
10811 * @param subId The sim that the GbaService is associated with.
10812 * @return The release time to unbind GbaService by millisecond.
10813 */
10814 @Override
10815 public int getGbaReleaseTime(int subId) {
10816 enforceReadPrivilegedPermission("getGbaReleaseTime");
10817
10818 final long identity = Binder.clearCallingIdentity();
10819 try {
10820 return getGbaManager(subId).getReleaseTime();
10821 } finally {
10822 Binder.restoreCallingIdentity(identity);
10823 }
10824 }
10825
10826 private GbaManager getGbaManager(int subId) {
10827 GbaManager instance = GbaManager.getInstance(subId);
10828 if (instance == null) {
10829 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10830 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10831 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10832 }
10833 return instance;
10834 }
Hui Wang761a6682020-10-31 05:12:53 +000010835
10836 /**
10837 * indicate whether the device and the carrier can support
10838 * RCS VoLTE single registration.
10839 */
10840 @Override
10841 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010842 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10843 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10844 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10845 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010846
10847 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10848 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10849 }
10850
10851 final long identity = Binder.clearCallingIdentity();
10852 try {
10853 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10854 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010855 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10856 if (isCapable != null) {
10857 return isCapable;
10858 }
Hui Wang761a6682020-10-31 05:12:53 +000010859 }
Hui Wang67af90e2021-06-04 16:57:15 -070010860 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10861 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010862 } finally {
10863 Binder.restoreCallingIdentity(identity);
10864 }
10865 }
10866
10867 /**
10868 * Register RCS provisioning callback.
10869 */
10870 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010871 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010872 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010873 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010874 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010875 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10876 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010877
10878 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10879 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10880 }
10881 if (!isImsAvailableOnDevice()) {
10882 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10883 "IMS not available on device.");
10884 }
10885
10886 final long identity = Binder.clearCallingIdentity();
10887 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010888 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010889 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010890 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10891 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010892 }
Hui Wang761a6682020-10-31 05:12:53 +000010893 } finally {
10894 Binder.restoreCallingIdentity(identity);
10895 }
10896 }
10897
10898 /**
10899 * Unregister RCS provisioning callback.
10900 */
10901 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010902 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010903 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010904 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010905 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010906 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10907 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010908
10909 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10910 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10911 }
10912 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010913 // operation failed silently
10914 Rlog.w(LOG_TAG, "IMS not available on device.");
10915 return;
Hui Wang761a6682020-10-31 05:12:53 +000010916 }
10917
10918 final long identity = Binder.clearCallingIdentity();
10919 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010920 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010921 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
10926
10927 /**
10928 * trigger RCS reconfiguration.
10929 */
10930 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010931 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10932 "triggerRcsReconfiguration",
10933 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010934
10935 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10936 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10937 }
10938 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010939 // ProvisioningManager can not handle ServiceSpecificException.
10940 // Throw the IllegalStateException and annotate ProvisioningManager.
10941 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010942 }
10943
10944 final long identity = Binder.clearCallingIdentity();
10945 try {
10946 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10947 } finally {
10948 Binder.restoreCallingIdentity(identity);
10949 }
10950 }
10951
10952 /**
10953 * Provide the client configuration parameters of the RCS application.
10954 */
10955 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010956 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10957 "setRcsClientConfiguration",
10958 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010959
10960 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10961 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10962 }
10963 if (!isImsAvailableOnDevice()) {
10964 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10965 "IMS not available on device.");
10966 }
10967
10968 final long identity = Binder.clearCallingIdentity();
10969
10970 try {
10971 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10972 if (configBinder == null) {
10973 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010974 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10975 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010976 } else {
10977 configBinder.setRcsClientConfiguration(rcc);
10978 }
joonhunshin3e154242021-09-17 06:33:39 +000010979
10980 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10981 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010982 } catch (RemoteException e) {
10983 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010984 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10985 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010986 } finally {
10987 Binder.restoreCallingIdentity(identity);
10988 }
10989 }
10990
10991 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010992 * Enables or disables the test mode for RCS VoLTE single registration.
10993 */
10994 @Override
10995 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10996 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10997 "setRcsSingleRegistrationTestModeEnabled");
10998
10999 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11000 }
11001
11002 /**
11003 * Gets the test mode for RCS VoLTE single registration.
11004 */
11005 @Override
11006 public boolean getRcsSingleRegistrationTestModeEnabled() {
11007 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11008 "getRcsSingleRegistrationTestModeEnabled");
11009
11010 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11011 }
11012
11013 /**
Hui Wang761a6682020-10-31 05:12:53 +000011014 * Overrides the config of RCS VoLTE single registration enabled for the device.
11015 */
11016 @Override
11017 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11019 "setDeviceSingleRegistrationEnabledOverride");
11020 enforceModifyPermission();
11021
11022 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11023 : Boolean.parseBoolean(enabledStr);
11024 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011025 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011026 }
11027
11028 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011029 * Sends a device to device communication message. Only usable via shell.
11030 * @param message message to send.
11031 * @param value message value.
11032 */
11033 @Override
11034 public void sendDeviceToDeviceMessage(int message, int value) {
11035 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011036 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011037 enforceModifyPermission();
11038
11039 final long identity = Binder.clearCallingIdentity();
11040 try {
11041 TelephonyConnectionService service =
11042 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11043 if (service == null) {
11044 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11045 return;
11046 }
11047 service.sendTestDeviceToDeviceMessage(message, value);
11048 } finally {
11049 Binder.restoreCallingIdentity(identity);
11050 }
11051 }
11052
Tyler Gunnbabbda02021-02-10 11:05:02 -080011053 /**
11054 * Sets the specified device to device transport active.
11055 * @param transport The transport to set active.
11056 */
11057 @Override
11058 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11060 "setActiveDeviceToDeviceTransport");
11061 enforceModifyPermission();
11062
11063 final long identity = Binder.clearCallingIdentity();
11064 try {
11065 TelephonyConnectionService service =
11066 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11067 if (service == null) {
11068 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11069 return;
11070 }
11071 service.setActiveDeviceToDeviceTransport(transport);
11072 } finally {
11073 Binder.restoreCallingIdentity(identity);
11074 }
11075 }
Tyler Gunn92479152021-01-20 16:30:10 -080011076
Tyler Gunnd4339262021-05-03 14:46:49 -070011077 @Override
11078 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11080 "setDeviceToDeviceForceEnabled");
11081
11082 final long identity = Binder.clearCallingIdentity();
11083 try {
11084 Arrays.stream(PhoneFactory.getPhones()).forEach(
11085 p -> {
11086 Phone thePhone = p.getImsPhone();
11087 if (thePhone != null && thePhone instanceof ImsPhone) {
11088 ImsPhone imsPhone = (ImsPhone) thePhone;
11089 CallTracker tracker = imsPhone.getCallTracker();
11090 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11091 ImsPhoneCallTracker imsPhoneCallTracker =
11092 (ImsPhoneCallTracker) tracker;
11093 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11094 }
11095 }
11096 }
11097 );
11098 } finally {
11099 Binder.restoreCallingIdentity(identity);
11100 }
11101 }
11102
Tyler Gunn92479152021-01-20 16:30:10 -080011103 /**
Hui Wang761a6682020-10-31 05:12:53 +000011104 * Gets the config of RCS VoLTE single registration enabled for the device.
11105 */
11106 @Override
11107 public boolean getDeviceSingleRegistrationEnabled() {
11108 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11109 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11110 }
11111
11112 /**
11113 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11114 */
11115 @Override
11116 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11118 "setCarrierSingleRegistrationEnabledOverride");
11119 enforceModifyPermission();
11120
11121 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11122 : Boolean.parseBoolean(enabledStr);
11123 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11124 subId, enabled);
11125 }
11126
11127 /**
11128 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11129 */
11130 @Override
11131 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11132 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11133 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11134 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011135
11136 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011137 * Overrides the ims feature validation result
11138 */
11139 @Override
11140 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11141 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11142 "setImsFeatureValidationOverride");
11143
11144 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11145 : Boolean.parseBoolean(enabledStr);
11146 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11147 subId, enabled);
11148 }
11149
11150 /**
11151 * Gets the ims feature validation override value
11152 */
11153 @Override
11154 public boolean getImsFeatureValidationOverride(int subId) {
11155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11156 "getImsFeatureValidationOverride");
11157 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11158 }
11159
11160 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011161 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11162 * their mobile plan.
11163 */
11164 @Override
11165 public String getMobileProvisioningUrl() {
11166 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11167 final long identity = Binder.clearCallingIdentity();
11168 try {
11169 return getDefaultPhone().getMobileProvisioningUrl();
11170 } finally {
11171 Binder.restoreCallingIdentity(identity);
11172 }
11173 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011174
James.cf Linbcdf8b32021-01-14 16:44:13 +080011175 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011176 * Get the EAB contact from the EAB database.
11177 */
11178 @Override
11179 public String getContactFromEab(String contact) {
11180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11181 enforceModifyPermission();
11182 final long identity = Binder.clearCallingIdentity();
11183 try {
11184 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11185 } finally {
11186 Binder.restoreCallingIdentity(identity);
11187 }
11188 }
11189
11190 /**
Calvin Pana1434322021-07-01 19:27:01 +080011191 * Get the EAB capability from the EAB database.
11192 */
11193 @Override
11194 public String getCapabilityFromEab(String contact) {
11195 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11196 enforceModifyPermission();
11197 final long identity = Binder.clearCallingIdentity();
11198 try {
11199 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11200 } finally {
11201 Binder.restoreCallingIdentity(identity);
11202 }
11203 }
11204
11205 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011206 * Remove the EAB contacts from the EAB database.
11207 */
11208 @Override
11209 public int removeContactFromEab(int subId, String contacts) {
11210 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11211 enforceModifyPermission();
11212 final long identity = Binder.clearCallingIdentity();
11213 try {
11214 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11215 } finally {
11216 Binder.restoreCallingIdentity(identity);
11217 }
11218 }
11219
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011220 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011221 public boolean getDeviceUceEnabled() {
11222 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11223 final long identity = Binder.clearCallingIdentity();
11224 try {
11225 return mApp.getDeviceUceEnabled();
11226 } finally {
11227 Binder.restoreCallingIdentity(identity);
11228 }
11229 }
11230
11231 @Override
11232 public void setDeviceUceEnabled(boolean isEnabled) {
11233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11234 final long identity = Binder.clearCallingIdentity();
11235 try {
11236 mApp.setDeviceUceEnabled(isEnabled);
11237 } finally {
11238 Binder.restoreCallingIdentity(identity);
11239 }
11240 }
11241
Brad Ebinger14d467f2021-02-12 06:18:28 +000011242 /**
11243 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11244 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11245 */
11246 // Used for SHELL command only right now.
11247 @Override
11248 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11249 List<String> featureTags) {
11250 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11251 "addUceRegistrationOverrideShell");
11252 final long identity = Binder.clearCallingIdentity();
11253 try {
11254 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11255 new ArraySet<>(featureTags));
11256 } catch (ImsException e) {
11257 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11258 } finally {
11259 Binder.restoreCallingIdentity(identity);
11260 }
11261 }
11262
11263 /**
11264 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11265 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11266 */
11267 // Used for SHELL command only right now.
11268 @Override
11269 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11270 List<String> featureTags) {
11271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11272 "removeUceRegistrationOverrideShell");
11273 final long identity = Binder.clearCallingIdentity();
11274 try {
11275 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11276 new ArraySet<>(featureTags));
11277 } catch (ImsException e) {
11278 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11279 } finally {
11280 Binder.restoreCallingIdentity(identity);
11281 }
11282 }
11283
11284 /**
11285 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11286 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11287 */
11288 // Used for SHELL command only right now.
11289 @Override
11290 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11291 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11292 "clearUceRegistrationOverrideShell");
11293 final long identity = Binder.clearCallingIdentity();
11294 try {
11295 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11296 } catch (ImsException e) {
11297 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11298 } finally {
11299 Binder.restoreCallingIdentity(identity);
11300 }
11301 }
11302
11303 /**
11304 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11305 */
11306 // Used for SHELL command only right now.
11307 @Override
11308 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11309 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11310 "getLatestRcsContactUceCapabilityShell");
11311 final long identity = Binder.clearCallingIdentity();
11312 try {
11313 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11314 } catch (ImsException e) {
11315 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11316 } finally {
11317 Binder.restoreCallingIdentity(identity);
11318 }
11319 }
11320
11321 /**
11322 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11323 * device does not have an active PUBLISH.
11324 */
11325 // Used for SHELL command only right now.
11326 @Override
11327 public String getLastUcePidfXmlShell(int subId) {
11328 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11329 final long identity = Binder.clearCallingIdentity();
11330 try {
11331 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11332 } catch (ImsException e) {
11333 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11334 } finally {
11335 Binder.restoreCallingIdentity(identity);
11336 }
11337 }
11338
James.cf Line8713a42021-04-29 16:04:26 +080011339 /**
11340 * Remove UCE requests cannot be sent to the network status.
11341 */
11342 // Used for SHELL command only right now.
11343 @Override
11344 public boolean removeUceRequestDisallowedStatus(int subId) {
11345 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11346 final long identity = Binder.clearCallingIdentity();
11347 try {
11348 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11349 } catch (ImsException e) {
11350 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11351 } finally {
11352 Binder.restoreCallingIdentity(identity);
11353 }
11354 }
11355
James.cf Lin18bb9002021-05-25 01:37:38 +080011356 /**
11357 * Remove UCE requests cannot be sent to the network status.
11358 */
11359 // Used for SHELL command only.
11360 @Override
11361 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11363 final long identity = Binder.clearCallingIdentity();
11364 try {
11365 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11366 } catch (ImsException e) {
11367 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11368 } finally {
11369 Binder.restoreCallingIdentity(identity);
11370 }
11371 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011372
James.cf Lin4b784aa2021-01-31 03:25:15 +080011373 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011374 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11375 String callingPackage) {
11376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11377 mApp, subId, "setSignalStrengthUpdateRequest");
11378
11379 final int callingUid = Binder.getCallingUid();
11380 // Verify that tha callingPackage belongs to the calling UID
11381 mApp.getSystemService(AppOpsManager.class)
11382 .checkPackage(callingUid, callingPackage);
11383
Rambo Wang3607f502021-02-01 21:51:40 -080011384 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011385
11386 final long identity = Binder.clearCallingIdentity();
11387 try {
11388 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11389 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11390
11391 if (result instanceof IllegalStateException) {
11392 throw (IllegalStateException) result;
11393 }
11394 } finally {
11395 Binder.restoreCallingIdentity(identity);
11396 }
11397 }
11398
11399 @Override
11400 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11401 String callingPackage) {
11402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11403 mApp, subId, "clearSignalStrengthUpdateRequest");
11404
11405 final int callingUid = Binder.getCallingUid();
11406 // Verify that tha callingPackage belongs to the calling UID
11407 mApp.getSystemService(AppOpsManager.class)
11408 .checkPackage(callingUid, callingPackage);
11409
11410 final long identity = Binder.clearCallingIdentity();
11411 try {
11412 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11413 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11414
11415 if (result instanceof IllegalStateException) {
11416 throw (IllegalStateException) result;
11417 }
11418 } finally {
11419 Binder.restoreCallingIdentity(identity);
11420 }
11421 }
11422
Rambo Wang3607f502021-02-01 21:51:40 -080011423 private static void validateSignalStrengthUpdateRequest(Context context,
11424 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011425 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11426 // phone/system process do not have further restriction on request
11427 return;
11428 }
11429
11430 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011431 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011432 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011433 context.enforceCallingOrSelfPermission(
11434 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11435 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011436 }
11437
11438 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011439 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011440 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011441 || info.isEnabled()) {
11442 throw new IllegalArgumentException(
11443 "Only system can set hide fields in SignalThresholdInfo");
11444 }
11445
11446 // Thresholds length for each RAN need in range. This has been validated in
11447 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11448 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11449 final int[] thresholds = info.getThresholds();
11450 Objects.requireNonNull(thresholds);
11451 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11452 || thresholds.length
11453 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11454 throw new IllegalArgumentException(
11455 "thresholds length is out of range: " + thresholds.length);
11456 }
11457 }
11458 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011459
11460 /**
11461 * Gets the current phone capability.
11462 *
11463 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11464 * @return the PhoneCapability which describes the data connection capability of modem.
11465 * It's used to evaluate possible phone config change, for example from single
11466 * SIM device to multi-SIM device.
11467 */
11468 @Override
11469 public PhoneCapability getPhoneCapability() {
11470 enforceReadPrivilegedPermission("getPhoneCapability");
11471 final long identity = Binder.clearCallingIdentity();
11472 try {
11473 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11474 } finally {
11475 Binder.restoreCallingIdentity(identity);
11476 }
11477 }
Michele Berionne5e411512020-11-13 02:36:59 +000011478
11479 /**
11480 * Prepare TelephonyManager for an unattended reboot. The reboot is
11481 * required to be done shortly after the API is invoked.
11482 */
11483 @Override
11484 @TelephonyManager.PrepareUnattendedRebootResult
11485 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011486 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011487 enforceRebootPermission();
11488
11489 final long identity = Binder.clearCallingIdentity();
11490 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011491 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011492 } finally {
11493 Binder.restoreCallingIdentity(identity);
11494 }
11495 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011496
11497 /**
11498 * Request to get the current slicing configuration including URSP rules and
11499 * NSSAIs (configured, allowed and rejected).
11500 *
11501 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11502 */
11503 @Override
11504 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011505 TelephonyPermissions
11506 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11507 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011508
11509 final long identity = Binder.clearCallingIdentity();
11510 try {
11511 Phone phone = getDefaultPhone();
11512 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11513 } finally {
11514 Binder.restoreCallingIdentity(identity);
11515 }
11516 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011517
11518 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011519 * Check whether the given premium capability is available for purchase from the carrier.
11520 *
11521 * @param capability The premium capability to check.
11522 * @param subId The subId to check the premium capability for.
11523 *
11524 * @return Whether the given premium capability is available to purchase.
11525 */
11526 @Override
11527 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11528 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11529 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11530 log("Premium capability "
11531 + TelephonyManager.convertPremiumCapabilityToString(capability)
11532 + " is not available for purchase due to missing permissions.");
11533 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11534 + "permission READ_BASIC_PHONE_STATE.");
11535 }
11536
11537 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011538 if (phone == null) {
11539 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11540 return false;
11541 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011542 final long identity = Binder.clearCallingIdentity();
11543 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011544 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011545 .isPremiumCapabilityAvailableForPurchase(capability);
11546 } finally {
11547 Binder.restoreCallingIdentity(identity);
11548 }
11549 }
11550
11551 /**
11552 * Purchase the given premium capability from the carrier.
11553 *
11554 * @param capability The premium capability to purchase.
11555 * @param callback The result of the purchase request.
11556 * @param subId The subId to purchase the premium capability for.
11557 */
11558 @Override
11559 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11560 log("purchasePremiumCapability: capability="
11561 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11562 + getCurrentPackageName());
11563
11564 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11565 mApp, "purchasePremiumCapability")) {
11566 log("purchasePremiumCapability "
11567 + TelephonyManager.convertPremiumCapabilityToString(capability)
11568 + " failed due to missing permissions.");
11569 throw new SecurityException("purchasePremiumCapability requires permission "
11570 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011571 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11572 mApp, "purchasePremiumCapability")) {
11573 log("purchasePremiumCapability "
11574 + TelephonyManager.convertPremiumCapabilityToString(capability)
11575 + " failed due to missing permissions.");
11576 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011577 }
11578
11579 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011580 if (phone == null) {
11581 try {
11582 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11583 callback.accept(result);
11584 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11585 } catch (RemoteException e) {
11586 String logStr = "Purchase premium capability "
11587 + TelephonyManager.convertPremiumCapabilityToString(capability)
11588 + " failed due to RemoteException handling null phone: " + e;
11589 if (DBG) log(logStr);
11590 AnomalyReporter.reportAnomaly(
11591 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11592 }
11593 return;
11594 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011595
11596 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011597 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011598 callingProcess = mApp.getPackageManager().getApplicationInfo(
11599 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011600 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011601 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011602 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011603
11604 boolean isVisible = false;
11605 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11606 if (am != null) {
11607 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11608 if (processes != null) {
11609 for (ActivityManager.RunningAppProcessInfo process : processes) {
11610 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011611 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011612 if (process.processName.equals(callingProcess) && process.importance
11613 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11614 isVisible = true;
11615 break;
11616 }
11617 }
11618 }
11619 }
11620
11621 if (!isVisible) {
11622 try {
11623 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11624 callback.accept(result);
11625 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11626 } catch (RemoteException e) {
11627 String logStr = "Purchase premium capability "
11628 + TelephonyManager.convertPremiumCapabilityToString(capability)
11629 + " failed due to RemoteException handling background application: " + e;
11630 if (DBG) log(logStr);
11631 AnomalyReporter.reportAnomaly(
11632 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11633 }
11634 return;
11635 }
11636
Sarah Chin71b3a852022-09-28 15:54:19 -070011637 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011638 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011639 }
11640
11641 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011642 * Register an IMS connection state callback
11643 */
11644 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011645 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11646 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011647 if (feature == ImsFeature.FEATURE_MMTEL) {
11648 // ImsMmTelManager
11649 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11650 TelephonyPermissions
11651 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11652 mApp, subId, "registerImsStateCallback");
11653 } else if (feature == ImsFeature.FEATURE_RCS) {
11654 // ImsRcsManager or SipDelegateManager
11655 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11656 Binder.getCallingUid(), "registerImsStateCallback",
11657 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11658 Manifest.permission.READ_PRECISE_PHONE_STATE,
11659 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11660 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11661 }
11662
11663 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11664 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11665 "IMS not available on device.");
11666 }
11667
11668 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11669 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11670 }
11671
11672 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11673 if (controller == null) {
11674 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11675 "IMS not available on device.");
11676 }
11677
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011678 if (callingPackage == null) {
11679 callingPackage = getCurrentPackageName();
11680 }
11681
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011682 final long token = Binder.clearCallingIdentity();
11683 try {
11684 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011685 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011686 } catch (ImsException e) {
11687 throw new ServiceSpecificException(e.getCode());
11688 } finally {
11689 Binder.restoreCallingIdentity(token);
11690 }
11691 }
11692
11693 /**
11694 * Unregister an IMS connection state callback
11695 */
11696 @Override
11697 public void unregisterImsStateCallback(IImsStateCallback cb) {
11698 final long token = Binder.clearCallingIdentity();
11699 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11700 if (controller == null) {
11701 return;
11702 }
11703 try {
11704 controller.unregisterImsStateCallback(cb);
11705 } finally {
11706 Binder.restoreCallingIdentity(token);
11707 }
11708 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011709
11710 /**
11711 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11712 *
11713 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11714 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11715 * SecurityException.
11716 * If there is current registered network this value will be same as the registered cell
11717 * identity. If the device goes out of service the previous cell identity is cached and
11718 * will be returned. If the cache age of the Cell identity is more than 24 hours
11719 * it will be cleared and null will be returned.
11720 *
11721 */
11722 @Override
11723 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11724 String callingFeatureId) {
11725 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11726 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11727 LocationAccessPolicy.checkLocationPermission(mApp,
11728 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11729 .setCallingPackage(callingPackage)
11730 .setCallingFeatureId(callingFeatureId)
11731 .setCallingPid(Binder.getCallingPid())
11732 .setCallingUid(Binder.getCallingUid())
11733 .setMethod("getLastKnownCellIdentity")
11734 .setLogAsInfo(true)
11735 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11736 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11737 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11738 .build());
11739
11740 boolean hasFinePermission =
11741 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11742 if (!hasFinePermission
11743 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11744 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011745 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011746 }
11747
11748 final long identity = Binder.clearCallingIdentity();
11749 try {
Ling Mac28f0212023-03-24 16:07:15 -070011750 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011751 if (sst == null) return null;
11752 return sst.getLastKnownCellIdentity();
11753 } finally {
11754 Binder.restoreCallingIdentity(identity);
11755 }
11756 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011757
jimsun3b9ccac2021-10-26 15:01:23 +080011758 /**
11759 * Sets the modem service class Name that Telephony will bind to.
11760 *
11761 * @param serviceName The class name of the modem service.
11762 * @return true if the operation is succeed, otherwise false.
11763 */
11764 public boolean setModemService(String serviceName) {
11765 Log.d(LOG_TAG, "setModemService - " + serviceName);
11766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011768 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11769 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011770 return mPhoneConfigurationManager.setModemService(serviceName);
11771 }
11772
11773 /**
11774 * Return the class name of the currently bounded modem service.
11775 *
11776 * @return the class name of the modem service.
11777 */
11778 public String getModemService() {
11779 String result;
11780 Log.d(LOG_TAG, "getModemService");
11781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11782 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011783 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011784 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11785 "getModemService");
11786 result = mPhoneConfigurationManager.getModemService();
11787 Log.d(LOG_TAG, "result = " + result);
11788 return result;
11789 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011790
11791 @Override
11792 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11793 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11794 mApp.enforceCallingOrSelfPermission(
11795 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11797
11798 final long identity = Binder.clearCallingIdentity();
11799 try {
11800 Phone phone = getPhone(subId);
11801 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011802 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11803 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011804 phone.setVoiceServiceStateOverride(hasService);
11805 } finally {
11806 Binder.restoreCallingIdentity(identity);
11807 }
11808 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011809
11810 /**
11811 * set removable eSIM as default eUICC.
11812 *
11813 * @hide
11814 */
11815 @Override
11816 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11817 enforceModifyPermission();
11818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11819
11820 final long identity = Binder.clearCallingIdentity();
11821 try {
11822 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11823 } finally {
11824 Binder.restoreCallingIdentity(identity);
11825 }
11826 }
11827
11828 /**
11829 * Returns whether the removable eSIM is default eUICC or not.
11830 *
11831 * @hide
11832 */
11833 @Override
11834 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11835 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11836 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11837
11838 final long identity = Binder.clearCallingIdentity();
11839 try {
11840 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11841 } finally {
11842 Binder.restoreCallingIdentity(identity);
11843 }
11844 }
11845
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011846 /**
11847 * Get the component name of the default app to direct respond-via-message intent for the
11848 * user associated with this subscription, update the cache if there is no respond-via-message
11849 * application currently configured for this user.
11850 * @return component name of the app and class to direct Respond Via Message intent to, or
11851 * {@code null} if the functionality is not supported.
11852 * @hide
11853 */
11854 @Override
11855 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11856 boolean updateIfNeeded) {
11857 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011858
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011859 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11860
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011861 UserHandle userHandle = null;
11862 final long identity = Binder.clearCallingIdentity();
11863 try {
11864 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11865 } finally {
11866 Binder.restoreCallingIdentity(identity);
11867 }
11868 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11869 updateIfNeeded, userHandle);
11870 }
Jack Yuf5badd92022-12-08 00:50:53 -080011871
11872 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011873 * Set whether the device is able to connect with null ciphering or integrity
11874 * algorithms. This is a global setting and will apply to all active subscriptions
11875 * and all new subscriptions after this.
11876 *
11877 * @param enabled when true, null cipher and integrity algorithms are allowed.
11878 * @hide
11879 */
11880 @Override
11881 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11882 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11883 enforceModifyPermission();
11884 checkForNullCipherAndIntegritySupport();
11885
11886 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11887 // for listening to these preference changes and applying them immediately.
11888 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11889 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11890 editor.apply();
11891
11892 for (Phone phone: PhoneFactory.getPhones()) {
11893 phone.handleNullCipherEnabledChange();
11894 }
11895 }
11896
11897
11898 /**
11899 * Get whether the device is able to connect with null ciphering or integrity
11900 * algorithms. Note that this retrieves the phone-global preference and not
11901 * the state of the radio.
11902 *
11903 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11904 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11905 * version for this feature.
11906 * @hide
11907 */
11908 @Override
11909 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11910 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11911 enforceReadPermission();
11912 checkForNullCipherAndIntegritySupport();
11913 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11914 }
11915
11916 private void checkForNullCipherAndIntegritySupport() {
11917 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11918 throw new UnsupportedOperationException(
11919 "Null cipher and integrity operations require HAL 2.1 or above");
11920 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011921 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11922 throw new UnsupportedOperationException(
11923 "Null cipher and integrity operations unsupported by modem");
11924 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011925 }
11926
11927 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011928 * Get the SIM state for the slot index.
11929 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11930 *
11931 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11932 */
11933 @Override
11934 @SimState
11935 public int getSimStateForSlotIndex(int slotIndex) {
11936 IccCardConstants.State simState;
11937 if (slotIndex < 0) {
11938 simState = IccCardConstants.State.UNKNOWN;
11939 } else {
11940 Phone phone = null;
11941 try {
11942 phone = PhoneFactory.getPhone(slotIndex);
11943 } catch (IllegalStateException e) {
11944 // ignore
11945 }
11946 if (phone == null) {
11947 simState = IccCardConstants.State.UNKNOWN;
11948 } else {
11949 IccCard icc = phone.getIccCard();
11950 if (icc == null) {
11951 simState = IccCardConstants.State.UNKNOWN;
11952 } else {
11953 simState = icc.getState();
11954 }
11955 }
11956 }
11957 return simState.ordinal();
11958 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011959
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011960 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11961 boolean enableLogcat,
11962 long logcatStartTimestampMillis, boolean enableTelecomDump,
11963 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011964 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11965 TelephonyManager.EmergencyCallDiagnosticParams edp =
11966 new TelephonyManager.EmergencyCallDiagnosticParams();
11967 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11968 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11969 edp.setTelecomDumpSysCollection(enableTelecomDump);
11970 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11971 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
11972 Executors.newCachedThreadPool(), db,
11973 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
11974 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011975 }
11976
11977 /**
11978 * Request telephony to persist state for debugging emergency call failures.
11979 *
11980 * @param dropBoxTag Tag to use when persisting data to dropbox service.
11981 * @param enableLogcat whether to collect logcat output
11982 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
11983 * @param enableTelecomDump whether to collect telecom dumpsys
11984 * @param enableTelephonyDump whether to collect telephony dumpsys
11985 */
11986 @Override
11987 @RequiresPermission(android.Manifest.permission.DUMP)
11988 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
11989 long logcatStartTimestampMillis, boolean enableTelecomDump,
11990 boolean enableTelephonyDump) {
11991 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
11992 "persistEmergencyCallDiagnosticData");
11993 final long identity = Binder.clearCallingIdentity();
11994 try {
11995 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
11996 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
11997
11998 } finally {
11999 Binder.restoreCallingIdentity(identity);
12000 }
12001 }
12002
Hui Wang9b5793a2022-12-05 14:38:06 -060012003 /**
12004 * Get current cell broadcast ranges.
12005 */
12006 @Override
12007 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12008 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12009 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12010 "getCellBroadcastIdRanges");
12011 final long identity = Binder.clearCallingIdentity();
12012 try {
12013 return getPhone(subId).getCellBroadcastIdRanges();
12014 } finally {
12015 Binder.restoreCallingIdentity(identity);
12016 }
12017 }
12018
12019 /**
12020 * Set reception of cell broadcast messages with the list of the given ranges
12021 *
12022 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12023 */
12024 @Override
12025 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12026 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12027 @Nullable IIntegerConsumer callback) {
12028 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12029 "setCellBroadcastIdRanges");
12030 final long identity = Binder.clearCallingIdentity();
12031 try {
12032 Phone phone = getPhoneFromSubId(subId);
12033 if (DBG) {
12034 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12035 }
12036 phone.setCellBroadcastIdRanges(ranges, result -> {
12037 if (callback != null) {
12038 try {
12039 callback.accept(result);
12040 } catch (RemoteException e) {
12041 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12042 }
12043 }
12044 });
12045 } finally {
12046 Binder.restoreCallingIdentity(identity);
12047 }
12048 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012049
12050 /**
12051 * Returns whether the device supports the domain selection service.
12052 *
12053 * @return {@code true} if the device supports the domain selection service.
12054 */
12055 @Override
12056 public boolean isDomainSelectionSupported() {
12057 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12058 "isDomainSelectionSupported");
12059
12060 final long identity = Binder.clearCallingIdentity();
12061 try {
12062 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12063 } finally {
12064 Binder.restoreCallingIdentity(identity);
12065 }
12066 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012067
12068 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012069 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12070 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12071 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012072 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012073 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012074 * @param enableSatellite {@code true} to enable the satellite modem and
12075 * {@code false} to disable.
12076 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12077 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012078 *
12079 * @throws SecurityException if the caller doesn't have the required permission.
12080 */
12081 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012082 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12083 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012084 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012085 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12086 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012087 }
12088
12089 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012090 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012091 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012092 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012093 * @param result The result receiver that returns whether the satellite modem is enabled
12094 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012095 *
12096 * @throws SecurityException if the caller doesn't have the required permission.
12097 */
12098 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012099 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12100 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012101 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012102 }
12103
12104 /**
Sarah Chin43457982023-02-15 17:50:38 -080012105 * Request to get whether the satellite service demo mode is enabled.
12106 *
12107 * @param subId The subId of the subscription to check whether the satellite demo mode
12108 * is enabled for.
12109 * @param result The result receiver that returns whether the satellite demo mode is enabled
12110 * if the request is successful or an error code if the request failed.
12111 *
12112 * @throws SecurityException if the caller doesn't have the required permission.
12113 */
12114 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012115 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12116 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12117 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012118 }
12119
12120 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012121 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012122 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012123 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012124 * @param result The result receiver that returns whether the satellite service is supported on
12125 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012126 */
12127 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012128 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012129 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012130 }
12131
12132 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012133 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012134 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012135 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012136 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12137 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012138 *
12139 * @throws SecurityException if the caller doesn't have required permission.
12140 */
12141 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012142 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12143 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012144 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012145 }
12146
12147 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012148 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012149 * This can be called by the pointing UI when the user starts pointing to the satellite.
12150 * Modem should continue to report the pointing input as the device or satellite moves.
12151 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012152 * @param subId The subId of the subscription to start satellite transmission updates for.
12153 * @param resultCallback The callback to get the result of the request.
12154 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012155 *
12156 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012157 */
12158 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012159 public void startSatelliteTransmissionUpdates(int subId,
12160 @NonNull IIntegerConsumer resultCallback,
12161 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12162 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12163 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012164 }
12165
12166 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012167 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012168 * This can be called by the pointing UI when the user stops pointing to the satellite.
12169 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012170 * @param subId The subId of the subscription to stop satellite transmission updates for.
12171 * @param resultCallback The callback to get the result of the request.
12172 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12173 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012174 *
12175 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012176 */
12177 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012178 public void stopSatelliteTransmissionUpdates(int subId,
12179 @NonNull IIntegerConsumer resultCallback,
12180 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12181 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12182 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012183 }
12184
12185 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012186 * Register the subscription with a satellite provider.
12187 * This is needed to register the subscription if the provider allows dynamic registration.
12188 *
12189 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012190 * @param token The token to be used as a unique identifier for provisioning with satellite
12191 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012192 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012193 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012194 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012195 * @return The signal transport used by the caller to cancel the provision request,
12196 * or {@code null} if the request failed.
12197 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012198 * @throws SecurityException if the caller doesn't have the required permission.
12199 */
12200 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012201 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012202 @NonNull String token, @NonNull byte[] provisionData,
12203 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012204 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012205 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12206 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012207 }
12208
12209 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012210 * Unregister the device/subscription with the satellite provider.
12211 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012212 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012213 * should report as deprovisioned.
12214 *
12215 * @param subId The subId of the subscription to be deprovisioned.
12216 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012217 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012218 *
12219 * @throws SecurityException if the caller doesn't have the required permission.
12220 */
12221 @Override
12222 public void deprovisionSatelliteService(int subId,
12223 @NonNull String token, @NonNull IIntegerConsumer callback) {
12224 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012225 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012226 }
12227
12228 /**
Sarah Chin43457982023-02-15 17:50:38 -080012229 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012230 *
Sarah Chin43457982023-02-15 17:50:38 -080012231 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012232 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012233 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012234 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012235 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012236 * @throws SecurityException if the caller doesn't have the required permission.
12237 */
12238 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012239 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12240 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012241 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012242 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012243 }
12244
12245 /**
Sarah Chin43457982023-02-15 17:50:38 -080012246 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012247 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012248 *
Sarah Chin43457982023-02-15 17:50:38 -080012249 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012250 * @param callback The callback that was passed to
12251 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012252 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012253 * @throws SecurityException if the caller doesn't have the required permission.
12254 */
12255 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012256 public void unregisterForSatelliteProvisionStateChanged(
12257 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012258 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012259 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012260 }
12261
12262 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012263 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012264 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012265 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012266 * @param result The result receiver that returns whether the device is provisioned with a
12267 * satellite provider if the request is successful or an error code if the
12268 * request failed.
12269 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012270 * @throws SecurityException if the caller doesn't have the required permission.
12271 */
12272 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012273 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12274 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012275 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012276 }
12277
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012278 /**
Sarah Chin43457982023-02-15 17:50:38 -080012279 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012280 *
Sarah Chin43457982023-02-15 17:50:38 -080012281 * @param subId The subId of the subscription to register for satellite modem state changed.
12282 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012283 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012284 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012285 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012286 * @throws SecurityException if the caller doesn't have the required permission.
12287 */
12288 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012289 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012290 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012291 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012292 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012293 }
12294
12295 /**
Sarah Chin43457982023-02-15 17:50:38 -080012296 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012297 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012298 *
Sarah Chin43457982023-02-15 17:50:38 -080012299 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012300 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012301 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012302 *
12303 * @throws SecurityException if the caller doesn't have the required permission.
12304 */
12305 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012306 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012307 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012308 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012309 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012310 }
12311
12312 /**
12313 * Register to receive incoming datagrams over satellite.
12314 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012315 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012316 * @param callback The callback to handle incoming datagrams over satellite.
12317 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012318 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012319 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012320 * @throws SecurityException if the caller doesn't have the required permission.
12321 */
12322 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012323 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012324 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012325 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012326 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012327 }
12328
12329 /**
12330 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012331 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012332 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012333 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12334 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012335 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012336 *
12337 * @throws SecurityException if the caller doesn't have the required permission.
12338 */
12339 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012340 public void unregisterForSatelliteDatagram(int subId,
12341 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012342 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012343 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012344 }
12345
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012346 /**
12347 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012348 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012349 * This method requests modem to check if there are any pending datagrams to be received over
12350 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012351 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012352 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012353 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012354 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012355 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012356 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012357 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012358 @Override
12359 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012360 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012361 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012362 }
12363
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012364 /**
12365 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012366 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012367 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12368 * input to this method. Datagram received here will be passed down to modem without any
12369 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012370 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012371 * @param subId The subId of the subscription to send satellite datagrams for.
12372 * @param datagramType datagram type indicating whether the datagram is of type
12373 * SOS_SMS or LOCATION_SHARING.
12374 * @param datagram encoded gateway datagram which is encrypted by the caller.
12375 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012376 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12377 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012378 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012379 *
12380 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012381 */
12382 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012383 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12384 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12385 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012386 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012387 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12388 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012389 }
12390
Sarah Chindf715ec2023-02-13 13:46:24 -080012391 /**
12392 * Request to get whether satellite communication is allowed for the current location.
12393 *
12394 * @param subId The subId of the subscription to check whether satellite communication is
12395 * allowed for the current location for.
12396 * @param result The result receiver that returns whether satellite communication is allowed
12397 * for the current location if the request is successful or an error code
12398 * if the request failed.
12399 *
12400 * @throws SecurityException if the caller doesn't have the required permission.
12401 */
12402 @Override
12403 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12404 @NonNull ResultReceiver result) {
12405 enforceSatelliteCommunicationPermission(
12406 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012407 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12408 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012409 }
12410
12411 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012412 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012413 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012414 * @param subId The subId to get the time after which the satellite will be visible for.
12415 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012416 * be visible if the request is successful or an error code if the request failed.
12417 *
12418 * @throws SecurityException if the caller doesn't have the required permission.
12419 */
12420 @Override
12421 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12422 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012423 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012424 }
12425
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012426 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012427 * Inform that Device is aligned to satellite for demo mode.
12428 *
12429 * @param subId The subId to get the time after which the satellite will be visible for.
12430 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12431 * {@code false} Device fails to align with the satellite for demo mode.
12432 *
12433 * @throws SecurityException if the caller doesn't have required permission.
12434 */
12435 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12436
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012437 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012438 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012439 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012440 }
12441
12442 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012443 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12444 * by modem.
12445 *
12446 * @param subId The subId of the subscription to request for.
12447 * @param reason Reason for disallowing satellite communication for carrier.
12448 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12449 * operation.
12450 *
12451 * @throws SecurityException if the caller doesn't have required permission.
12452 */
12453 public void addSatelliteAttachRestrictionForCarrier(int subId,
12454 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12455 @NonNull IIntegerConsumer callback) {
12456 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12457 final long identity = Binder.clearCallingIdentity();
12458 try {
12459 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12460 } finally {
12461 Binder.restoreCallingIdentity(identity);
12462 }
12463 }
12464
12465 /**
12466 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12467 * by modem.
12468 *
12469 * @param subId The subId of the subscription to request for.
12470 * @param reason Reason for disallowing satellite communication.
12471 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12472 * operation.
12473 *
12474 * @throws SecurityException if the caller doesn't have required permission.
12475 */
12476 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12477 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12478 @NonNull IIntegerConsumer callback) {
12479 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12480 final long identity = Binder.clearCallingIdentity();
12481 try {
12482 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12483 callback);
12484 } finally {
12485 Binder.restoreCallingIdentity(identity);
12486 }
12487 }
12488
12489 /**
12490 * Get reasons for disallowing satellite communication, as requested by
12491 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12492 *
12493 * @param subId The subId of the subscription to request for.
12494 *
12495 * @return Integer array of reasons for disallowing satellite communication.
12496 *
12497 * @throws SecurityException if the caller doesn't have the required permission.
12498 */
12499 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12500 int subId) {
12501 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12502 final long identity = Binder.clearCallingIdentity();
12503 try {
12504 Set<Integer> reasonSet =
12505 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12506 return reasonSet.stream().mapToInt(i->i).toArray();
12507 } finally {
12508 Binder.restoreCallingIdentity(identity);
12509 }
12510 }
12511
12512 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012513 * This API can be used by only CTS to update satellite vendor service package name.
12514 *
12515 * @param servicePackageName The package name of the satellite vendor service.
12516 * @return {@code true} if the satellite vendor service is set successfully,
12517 * {@code false} otherwise.
12518 */
12519 public boolean setSatelliteServicePackageName(String servicePackageName) {
12520 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12521 TelephonyPermissions.enforceShellOnly(
12522 Binder.getCallingUid(), "setSatelliteServicePackageName");
12523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12524 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12525 "setSatelliteServicePackageName");
12526 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12527 }
12528
12529 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012530 * This API can be used by only CTS to update satellite gateway service package name.
12531 *
12532 * @param servicePackageName The package name of the satellite gateway service.
12533 * @return {@code true} if the satellite gateway service is set successfully,
12534 * {@code false} otherwise.
12535 */
12536 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12537 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12538 TelephonyPermissions.enforceShellOnly(
12539 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12541 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12542 "setSatelliteGatewayServicePackageName");
12543 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12544 }
12545
12546 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012547 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12548 *
12549 * @param packageName The package name of the satellite pointing UI app.
12550 * @param className The class name of the satellite pointing UI app.
12551 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12552 * {@code false} otherwise.
12553 */
12554 public boolean setSatellitePointingUiClassName(
12555 @Nullable String packageName, @Nullable String className) {
12556 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12557 + ", className=" + className);
12558 TelephonyPermissions.enforceShellOnly(
12559 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12561 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12562 "setSatelliteGatewayServicePackageName");
12563 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12564 }
12565
12566 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012567 * This API can be used by only CTS to update the timeout duration in milliseconds that
12568 * satellite should stay at listening mode to wait for the next incoming page before disabling
12569 * listening mode.
12570 *
12571 * @param timeoutMillis The timeout duration in millisecond.
12572 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12573 */
12574 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12575 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12576 TelephonyPermissions.enforceShellOnly(
12577 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12579 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12580 "setSatelliteListeningTimeoutDuration");
12581 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12582 }
12583
12584 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012585 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12586 * the device is aligned with the satellite for demo mode
12587 *
12588 * @param timeoutMillis The timeout duration in millisecond.
12589 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12590 */
12591 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12592 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12593 TelephonyPermissions.enforceShellOnly(
12594 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12596 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12597 "setDeviceAlignedTimeoutDuration");
12598 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12599 }
12600
12601 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012602 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12603 *
12604 * <p>This method behaves in one of the following ways:
12605 * <ul>
12606 * <li>return true : if the calling package has the appop permission {@link
12607 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12608 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12609 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12610 * Owner device identifier access check, or the calling package has carrier privileges</>
12611 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12612 * </ul>
12613 */
12614 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12615 String callingPackage, @Nullable String callingFeatureId, String message) {
12616 for (Phone phone : PhoneFactory.getPhones()) {
12617 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12618 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12619 return true;
12620 }
12621 }
12622 return false;
12623 }
arunvoddud7401012022-12-15 16:08:12 +000012624
12625 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012626 * @return The subscription manager service instance.
12627 */
12628 public SubscriptionManagerService getSubscriptionManagerService() {
12629 return SubscriptionManagerService.getInstance();
12630 }
12631
12632 /**
arunvoddud7401012022-12-15 16:08:12 +000012633 * Class binds the consumer[callback] and carrierId.
12634 */
12635 private static class CallerCallbackInfo {
12636 private final Consumer<Integer> mConsumer;
12637 private final int mCarrierId;
12638
12639 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12640 mConsumer = consumer;
12641 mCarrierId = carrierId;
12642 }
12643
12644 public Consumer<Integer> getConsumer() {
12645 return mConsumer;
12646 }
12647
12648 public int getCarrierId() {
12649 return mCarrierId;
12650 }
12651 }
Jack Yufa8ed012023-02-11 15:42:28 -080012652}