blob: fdb0ead358faca74b2ec3d4fecaece1b23bed3e9 [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 Nguyenb47fc3c2023-04-06 13:30:32 -07003024 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003025 if (phone != null) {
3026 phone.setRadioPowerForReason(false, reason);
3027 return true;
3028 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003029 loge("requestRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003030 return false;
3031 }
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
3037 /**
3038 * Remove the vote on powering off the radio for a reason, as requested by
3039 * {@link requestRadioPowerOffForReason}.
3040 *
3041 * @param subId The subscription ID.
3042 * @param reason The reason for powering off radio.
3043 * @return true on success and false on failure.
3044 */
3045 public boolean clearRadioPowerOffForReason(int subId,
3046 @TelephonyManager.RadioPowerReason int reason) {
3047 enforceModifyPermission();
3048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003051 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003052 if (phone != null) {
3053 phone.setRadioPowerForReason(true, reason);
3054 return true;
3055 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003056 loge("clearRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003057 return false;
3058 }
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
3062 }
3063
3064 /**
3065 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3066 *
3067 * @param subId The subscription ID.
3068 * @param callingPackage The package making the call.
3069 * @param callingFeatureId The feature in the package.
3070 * @return List of reasons for powering off radio.
3071 */
3072 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3073 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3074
3075 final long identity = Binder.clearCallingIdentity();
3076 List result = new ArrayList();
3077 try {
3078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3079 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3080 return result;
3081 }
3082
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003083 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003084 if (phone != null) {
3085 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003086 } else {
3087 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003088 }
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
3092 return result;
3093 }
3094
Wink Saville36469e72014-06-11 15:17:00 -07003095 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003096 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003097 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
Jack Yu285100e2022-12-02 22:48:35 -08003102 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final Phone phone = getPhone(subId);
3104 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003105 phone.getDataSettingsManager().setDataEnabled(
3106 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 return true;
3108 } else {
3109 return false;
3110 }
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 }
3115
Wink Saville36469e72014-06-11 15:17:00 -07003116 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003117 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003118 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120
3121 final long identity = Binder.clearCallingIdentity();
3122 try {
Jack Yu285100e2022-12-02 22:48:35 -08003123 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124 final Phone phone = getPhone(subId);
3125 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003126 phone.getDataSettingsManager().setDataEnabled(
3127 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003128 return true;
3129 } else {
3130 return false;
3131 }
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 }
3136
Sanket Padawe356d7632015-06-22 14:03:32 -07003137 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003138 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 final Phone phone = getPhone(subId);
3142 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003143 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 } else {
3145 return false;
3146 }
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
3151
3152 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003153 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003154 }
3155
pkanwarae03a6b2016-11-06 20:37:09 -08003156 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 enforceCallPermission();
3158
3159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3162 return;
3163 }
3164 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3165 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
3168 }
pkanwar32d516d2016-10-14 19:37:38 -07003169 };
3170
Wink Savilleb564aae2014-10-23 10:18:09 -07003171 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173
3174 final long identity = Binder.clearCallingIdentity();
3175 try {
3176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3177 return false;
3178 }
3179 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 }
3184
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003185 /**
3186 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3187 * tag on getCallState Binder call.
3188 */
3189 @Deprecated
3190 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003192 if (CompatChanges.isChangeEnabled(
3193 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3194 Binder.getCallingUid())) {
3195 // Do not allow this API to be called on API version 31+, it should only be
3196 // called on old apps using this Binder call directly.
3197 throw new SecurityException("This method can only be used for applications "
3198 + "targeting API version 30 or less.");
3199 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
Ling Mac28f0212023-03-24 16:07:15 -07003202 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3203 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
3207 }
3208
3209 @Override
3210 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3211 if (CompatChanges.isChangeEnabled(
3212 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3213 Binder.getCallingUid())) {
3214 // Check READ_PHONE_STATE for API version 31+
3215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3216 featureId, "getCallStateForSubscription")) {
3217 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3218 + "targeting API level 31+.");
3219 }
3220 }
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3225 PhoneConstantConversions.convertCallState(phone.getState());
3226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003229 }
3230
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003232 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003233 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003234 }
3235
3236 @Override
3237 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 final long identity = Binder.clearCallingIdentity();
3239 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003240 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003242 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243 } else {
3244 return PhoneConstantConversions.convertDataState(
3245 PhoneConstants.DataState.DISCONNECTED);
3246 }
3247 } finally {
3248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 }
3251
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003253 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003254 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003255 }
3256
3257 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003258 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259 final long identity = Binder.clearCallingIdentity();
3260 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003261 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003263 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003264 } else {
3265 return TelephonyManager.DATA_ACTIVITY_NONE;
3266 }
3267 } finally {
3268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 }
3271
3272 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003273 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003275 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003276
3277 LocationAccessPolicy.LocationPermissionResult locationResult =
3278 LocationAccessPolicy.checkLocationPermission(mApp,
3279 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3280 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003281 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003282 .setCallingPid(Binder.getCallingPid())
3283 .setCallingUid(Binder.getCallingUid())
3284 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003285 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003286 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3287 .build());
3288 switch (locationResult) {
3289 case DENIED_HARD:
3290 throw new SecurityException("Not allowed to access cell location");
3291 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003292 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3293 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003294 }
3295
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003300 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003301 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
Svetoslav64fad262015-04-14 14:35:21 -07003305 }
3306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003308 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003309 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3310 // registered cell info, so return a NULL country instead.
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003313 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3314 // Get default phone in this case.
3315 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3316 }
Jack Yu285100e2022-12-02 22:48:35 -08003317 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003319 if (phone == null) return "";
3320 ServiceStateTracker sst = phone.getServiceStateTracker();
3321 if (sst == null) return "";
3322 LocaleTracker lt = sst.getLocaleTracker();
3323 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003324 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003328 }
3329
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003330 /**
3331 * This method was removed due to potential issues caused by performing partial
3332 * updates of service state, and lack of a credible use case.
3333 *
3334 * This has the ability to break the telephony implementation by disabling notification of
3335 * changes in device connectivity. DO NOT USE THIS!
3336 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003337 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003338 public void enableLocationUpdates() {
3339 mApp.enforceCallingOrSelfPermission(
3340 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003341 }
3342
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003343 /**
3344 * This method was removed due to potential issues caused by performing partial
3345 * updates of service state, and lack of a credible use case.
3346 *
3347 * This has the ability to break the telephony implementation by disabling notification of
3348 * changes in device connectivity. DO NOT USE THIS!
3349 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 @Override
3351 public void disableLocationUpdates() {
3352 mApp.enforceCallingOrSelfPermission(
3353 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354 }
3355
3356 @Override
3357 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003358 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3359 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003360 try {
3361 mApp.getSystemService(AppOpsManager.class)
3362 .checkPackage(Binder.getCallingUid(), callingPackage);
3363 } catch (SecurityException e) {
3364 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3365 throw e;
3366 }
3367
Nathan Haroldf096d982020-11-18 17:18:06 -08003368 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003369 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3370 throw new SecurityException(
3371 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3372 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003373
Jordan Liu1617b712019-07-10 15:06:26 -07003374 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003375 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3376 return null;
3377 }
Svetoslav64fad262015-04-14 14:35:21 -07003378
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003379 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003380
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003381 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003382 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383
Nathan Haroldf180aac2018-06-01 18:43:55 -07003384 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3385 for (CellInfo ci : info) {
3386 if (ci instanceof CellInfoGsm) {
3387 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3388 } else if (ci instanceof CellInfoWcdma) {
3389 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003391 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003392 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393 }
3394
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003395 private List<CellInfo> getCachedCellInfo() {
3396 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3397 for (Phone phone : PhoneFactory.getPhones()) {
3398 List<CellInfo> info = phone.getAllCellInfo();
3399 if (info != null) cellInfos.addAll(info);
3400 }
3401 return cellInfos;
3402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403
3404 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003405 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003406 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003407 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003408
3409 LocationAccessPolicy.LocationPermissionResult locationResult =
3410 LocationAccessPolicy.checkLocationPermission(mApp,
3411 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3412 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003413 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003414 .setCallingPid(Binder.getCallingPid())
3415 .setCallingUid(Binder.getCallingUid())
3416 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003417 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003418 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3419 .build());
3420 switch (locationResult) {
3421 case DENIED_HARD:
3422 throw new SecurityException("Not allowed to access cell info");
3423 case DENIED_SOFT:
3424 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 }
3426
Nathan Haroldf096d982020-11-18 17:18:06 -08003427 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003428 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3429 return getCachedCellInfo();
3430 }
3431
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003432 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003433 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3437 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003438 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003439 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440 if (info != null) cellInfos.addAll(info);
3441 }
3442 return cellInfos;
3443 } finally {
3444 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446 }
3447
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003448 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003449 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3450 String callingFeatureId) {
3451 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3452 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003453 }
3454
3455 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003456 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3457 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003458 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003459 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003460 }
3461
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003462 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3463 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003465 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003466
3467 LocationAccessPolicy.LocationPermissionResult locationResult =
3468 LocationAccessPolicy.checkLocationPermission(mApp,
3469 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3470 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003471 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003472 .setCallingPid(Binder.getCallingPid())
3473 .setCallingUid(Binder.getCallingUid())
3474 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003475 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3476 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003477 .build());
3478 switch (locationResult) {
3479 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003480 if (TelephonyPermissions
3481 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003482 // Safetynet logging for b/154934934
3483 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3484 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003485 throw new SecurityException("Not allowed to access cell info");
3486 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003487 if (TelephonyPermissions
3488 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003489 // Safetynet logging for b/154934934
3490 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3491 }
Nathan Harold5320c422019-05-09 10:26:08 -07003492 try {
3493 cb.onCellInfo(new ArrayList<CellInfo>());
3494 } catch (RemoteException re) {
3495 // Drop without consequences
3496 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003497 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003498 }
3499
Nathan Harolda939a962019-05-09 10:13:47 -07003500
3501 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003502 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3503
3504 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3505 }
3506
3507 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003508 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003509 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003514 Phone phone = getPhone(subId);
3515 if (phone == null) {
3516 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3517 } else {
3518 phone.setCellInfoListRate(rateInMillis, workSource);
3519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 } finally {
3521 Binder.restoreCallingIdentity(identity);
3522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 }
3524
Shishir Agrawala9f32182016-04-12 12:00:16 -07003525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003526 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003527 Phone phone = PhoneFactory.getPhone(slotIndex);
3528 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003529 return null;
3530 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003531 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003532 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003533 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003534 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003535 return null;
3536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 return phone.getImei();
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003544 }
3545
3546 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003547 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3548 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3549 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3550 callingFeatureId, "getPrimaryImei")) {
3551 throw new SecurityException("Caller does not have permission");
3552 }
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 for (Phone phone : PhoneFactory.getPhones()) {
3556 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3557 return phone.getImei();
3558 }
3559 }
3560 throw new UnsupportedOperationException("Operation not supported");
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
3564 }
3565
3566 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003567 public String getTypeAllocationCodeForSlot(int slotIndex) {
3568 Phone phone = PhoneFactory.getPhone(slotIndex);
3569 String tac = null;
3570 if (phone != null) {
3571 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003572 try {
3573 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3574 } catch (IndexOutOfBoundsException e) {
3575 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3576 return null;
3577 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003578 }
3579 return tac;
3580 }
3581
3582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003583 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003584 try {
3585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3586 } catch (SecurityException se) {
3587 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3588 throw new SecurityException("Package " + callingPackage + " does not belong to "
3589 + Binder.getCallingUid());
3590 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003591 Phone phone = PhoneFactory.getPhone(slotIndex);
3592 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003593 return null;
3594 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595
Jeff Davidson913390f2018-02-23 17:11:49 -08003596 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003597 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003598 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003599 return null;
3600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601
3602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 return phone.getMeid();
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
Jack Yu2af8d712017-03-15 17:14:14 -07003608 }
3609
3610 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003611 public String getManufacturerCodeForSlot(int slotIndex) {
3612 Phone phone = PhoneFactory.getPhone(slotIndex);
3613 String manufacturerCode = null;
3614 if (phone != null) {
3615 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003616 try {
3617 manufacturerCode =
3618 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3619 } catch (IndexOutOfBoundsException e) {
3620 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3621 return null;
3622 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003623 }
3624 return manufacturerCode;
3625 }
3626
3627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003628 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3629 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003630 Phone phone = PhoneFactory.getPhone(slotIndex);
3631 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003632 return null;
3633 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003634 int subId = phone.getSubId();
3635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003636 mApp, subId, callingPackage, callingFeatureId,
3637 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003638 return null;
3639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640
3641 final long identity = Binder.clearCallingIdentity();
3642 try {
3643 return phone.getDeviceSvn();
3644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003647 }
3648
fionaxu43304da2017-11-27 22:51:16 -08003649 @Override
3650 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 final Phone phone = getPhone(subId);
3654 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
fionaxu43304da2017-11-27 22:51:16 -08003658 }
3659
3660 @Override
3661 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
3665 return phone == null ? null : phone.getCarrierName();
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
fionaxu43304da2017-11-27 22:51:16 -08003669 }
3670
calvinpanffe225e2018-11-01 19:43:06 +08003671 @Override
chen xu0026ca62019-03-06 15:28:50 -08003672 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 final Phone phone = getPhone(subId);
3676 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003677 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
3681 }
3682
3683 @Override
chen xu0026ca62019-03-06 15:28:50 -08003684 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003688 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
3692 }
3693
chen xu651eec72018-11-11 19:03:44 -08003694 @Override
chen xu864e11c2018-12-06 22:10:03 -08003695 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3696 if (!isSubscriptionMccMnc) {
3697 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3698 }
chen xu651eec72018-11-11 19:03:44 -08003699 final Phone phone = PhoneFactory.getPhone(slotIndex);
3700 if (phone == null) {
3701 return TelephonyManager.UNKNOWN_CARRIER_ID;
3702 }
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
3709 }
3710
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003711 //
3712 // Internal helper methods.
3713 //
3714
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003715 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003716 * Make sure the caller is the calling package itself
3717 *
3718 * @throws SecurityException if the caller is not the calling package
3719 */
3720 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3721 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003722 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3723 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003724 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003725 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003726 } catch (PackageManager.NameNotFoundException e) {
3727 // packageUid is -1
3728 }
3729 if (packageUid != callingUid) {
3730 throw new SecurityException(message + ": Package " + callingPackage
3731 + " does not belong to " + callingUid);
3732 }
3733 }
3734
3735 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003736 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3737 *
3738 * @throws SecurityException if the caller does not have the required permission
3739 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003740 @VisibleForTesting
3741 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003742 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3743 }
3744
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003745 /**
arunvoddud7401012022-12-15 16:08:12 +00003746 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003747 *
3748 * @throws SecurityException if the caller does not have the required permission
3749 */
3750 @VisibleForTesting
3751 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003752 enforceReadPermission(null);
3753 }
3754
3755 /**
3756 * Make sure the caller has the READ_PHONE_STATE permissions.
3757 *
3758 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3759 */
3760 @VisibleForTesting
3761 public void enforceReadPermission(String msg) {
3762 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003763 }
3764
Shuo Qian3b6ee772019-11-13 17:43:31 -08003765 private void enforceActiveEmergencySessionPermission() {
3766 mApp.enforceCallingOrSelfPermission(
3767 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3768 }
3769
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003770 /**
3771 * Make sure the caller has the CALL_PHONE permission.
3772 *
3773 * @throws SecurityException if the caller does not have the required permission
3774 */
3775 private void enforceCallPermission() {
3776 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3777 }
3778
paulhu5a773602019-08-23 19:17:33 +08003779 private void enforceSettingsPermission() {
3780 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003781 }
3782
Michele Berionne5e411512020-11-13 02:36:59 +00003783 private void enforceRebootPermission() {
3784 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3785 }
3786
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003787 /**
3788 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3789 * @param message - log message to print.
3790 * @throws SecurityException if the caller does not have the required permission
3791 */
3792 private void enforceSatelliteCommunicationPermission(String message) {
3793 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3794 }
3795
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003796 private String createTelUrl(String number) {
3797 if (TextUtils.isEmpty(number)) {
3798 return null;
3799 }
3800
Jake Hambye994d462014-02-03 13:10:13 -08003801 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003802 }
3803
Ihab Awadf9e92732013-12-05 18:02:52 -08003804 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003805 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003806 }
3807
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003808 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003809 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003810 }
3811
Ihab Awadf9e92732013-12-05 18:02:52 -08003812 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003813 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003814 }
3815
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003817 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003818 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003819 }
3820
Sanket Padawe356d7632015-06-22 14:03:32 -07003821 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003822 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 final Phone phone = PhoneFactory.getPhone(slotIndex);
3826 if (phone == null) {
3827 return PhoneConstants.PHONE_TYPE_NONE;
3828 } else {
3829 return phone.getPhoneType();
3830 }
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003834 }
3835
3836 /**
3837 * Returns the CDMA ERI icon index to display
3838 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003839 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003840 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3841 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3842 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003843 }
3844
Sanket Padawe356d7632015-06-22 14:03:32 -07003845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003846 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3847 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003849 mApp, subId, callingPackage, callingFeatureId,
3850 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003851 return -1;
3852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853
3854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 final Phone phone = getPhone(subId);
3857 if (phone != null) {
3858 return phone.getCdmaEriIconIndex();
3859 } else {
3860 return -1;
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003865 }
3866
3867 /**
3868 * Returns the CDMA ERI icon mode,
3869 * 0 - ON
3870 * 1 - FLASHING
3871 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003872 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003873 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3874 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3875 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003876 }
3877
Sanket Padawe356d7632015-06-22 14:03:32 -07003878 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003879 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3880 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003882 mApp, subId, callingPackage, callingFeatureId,
3883 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003884 return -1;
3885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886
3887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 final Phone phone = getPhone(subId);
3890 if (phone != null) {
3891 return phone.getCdmaEriIconMode();
3892 } else {
3893 return -1;
3894 }
3895 } finally {
3896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003898 }
3899
3900 /**
3901 * Returns the CDMA ERI text,
3902 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003903 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003904 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3905 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3906 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003907 }
3908
Sanket Padawe356d7632015-06-22 14:03:32 -07003909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003910 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3911 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003913 mApp, subId, callingPackage, callingFeatureId,
3914 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003915 return null;
3916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917
3918 final long identity = Binder.clearCallingIdentity();
3919 try {
3920 final Phone phone = getPhone(subId);
3921 if (phone != null) {
3922 return phone.getCdmaEriText();
3923 } else {
3924 return null;
3925 }
3926 } finally {
3927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003929 }
3930
3931 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003932 * Returns the CDMA MDN.
3933 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003934 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003935 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3937 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938
3939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003942 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 return phone.getLine1Number();
3944 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003945 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946 return null;
3947 }
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003950 }
3951 }
3952
3953 /**
3954 * Returns the CDMA MIN.
3955 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003956 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003957 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3959 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 final Phone phone = getPhone(subId);
3964 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3965 return phone.getCdmaMin();
3966 } else {
3967 return null;
3968 }
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003971 }
3972 }
3973
Hall Liud892bec2018-11-30 14:51:45 -08003974 @Override
3975 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3976 INumberVerificationCallback callback, String callingPackage) {
3977 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3978 != PERMISSION_GRANTED) {
3979 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3980 }
3981 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3982
3983 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3984 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003985 throw new SecurityException("Calling package must be configured in the device config: "
3986 + "calling package: " + callingPackage
3987 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003988 }
3989
3990 if (range == null) {
3991 throw new NullPointerException("Range must be non-null");
3992 }
3993
3994 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003995 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003996
3997 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3998 }
3999
Junda Liuca05d5d2014-08-14 22:36:34 -07004000 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004001 * Returns true if CDMA provisioning needs to run.
4002 */
4003 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 final long identity = Binder.clearCallingIdentity();
4005 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004006 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004010 }
4011
4012 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004013 * Sets the voice mail number of a given subId.
4014 */
4015 @Override
4016 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004017 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4018 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019
4020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4023 new Pair<String, String>(alphaTag, number), new Integer(subId));
4024 return success;
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004028 }
4029
Ta-wei Yen87c49842016-05-13 21:19:52 -07004030 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004031 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004033 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4034 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004035 if (!TextUtils.equals(callingPackage, systemDialer)) {
4036 throw new SecurityException("caller must be system dialer");
4037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038
4039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4042 if (phoneAccountHandle == null) {
4043 return null;
4044 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004045 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 } finally {
4047 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004048 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004049 }
4050
4051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004052 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4053 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004054 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004056 mApp, subId, callingPackage, callingFeatureId,
4057 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004058 return null;
4059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004061 final long identity = Binder.clearCallingIdentity();
4062 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004063 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004067 }
4068
4069 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004070 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4071 VisualVoicemailSmsFilterSettings settings) {
4072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073
4074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004077 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004081 }
4082
4083 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004084 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4085 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004090 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004094 }
4095
4096 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004097 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4098 String callingPackage, int subId) {
4099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100
4101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004104 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004108 }
4109
4110 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004111 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113
4114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004117 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004121 }
4122
4123 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004124 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4125 String callingAttributionTag, int subId, String number, int port, String text,
4126 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004127 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004128 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004129 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004130 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004131 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4132 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004133 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004134
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004135 /**
fionaxu0152e512016-11-14 13:36:14 -08004136 * Sets the voice activation state of a given subId.
4137 */
4138 @Override
4139 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4141 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142
4143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 final Phone phone = getPhone(subId);
4146 if (phone != null) {
4147 phone.setVoiceActivationState(activationState);
4148 } else {
4149 loge("setVoiceActivationState fails with invalid subId: " + subId);
4150 }
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004153 }
4154 }
4155
4156 /**
4157 * Sets the data activation state of a given subId.
4158 */
4159 @Override
4160 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4162 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163
4164 final long identity = Binder.clearCallingIdentity();
4165 try {
4166 final Phone phone = getPhone(subId);
4167 if (phone != null) {
4168 phone.setDataActivationState(activationState);
4169 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004170 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004171 }
4172 } finally {
4173 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004174 }
4175 }
4176
4177 /**
4178 * Returns the voice activation state of a given subId.
4179 */
4180 @Override
4181 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183
fionaxu0152e512016-11-14 13:36:14 -08004184 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185 final long identity = Binder.clearCallingIdentity();
4186 try {
4187 if (phone != null) {
4188 return phone.getVoiceActivationState();
4189 } else {
4190 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4191 }
4192 } finally {
4193 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004194 }
4195 }
4196
4197 /**
4198 * Returns the data activation state of a given subId.
4199 */
4200 @Override
4201 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203
fionaxu0152e512016-11-14 13:36:14 -08004204 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 final long identity = Binder.clearCallingIdentity();
4206 try {
4207 if (phone != null) {
4208 return phone.getDataActivationState();
4209 } else {
4210 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4211 }
4212 } finally {
4213 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004214 }
4215 }
4216
4217 /**
Wink Saville36469e72014-06-11 15:17:00 -07004218 * Returns the unread count of voicemails for a subId
4219 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004220 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004221 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4222 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004224 mApp, subId, callingPackage, callingFeatureId,
4225 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004226 return 0;
4227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228 final long identity = Binder.clearCallingIdentity();
4229 try {
4230 final Phone phone = getPhone(subId);
4231 if (phone != null) {
4232 return phone.getVoiceMessageCount();
4233 } else {
4234 return 0;
4235 }
4236 } finally {
4237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004239 }
4240
4241 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004242 * returns true, if the device is in a state where both voice and data
4243 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004244 */
4245 @Override
4246 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 final long identity = Binder.clearCallingIdentity();
4248 try {
Ling Mac28f0212023-03-24 16:07:15 -07004249 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004253 }
4254
4255 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004256 * Send the dialer code if called from the current default dialer or the caller has
4257 * carrier privilege.
4258 * @param inputCode The dialer code to send
4259 */
4260 @Override
4261 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004262 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004263 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004264 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4265 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004266 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004267 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004268 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004269 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270
4271 final long identity = Binder.clearCallingIdentity();
4272 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004273 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274 } finally {
4275 Binder.restoreCallingIdentity(identity);
4276 }
fionaxu235cc5e2017-03-06 22:25:57 -08004277 }
4278
Pengquan Menga1bb6272018-09-06 09:59:22 -07004279 @Override
4280 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004281 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004282 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4283 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 if (!isActiveSubscription(subId)) {
4287 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4288 }
4289 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004292 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004293 }
4294
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004296 public boolean isInEmergencySmsMode() {
4297 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 for (Phone phone : PhoneFactory.getPhones()) {
4301 if (phone.isInEmergencySmsMode()) {
4302 return true;
4303 }
4304 }
4305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308 return false;
4309 }
4310
shilu366312e2019-12-17 09:28:10 -08004311 /**
4312 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4313 * @param subId The subscription to use to check the configuration.
4314 * @param c The callback that will be used to send the result.
4315 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004316 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004317 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4318 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004319 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004320 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004321
4322 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4323 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4324 "IMS not available on device.");
4325 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004326 final long token = Binder.clearCallingIdentity();
4327 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004328 int slotId = getSlotIndexOrException(subId);
4329 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004330
4331 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4332 if (controller != null) {
4333 ImsManager imsManager = controller.getImsManager(subId);
4334 if (imsManager != null) {
4335 imsManager.addRegistrationCallbackForSubscription(c, subId);
4336 } else {
4337 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4338 }
4339 } else {
4340 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4341 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004342 } catch (ImsException e) {
4343 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004344 } finally {
4345 Binder.restoreCallingIdentity(token);
4346 }
4347 }
4348
shilu366312e2019-12-17 09:28:10 -08004349 /**
4350 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4351 * @param subId The subscription to use to check the configuration.
4352 * @param c The callback that will be used to send the result.
4353 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004355 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004356 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004357 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004358 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4359 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4360 }
Meng Wangafbc5852019-09-19 17:37:13 -07004361 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004362
Meng Wangafbc5852019-09-19 17:37:13 -07004363 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004364 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4365 if (controller != null) {
4366 ImsManager imsManager = controller.getImsManager(subId);
4367 if (imsManager != null) {
4368 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4369 } else {
4370 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4371 + "is inactive, ignoring unregister.");
4372 // If the ImsManager is not valid, just return, since the callback
4373 // will already have been removed internally.
4374 }
4375 }
Meng Wangafbc5852019-09-19 17:37:13 -07004376 } finally {
4377 Binder.restoreCallingIdentity(token);
4378 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 }
4380
Brad Ebingera34a6c22019-10-22 17:36:18 -07004381 /**
4382 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4383 */
4384 @Override
4385 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4386 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4387 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4388 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4389 "IMS not available on device.");
4390 }
4391 final long token = Binder.clearCallingIdentity();
4392 try {
4393 Phone phone = getPhone(subId);
4394 if (phone == null) {
4395 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4396 + subId + "'");
4397 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4398 }
4399 phone.getImsRegistrationState(regState -> {
4400 try {
4401 consumer.accept((regState == null)
4402 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4403 } catch (RemoteException e) {
4404 // Ignore if the remote process is no longer available to call back.
4405 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4406 }
4407 });
4408 } finally {
4409 Binder.restoreCallingIdentity(token);
4410 }
4411 }
4412
4413 /**
4414 * Get the transport type for the IMS service registration state.
4415 */
4416 @Override
4417 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004418 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004419 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004420 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4421 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4422 "IMS not available on device.");
4423 }
4424 final long token = Binder.clearCallingIdentity();
4425 try {
4426 Phone phone = getPhone(subId);
4427 if (phone == null) {
4428 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4429 + subId + "'");
4430 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4431 }
4432 phone.getImsRegistrationTech(regTech -> {
4433 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4434 int regTechConverted = (regTech == null)
4435 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4436 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4437 regTechConverted);
4438 try {
4439 consumer.accept(regTechConverted);
4440 } catch (RemoteException e) {
4441 // Ignore if the remote process is no longer available to call back.
4442 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4443 }
4444 });
4445 } finally {
4446 Binder.restoreCallingIdentity(token);
4447 }
4448 }
4449
shilu366312e2019-12-17 09:28:10 -08004450 /**
4451 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4452 * @param subId The subscription to use to check the configuration.
4453 * @param c The callback that will be used to send the result.
4454 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004456 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4457 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004458 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004459 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004460 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4461 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4462 "IMS not available on device.");
4463 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 final long token = Binder.clearCallingIdentity();
4465 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004466 int slotId = getSlotIndexOrException(subId);
4467 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004468
4469 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4470 if (controller != null) {
4471 ImsManager imsManager = controller.getImsManager(subId);
4472 if (imsManager != null) {
4473 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4474 } else {
4475 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4476 }
4477 } else {
4478 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4479 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004480 } catch (ImsException e) {
4481 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004482 } finally {
4483 Binder.restoreCallingIdentity(token);
4484 }
4485 }
4486
shilu366312e2019-12-17 09:28:10 -08004487 /**
4488 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4489 * @param subId The subscription to use to check the configuration.
4490 * @param c The callback that will be used to send the result.
4491 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004493 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004494 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004495 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004496 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4497 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4498 }
Meng Wangafbc5852019-09-19 17:37:13 -07004499
4500 final long token = Binder.clearCallingIdentity();
4501 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004502 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4503 if (controller != null) {
4504 ImsManager imsManager = controller.getImsManager(subId);
4505 if (imsManager != null) {
4506 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4507 } else {
4508 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4509 + " is inactive, ignoring unregister.");
4510 // If the ImsManager is not valid, just return, since the callback
4511 // will already have been removed internally.
4512 }
4513 }
Meng Wangafbc5852019-09-19 17:37:13 -07004514 } finally {
4515 Binder.restoreCallingIdentity(token);
4516 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 }
4518
4519 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004520 public boolean isCapable(int subId, int capability, int regTech) {
4521 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004522 final long token = Binder.clearCallingIdentity();
4523 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004524 int slotId = getSlotIndexOrException(subId);
4525 verifyImsMmTelConfiguredOrThrow(slotId);
4526 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4527 } catch (com.android.ims.ImsException e) {
4528 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4529 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004530 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004531 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4532 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 } finally {
4534 Binder.restoreCallingIdentity(token);
4535 }
4536 }
4537
4538 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004539 public boolean isAvailable(int subId, int capability, int regTech) {
4540 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004541 final long token = Binder.clearCallingIdentity();
4542 try {
4543 Phone phone = getPhone(subId);
4544 if (phone == null) return false;
4545 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004546 } catch (com.android.ims.ImsException e) {
4547 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4548 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 } finally {
4550 Binder.restoreCallingIdentity(token);
4551 }
4552 }
4553
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004554 /**
4555 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4556 * subscription.
4557 * @param subId The subscription to use to check the configuration.
4558 * @param callback The callback that will be used to send the result.
4559 * @param capability The MmTelFeature capability that will be used to send the result.
4560 * @param transportType The transport type of the MmTelFeature capability.
4561 */
4562 @Override
4563 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4564 int transportType) {
4565 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004566 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4567 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4568 "IMS not available on device.");
4569 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004570 final long token = Binder.clearCallingIdentity();
4571 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004572 int slotId = getSlotIndex(subId);
4573 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4574 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4575 + subId + "'");
4576 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4577 }
4578 verifyImsMmTelConfiguredOrThrow(slotId);
4579 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4580 transportType, aBoolean -> {
4581 try {
4582 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4583 } catch (RemoteException e) {
4584 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4585 + "running. Ignore");
4586 }
4587 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004588 } catch (ImsException e) {
4589 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004590 } finally {
4591 Binder.restoreCallingIdentity(token);
4592 }
4593 }
4594
shilu366312e2019-12-17 09:28:10 -08004595 /**
4596 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4597 * @param subId The subscription to use to check the configuration.
4598 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 @Override
4600 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004601 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004602 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004603
Brad Ebinger35c841c2018-10-01 10:40:55 -07004604 final long token = Binder.clearCallingIdentity();
4605 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004606 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004607 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004608 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004609 } catch (ImsException e) {
4610 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 } finally {
4612 Binder.restoreCallingIdentity(token);
4613 }
4614 }
4615
4616 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004617 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004619 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 final long identity = Binder.clearCallingIdentity();
4621 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004622 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004623 // This setting doesn't require an active ImsService connection, so do not verify. The
4624 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004625 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004626 } catch (ImsException e) {
4627 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
4631 }
4632
shilu366312e2019-12-17 09:28:10 -08004633 /**
4634 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4635 * @param subId The subscription to use to check the configuration.
4636 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004637 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004638 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004639 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004640 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004641 final long identity = Binder.clearCallingIdentity();
4642 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004643 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004644 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004645 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004646 } catch (ImsException e) {
4647 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
4651 }
4652
4653 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004654 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004656 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004657 final long identity = Binder.clearCallingIdentity();
4658 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004659 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004660 // This setting doesn't require an active ImsService connection, so do not verify. The
4661 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004662 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004663 } catch (ImsException e) {
4664 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
4668 }
4669
shilu366312e2019-12-17 09:28:10 -08004670 /**
4671 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4672 * @param subId The subscription to use to check the configuration.
4673 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004674 @Override
4675 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004676 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004677 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004678 final long identity = Binder.clearCallingIdentity();
4679 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004680 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004681 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004682 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004683 } catch (ImsException e) {
4684 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004685 } finally {
4686 Binder.restoreCallingIdentity(identity);
4687 }
4688 }
4689
4690 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004691 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004693 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004694 final long identity = Binder.clearCallingIdentity();
4695 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004696 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004697 // This setting doesn't require an active ImsService connection, so do not verify. The
4698 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004699 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004700 } catch (ImsException e) {
4701 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
4705 }
4706
shilu366312e2019-12-17 09:28:10 -08004707 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004708 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4709 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4710 * @param subId The subscription to use to check the configuration.
4711 */
4712 @Override
4713 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004714 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004715 mApp, subId, "isCrossSimCallingEnabledByUser");
4716 final long identity = Binder.clearCallingIdentity();
4717 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004718 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004719 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004720 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004721 } catch (ImsException e) {
4722 throw new ServiceSpecificException(e.getCode());
4723 } finally {
4724 Binder.restoreCallingIdentity(identity);
4725 }
4726 }
4727
4728 /**
4729 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4730 * Requires MODIFY_PHONE_STATE permission.
4731 * @param subId The subscription to use to check the configuration.
4732 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4733 * false otherwise
4734 */
4735 @Override
4736 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4738 "setCrossSimCallingEnabled");
4739 final long identity = Binder.clearCallingIdentity();
4740 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004741 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004742 // This setting doesn't require an active ImsService connection, so do not verify. The
4743 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004744 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004745 } catch (ImsException e) {
4746 throw new ServiceSpecificException(e.getCode());
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
4750 }
4751
4752 /**
shilu366312e2019-12-17 09:28:10 -08004753 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4754 * @param subId The subscription to use to check the configuration.
4755 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004756 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004757
Brad Ebinger35c841c2018-10-01 10:40:55 -07004758 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004759 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004760 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004761 final long identity = Binder.clearCallingIdentity();
4762 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004763 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004764 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004765 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004766 } catch (ImsException e) {
4767 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 } finally {
4769 Binder.restoreCallingIdentity(identity);
4770 }
4771 }
4772
4773 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004774 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004776 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004777 final long identity = Binder.clearCallingIdentity();
4778 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004779 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004780 // This setting doesn't require an active ImsService connection, so do not verify. The
4781 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004782 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004783 } catch (ImsException e) {
4784 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
4788 }
4789
4790 @Override
4791 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4793 "setVoWiFiNonPersistent");
4794 final long identity = Binder.clearCallingIdentity();
4795 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004796 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004797 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004798 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004799 } catch (ImsException e) {
4800 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
4804 }
4805
shilu366312e2019-12-17 09:28:10 -08004806 /**
4807 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4808 * @param subId The subscription to use to check the configuration.
4809 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004810 @Override
4811 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004812 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004813 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004814 final long identity = Binder.clearCallingIdentity();
4815 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004816 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004817 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004818 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004819 } catch (ImsException e) {
4820 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
4824 }
4825
4826 @Override
4827 public void setVoWiFiModeSetting(int subId, int mode) {
4828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4829 "setVoWiFiModeSetting");
4830 final long identity = Binder.clearCallingIdentity();
4831 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004832 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004833 // This setting doesn't require an active ImsService connection, so do not verify. The
4834 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004835 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004836 } catch (ImsException e) {
4837 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
4841 }
4842
4843 @Override
4844 public int getVoWiFiRoamingModeSetting(int subId) {
4845 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4846 final long identity = Binder.clearCallingIdentity();
4847 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004848 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004849 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004850 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004851 } catch (ImsException e) {
4852 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
4856 }
4857
4858 @Override
4859 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4861 "setVoWiFiRoamingModeSetting");
4862 final long identity = Binder.clearCallingIdentity();
4863 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004864 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004865 // This setting doesn't require an active ImsService connection, so do not verify. The
4866 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004867 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004868 } catch (ImsException e) {
4869 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004870 } finally {
4871 Binder.restoreCallingIdentity(identity);
4872 }
4873 }
4874
4875 @Override
4876 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4878 "setRttCapabilityEnabled");
4879 final long identity = Binder.clearCallingIdentity();
4880 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004881 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004882 // This setting doesn't require an active ImsService connection, so do not verify. The
4883 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004884 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004885 } catch (ImsException e) {
4886 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004887 } finally {
4888 Binder.restoreCallingIdentity(identity);
4889 }
4890 }
4891
shilu366312e2019-12-17 09:28:10 -08004892 /**
4893 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4894 * @param subId The subscription to use to check the configuration.
4895 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004896 @Override
4897 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004898 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004899 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004900 final long identity = Binder.clearCallingIdentity();
4901 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004902 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004903 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004904 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004905 } catch (ImsException e) {
4906 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
4910 }
4911
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004912 @Override
4913 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4914 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004915
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004916 final long identity = Binder.clearCallingIdentity();
4917 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004918 if (!isImsAvailableOnDevice()) {
4919 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4920 "IMS not available on device.");
4921 }
4922 int slotId = getSlotIndexOrException(subId);
4923 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004924
4925 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4926 if (controller != null) {
4927 ImsManager imsManager = controller.getImsManager(subId);
4928 if (imsManager != null) {
4929 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4930 } else {
4931 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4932 }
4933 } else {
4934 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4935 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004936 } catch (ImsException e) {
4937 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
4941 }
4942
4943 @Override
4944 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4945 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004946
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004947 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004948 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4949 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4950 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004951 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004952 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4953 if (controller != null) {
4954 ImsManager imsManager = controller.getImsManager(subId);
4955 if (imsManager != null) {
4956 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4957 } else {
4958 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4959 + " is inactive, ignoring unregister.");
4960 // If the ImsManager is not valid, just return, since the callback will already
4961 // have been removed internally.
4962 }
4963 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
4967 }
4968
joonhunshincffb7fc2021-11-28 07:32:01 +00004969 @Override
4970 public void registerFeatureProvisioningChangedCallback(int subId,
4971 IFeatureProvisioningCallback callback) {
4972 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4973 mApp, subId, "registerFeatureProvisioningChangedCallback");
4974
4975 final long identity = Binder.clearCallingIdentity();
4976 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4977 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4978 }
4979
joonhunshin91bc1952022-04-29 08:47:15 +00004980 try {
4981 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4982 if (controller == null) {
4983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4984 "Device does not support IMS");
4985 }
4986 controller.addFeatureProvisioningChangedCallback(subId, callback);
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004990 }
4991
4992 @Override
4993 public void unregisterFeatureProvisioningChangedCallback(int subId,
4994 IFeatureProvisioningCallback callback) {
4995 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4996 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4997
4998 final long identity = Binder.clearCallingIdentity();
4999 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5000 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5001 }
5002
joonhunshin91bc1952022-04-29 08:47:15 +00005003 try {
5004 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5005 if (controller == null) {
5006 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5007 return;
5008 }
5009 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5010 } finally {
5011 Binder.restoreCallingIdentity(identity);
5012 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005013 }
allenwtsu99c623b2020-01-03 18:24:23 +08005014
5015 private void checkModifyPhoneStatePermission(int subId, String message) {
5016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5017 message);
5018 }
5019
allenwtsu99c623b2020-01-03 18:24:23 +08005020 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005021 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005022 boolean isProvisioned) {
5023 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005027 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5028 if (controller == null) {
5029 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5030 return;
5031 }
5032 controller.setRcsProvisioningStatusForCapability(
5033 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
allenwtsu99c623b2020-01-03 18:24:23 +08005037 }
5038
5039
5040 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005041 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5042 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5043 mApp, subId, "getRcsProvisioningStatusForCapability");
5044
allenwtsu99c623b2020-01-03 18:24:23 +08005045 final long identity = Binder.clearCallingIdentity();
5046 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005047 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5048 if (controller == null) {
5049 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5050
5051 // device does not support IMS, this method will return true always.
5052 return true;
5053 }
5054 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
5058 }
5059
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005060 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005061 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5062 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005063 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005064
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005067 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5068 if (controller == null) {
5069 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5070 return;
5071 }
5072 controller.setImsProvisioningStatusForCapability(
5073 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
5077 }
5078
5079 @Override
5080 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005081 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5082 mApp, subId, "getProvisioningStatusForCapability");
5083
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005084 final long identity = Binder.clearCallingIdentity();
5085 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005086 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5087 if (controller == null) {
5088 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005089
joonhunshin91bc1952022-04-29 08:47:15 +00005090 // device does not support IMS, this method will return true always.
5091 return true;
5092 }
5093 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
5097 }
5098
5099 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005100 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5101 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5102 mApp, subId, "isProvisioningRequiredForCapability");
5103
5104 final long identity = Binder.clearCallingIdentity();
5105 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005106 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5107 if (controller == null) {
5108 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5109
5110 // device does not support IMS, this method will return false
5111 return false;
5112 }
5113 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005114 } finally {
5115 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005116 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005117 }
5118
5119 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005120 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5121 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5122 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005123
joonhunshincffb7fc2021-11-28 07:32:01 +00005124 final long identity = Binder.clearCallingIdentity();
5125 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005126 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5127 if (controller == null) {
5128 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5129
5130 // device does not support IMS, this method will return false
5131 return false;
5132 }
5133 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005137 }
5138
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005139 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005140 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005141 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5142 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5143 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005144 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5145 mApp, subId, "getImsProvisioningInt");
5146
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005147 final long identity = Binder.clearCallingIdentity();
5148 try {
5149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005150 int slotId = getSlotIndex(subId);
5151 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5152 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5153 + subId + "' for key:" + key);
5154 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5155 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005156
joonhunshin91bc1952022-04-29 08:47:15 +00005157 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5158 if (controller == null) {
5159 loge("getImsProvisioningInt: Device does not support IMS");
5160
5161 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5162 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5163 }
5164 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005165 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5166 return retVal;
5167 }
5168
calvinpanb5a34062021-02-08 19:59:36 +08005169 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005170 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005171 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5172 + subId + "' for key:" + key);
5173 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
5177 }
5178
5179 @Override
5180 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005181 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5182 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5183 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005184 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5185 mApp, subId, "getImsProvisioningString");
5186
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005190 int slotId = getSlotIndex(subId);
5191 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5192 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5193 + subId + "' for key:" + key);
5194 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5195 }
calvinpanb5a34062021-02-08 19:59:36 +08005196 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005197 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005198 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5199 + subId + "' for key:" + key);
5200 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
5204 }
5205
5206 @Override
5207 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005208 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5209 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5210 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5212 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005213
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005214 final long identity = Binder.clearCallingIdentity();
5215 try {
5216 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005217 int slotId = getSlotIndex(subId);
5218 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5219 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5220 + subId + "' for key:" + key);
5221 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5222 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005223
joonhunshin91bc1952022-04-29 08:47:15 +00005224 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5225 if (controller == null) {
5226 loge("setImsProvisioningInt: Device does not support IMS");
5227
5228 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5229 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5230 }
5231 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005232 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5233 return retVal;
5234 }
5235
calvinpanb5a34062021-02-08 19:59:36 +08005236 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5237 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005238 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005239 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005240 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
5244 }
5245
5246 @Override
5247 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005248 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5249 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5250 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5252 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005256 int slotId = getSlotIndex(subId);
5257 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5258 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5259 + subId + "' for key:" + key);
5260 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5261 }
calvinpanb5a34062021-02-08 19:59:36 +08005262 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5263 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005264 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005265 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005266 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005267 } finally {
5268 Binder.restoreCallingIdentity(identity);
5269 }
5270 }
5271
Brad Ebinger919631e2021-06-02 17:46:35 -07005272 /**
5273 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5274 * for the given slot ID or no ImsResolver instance has been created.
5275 * @param slotId The slot ID that the IMS service is created for.
5276 * @throws ImsException If there is no ImsService configured for this slot.
5277 */
5278 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5279 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5280 ImsFeature.FEATURE_MMTEL)) {
5281 throw new ImsException("This subscription does not support MMTEL over IMS",
5282 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5283 }
5284 }
5285
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005286 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005287 int slotId = SubscriptionManager.getSlotIndex(subId);
5288 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005289 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5290 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005291 }
5292 return slotId;
5293 }
5294
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005295 private int getSlotIndex(int subId) {
5296 int slotId = SubscriptionManager.getSlotIndex(subId);
5297 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5298 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5299 }
5300 return slotId;
5301 }
5302
Wink Saville36469e72014-06-11 15:17:00 -07005303 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005304 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005305 */
5306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005307 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5308 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005309 try {
5310 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5311 } catch (SecurityException se) {
5312 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5313 throw new SecurityException("Package " + callingPackage + " does not belong to "
5314 + Binder.getCallingUid());
5315 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005316 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005317 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005318 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005319 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005320 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005321 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005322 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005323 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5324 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 final Phone phone = getPhone(subId);
5329 if (phone != null) {
5330 return phone.getServiceState().getDataNetworkType();
5331 } else {
5332 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5333 }
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005337 }
5338
5339 /**
5340 * Returns the data network type
5341 */
5342 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005343 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005344 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005345 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005346 }
5347
5348 /**
5349 * Returns the data network type for a subId
5350 */
5351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005352 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5353 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005354 String functionName = "getDataNetworkTypeForSubscriber";
5355 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5356 mApp, functionName)) {
5357 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5358 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5359 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5360 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005361 }
5362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 final long identity = Binder.clearCallingIdentity();
5364 try {
5365 final Phone phone = getPhone(subId);
5366 if (phone != null) {
5367 return phone.getServiceState().getDataNetworkType();
5368 } else {
5369 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5370 }
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005374 }
5375
5376 /**
Wink Saville36469e72014-06-11 15:17:00 -07005377 * Returns the Voice network type for a subId
5378 */
5379 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005380 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5381 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005382 String functionName = "getVoiceNetworkTypeForSubscriber";
5383 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5384 mApp, functionName)) {
5385 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5386 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5387 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5388 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005389 }
5390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 final Phone phone = getPhone(subId);
5394 if (phone != null) {
5395 return phone.getServiceState().getVoiceNetworkType();
5396 } else {
5397 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5398 }
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005402 }
5403
5404 /**
5405 * @return true if a ICC card is present
5406 */
5407 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005408 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005409 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005410 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005411 }
5412
5413 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005414 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005415 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005416 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005417 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 final long identity = Binder.clearCallingIdentity();
5419 try {
5420 final Phone phone = PhoneFactory.getPhone(slotIndex);
5421 if (phone != null) {
5422 return phone.getIccCard().hasIccCard();
5423 } else {
5424 return false;
5425 }
5426 } finally {
5427 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005429 }
5430
5431 /**
5432 * Return if the current radio is LTE on CDMA. This
5433 * is a tri-state return value as for a period of time
5434 * the mode may be unknown.
5435 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005436 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005437 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005438 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005439 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005441 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5442 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5443 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005444 }
5445
Sanket Padawe356d7632015-06-22 14:03:32 -07005446 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005447 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5448 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005449 try {
5450 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5451 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005452 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5453 }
5454
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455 final long identity = Binder.clearCallingIdentity();
5456 try {
5457 final Phone phone = getPhone(subId);
5458 if (phone == null) {
5459 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5460 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005461 return TelephonyProperties.lte_on_cdma_device()
5462 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 }
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005466 }
Wink Saville36469e72014-06-11 15:17:00 -07005467 }
5468
Wink Saville36469e72014-06-11 15:17:00 -07005469 /**
5470 * {@hide}
5471 * Returns Default subId, 0 in the case of single standby.
5472 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005473 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005474 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005475 }
5476
Shishir Agrawala9f32182016-04-12 12:00:16 -07005477 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005478 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005479 }
5480
Wink Savilleb564aae2014-10-23 10:18:09 -07005481 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005482 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005483 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005484
Pengquan Menge92a50d2018-09-21 15:54:48 -07005485 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005486 return getSubscriptionManagerService().isActiveSubId(subId,
5487 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005488 }
5489
Ihab Awadf2177b72013-11-25 13:33:23 -08005490 /**
5491 * @see android.telephony.TelephonyManager.WifiCallingChoices
5492 */
5493 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 final long identity = Binder.clearCallingIdentity();
5495 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005496 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5498 getWhenToMakeWifiCallsDefaultPreference());
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005502 }
5503
5504 /**
5505 * @see android.telephony.TelephonyManager.WifiCallingChoices
5506 */
5507 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005511 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005516 }
5517
Sailesh Nepald1e68152013-12-12 19:08:02 -08005518 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005519 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005520 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005521 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005522
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005523 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5524 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5525 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005526 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005527 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005528 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005529 }
5530 return PhoneFactory.getPhone(phoneId);
5531 }
5532
Shishir Agrawal566b7612013-10-28 14:41:00 -07005533 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005534 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005535 @NonNull IccLogicalChannelRequest request) {
5536 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5537 /*message=*/ "iccOpenLogicalChannel");
5538
5539 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5540 // Verify that the callingPackage in the request belongs to the calling UID
5541 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5542
5543 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005544 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005545
Rambo Wanga1782702021-11-10 20:15:19 -08005546 private Phone getPhoneFromValidIccLogicalChannelRequest(
5547 @NonNull IccLogicalChannelRequest request, String message) {
5548 Phone phone;
5549 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5551 mApp, request.subId, message);
5552 phone = getPhoneFromSubId(request.subId);
5553 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5554 enforceModifyPermission();
5555 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5556 } else {
5557 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005558 }
Rambo Wanga1782702021-11-10 20:15:19 -08005559 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005560 }
5561
5562 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005563 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 final long identity = Binder.clearCallingIdentity();
5565 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005566 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005568 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5569 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005570 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5571 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 loge("The calling package is not allowed to access ISD-R.");
5573 throw new SecurityException(
5574 "The calling package is not allowed to access ISD-R.");
5575 }
Derek Tan740e1672017-06-27 14:56:27 -07005576 }
Derek Tan740e1672017-06-27 14:56:27 -07005577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005579 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5580 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 return response;
5582 } finally {
5583 Binder.restoreCallingIdentity(identity);
5584 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005585 }
5586
5587 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005588 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5589 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5590 /*message=*/"iccCloseLogicalChannel");
5591
5592 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5593
5594 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005595 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005596
Rambo Wanga1782702021-11-10 20:15:19 -08005597 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5598 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005599 // before this feature is enabled, this API should only return false if
5600 // the operation fails instead of throwing runtime exception for
5601 // backward-compatibility.
5602 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5603 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 final long identity = Binder.clearCallingIdentity();
5605 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005606 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005607 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 }
Chen Xue9d737e2022-01-01 23:41:31 -08005609 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005610 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005611 Boolean success = false;
5612 if (result instanceof RuntimeException) {
5613 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005614 if (shouldThrowExceptionOnFailure) {
5615 throw (RuntimeException) result;
5616 } else {
5617 return false;
5618 }
Chen Xue9d737e2022-01-01 23:41:31 -08005619 } else if (result instanceof Boolean) {
5620 success = (Boolean) result;
5621 } else {
5622 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5623 }
Rambo Wanga1782702021-11-10 20:15:19 -08005624 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 return success;
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005628 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005629 }
5630
5631 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005632 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005633 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005636 if (DBG) {
5637 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5638 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5639 + p3 + " data=" + data);
5640 }
5641 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5642 command, p1, p2, p3, data);
5643 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005644
Jordan Liu4c733742019-02-28 12:03:40 -08005645 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005646 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005647 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005648 enforceModifyPermission();
5649 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005650 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005651 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5652 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005653 }
5654 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005655 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5656 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005657 }
5658
5659 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5660 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 final long identity = Binder.clearCallingIdentity();
5662 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005663 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 return "";
5665 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005668 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5669 null /* workSource */);
5670 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 // Append the returned status code to the end of the response payload.
5673 String s = Integer.toHexString(
5674 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5675 if (response.payload != null) {
5676 s = IccUtils.bytesToHexString(response.payload) + s;
5677 }
5678 return s;
5679 } finally {
5680 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005682 }
Jake Hambye994d462014-02-03 13:10:13 -08005683
Evan Charltonc66da362014-05-16 14:06:40 -07005684 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005685 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5686 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5688 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005690 if (DBG) {
5691 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5692 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5693 }
5694 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5695 cla, command, p1, p2, p3, data);
5696 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005697
Jordan Liu4c733742019-02-28 12:03:40 -08005698 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005699 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005700 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005701 enforceModifyPermission();
5702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5703 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005704 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005705 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5706 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005707 }
5708
5709 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005710 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5711 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005712 }
5713
5714 // open APDU basic channel assuming the caller has sufficient permissions
5715 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5716 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5720 && TextUtils.equals(ISDR_AID, data)) {
5721 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005722 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5723 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 if (bestComponent == null
5725 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5726 loge("The calling package is not allowed to select ISD-R.");
5727 throw new SecurityException(
5728 "The calling package is not allowed to select ISD-R.");
5729 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005730 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005733 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5734 null /* workSource */);
5735 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 // Append the returned status code to the end of the response payload.
5738 String s = Integer.toHexString(
5739 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5740 if (response.payload != null) {
5741 s = IccUtils.bytesToHexString(response.payload) + s;
5742 }
5743 return s;
5744 } finally {
5745 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005746 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005747 }
5748
5749 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005750 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005751 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5753 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 if (DBG) {
5758 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5759 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5760 }
5761
5762 IccIoResult response =
5763 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5764 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5765 subId);
5766
5767 if (DBG) {
5768 log("Exchange SIM_IO [R]" + response);
5769 }
5770
5771 byte[] result = null;
5772 int length = 2;
5773 if (response.payload != null) {
5774 length = 2 + response.payload.length;
5775 result = new byte[length];
5776 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5777 } else {
5778 result = new byte[length];
5779 }
5780
5781 result[length - 1] = (byte) response.sw2;
5782 result[length - 2] = (byte) response.sw1;
5783 return result;
5784 } finally {
5785 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005786 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005787 }
5788
Nathan Haroldb3014052017-01-25 15:57:32 -08005789 /**
5790 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5791 * on a particular subscription
5792 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005793 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5794 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005796 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005797 return null;
5798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799
5800 final long identity = Binder.clearCallingIdentity();
5801 try {
5802 if (appType != TelephonyManager.APPTYPE_USIM
5803 && appType != TelephonyManager.APPTYPE_SIM) {
5804 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5805 return null;
5806 }
5807 Object response = sendRequest(
5808 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5809 if (response instanceof String[]) {
5810 return (String[]) response;
5811 }
yincheng zhao2737e882019-09-06 17:06:54 -07005812 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005814 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 } finally {
5816 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005817 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005818 }
5819
yincheng zhao2737e882019-09-06 17:06:54 -07005820 /**
5821 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5822 * subscription.
5823 *
5824 * @param subId the id of the subscription.
5825 * @param appType the uicc app type, must be USIM or SIM.
5826 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5827 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005828 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005829 * @return number of fplmns that is successfully written to the SIM.
5830 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005831 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5832 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5834 mApp, subId, "setForbiddenPlmns");
5835
yincheng zhao2737e882019-09-06 17:06:54 -07005836 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5837 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5838 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5839 }
5840 if (fplmns == null) {
5841 throw new IllegalArgumentException("Fplmn List provided is null");
5842 }
5843 for (String fplmn : fplmns) {
5844 if (!CellIdentity.isValidPlmn(fplmn)) {
5845 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5846 }
5847 }
5848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 Object response = sendRequest(
5851 CMD_SET_FORBIDDEN_PLMNS,
5852 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5853 subId);
5854 return (int) response;
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
5858 }
5859
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005860 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005861 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5863 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5868 if (response.payload == null) {
5869 return "";
5870 }
Evan Charltonc66da362014-05-16 14:06:40 -07005871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 // Append the returned status code to the end of the response payload.
5873 String s = Integer.toHexString(
5874 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5875 s = IccUtils.bytesToHexString(response.payload) + s;
5876 return s;
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
Evan Charltonc66da362014-05-16 14:06:40 -07005880 }
5881
Jake Hambye994d462014-02-03 13:10:13 -08005882 /**
5883 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5884 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5885 *
5886 * @param itemID the ID of the item to read
5887 * @return the NV item as a String, or null on error.
5888 */
5889 @Override
5890 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005891 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5893 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894
5895 final long identity = Binder.clearCallingIdentity();
5896 try {
5897 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005898 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5900 return value;
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Jake Hambye994d462014-02-03 13:10:13 -08005904 }
5905
5906 /**
5907 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5908 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5909 *
5910 * @param itemID the ID of the item to read
5911 * @param itemValue the value to write, as a String
5912 * @return true on success; false on any failure
5913 */
5914 @Override
5915 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005916 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5918 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919
5920 final long identity = Binder.clearCallingIdentity();
5921 try {
5922 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5923 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005924 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5926 return success;
5927 } finally {
5928 Binder.restoreCallingIdentity(identity);
5929 }
Jake Hambye994d462014-02-03 13:10:13 -08005930 }
5931
5932 /**
5933 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5934 * Used for device configuration by some CDMA operators.
5935 *
5936 * @param preferredRoamingList byte array containing the new PRL
5937 * @return true on success; false on any failure
5938 */
5939 @Override
5940 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5942 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943
5944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5947 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5948 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5949 return success;
5950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
Jake Hambye994d462014-02-03 13:10:13 -08005953 }
5954
5955 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005956 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005957 * Used for device configuration by some CDMA operators.
5958 *
chen xu6dac5ab2018-10-26 17:39:23 -07005959 * @param slotIndex - device slot.
5960 *
Jake Hambye994d462014-02-03 13:10:13 -08005961 * @return true on success; false on any failure
5962 */
5963 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005964 public boolean resetModemConfig(int slotIndex) {
5965 Phone phone = PhoneFactory.getPhone(slotIndex);
5966 if (phone != null) {
5967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5968 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969
chen xu6dac5ab2018-10-26 17:39:23 -07005970 final long identity = Binder.clearCallingIdentity();
5971 try {
5972 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5973 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5974 return success;
5975 } finally {
5976 Binder.restoreCallingIdentity(identity);
5977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 }
chen xu6dac5ab2018-10-26 17:39:23 -07005979 return false;
5980 }
5981
5982 /**
5983 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5984 *
5985 * @param slotIndex - device slot.
5986 *
5987 * @return true on success; false on any failure
5988 */
5989 @Override
5990 public boolean rebootModem(int slotIndex) {
5991 Phone phone = PhoneFactory.getPhone(slotIndex);
5992 if (phone != null) {
5993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5994 mApp, phone.getSubId(), "rebootModem");
5995
5996 final long identity = Binder.clearCallingIdentity();
5997 try {
5998 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5999 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6000 return success;
6001 } finally {
6002 Binder.restoreCallingIdentity(identity);
6003 }
6004 }
6005 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006006 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006007
Brad Ebinger51f743a2017-01-23 13:50:20 -08006008 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006009 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6010 * {@link #disableIms(int)}.
6011 * @param slotIndex device slot.
6012 */
6013 public void resetIms(int slotIndex) {
6014 enforceModifyPermission();
6015
6016 final long identity = Binder.clearCallingIdentity();
6017 try {
6018 if (mImsResolver == null) {
6019 // may happen if the does not support IMS.
6020 return;
6021 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006022 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006023 } finally {
6024 Binder.restoreCallingIdentity(identity);
6025 }
6026 }
6027
6028 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006029 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6030 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006031 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006032 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006033 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034
6035 final long identity = Binder.clearCallingIdentity();
6036 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006037 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006038 // may happen if the device does not support IMS.
6039 return;
6040 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006041 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006045 }
6046
6047 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006048 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6049 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006050 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006051 public void disableIms(int slotId) {
6052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
6054 final long identity = Binder.clearCallingIdentity();
6055 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006056 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006057 // may happen if the device does not support IMS.
6058 return;
6059 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006060 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006064 }
6065
6066 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006067 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6068 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006069 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006070 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006071 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006072 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073
6074 final long identity = Binder.clearCallingIdentity();
6075 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006076 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006077 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6078 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006079 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006080 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006084 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006085 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006086 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6087 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006088 @Override
6089 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006090 enforceModifyPermission();
6091
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006095 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006096 } finally {
6097 Binder.restoreCallingIdentity(identity);
6098 }
6099 }
6100
6101 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006102 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006103 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006104 */
6105 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6106 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006110 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006111 // may happen if the device does not support IMS.
6112 return null;
6113 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006114 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006118 }
6119
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006120 /**
6121 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006122 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006123 */
6124 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6125 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006129 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006130 // may happen if the device does not support IMS.
6131 return null;
6132 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006133 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006137 }
6138
Brad Ebinger884c07b2018-02-15 16:17:40 -08006139 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006140 * Sets the ImsService Package Name that Telephony will bind to.
6141 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006142 * @param slotIndex the slot ID that the ImsService should bind for.
6143 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006144 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006145 * @param featureTypes An integer array of feature types associated with a packageName.
6146 * @param packageName The name of the package that the current configuration will be replaced
6147 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006148 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006149 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006150 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6151 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006154 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 final long identity = Binder.clearCallingIdentity();
6157 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006158 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006159 // may happen if the device does not support IMS.
6160 return false;
6161 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006162 Map<Integer, String> featureConfig = new HashMap<>();
6163 for (int featureType : featureTypes) {
6164 featureConfig.put(featureType, packageName);
6165 }
6166 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6167 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006171 }
6172
6173 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006174 * Clears any carrier ImsService overrides for the slot index specified that were previously
6175 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6176 *
6177 * This should only be used for testing.
6178 *
6179 * @param slotIndex the slot ID that the ImsService should bind for.
6180 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6181 */
6182 @Override
6183 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006184 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6185 "clearCarrierImsServiceOverride");
6186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006187 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006188
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 if (mImsResolver == null) {
6192 // may happen if the device does not support IMS.
6193 return false;
6194 }
6195 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
6199 }
6200
6201 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006202 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006203 *
6204 * @param slotId The slot that the ImsService is associated with.
6205 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6206 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006207 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006208 * @return the package name of the ImsService configuration.
6209 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006210 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6211 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006212 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006213 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6214 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 final long identity = Binder.clearCallingIdentity();
6217 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006218 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006219 // may happen if the device does not support IMS.
6220 return "";
6221 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006222 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006223 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6224 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225 } finally {
6226 Binder.restoreCallingIdentity(identity);
6227 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006228 }
6229
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006230 /**
6231 * Get the MmTelFeature state associated with the requested subscription id.
6232 * @param subId The subscription that the MmTelFeature is associated with.
6233 * @param callback A callback with an integer containing the
6234 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6235 */
6236 @Override
6237 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6238 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006239 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6240 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6241 "IMS not available on device.");
6242 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006243 final long token = Binder.clearCallingIdentity();
6244 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006245 int slotId = getSlotIndex(subId);
6246 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6247 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6248 + subId + "'");
6249 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6250 }
6251 verifyImsMmTelConfiguredOrThrow(slotId);
6252 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6253 try {
6254 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6255 } catch (RemoteException e) {
6256 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6257 + "Ignore");
6258 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006259 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006260 } catch (ImsException e) {
6261 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006262 } finally {
6263 Binder.restoreCallingIdentity(token);
6264 }
6265 }
6266
Daniel Brightbb5840b2021-01-12 15:48:18 -08006267 /**
6268 * Sets the ims registration state on all valid {@link Phone}s.
6269 */
6270 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006271 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272
6273 final long identity = Binder.clearCallingIdentity();
6274 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006275 // NOTE: Before S, this method only set the default phone.
6276 for (final Phone phone : PhoneFactory.getPhones()) {
6277 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6278 phone.setImsRegistrationState(registered);
6279 }
6280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 } finally {
6282 Binder.restoreCallingIdentity(identity);
6283 }
Wink Saville36469e72014-06-11 15:17:00 -07006284 }
6285
6286 /**
Stuart Scott54788802015-03-30 13:18:01 -07006287 * Set the network selection mode to automatic.
6288 *
6289 */
6290 @Override
6291 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6293 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294
6295 final long identity = Binder.clearCallingIdentity();
6296 try {
shilufc958392020-01-20 11:36:01 -08006297 if (!isActiveSubscription(subId)) {
6298 return;
6299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006301 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6302 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 } finally {
6304 Binder.restoreCallingIdentity(identity);
6305 }
Stuart Scott54788802015-03-30 13:18:01 -07006306 }
6307
Jack Yud10cdd42020-09-28 20:28:01 -07006308 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006309 * Ask the radio to connect to the input network and change selection mode to manual.
6310 *
6311 * @param subId the id of the subscription.
6312 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6313 * the operator to attach to.
6314 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6315 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6316 * normal network selection next time.
6317 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006318 */
6319 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006320 public boolean setNetworkSelectionModeManual(
6321 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6323 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006324
Jack Yu285100e2022-12-02 22:48:35 -08006325 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006326 if (!isActiveSubscription(subId)) {
6327 return false;
6328 }
6329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006331 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006333 if (DBG) {
6334 log("setNetworkSelectionModeManual: subId: " + subId
6335 + " operator: " + operatorInfo);
6336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6338 } finally {
6339 Binder.restoreCallingIdentity(identity);
6340 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006341 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006342 /**
shilu84f6e8b2019-12-19 13:58:01 -08006343 * Get the manual network selection
6344 *
6345 * @param subId the id of the subscription.
6346 *
6347 * @return the previously saved user selected PLMN
6348 */
6349 @Override
6350 public String getManualNetworkSelectionPlmn(int subId) {
6351 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006352 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6353 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006358 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006359 }
6360
6361 final Phone phone = getPhone(subId);
6362 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006363 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006364 }
6365 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6366 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006367 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
6371 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006372
6373 /**
6374 * Scans for available networks.
6375 */
6376 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006377 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6378 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6380 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006381 LocationAccessPolicy.LocationPermissionResult locationResult =
6382 LocationAccessPolicy.checkLocationPermission(mApp,
6383 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6384 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006385 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006386 .setCallingPid(Binder.getCallingPid())
6387 .setCallingUid(Binder.getCallingUid())
6388 .setMethod("getCellNetworkScanResults")
6389 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006390 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6391 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006392 .build());
6393 switch (locationResult) {
6394 case DENIED_HARD:
6395 throw new SecurityException("Not allowed to access scan results -- location");
6396 case DENIED_SOFT:
6397 return null;
6398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
Pengquan Menga1bb6272018-09-06 09:59:22 -07006400 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 try {
6402 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006403 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006408 }
6409
6410 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006411 * Get the call forwarding info, given the call forwarding reason.
6412 */
6413 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006414 public void getCallForwarding(int subId, int callForwardingReason,
6415 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006416 enforceReadPrivilegedPermission("getCallForwarding");
6417 long identity = Binder.clearCallingIdentity();
6418 try {
6419 if (DBG) {
6420 log("getCallForwarding: subId " + subId
6421 + " callForwardingReason" + callForwardingReason);
6422 }
Hall Liu27d24262020-09-18 19:04:59 -07006423
6424 Phone phone = getPhone(subId);
6425 if (phone == null) {
6426 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006427 callback.onError(
6428 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006429 } catch (RemoteException e) {
6430 // ignore
6431 }
6432 return;
6433 }
6434
6435 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6436 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6437 @Override
6438 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6439 try {
6440 callback.onCallForwardingInfoAvailable(info);
6441 } catch (RemoteException e) {
6442 // ignore
6443 }
6444 }
6445
6446 @Override
6447 public void onError(int error) {
6448 try {
6449 callback.onError(error);
6450 } catch (RemoteException e) {
6451 // ignore
6452 }
6453 }
6454 });
6455 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
6459 }
6460
6461 /**
6462 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6463 * reason, the number to forward, and the timeout before the forwarding is attempted.
6464 */
6465 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006466 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6467 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006468 enforceModifyPermission();
6469 long identity = Binder.clearCallingIdentity();
6470 try {
6471 if (DBG) {
6472 log("setCallForwarding: subId " + subId
6473 + " callForwardingInfo" + callForwardingInfo);
6474 }
Hall Liu27d24262020-09-18 19:04:59 -07006475
6476 Phone phone = getPhone(subId);
6477 if (phone == null) {
6478 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006479 callback.accept(
6480 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006481 } catch (RemoteException e) {
6482 // ignore
6483 }
6484 return;
6485 }
6486
6487 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6488 FunctionalUtils.ignoreRemoteException(callback::accept));
6489
6490 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006491 } finally {
6492 Binder.restoreCallingIdentity(identity);
6493 }
6494 }
6495
6496 /**
Hall Liu27d24262020-09-18 19:04:59 -07006497 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006498 */
6499 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006500 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006501 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006502 long identity = Binder.clearCallingIdentity();
6503 try {
Hall Liu27d24262020-09-18 19:04:59 -07006504 Phone phone = getPhone(subId);
6505 if (phone == null) {
6506 try {
6507 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6508 } catch (RemoteException e) {
6509 // ignore
6510 }
6511 return;
6512 }
SongFerngWang0e767992021-03-31 22:08:45 +08006513 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6514 PersistableBundle c = configManager.getConfigForSubId(subId);
6515 boolean requireUssd = c.getBoolean(
6516 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006517
Shuo Qian4a594052020-01-23 11:59:30 -08006518 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006519 if (requireUssd) {
6520 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6521 getSubscriptionCarrierId(subId));
6522 String newUssdCommand = "";
6523 try {
6524 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006525 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006526 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6527 } catch (NullPointerException e) {
6528 loge("Failed to generate USSD number" + e);
6529 }
6530 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6531 mMainThreadHandler, callback, carrierXmlParser,
6532 CarrierXmlParser.SsEntry.SSAction.QUERY);
6533 final String ussdCommand = newUssdCommand;
6534 Executors.newSingleThreadExecutor().execute(() -> {
6535 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6536 });
6537 } else {
6538 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6539 callback::accept);
6540 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6541 }
Shuo Qian4a594052020-01-23 11:59:30 -08006542 } finally {
6543 Binder.restoreCallingIdentity(identity);
6544 }
6545 }
6546
6547 /**
Hall Liu27d24262020-09-18 19:04:59 -07006548 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006549 */
6550 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006551 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006552 enforceModifyPermission();
6553 long identity = Binder.clearCallingIdentity();
6554 try {
Hall Liu27d24262020-09-18 19:04:59 -07006555 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6556
6557 Phone phone = getPhone(subId);
6558 if (phone == null) {
6559 try {
6560 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6561 } catch (RemoteException e) {
6562 // ignore
6563 }
6564 return;
6565 }
6566
SongFerngWang0e767992021-03-31 22:08:45 +08006567 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6568 PersistableBundle c = configManager.getConfigForSubId(subId);
6569 boolean requireUssd = c.getBoolean(
6570 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006571
SongFerngWang0e767992021-03-31 22:08:45 +08006572 if (DBG) log("getCallWaitingStatus: subId " + subId);
6573 if (requireUssd) {
6574 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6575 getSubscriptionCarrierId(subId));
6576 CarrierXmlParser.SsEntry.SSAction ssAction =
6577 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6578 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6579 String newUssdCommand = "";
6580 try {
6581 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006582 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006583 .makeCommand(ssAction, null);
6584 } catch (NullPointerException e) {
6585 loge("Failed to generate USSD number" + e);
6586 }
6587 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6588 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6589 final String ussdCommand = newUssdCommand;
6590 Executors.newSingleThreadExecutor().execute(() -> {
6591 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6592 });
6593 } else {
6594 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6595 FunctionalUtils.ignoreRemoteException(callback::accept));
6596
6597 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6598 }
Shuo Qian4a594052020-01-23 11:59:30 -08006599 } finally {
6600 Binder.restoreCallingIdentity(identity);
6601 }
6602 }
6603
6604 /**
yinxub1bed742017-04-17 11:45:04 -07006605 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006606 *
yinxub1bed742017-04-17 11:45:04 -07006607 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006608 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6609 * location related information which will be sent if the caller already possess
6610 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006611 * @param request contains the radio access networks with bands/channels to scan
6612 * @param messenger callback messenger for scan results or errors
6613 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006614 * @return the id of the requested scan which can be used to stop the scan.
6615 */
6616 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006617 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6618 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006619 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6621 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006622 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006623 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6624 if (!renounceFineLocationAccess) {
6625 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006626 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6627 .setCallingPackage(callingPackage)
6628 .setCallingFeatureId(callingFeatureId)
6629 .setCallingPid(Binder.getCallingPid())
6630 .setCallingUid(Binder.getCallingUid())
6631 .setMethod("requestNetworkScan")
6632 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6633 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6634 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6635 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006636 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006637 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006638 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6639 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006640 if (e != null) {
6641 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6642 throw e;
6643 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006644 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006645 return TelephonyScanManager.INVALID_SCAN_ID;
6646 }
6647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648 }
Hall Liu912dfd32019-04-25 14:02:26 -07006649 int callingUid = Binder.getCallingUid();
6650 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006651 final long identity = Binder.clearCallingIdentity();
6652 try {
6653 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006654 renounceFineLocationAccess, request, messenger, binder,
6655 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006656 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006657 } finally {
6658 Binder.restoreCallingIdentity(identity);
6659 }
yinxu504e1392017-04-12 16:03:22 -07006660 }
6661
Hall Liub2ac8ef2019-02-28 15:56:23 -08006662 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006663 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006664 boolean hasCarrierPriv;
6665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6668 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6669 } finally {
6670 Binder.restoreCallingIdentity(identity);
6671 }
Hall Liu558027f2019-05-15 19:14:05 -07006672 boolean hasNetworkScanPermission =
6673 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006674 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006675
6676 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6677 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6678 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006679 }
6680
6681 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6682 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006683 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6684 return new SecurityException("Specific channels must not be"
6685 + " scanned without location access.");
6686 }
6687 }
6688 }
6689
Hall Liub2ac8ef2019-02-28 15:56:23 -08006690 return null;
6691 }
6692
yinxu504e1392017-04-12 16:03:22 -07006693 /**
6694 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006695 *
6696 * @param subId id of the subscription
6697 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006698 */
6699 @Override
6700 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6702 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703
Hall Liu912dfd32019-04-25 14:02:26 -07006704 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 final long identity = Binder.clearCallingIdentity();
6706 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006707 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
yinxu504e1392017-04-12 16:03:22 -07006711 }
6712
6713 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006714 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006715 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006716 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006717 */
6718 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006719 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006720 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006721 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006722 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723
6724 final long identity = Binder.clearCallingIdentity();
6725 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006726 if (DBG) log("getAllowedNetworkTypesBitmask");
6727 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6728 int networkTypesBitmask = (result != null ? result[0] : -1);
6729 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6730 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006734 }
6735
6736 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006737 * Get the allowed network types for certain reason.
6738 *
6739 * @param subId the id of the subscription.
6740 * @param reason the reason the allowed network type change is taking place
6741 * @return the allowed network types.
6742 */
6743 @Override
6744 public long getAllowedNetworkTypesForReason(int subId,
6745 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006746 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006747 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006748 final long identity = Binder.clearCallingIdentity();
6749 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006750 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
6754 }
6755
6756 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006757 * Enable/Disable E-UTRA-NR Dual Connectivity
6758 * @param subId subscription id of the sim card
6759 * @param nrDualConnectivityState expected NR dual connectivity state
6760 * This can be passed following states
6761 * <ol>
6762 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6763 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6764 * <li>Disable NR dual connectivity and force secondary cell to be released
6765 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6766 * </ol>
6767 * @return operation result.
6768 */
6769 @Override
6770 public int setNrDualConnectivityState(int subId,
6771 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6773 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006774 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006775 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6776 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6777 }
6778
Sooraj Sasindran37444802020-08-11 10:40:43 -07006779 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6780 final long identity = Binder.clearCallingIdentity();
6781 try {
6782 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6783 nrDualConnectivityState, subId,
6784 workSource);
6785 if (DBG) log("enableNRDualConnectivity result: " + result);
6786 return result;
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
6789 }
6790 }
6791
6792 /**
6793 * Is E-UTRA-NR Dual Connectivity enabled
6794 * @return true if dual connectivity is enabled else false
6795 */
6796 @Override
6797 public boolean isNrDualConnectivityEnabled(int subId) {
6798 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006799 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006800 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006801 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006802 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6803 return false;
6804 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006805 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6809 null, subId, workSource);
6810 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6811 return isEnabled;
6812 } finally {
6813 Binder.restoreCallingIdentity(identity);
6814 }
6815 }
6816
6817 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006818 * Set the allowed network types of the device and
6819 * provide the reason triggering the allowed network change.
6820 *
6821 * @param subId the id of the subscription.
6822 * @param reason the reason the allowed network type change is taking place
6823 * @param allowedNetworkTypes the allowed network types.
6824 * @return true on success; false on any failure.
6825 */
6826 @Override
6827 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006828 @TelephonyManager.AllowedNetworkTypesReason int reason,
6829 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6831 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006832 // If the caller only has carrier privileges, then they should not be able to override
6833 // any network types which were set for security reasons.
6834 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6835 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006836 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006837 throw new SecurityException(
6838 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006839 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006840 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006841 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006842 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006843 return false;
6844 }
6845 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6846 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006847 return false;
6848 }
6849
Jack Yu5b494332023-01-23 18:18:04 +00006850 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6851 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006852
Jack Yue37dd262022-12-16 11:53:37 -08006853 Phone phone = getPhone(subId);
6854 if (phone == null) {
6855 return false;
6856 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006857
Jack Yue37dd262022-12-16 11:53:37 -08006858 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006859 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006860 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006861 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006862
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006863 final long identity = Binder.clearCallingIdentity();
6864 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006865 Boolean success = (Boolean) sendRequest(
6866 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6867 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6868
6869 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6870 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
6874 }
6875
6876 /**
Miaoa84611c2019-03-15 09:21:10 +08006877 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006878 *
Miaoa84611c2019-03-15 09:21:10 +08006879 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006880 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006881 * @hide
6882 */
6883 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006884 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006885 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006887 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 try {
Miaoa84611c2019-03-15 09:21:10 +08006889 if (phone != null) {
6890 return phone.hasMatchedTetherApnSetting();
6891 } else {
6892 return false;
6893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 } finally {
6895 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006896 }
Junda Liu475951f2014-11-07 16:45:03 -08006897 }
6898
6899 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006900 * Get the user enabled state of Mobile Data.
6901 *
6902 * TODO: remove and use isUserDataEnabled.
6903 * This can't be removed now because some vendor codes
6904 * calls through ITelephony directly while they should
6905 * use TelephonyManager.
6906 *
6907 * @return true on enabled
6908 */
6909 @Override
6910 public boolean getDataEnabled(int subId) {
6911 return isUserDataEnabled(subId);
6912 }
6913
6914 /**
6915 * Get whether mobile data is enabled per user setting.
6916 *
6917 * There are other factors deciding whether mobile data is actually enabled, but they are
6918 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006919 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006920 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6921 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006922 *
6923 * @return {@code true} if data is enabled else {@code false}
6924 */
6925 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006926 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006927 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006928 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006929 try {
6930 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6931 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006932 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006933 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6934 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006935 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006937 mApp, subId, functionName);
6938
Robert Greenwalt646120a2014-05-23 11:54:03 -07006939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940
6941 final long identity = Binder.clearCallingIdentity();
6942 try {
Jack Yu285100e2022-12-02 22:48:35 -08006943 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6945 Phone phone = PhoneFactory.getPhone(phoneId);
6946 if (phone != null) {
6947 boolean retVal = phone.isUserDataEnabled();
6948 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6949 return retVal;
6950 } else {
6951 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6952 return false;
6953 }
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006956 }
6957 }
6958
6959 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006960 * Checks if the device is capable of mobile data by considering whether whether the
6961 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6962 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006963 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006964 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006965 */
6966 @Override
6967 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006968 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006969 try {
6970 try {
6971 mApp.enforceCallingOrSelfPermission(
6972 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006973 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006974 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006975 try {
6976 mApp.enforceCallingOrSelfPermission(
6977 android.Manifest.permission.READ_PHONE_STATE,
6978 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006979 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006980 mApp.enforceCallingOrSelfPermission(
6981 permission.READ_BASIC_PHONE_STATE, functionName);
6982 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006983 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006984 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006985 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987
6988 final long identity = Binder.clearCallingIdentity();
6989 try {
Jack Yu285100e2022-12-02 22:48:35 -08006990 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991 Phone phone = PhoneFactory.getPhone(phoneId);
6992 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006993 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006994 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 return retVal;
6996 } else {
6997 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6998 return false;
6999 }
7000 } finally {
7001 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007002 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007003 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007004
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007005 /**
7006 * Check if data is enabled for a specific reason
7007 * @param subId Subscription index
7008 * @param reason the reason the data enable change is taking place
7009 * @return {@code true} if the overall data is enabled; {@code false} if not.
7010 */
7011 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007012 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007013 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007014 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007015 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007016 try {
7017 mApp.enforceCallingOrSelfPermission(
7018 android.Manifest.permission.ACCESS_NETWORK_STATE,
7019 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007020 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007021 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7022 functionName);
7023 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007024 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007025 try {
7026 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007027 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007028 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007030 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007031 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007032 }
7033
7034
7035 final long identity = Binder.clearCallingIdentity();
7036 try {
Jack Yu285100e2022-12-02 22:48:35 -08007037 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007038 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007039 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007040 + " reason=" + reason);
7041 }
7042 Phone phone = PhoneFactory.getPhone(phoneId);
7043 if (phone != null) {
7044 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007045 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007046 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007047 return retVal;
7048 } else {
7049 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007050 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007051 + subId + " retVal=false");
7052 }
7053 return false;
7054 }
7055 } finally {
7056 Binder.restoreCallingIdentity(identity);
7057 }
7058 }
7059
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007060 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007061 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007062 // No permission needed; this only lets the caller inspect their own status.
7063 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007064 }
Junda Liu29340342014-07-10 15:23:27 -07007065
7066 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007067 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007068 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007069 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7070 }
7071
7072 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7073 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007074 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007075 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007076 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7077 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007078 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7079 if (cpt == null) {
7080 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007081 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7082 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007083 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 }
7085
7086 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007087 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007088 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007089 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007090 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007091 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007092 Phone phone = getPhone(subId);
7093 if (phone == null) {
7094 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7095 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7096 }
7097 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7098 if (cpt == null) {
7099 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7101 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007102 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007103 }
7104
7105 @Override
7106 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007107 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007108 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7109 }
7110
7111 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007112 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007113 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007114 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007115 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007116 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7117 Phone phone = PhoneFactory.getPhone(phoneId);
7118 if (phone == null) {
7119 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007120 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007121 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7122 if (cpt == null) {
7123 continue;
7124 }
7125 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007126 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7127 break;
7128 }
7129 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007130 return result;
Junda Liu29340342014-07-10 15:23:27 -07007131 }
Derek Tan89e89d42014-07-08 17:00:10 -07007132
7133 @Override
Junda Liue64de782015-04-16 17:19:16 -07007134 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007135 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007136 Phone phone = PhoneFactory.getPhone(phoneId);
7137 if (phone == null) {
7138 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007139 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007140 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7141 if (cpt == null) {
7142 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007143 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007144 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007145 }
7146
Amith Yamasani6e118872016-02-19 12:53:51 -08007147 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007148 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007149 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007150 Phone phone = PhoneFactory.getPhone(phoneId);
7151 if (phone == null) {
7152 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007153 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007154 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7155 if (cpt == null) {
7156 return Collections.emptyList();
7157 }
7158 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007159 }
7160
chen xuf7e9fe82019-05-09 19:31:02 -07007161 @Override
7162 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007163 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007164 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007165 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007166 try {
7167 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7168 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7169 }
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007172 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007173 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007174 }
7175
Rambo Wang6812ffb2022-03-15 16:54:17 -07007176 @Override
7177 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7178 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7179
7180 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7181 if (phone == null) {
7182 return null;
7183 }
7184 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7185 if (cpt == null) {
7186 return null;
7187 }
7188 return cpt.getCarrierServicePackageName();
7189 }
7190
Wink Savilleb564aae2014-10-23 10:18:09 -07007191 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007192 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007193 UiccPort port = phone == null ? null : phone.getUiccPort();
7194 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007195 return null;
7196 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007197 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007198 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007199 return null;
7200 }
7201 return iccId;
7202 }
7203
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007204 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007205 public void setCallComposerStatus(int subId, int status) {
7206 enforceModifyPermission();
7207
7208 final long identity = Binder.clearCallingIdentity();
7209 try {
7210 Phone phone = getPhone(subId);
7211 if (phone != null) {
7212 Phone defaultPhone = phone.getImsPhone();
7213 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7214 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7215 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007216 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7217 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007218 }
7219 }
Shuo Qian284ae752020-12-22 19:10:14 -08007220 } catch (ImsException e) {
7221 throw new ServiceSpecificException(e.getCode());
7222 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007223 Binder.restoreCallingIdentity(identity);
7224 }
7225 }
7226
7227 @Override
7228 public int getCallComposerStatus(int subId) {
7229 enforceReadPrivilegedPermission("getCallComposerStatus");
7230
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 Phone phone = getPhone(subId);
7234 if (phone != null) {
7235 Phone defaultPhone = phone.getImsPhone();
7236 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7237 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7238 return imsPhone.getCallComposerStatus();
7239 }
7240 }
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7245 }
7246
7247 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007248 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7249 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007250 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007251 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 final long identity = Binder.clearCallingIdentity();
7254 try {
7255 final String iccId = getIccId(subId);
7256 final Phone phone = getPhone(subId);
7257 if (phone == null) {
7258 return false;
7259 }
7260 final String subscriberId = phone.getSubscriberId();
7261
7262 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007263 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264 + subscriberId + " to " + number);
7265 }
7266
7267 if (TextUtils.isEmpty(iccId)) {
7268 return false;
7269 }
7270
7271 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7272
7273 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7274 if (alphaTag == null) {
7275 editor.remove(alphaTagPrefKey);
7276 } else {
7277 editor.putString(alphaTagPrefKey, alphaTag);
7278 }
7279
7280 // Record both the line number and IMSI for this ICCID, since we need to
7281 // track all merged IMSIs based on line number
7282 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7283 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7284 if (number == null) {
7285 editor.remove(numberPrefKey);
7286 editor.remove(subscriberPrefKey);
7287 } else {
7288 editor.putString(numberPrefKey, number);
7289 editor.putString(subscriberPrefKey, subscriberId);
7290 }
7291
7292 editor.commit();
7293 return true;
7294 } finally {
7295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007296 }
Derek Tan7226c842014-07-02 17:42:23 -07007297 }
7298
7299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007300 public String getLine1NumberForDisplay(int subId, String callingPackage,
7301 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007302 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007304 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007305 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007306 return null;
7307 }
Derek Tan97ebb422014-09-05 16:55:38 -07007308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309 final long identity = Binder.clearCallingIdentity();
7310 try {
7311 String iccId = getIccId(subId);
7312 if (iccId != null) {
7313 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7314 if (DBG_MERGE) {
7315 log("getLine1NumberForDisplay returning "
7316 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7317 }
7318 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007320 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7321 return null;
7322 } finally {
7323 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007324 }
Derek Tan7226c842014-07-02 17:42:23 -07007325 }
7326
7327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007328 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7329 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007331 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007332 return null;
7333 }
Derek Tan97ebb422014-09-05 16:55:38 -07007334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 String iccId = getIccId(subId);
7338 if (iccId != null) {
7339 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7340 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7341 }
7342 return null;
7343 } finally {
7344 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007345 }
Derek Tan7226c842014-07-02 17:42:23 -07007346 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007347
7348 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007349 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7350 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007351 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7352 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007354 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007355 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007356 return null;
7357 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007358
Jordan Liub49b04b2019-05-06 14:45:15 -07007359 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7360 // the process, where TelephonyManager was instantiated.
7361 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007362 final long identity = Binder.clearCallingIdentity();
7363 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007364 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 final TelephonyManager tele = TelephonyManager.from(context);
7366 final SubscriptionManager sub = SubscriptionManager.from(context);
7367
7368 // Figure out what subscribers are currently active
7369 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370
Jordan Liub49b04b2019-05-06 14:45:15 -07007371 // Only consider subs which match the current subId
7372 // This logic can be simplified. See b/131189269 for progress.
7373 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007374 activeSubscriberIds.add(tele.getSubscriberId(subId));
7375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376
7377 // First pass, find a number override for an active subscriber
7378 String mergeNumber = null;
7379 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7380 for (String key : prefs.keySet()) {
7381 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7382 final String subscriberId = (String) prefs.get(key);
7383 if (activeSubscriberIds.contains(subscriberId)) {
7384 final String iccId = key.substring(
7385 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7386 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7387 mergeNumber = (String) prefs.get(numberKey);
7388 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007389 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 + " for active subscriber " + subscriberId);
7391 }
7392 if (!TextUtils.isEmpty(mergeNumber)) {
7393 break;
7394 }
7395 }
7396 }
7397 }
7398
7399 // Shortcut when no active merged subscribers
7400 if (TextUtils.isEmpty(mergeNumber)) {
7401 return null;
7402 }
7403
7404 // Second pass, find all subscribers under that line override
7405 final ArraySet<String> result = new ArraySet<>();
7406 for (String key : prefs.keySet()) {
7407 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7408 final String number = (String) prefs.get(key);
7409 if (mergeNumber.equals(number)) {
7410 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7411 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7412 final String subscriberId = (String) prefs.get(subscriberKey);
7413 if (!TextUtils.isEmpty(subscriberId)) {
7414 result.add(subscriberId);
7415 }
7416 }
7417 }
7418 }
7419
7420 final String[] resultArray = result.toArray(new String[result.size()]);
7421 Arrays.sort(resultArray);
7422 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007423 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7425 }
7426 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007427 } finally {
7428 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007429 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007430 }
7431
7432 @Override
zoey chen38003472019-12-13 17:16:31 +08007433 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7434 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007435
7436 final long identity = Binder.clearCallingIdentity();
7437 try {
7438 final TelephonyManager telephonyManager = mApp.getSystemService(
7439 TelephonyManager.class);
7440 String subscriberId = telephonyManager.getSubscriberId(subId);
7441 if (subscriberId == null) {
7442 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007443 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007444 + subId);
7445 }
7446 return null;
7447 }
7448
Jack Yu3beaf9d2023-04-14 09:17:27 -07007449 final SubscriptionInfo info = getSubscriptionManagerService()
7450 .getSubscriptionInfo(subId);
7451 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007452 // If it doesn't belong to any group, return just subscriberId of itself.
7453 if (groupUuid == null) {
7454 return new String[]{subscriberId};
7455 }
7456
7457 // Get all subscriberIds from the group.
7458 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007459 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7460 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7461 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007462 for (SubscriptionInfo subInfo : groupInfos) {
7463 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7464 if (subscriberId != null) {
7465 mergedSubscriberIds.add(subscriberId);
7466 }
7467 }
7468
7469 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472
7473 }
7474 }
7475
7476 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007477 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007478 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007479 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 final Phone phone = getPhone(subId);
7484 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007488 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007489
7490 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007491 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007492 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7493 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007494 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7495 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496
7497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 final Phone phone = getPhone(subId);
7500 if (phone == null) {
7501 return false;
7502 }
7503 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7504 cdmaNonRoamingList);
7505 } finally {
7506 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007507 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007508 }
7509
7510 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007511 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007512 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007513 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007514 if (phone == null) {
7515 return raf;
7516 }
7517
Shuo Qiandee53402020-05-29 14:08:15 -07007518 try {
7519 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007520 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007521 mApp, phone.getSubId(), "getRadioAccessFamily");
7522 } catch (SecurityException e) {
7523 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7524 throw e;
7525 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 final long identity = Binder.clearCallingIdentity();
7528 try {
chen xub97461a2018-10-26 14:17:57 -07007529 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
chen xub97461a2018-10-26 14:17:57 -07007533 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007534 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007535
7536 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007537 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007538 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007539 try {
7540 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7541 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007542 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007543 }
7544 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007545 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007546 }
7547 RoleManager rm = mApp.getSystemService(RoleManager.class);
7548 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7549 if (!dialerRoleHolders.contains(callingPackage)) {
7550 throw new SecurityException("App must be the dialer role holder to"
7551 + " upload a call composer pic");
7552 }
7553
7554 Executors.newSingleThreadExecutor().execute(() -> {
7555 ByteArrayOutputStream output = new ByteArrayOutputStream(
7556 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7557 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7558 boolean readUntilEnd = false;
7559 int totalBytesRead = 0;
7560 byte[] buffer = new byte[16 * 1024];
7561 while (true) {
7562 int numRead;
7563 try {
7564 numRead = input.read(buffer);
7565 } catch (IOException e) {
7566 try {
7567 fd.checkError();
7568 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7569 null);
7570 } catch (IOException e1) {
7571 // This means that the other side closed explicitly with an error. If this
7572 // happens, log and ignore.
7573 loge("Remote end of call composer picture pipe closed: " + e1);
7574 }
7575 break;
7576 }
7577 if (numRead == -1) {
7578 readUntilEnd = true;
7579 break;
7580 }
7581 totalBytesRead += numRead;
7582 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7583 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7584 try {
7585 input.close();
7586 } catch (IOException e) {
7587 // ignore
7588 }
7589 break;
7590 }
7591 output.write(buffer, 0, numRead);
7592 }
7593 // Generally, the remote end will close the file descriptors. The only case where we
7594 // close is above, where the picture size is too big.
7595
7596 try {
7597 fd.checkError();
7598 } catch (IOException e) {
7599 loge("Remote end for call composer closed with an error: " + e);
7600 return;
7601 }
7602
Hall Liuaa4211e2021-01-20 15:43:39 -08007603 if (!readUntilEnd) {
7604 loge("Did not finish reading entire image; aborting");
7605 return;
7606 }
Hall Liu82694d52020-12-11 18:22:04 -08007607
Hall Liuaa4211e2021-01-20 15:43:39 -08007608 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7609 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7610 new CallComposerPictureTransfer.Factory() {},
7611 imageData,
7612 (result) -> {
7613 if (result.first != null) {
7614 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7615 Bundle outputResult = new Bundle();
7616 outputResult.putParcelable(
7617 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7618 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7619 outputResult);
7620 } else {
7621 callback.send(result.second, null);
7622 }
7623 }
7624 );
Hall Liu82694d52020-12-11 18:22:04 -08007625 });
7626 }
7627
7628 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007629 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007630 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632
7633 final long identity = Binder.clearCallingIdentity();
7634 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007635 ImsManager.getInstance(defaultPhone.getContext(),
7636 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007640 }
7641
7642 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007643 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007644 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7646 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007647 return false;
7648 }
Svet Ganovb320e182015-04-16 12:30:10 -07007649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 // Check the user preference and the system-level IMS setting. Even if the user has
7653 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7654 // In the long run, we may instead need to check if there exists a connection service
7655 // which can support video calling.
7656 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007657 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658 return imsManager.isVtEnabledByPlatform()
7659 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7660 && imsManager.isVtEnabledByUser();
7661 } finally {
7662 Binder.restoreCallingIdentity(identity);
7663 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007664 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007665
Andrew Leea1239f22015-03-02 17:44:07 -08007666 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007667 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7668 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007670 mApp, subId, callingPackage, callingFeatureId,
7671 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 return false;
7673 }
7674
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 CarrierConfigManager configManager =
7678 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007679 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
7683 }
Andrew Leea1239f22015-03-02 17:44:07 -08007684 }
7685
7686 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007687 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007689 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 return false;
7691 }
7692
7693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 CarrierConfigManager configManager =
7696 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007697 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
Andrew Leea1239f22015-03-02 17:44:07 -08007702 }
7703
Andrew Lee9431b832015-03-09 18:46:45 -07007704 @Override
7705 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007706 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007707 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007708 }
7709
7710 @Override
7711 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 final long identity = Binder.clearCallingIdentity();
7713 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007714 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 } finally {
7716 Binder.restoreCallingIdentity(identity);
7717 }
Andrew Lee9431b832015-03-09 18:46:45 -07007718 }
7719
Hall Liuf6668912018-10-31 17:05:23 -07007720 /**
7721 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7722 * support for the feature and device firmware support.
7723 *
7724 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7725 */
7726 @Override
7727 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007729 final Phone phone = getPhone(subscriptionId);
7730 if (phone == null) {
7731 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7732 return false;
7733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007735 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7737 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007738 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 return isCarrierSupported && isDeviceSupported;
7740 } finally {
7741 Binder.restoreCallingIdentity(identity);
7742 }
Hall Liu98187582018-01-22 19:15:32 -08007743 }
7744
Hall Liuf6668912018-10-31 17:05:23 -07007745 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007746 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7747 * RTT setting, will return true if the device and carrier both support RTT.
7748 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007749 */
7750 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 final long identity = Binder.clearCallingIdentity();
7752 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007753 boolean isRttSupported = isRttSupported(subscriptionId);
7754 boolean isUserRttSettingOn = Settings.Secure.getInt(
7755 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7756 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7757 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7758 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 } finally {
7760 Binder.restoreCallingIdentity(identity);
7761 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007762 }
7763
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007764 @Deprecated
7765 @Override
7766 public String getDeviceId(String callingPackage) {
7767 return getDeviceIdWithFeature(callingPackage, null);
7768 }
7769
Sanket Padawe7310cc72015-01-14 09:53:20 -08007770 /**
7771 * Returns the unique device ID of phone, for example, the IMEI for
7772 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7773 *
7774 * <p>Requires Permission:
7775 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7776 */
7777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007778 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007779 try {
7780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7781 } catch (SecurityException se) {
7782 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7783 throw new SecurityException("Package " + callingPackage + " does not belong to "
7784 + Binder.getCallingUid());
7785 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007786 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007787 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007788 return null;
7789 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007790 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007791 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007792 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007793 return null;
7794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795
7796 final long identity = Binder.clearCallingIdentity();
7797 try {
7798 return phone.getDeviceId();
7799 } finally {
7800 Binder.restoreCallingIdentity(identity);
7801 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007802 }
7803
Ping Sunc67b7c22016-03-02 19:16:45 +08007804 /**
7805 * {@hide}
7806 * Returns the IMS Registration Status on a particular subid
7807 *
7808 * @param subId
7809 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007810 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007811 Phone phone = getPhone(subId);
7812 if (phone != null) {
7813 return phone.isImsRegistered();
7814 } else {
7815 return false;
7816 }
7817 }
7818
Santos Cordon7a1885b2015-02-03 11:15:19 -08007819 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007820 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007821 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007824 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7825 }
7826 final long identity = Binder.clearCallingIdentity();
7827 try {
7828 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7829 } finally {
7830 Binder.restoreCallingIdentity(identity);
7831 }
7832 }
7833
7834 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007835 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007836 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007837 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007838 mApp,
7839 subscriptionId,
7840 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7841 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007842 final long identity = Binder.clearCallingIdentity();
7843 try {
7844 Phone phone = getPhone(subscriptionId);
7845 if (phone == null) {
7846 return null;
7847 }
7848 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
7852 }
7853
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007854 /**
7855 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007856 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007857 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 final long identity = Binder.clearCallingIdentity();
7859 try {
7860 Phone phone = getPhone(subId);
7861 if (phone != null) {
7862 return phone.isWifiCallingEnabled();
7863 } else {
7864 return false;
7865 }
7866 } finally {
7867 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007868 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007869 }
7870
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007871 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007872 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007873 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007874 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 Phone phone = getPhone(subId);
7878 if (phone != null) {
7879 return phone.isVideoEnabled();
7880 } else {
7881 return false;
7882 }
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007885 }
7886 }
7887
7888 /**
7889 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7890 * defined in {@link ImsRegistrationImplBase}.
7891 */
7892 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007893 final long identity = Binder.clearCallingIdentity();
7894 try {
7895 Phone phone = getPhone(subId);
7896 if (phone != null) {
7897 return phone.getImsRegistrationTech();
7898 } else {
7899 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7900 }
7901 } finally {
7902 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007903 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007904 }
7905
Stuart Scott8eef64f2015-04-08 15:13:54 -07007906 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007907 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007908 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007909 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7910 return;
7911 }
Kai Shif70f46f2021-03-03 13:59:46 -08007912 Phone defaultPhone = getDefaultPhone();
7913 if (defaultPhone != null) {
7914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7915 mApp, getDefaultPhone().getSubId(), "factoryReset");
7916 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007917 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007918
Svet Ganovcc087f82015-05-12 20:35:54 -07007919 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007920 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7921 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007922 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007923 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007924 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007925 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007926 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007927 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007928 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007929 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007930 // There has been issues when Sms raw table somehow stores orphan
7931 // fragments. They lead to garbled message when new fragments come
7932 // in and combined with those stale ones. In case this happens again,
7933 // user can reset all network settings which will clean up this table.
7934 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007935 // Clean up IMS settings as well here.
7936 int slotId = getSlotIndex(subId);
7937 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7938 ImsManager.getInstance(mApp, slotId).factoryReset();
7939 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007940
Kai Shif70f46f2021-03-03 13:59:46 -08007941 if (defaultPhone == null) {
7942 return;
7943 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007944 // Erase modem config if erase modem on network setting is enabled.
7945 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7946 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7947 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007948 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007949 }
Kai Shif70f46f2021-03-03 13:59:46 -08007950
7951 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007952 } finally {
7953 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007954 }
7955 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007956
SongFerngWangfd89b102021-05-27 22:44:54 +08007957 @VisibleForTesting
7958 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7959 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7960 return;
7961 }
7962 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7963 RILConstants.PREFERRED_NETWORK_MODE);
7964 SubscriptionManager.setSubscriptionProperty(subId,
7965 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7966 "user=" + defaultNetworkType);
7967 phone.loadAllowedNetworksFromSubscriptionDatabase();
7968 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7969 defaultNetworkType, null);
7970 }
7971
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007972 private void cleanUpSmsRawTable(Context context) {
7973 ContentResolver resolver = context.getContentResolver();
7974 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7975 resolver.delete(uri, null, null);
7976 }
7977
Narayan Kamath1c496c22015-04-16 14:40:19 +01007978 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007979 public String getSimLocaleForSubscriber(int subId) {
7980 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7981 final Phone phone = getPhone(subId);
7982 if (phone == null) {
7983 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007984 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986 final long identity = Binder.clearCallingIdentity();
7987 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07007988 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
7989 phone.getContext().getOpPackageName(),
7990 phone.getContext().getAttributionTag());
7991 if (info == null) {
7992 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7993 return null;
chen xu6291c472019-02-04 12:55:53 -08007994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 // Try and fetch the locale from the carrier properties or from the SIM language
7996 // preferences (EF-PL and EF-LI)...
7997 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007999 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8000 if (localeFromDefaultSim != null) {
8001 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8002 if (DBG) log("Using locale from subId: " + subId + " locale: "
8003 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008004 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008005 } else {
8006 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007 }
8008 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 // The SIM language preferences only store a language (e.g. fr = French), not an
8011 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8012 // the SIM and carrier preferences does not include a country we add the country
8013 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008014 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008016 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008017 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 }
8019
8020 if (DBG) log("No locale found - returning null");
8021 return null;
8022 } finally {
8023 Binder.restoreCallingIdentity(identity);
8024 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008025 }
8026
tom hsu0b59d292022-09-29 23:49:21 +08008027 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008028 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008029 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008030 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008031 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008032 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8033 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008034 Locale.forLanguageTag(localeTag).getCountry())) {
8035 return localeTag;
8036 }
8037 }
8038 return inputLocale.toLanguageTag();
8039 }
8040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041 /**
8042 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8043 */
8044 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008045 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
8046 mApp.getOpPackageName(), mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008047 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008048
Gary Jian3aa9a762022-01-24 16:41:19 +08008049 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8050 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008051
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008052 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008053 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8054 * representing the state of the modem.
8055 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008056 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8057 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008058 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008059 */
8060 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008061 public void requestModemActivityInfo(ResultReceiver result) {
8062 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008063 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008064
8065 final long identity = Binder.clearCallingIdentity();
8066 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008067 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 } finally {
8069 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008070 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008071 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008072
Gary Jian76280a42022-12-07 16:18:33 +08008073 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008074 // less than total activity duration.
8075 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8076 if (info == null) {
8077 return false;
8078 }
8079 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008080 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008081 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8082
Hall Liu49656c02020-10-09 19:00:11 -07008083 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8084
Siddharth Rayb8114062018-06-17 15:02:38 -07008085 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008086 && (info.getSleepTimeMillis() <= activityDurationMs)
8087 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008088 }
8089
Gary Jian3aa9a762022-01-24 16:41:19 +08008090 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8091 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8092 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8093 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8094
8095 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8096 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8097 }
8098
8099 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8100 mLastModemActivityInfo.setReceiveTimeMillis(
8101 rat,
8102 freq,
8103 info.getReceiveTimeMillis(rat, freq)
8104 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8105 }
8106
8107 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8108 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8109 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8110 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8111
8112 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8113 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8114 }
8115 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8116 mLastModemActivityInfo.setReceiveTimeMillis(
8117 rat,
8118 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8119 }
8120
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008121 /**
8122 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8123 * @param info recent ModemActivityInfo
8124 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008125 private void mergeModemActivityInfo(ModemActivityInfo info) {
8126 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008127 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008128 boolean matched;
8129 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8130 matched = false;
8131 int rat = info.getSpecificInfoRat(i);
8132 int freq = info.getSpecificInfoFrequencyRange(i);
8133 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8134 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8135 //if it already exists
8136 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8137 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8138 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8139 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8140 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8141 updateLastModemActivityInfo(info, rat, freq);
8142 matched = true;
8143 }
8144 } else {
8145 updateLastModemActivityInfo(info, rat);
8146 matched = true;
8147 }
8148 }
8149 }
8150
8151 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008152 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008153 new ActivityStatsTechSpecificInfo(
8154 rat,
8155 freq,
8156 info.getTransmitTimeMillis(rat, freq),
8157 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008158 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008159 }
8160 }
8161 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8162 mLastModemActivitySpecificInfo =
8163 new ActivityStatsTechSpecificInfo[merged.size()];
8164 merged.toArray(mLastModemActivitySpecificInfo);
8165
8166 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8167 mLastModemActivityInfo.setSleepTimeMillis(
8168 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008169 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008170 mLastModemActivityInfo.setIdleTimeMillis(
8171 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008172 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008173
8174 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008175 new ModemActivityInfo(
8176 mLastModemActivityInfo.getTimestampMillis(),
8177 mLastModemActivityInfo.getSleepTimeMillis(),
8178 mLastModemActivityInfo.getIdleTimeMillis(),
8179 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008180 }
8181
8182 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8183 ActivityStatsTechSpecificInfo[] info) {
8184 int infoSize = info.length;
8185 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8186 for (int i = 0; i < infoSize; i++) {
8187 ret[i] = new ActivityStatsTechSpecificInfo(
8188 info[i].getRat(), info[i].getFrequencyRange(),
8189 info[i].getTransmitTimeMillis(),
8190 (int) info[i].getReceiveTimeMillis());
8191 }
8192 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008193 }
8194
Jack Yu85bd38a2015-11-09 11:34:32 -08008195 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008196 * Returns the service state information on specified subscription.
8197 */
8198 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008199 public ServiceState getServiceStateForSubscriber(int subId,
8200 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8201 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008203 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008204 return null;
8205 }
8206
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008207 boolean hasFinePermission = false;
8208 boolean hasCoarsePermission = false;
8209 if (!renounceFineLocationAccess) {
8210 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8211 LocationAccessPolicy.checkLocationPermission(mApp,
8212 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8213 .setCallingPackage(callingPackage)
8214 .setCallingFeatureId(callingFeatureId)
8215 .setCallingPid(Binder.getCallingPid())
8216 .setCallingUid(Binder.getCallingUid())
8217 .setMethod("getServiceStateForSubscriber")
8218 .setLogAsInfo(true)
8219 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8220 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8221 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8222 .build());
8223 hasFinePermission =
8224 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8225 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008226
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008227 if (!renounceCoarseLocationAccess) {
8228 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8229 LocationAccessPolicy.checkLocationPermission(mApp,
8230 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8231 .setCallingPackage(callingPackage)
8232 .setCallingFeatureId(callingFeatureId)
8233 .setCallingPid(Binder.getCallingPid())
8234 .setCallingUid(Binder.getCallingUid())
8235 .setMethod("getServiceStateForSubscriber")
8236 .setLogAsInfo(true)
8237 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8238 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8239 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8240 .build());
8241 hasCoarsePermission =
8242 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8243 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008244
Jack Yu479f40e2020-10-27 21:29:25 -07008245 final Phone phone = getPhone(subId);
8246 if (phone == null) {
8247 return null;
8248 }
8249
Jordan Liu0f2bc442020-11-18 16:47:37 -08008250 final long identity = Binder.clearCallingIdentity();
8251
Jack Yu479f40e2020-10-27 21:29:25 -07008252 boolean isCallingPackageDataService = phone.getDataServicePackages()
8253 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008255 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008256 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8257 .getSubscriptionInfoInternal(subId);
8258 if (subInfo == null || !subInfo.isActive()) {
8259 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8260 + "subId=" + subId);
8261 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008262 }
8263
Hall Liuf19c44f2018-11-27 14:38:17 -08008264 ServiceState ss = phone.getServiceState();
8265
8266 // Scrub out the location info in ServiceState depending on what level of access
8267 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008268 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008269 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8270 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271 } finally {
8272 Binder.restoreCallingIdentity(identity);
8273 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008274 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008275
8276 /**
8277 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8278 *
8279 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8280 * voicemail ringtone.
8281 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8282 * PhoneAccount.
8283 */
8284 @Override
8285 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 final long identity = Binder.clearCallingIdentity();
8287 try {
8288 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8289 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008290 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8294 } finally {
8295 Binder.restoreCallingIdentity(identity);
8296 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008297 }
8298
8299 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008300 * Sets the per-account voicemail ringtone.
8301 *
8302 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8303 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8304 *
8305 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8306 * voicemail ringtone.
8307 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8308 * PhoneAccount.
8309 */
8310 @Override
8311 public void setVoicemailRingtoneUri(String callingPackage,
8312 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008313 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008315 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8316 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8318 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8319 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321
8322 final long identity = Binder.clearCallingIdentity();
8323 try {
8324 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8325 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008326 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 }
8328 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8329 } finally {
8330 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008331 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008332 }
8333
8334 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008335 * Returns whether vibration is set for voicemail notification in Phone settings.
8336 *
8337 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8338 * voicemail vibration setting.
8339 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8340 */
8341 @Override
8342 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 final long identity = Binder.clearCallingIdentity();
8344 try {
8345 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8346 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008347 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8351 } finally {
8352 Binder.restoreCallingIdentity(identity);
8353 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008354 }
8355
Youhan Wange64578a2016-05-02 15:32:42 -07008356 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008357 * Sets the per-account voicemail vibration.
8358 *
8359 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8360 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8361 *
8362 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8363 * voicemail vibration setting.
8364 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8365 * specific PhoneAccount.
8366 */
8367 @Override
8368 public void setVoicemailVibrationEnabled(String callingPackage,
8369 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008370 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008372 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8373 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8375 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8376 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008377 }
8378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 final long identity = Binder.clearCallingIdentity();
8380 try {
8381 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8382 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008383 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008384 }
8385 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8386 } finally {
8387 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008388 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008389 }
8390
8391 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008392 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8393 *
8394 * @throws SecurityException if the caller does not have the required permission
8395 */
arunvoddud7401012022-12-15 16:08:12 +00008396 @VisibleForTesting
8397 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008399 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008400 }
8401
8402 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008403 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8404 * permission.
8405 *
8406 * @throws SecurityException if the caller does not have the required permission
8407 */
8408 private void enforceSendSmsPermission() {
8409 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8410 }
8411
8412 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008413 * Make sure either called from same process as self (phone) or IPC caller has interact across
8414 * users permission.
8415 *
8416 * @throws SecurityException if the caller does not have the required permission
8417 */
8418 private void enforceInteractAcrossUsersPermission(String message) {
8419 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8420 }
8421
8422 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008423 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008424 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008425 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008426 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008427 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008431 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432 if (componentName == null) {
8433 throw new SecurityException(
8434 "Caller not current active visual voicemail package[null]");
8435 }
8436 String vvmPackage = componentName.getPackageName();
8437 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008438 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439 }
8440 } finally {
8441 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008442 }
8443 }
8444
8445 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008446 * Return the application ID for the app type.
8447 *
8448 * @param subId the subscription ID that this request applies to.
8449 * @param appType the uicc app type.
8450 * @return Application ID for specificied app type, or null if no uicc.
8451 */
8452 @Override
8453 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008454 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008455 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456
8457 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008458 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459 if (phone == null) {
8460 return null;
8461 }
8462 String aid = null;
8463 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008464 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465 .getApplicationByType(appType).getAid();
8466 } catch (Exception e) {
8467 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8468 }
8469 return aid;
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008472 }
Youhan Wange64578a2016-05-02 15:32:42 -07008473 }
8474
Youhan Wang4001d252016-05-11 10:29:41 -07008475 /**
8476 * Return the Electronic Serial Number.
8477 *
8478 * @param subId the subscription ID that this request applies to.
8479 * @return ESN or null if error.
8480 */
8481 @Override
8482 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008483 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008484 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008485
8486 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008487 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008488 if (phone == null) {
8489 return null;
8490 }
8491 String esn = null;
8492 try {
8493 esn = phone.getEsn();
8494 } catch (Exception e) {
8495 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8496 }
8497 return esn;
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008500 }
Youhan Wang4001d252016-05-11 10:29:41 -07008501 }
8502
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008503 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008504 * Return the Preferred Roaming List Version.
8505 *
8506 * @param subId the subscription ID that this request applies to.
8507 * @return PRLVersion or null if error.
8508 */
8509 @Override
8510 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008511 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008512 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513
8514 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008515 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516 if (phone == null) {
8517 return null;
8518 }
8519 String cdmaPrlVersion = null;
8520 try {
8521 cdmaPrlVersion = phone.getCdmaPrlVersion();
8522 } catch (Exception e) {
8523 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8524 }
8525 return cdmaPrlVersion;
8526 } finally {
8527 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008528 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008529 }
8530
8531 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008532 * Get snapshot of Telephony histograms
8533 * @return List of Telephony histograms
8534 * @hide
8535 */
8536 @Override
8537 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8539 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008540
8541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 return RIL.getTelephonyRILTimingHistograms();
8544 } finally {
8545 Binder.restoreCallingIdentity(identity);
8546 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008547 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008548
8549 /**
8550 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008551 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8552 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008553 * Require system privileges. In the future we may add this to carrier APIs.
8554 *
Michele Berionne482f8202018-11-27 18:57:59 -08008555 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008556 */
8557 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008558 @TelephonyManager.SetCarrierRestrictionResult
8559 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008560 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008561 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008562
Michele Berionne482f8202018-11-27 18:57:59 -08008563 if (carrierRestrictionRules == null) {
8564 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008565 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567 final long identity = Binder.clearCallingIdentity();
8568 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008569 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008570 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 } finally {
8572 Binder.restoreCallingIdentity(identity);
8573 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008574 }
8575
8576 /**
8577 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008578 * Get the allowed carrier list and the excluded carrier list, including the priority between
8579 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008580 * Require system privileges. In the future we may add this to carrier APIs.
8581 *
Michele Berionne482f8202018-11-27 18:57:59 -08008582 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008583 */
8584 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008585 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008586 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008587 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008588
8589 final long identity = Binder.clearCallingIdentity();
8590 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008591 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8592 if (response instanceof CarrierRestrictionRules) {
8593 return (CarrierRestrictionRules) response;
8594 }
8595 // Response is an Exception of some kind,
8596 // which is signalled to the user as a NULL retval
8597 return null;
8598 } catch (Exception e) {
8599 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8600 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 } finally {
8602 Binder.restoreCallingIdentity(identity);
8603 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008604 }
8605
fionaxu59545b42016-05-25 15:53:37 -07008606 /**
arunvoddud7401012022-12-15 16:08:12 +00008607 * Fetches the carrier restriction status of the device and sends the status to the caller
8608 * through the callback.
8609 *
8610 * @param callback The callback that will be used to send the result.
8611 * @throws SecurityException if the caller does not have the required permission/privileges or
8612 * the caller is not allowlisted.
8613 */
8614 @Override
8615 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8616 enforceReadPermission("getCarrierRestrictionStatus");
8617 int carrierId = validateCallerAndGetCarrierId(packageName);
8618 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8619 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8620 throw new SecurityException("Not an authorized caller");
8621 }
8622 final long identity = Binder.clearCallingIdentity();
8623 try {
8624 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8625 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8626 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8627 } finally {
8628 Binder.restoreCallingIdentity(identity);
8629 }
8630 }
8631
arunvoddu567f2b42023-04-25 17:22:00 +00008632 @Override
8633 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8634 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8635 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8636 return allowListInfo.getShaIdList(pkgName, carrierId);
8637 }
8638
arunvoddud7401012022-12-15 16:08:12 +00008639 @VisibleForTesting
8640 public int validateCallerAndGetCarrierId(String packageName) {
8641 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8642 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8643 }
8644
8645 /**
fionaxu59545b42016-05-25 15:53:37 -07008646 * Action set from carrier signalling broadcast receivers to enable/disable radio
8647 * @param subId the subscription ID that this action applies to.
8648 * @param enabled control enable or disable radio.
8649 * {@hide}
8650 */
8651 @Override
8652 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8653 enforceModifyPermission();
8654 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655
8656 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008657 if (phone == null) {
8658 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8659 return;
8660 }
8661 try {
8662 phone.carrierActionSetRadioEnabled(enabled);
8663 } catch (Exception e) {
8664 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008665 } finally {
8666 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008667 }
8668 }
8669
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008670 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008671 * Enable or disable Voice over NR (VoNR)
8672 * @param subId the subscription ID that this action applies to.
8673 * @param enabled enable or disable VoNR.
8674 * @return operation result.
8675 */
8676 @Override
8677 public int setVoNrEnabled(int subId, boolean enabled) {
8678 enforceModifyPermission();
8679 final Phone phone = getPhone(subId);
8680
8681 final long identity = Binder.clearCallingIdentity();
8682 if (phone == null) {
8683 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8684 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8685 }
8686
8687 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8688 try {
8689 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8690 workSource);
8691 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008692
8693 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8694 if (DBG) {
8695 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8696 }
8697 SubscriptionManager.setSubscriptionProperty(
8698 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8699 (enabled ? "1" : "0"));
8700 }
8701
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008702 return result;
8703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
8706 }
8707
8708 /**
8709 * Is voice over NR enabled
8710 * @return true if VoNR is enabled else false
8711 */
8712 @Override
8713 public boolean isVoNrEnabled(int subId) {
8714 enforceReadPrivilegedPermission("isVoNrEnabled");
8715 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8716 final long identity = Binder.clearCallingIdentity();
8717 try {
8718 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8719 null, subId, workSource);
8720 if (DBG) log("isVoNrEnabled: " + isEnabled);
8721 return isEnabled;
8722 } finally {
8723 Binder.restoreCallingIdentity(identity);
8724 }
8725 }
8726
8727 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008728 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8729 * network status based on which carrier apps could apply actions accordingly,
8730 * enable/disable default url handler for example.
8731 *
8732 * @param subId the subscription ID that this action applies to.
8733 * @param report control start/stop reporting the default network status.
8734 * {@hide}
8735 */
8736 @Override
8737 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8738 enforceModifyPermission();
8739 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008740
8741 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008742 if (phone == null) {
8743 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8744 return;
8745 }
8746 try {
8747 phone.carrierActionReportDefaultNetworkStatus(report);
8748 } catch (Exception e) {
8749 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008750 } finally {
8751 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008752 }
8753 }
8754
8755 /**
fionaxud9622282017-07-17 17:51:30 -07008756 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8757 * @param subId the subscription ID that this action applies to.
8758 * {@hide}
8759 */
8760 @Override
8761 public void carrierActionResetAll(int subId) {
8762 enforceModifyPermission();
8763 final Phone phone = getPhone(subId);
8764 if (phone == null) {
8765 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8766 return;
8767 }
8768 try {
8769 phone.carrierActionResetAll();
8770 } catch (Exception e) {
8771 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8772 }
8773 }
8774
8775 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008776 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8777 * bug report is being generated.
8778 */
8779 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008780 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008781 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8782 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008783 writer.println("Permission Denial: can't dump Phone from pid="
8784 + Binder.getCallingPid()
8785 + ", uid=" + Binder.getCallingUid()
8786 + "without permission "
8787 + android.Manifest.permission.DUMP);
8788 return;
8789 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008790 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008791 }
Jack Yueb89b242016-06-22 13:27:47 -07008792
Brad Ebingerdac2f002018-04-03 15:17:52 -07008793 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008794 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8795 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8796 @NonNull String[] args) {
8797 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8798 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008799 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008800 }
8801
Jack Yueb89b242016-06-22 13:27:47 -07008802 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008803 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008804 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008805 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008806 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008807 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008808 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008809 */
8810 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008811 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008812 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008813 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8814 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8815 try {
8816 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008817 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008818 } catch (SecurityException se) {
8819 enforceModifyPermission();
8820 }
8821 } else {
8822 enforceModifyPermission();
8823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008824
8825 final long identity = Binder.clearCallingIdentity();
8826 try {
8827 Phone phone = getPhone(subId);
8828 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008829 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8830 phone.carrierActionSetMeteredApnsEnabled(enabled);
8831 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008832 phone.getDataSettingsManager().setDataEnabled(
8833 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008835 }
8836 } finally {
8837 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008838 }
8839 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008840
8841 /**
8842 * Get Client request stats
8843 * @return List of Client Request Stats
8844 * @hide
8845 */
8846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008847 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8848 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008850 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008851 return null;
8852 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008853 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008855 final long identity = Binder.clearCallingIdentity();
8856 try {
8857 if (phone != null) {
8858 return phone.getClientRequestStats();
8859 }
8860
8861 return null;
8862 } finally {
8863 Binder.restoreCallingIdentity(identity);
8864 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008865 }
8866
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008867 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008868 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008869 if (uid == Process.ROOT_UID && packageName == null) {
8870 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8871 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8872 // exception. ROOT_UID seems not to have a valid package name returned by
8873 // PackageManager, so just fake it here to avoid issues when running telephony shell
8874 // commands that plumb through the RIL as root, like so:
8875 // $ adb root
8876 // $ adb shell cmd phone ...
8877 packageName = "root";
8878 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008879 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008880 }
Jack Yueb4124c2017-02-16 15:32:43 -08008881
8882 /**
Grace Chen70990072017-03-24 17:21:30 -07008883 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008884 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008885 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008886 * @param state State of SIM (power down, power up, pass through)
8887 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8888 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8889 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008890 *
8891 **/
8892 @Override
Grace Chen70990072017-03-24 17:21:30 -07008893 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008894 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008895 Phone phone = PhoneFactory.getPhone(slotIndex);
8896
vagdeviaf9a5b92018-08-15 16:01:53 -07008897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 final long identity = Binder.clearCallingIdentity();
8900 try {
8901 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008902 phone.setSimPowerState(state, null, workSource);
8903 }
8904 } finally {
8905 Binder.restoreCallingIdentity(identity);
8906 }
8907 }
8908
8909 /**
8910 * Set SIM card power state.
8911 *
8912 * @param slotIndex SIM slot id.
8913 * @param state State of SIM (power down, power up, pass through)
8914 * @param callback callback to trigger after success or failure
8915 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8916 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8917 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8918 *
8919 **/
8920 @Override
8921 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8922 IIntegerConsumer callback) {
8923 enforceModifyPermission();
8924 Phone phone = PhoneFactory.getPhone(slotIndex);
8925
8926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8927
8928 final long identity = Binder.clearCallingIdentity();
8929 try {
8930 if (phone != null) {
8931 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8932 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 }
8934 } finally {
8935 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008936 }
8937 }
Shuo Qiandd210312017-04-12 22:11:33 +00008938
Tyler Gunn65d45c22017-06-05 11:22:26 -07008939 private boolean isUssdApiAllowed(int subId) {
8940 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008941 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008942 if (configManager == null) {
8943 return false;
8944 }
8945 PersistableBundle pb = configManager.getConfigForSubId(subId);
8946 if (pb == null) {
8947 return false;
8948 }
8949 return pb.getBoolean(
8950 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8951 }
8952
Shuo Qiandd210312017-04-12 22:11:33 +00008953 /**
Ling Mac28f0212023-03-24 16:07:15 -07008954 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008955 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008956 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008957 */
goneil9c5f4872017-12-05 14:07:56 -08008958 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008959 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008960 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008961 final long identity = Binder.clearCallingIdentity();
8962 try {
Ling Mac28f0212023-03-24 16:07:15 -07008963 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008964 } finally {
8965 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008966 }
8967 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008968
8969 /**
8970 * Get the current signal strength information for the given subscription.
8971 * Because this information is not updated when the device is in a low power state
8972 * it should not be relied-upon to be current.
8973 * @param subId Subscription index
8974 * @return the most recent cached signal strength info from the modem
8975 */
8976 @Override
8977 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 final long identity = Binder.clearCallingIdentity();
8979 try {
8980 Phone p = getPhone(subId);
8981 if (p == null) {
8982 return null;
8983 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 return p.getSignalStrength();
8986 } finally {
8987 Binder.restoreCallingIdentity(identity);
8988 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008989 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008990
Pengquan Meng77b7f132018-08-22 14:49:57 -07008991 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008992 * Get the current modem radio state for the given slot.
8993 * @param slotIndex slot index.
8994 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008995 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008996 * @return the current radio power state from the modem
8997 */
8998 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008999 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009000 Phone phone = PhoneFactory.getPhone(slotIndex);
9001 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9003 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009004 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9005 }
9006
9007 final long identity = Binder.clearCallingIdentity();
9008 try {
9009 return phone.getRadioPowerState();
9010 } finally {
9011 Binder.restoreCallingIdentity(identity);
9012 }
9013 }
9014 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9015 }
9016
9017 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009018 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9019 *
9020 * <p>Requires one of the following permissions:
9021 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009022 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009023 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9024 * privileges.
9025 *
9026 * @param subId subscription id
9027 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9028 * {@code false}.
9029 */
9030 @Override
9031 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009032 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009033 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009034 try {
9035 mApp.enforceCallingOrSelfPermission(
9036 android.Manifest.permission.ACCESS_NETWORK_STATE,
9037 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009038 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009039 mApp.enforceCallingOrSelfPermission(
9040 permission.READ_BASIC_PHONE_STATE, functionName);
9041 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009042 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009043 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009044 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009045 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009046
Pengquan Menga1bb6272018-09-06 09:59:22 -07009047 boolean isEnabled = false;
9048 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009049 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009050 Phone phone = getPhone(subId);
9051 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009052 } finally {
9053 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009054 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009055 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009056 }
9057
9058
9059 /**
9060 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9061 *
9062 * <p> Requires permission:
9063 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9064 * privileges.
9065 *
9066 * @param subId subscription id
9067 * @param isEnabled {@code true} means enable, {@code false} means disable.
9068 */
9069 @Override
9070 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9072 mApp, subId, "setDataRoamingEnabled");
9073
Pengquan Menga1bb6272018-09-06 09:59:22 -07009074 final long identity = Binder.clearCallingIdentity();
9075 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009076 Phone phone = getPhone(subId);
9077 if (phone != null) {
9078 phone.setDataRoamingEnabled(isEnabled);
9079 }
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009082 }
9083 }
9084
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009085 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009086 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009087 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009088 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009089 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009090
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009091 boolean isAllowed = true;
9092 final long identity = Binder.clearCallingIdentity();
9093 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009094 Phone phone = getPhone(subId);
9095 if (phone != null) {
9096 isAllowed = phone.isCspPlmnEnabled();
9097 }
9098 } finally {
9099 Binder.restoreCallingIdentity(identity);
9100 }
9101 return isAllowed;
9102 }
9103
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009104 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9105 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009106 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009107 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009108 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009109 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9110 if (phone == null) {
9111 return false;
9112 }
9113 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9114 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9115 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009116 }
9117
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009118 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009119 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009120 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009121 mApp.getSystemService(AppOpsManager.class)
9122 .checkPackage(Binder.getCallingUid(), callingPackage);
9123
Jordan Liu1e142fc2019-04-22 15:10:43 -07009124 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009125 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009126 try {
9127 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009128 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009129 } catch (SecurityException e) {
9130 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9131 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009132 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009133 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009134 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009135 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009136 }
sandeepjsb6c87872021-09-27 15:34:44 +00009137 // checking compatibility, if calling app's target SDK is T and beyond.
9138 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9139 Binder.getCallingUid())) {
9140 isIccIdAccessRestricted = true;
9141 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009142 final long identity = Binder.clearCallingIdentity();
9143 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009144 UiccController uiccController = UiccController.getInstance();
9145 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009146 if (hasReadPermission) {
9147 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009148 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009149
9150 // Remove private info if the caller doesn't have access
9151 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9152 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009153 //setting the value after compatibility check
9154 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009155 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9156 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009157 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009158 if (card == null) {
9159 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009160 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009161 continue;
9162 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009163 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9164 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009165 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009166 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009167 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009168 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9169 for (UiccPortInfo portInfo : portInfos) {
9170 UiccPort port = uiccController.getUiccPortForSlot(
9171 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9172 if (port == null) {
9173 // assume no access if port is null
9174 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9175 continue;
9176 }
9177 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9178 uiccPortInfos.add(portInfo);
9179 } else {
9180 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9181 }
9182 }
9183 filteredInfos.add(new UiccCardInfo(
9184 cardInfo.isEuicc(),
9185 cardInfo.getCardId(),
9186 null,
9187 cardInfo.getPhysicalSlotIndex(),
9188 cardInfo.isRemovable(),
9189 cardInfo.isMultipleEnabledProfilesSupported(),
9190 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009191 }
9192 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009193 } finally {
9194 Binder.restoreCallingIdentity(identity);
9195 }
9196 }
9197
sandeepjsb6c87872021-09-27 15:34:44 +00009198 /**
9199 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9200 * generally private and require carrier privileges to view.
9201 *
9202 * @hide
9203 */
9204 @NonNull
9205 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9206 List<UiccPortInfo> portinfo = new ArrayList<>();
9207 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9208 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9209 }
9210 return new UiccCardInfo(
9211 cardInfo.isEuicc(),
9212 cardInfo.getCardId(),
9213 null,
9214 cardInfo.getPhysicalSlotIndex(),
9215 cardInfo.isRemovable(),
9216 cardInfo.isMultipleEnabledProfilesSupported(),
9217 portinfo
9218 );
9219 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009220
sandeepjsb6c87872021-09-27 15:34:44 +00009221 /**
9222 * @hide
9223 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9224 * These values are generally private and require carrier privileges to view.
9225 */
9226 @NonNull
9227 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9228 return new UiccPortInfo(
9229 UiccPortInfo.ICCID_REDACTED,
9230 portInfo.getPortIndex(),
9231 portInfo.getLogicalSlotIndex(),
9232 portInfo.isActive()
9233 );
9234 }
9235 @Override
9236 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009237 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009238 mApp.getSystemService(AppOpsManager.class)
9239 .checkPackage(Binder.getCallingUid(), callingPackage);
9240
sandeepjsb6c87872021-09-27 15:34:44 +00009241 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009242
Aman Guptaf3c90b32022-03-17 04:54:16 +00009243 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9244 // we are reading iccId which is PII data.
9245 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009246
9247 // checking compatibility, if calling app's target SDK is T and beyond.
9248 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9249 Binder.getCallingUid())) {
9250 isLogicalSlotAccessRestricted = true;
9251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009252 final long identity = Binder.clearCallingIdentity();
9253 try {
9254 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009255 if (slots == null || slots.length == 0) {
9256 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009257 return null;
9258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009259 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9260 for (int i = 0; i < slots.length; i++) {
9261 UiccSlot slot = slots[i];
9262 if (slot == null) {
9263 continue;
9264 }
9265
Jordan Liu7be7e652019-05-06 18:55:02 +00009266 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009267 UiccCard card = slot.getUiccCard();
9268 if (card != null) {
9269 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009270 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009271 cardId = slot.getEid();
9272 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009273 // If cardId is null, use iccId of default port as cardId.
9274 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009276 }
9277
Jordan Liu857451f2019-05-09 16:35:35 -07009278 if (cardId != null) {
9279 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9280 // if cardId is an EID, it's all digits so this is fine
9281 cardId = IccUtils.stripTrailingFs(cardId);
9282 }
9283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009284 int cardState = 0;
9285 switch (slot.getCardState()) {
9286 case CARDSTATE_ABSENT:
9287 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9288 break;
9289 case CARDSTATE_PRESENT:
9290 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9291 break;
9292 case CARDSTATE_ERROR:
9293 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9294 break;
9295 case CARDSTATE_RESTRICTED:
9296 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9297 break;
9298 default:
9299 break;
9300
9301 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009302 List<UiccPortInfo> portInfos = new ArrayList<>();
9303 int[] portIndexes = slot.getPortList();
9304 for (int portIdx : portIndexes) {
9305 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009306 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009307 portInfos.add(new UiccPortInfo(iccId, portIdx,
9308 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009310 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009311 slot.isEuicc(),
9312 cardId,
9313 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009314 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009315 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009316 //setting the value after compatibility check
9317 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009318 }
9319 return infos;
9320 } finally {
9321 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009322 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009323 }
9324
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009325 /* Returns null if doesn't have read permission or carrier privilege access. */
9326 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9327 boolean hasReadPermission) {
9328 String iccId = slot.getIccId(portIndex);
9329 if (hasReadPermission) { // if has read permission
9330 return iccId;
9331 } else {
9332 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9333 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9334 // if no read permission, checking carrier privilege access
9335 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9336 return iccId;
9337 }
9338 }
9339 }
9340 // No read permission or carrier privilege access.
9341 return UiccPortInfo.ICCID_REDACTED;
9342 }
9343
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009344 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009345 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009346 public boolean switchSlots(int[] physicalSlots) {
9347 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009348
9349 final long identity = Binder.clearCallingIdentity();
9350 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009351 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9352 for (int i = 0; i < physicalSlots.length; i++) {
9353 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9354 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9355 physicalSlots[i], i));
9356 }
9357 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009358 } finally {
9359 Binder.restoreCallingIdentity(identity);
9360 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009361 }
Jack Yu4c988042018-02-27 15:30:01 -08009362
9363 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009364 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9365 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9366 enforceModifyPermission();
9367
9368 final long identity = Binder.clearCallingIdentity();
9369 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009370 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009371 } finally {
9372 Binder.restoreCallingIdentity(identity);
9373 }
9374 }
9375
9376 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009377 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009378 final long identity = Binder.clearCallingIdentity();
9379 try {
9380 return UiccController.getInstance().getCardIdForDefaultEuicc();
9381 } finally {
9382 Binder.restoreCallingIdentity(identity);
9383 }
9384 }
9385
Pengquan Meng85728fb2018-03-12 16:31:21 -07009386 /**
goneil47ffb6e2018-04-06 15:40:58 -07009387 * A test API to reload the UICC profile.
9388 *
9389 * <p>Requires that the calling app has permission
9390 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9391 * @hide
9392 */
9393 @Override
9394 public void refreshUiccProfile(int subId) {
9395 enforceModifyPermission();
9396
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 Phone phone = getPhone(subId);
9400 if (phone == null) {
9401 return;
9402 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009403 UiccPort uiccPort = phone.getUiccPort();
9404 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009405 return;
9406 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009407 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009408 if (uiccProfile == null) {
9409 return;
9410 }
9411 uiccProfile.refresh();
9412 } finally {
9413 Binder.restoreCallingIdentity(identity);
9414 }
9415 }
9416
9417 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009418 * Returns false if the mobile data is disabled by default, otherwise return true.
9419 */
9420 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009421 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009422 }
9423
9424 /**
9425 * Returns true if the data roaming is enabled by default, i.e the system property
9426 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9427 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9428 */
9429 private boolean getDefaultDataRoamingEnabled(int subId) {
9430 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009431 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009432 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009433 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9434 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9435 return isDataRoamingEnabled;
9436 }
9437
9438 /**
9439 * Returns the default network type for the given {@code subId}, if the default network type is
9440 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9441 */
9442 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009443 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009444 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009445 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9446 return list.get(phoneId);
9447 }
9448 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009449 }
fionaxua13278b2018-03-21 00:08:13 -07009450
9451 @Override
9452 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009453 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009454 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009455
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
9458 final Phone phone = getPhone(subId);
9459 if (phone == null) {
9460 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9461 return;
9462 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009463 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9464 if (cpt != null) {
9465 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9466 }
9467 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009468 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9469 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009470 if (carrierPrivilegeRules == null) {
9471 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9472 } else {
9473 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009475 } finally {
9476 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009477 }
fionaxua13278b2018-03-21 00:08:13 -07009478 }
9479
9480 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009481 public void setCarrierServicePackageOverride(
9482 int subId, String carrierServicePackage, String callingPackage) {
9483 TelephonyPermissions.enforceShellOnly(
9484 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9485
9486 // Verify that the callingPackage belongs to the calling UID
9487 mApp.getSystemService(AppOpsManager.class)
9488 .checkPackage(Binder.getCallingUid(), callingPackage);
9489
9490 final long identity = Binder.clearCallingIdentity();
9491 try {
9492 final Phone phone = getPhone(subId);
9493 if (phone == null || phone.getSubId() != subId) {
9494 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9495 throw new IllegalArgumentException("No phone for subid");
9496 }
9497 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9498 if (cpt == null) {
9499 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9500 throw new IllegalStateException("No CPT for phone");
9501 }
9502 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9503 } finally {
9504 Binder.restoreCallingIdentity(identity);
9505 }
9506 }
9507
9508 @Override
fionaxua13278b2018-03-21 00:08:13 -07009509 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009510 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009511
9512 final long identity = Binder.clearCallingIdentity();
9513 try {
9514 final Phone phone = getPhone(subId);
9515 if (phone == null) {
9516 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9517 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9518 }
9519 return phone.getCarrierIdListVersion();
9520 } finally {
9521 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009522 }
fionaxua13278b2018-03-21 00:08:13 -07009523 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009524
9525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009526 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9527 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009529 mApp, subId, callingPackage, callingFeatureId,
9530 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009531 return -1;
9532 }
9533
9534 final long identity = Binder.clearCallingIdentity();
9535 try {
9536 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9537 } finally {
9538 Binder.restoreCallingIdentity(identity);
9539 }
9540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009541
9542 @Override
9543 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009544 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009545 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009546 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009547
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
9550 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 }
9555
9556 @Override
9557 public boolean setCdmaRoamingMode(int subId, int mode) {
9558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9559 mApp, subId, "setCdmaRoamingMode");
9560
9561 final long identity = Binder.clearCallingIdentity();
9562 try {
9563 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
9569 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009570 public int getCdmaSubscriptionMode(int subId) {
9571 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009572 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009573 mApp, subId, "getCdmaSubscriptionMode");
9574
9575 final long identity = Binder.clearCallingIdentity();
9576 try {
9577 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
9581 }
9582
9583 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009584 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9586 mApp, subId, "setCdmaSubscriptionMode");
9587
9588 final long identity = Binder.clearCallingIdentity();
9589 try {
9590 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9591 } finally {
9592 Binder.restoreCallingIdentity(identity);
9593 }
9594 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009595
sqianc5eccab2018-10-19 18:46:41 -07009596 @Override
sqian8c685422019-02-22 15:55:18 -08009597 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009598 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009600 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9601 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009602 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9603 }
9604 final long identity = Binder.clearCallingIdentity();
9605 try {
sqian854d44b2018-12-12 16:48:18 -08009606 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9607 for (Phone phone: PhoneFactory.getPhones()) {
9608 if (phone.getEmergencyNumberTracker() != null
9609 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9610 emergencyNumberListInternal.put(
9611 phone.getSubId(),
9612 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9613 }
sqian11b7a0e2018-12-05 18:48:28 -08009614 }
sqian854d44b2018-12-12 16:48:18 -08009615 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009616 } finally {
9617 Binder.restoreCallingIdentity(identity);
9618 }
sqianc5eccab2018-10-19 18:46:41 -07009619 }
9620
9621 @Override
sqian8c685422019-02-22 15:55:18 -08009622 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009623 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009624 if (!exactMatch) {
9625 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009626 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009627 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009628 }
9629 final long identity = Binder.clearCallingIdentity();
9630 try {
sqian854d44b2018-12-12 16:48:18 -08009631 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009632 //Note: we ignore passed in param exactMatch. We can remove it once
9633 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009634 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009635 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009636 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009637 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009638 }
sqian11b7a0e2018-12-05 18:48:28 -08009639 }
9640 return false;
9641 } finally {
9642 Binder.restoreCallingIdentity(identity);
9643 }
9644 }
9645
sqianf4ca7ed2019-01-15 18:32:07 -08009646 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009647 * Start emergency callback mode for GsmCdmaPhone for testing.
9648 */
9649 @Override
9650 public void startEmergencyCallbackMode() {
9651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9652 "startEmergencyCallbackMode");
9653 enforceModifyPermission();
9654 final long identity = Binder.clearCallingIdentity();
9655 try {
9656 for (Phone phone : PhoneFactory.getPhones()) {
9657 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9658 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9659 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9660 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9661 gsmCdmaPhone.obtainMessage(
9662 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9663 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9664 }
9665 }
9666 } finally {
9667 Binder.restoreCallingIdentity(identity);
9668 }
9669 }
9670
9671 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009672 * Update emergency number list for test mode.
9673 */
9674 @Override
9675 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9677 "updateEmergencyNumberListTestMode");
9678
9679 final long identity = Binder.clearCallingIdentity();
9680 try {
9681 for (Phone phone: PhoneFactory.getPhones()) {
9682 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9683 if (tracker != null) {
9684 tracker.executeEmergencyNumberTestModeCommand(action, num);
9685 }
9686 }
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
9691
9692 /**
9693 * Get the full emergency number list for test mode.
9694 */
9695 @Override
9696 public List<String> getEmergencyNumberListTestMode() {
9697 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9698 "getEmergencyNumberListTestMode");
9699
9700 final long identity = Binder.clearCallingIdentity();
9701 try {
9702 Set<String> emergencyNumbers = new HashSet<>();
9703 for (Phone phone: PhoneFactory.getPhones()) {
9704 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9705 if (tracker != null) {
9706 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9707 emergencyNumbers.add(num.getNumber());
9708 }
9709 }
9710 }
9711 return new ArrayList<>(emergencyNumbers);
9712 } finally {
9713 Binder.restoreCallingIdentity(identity);
9714 }
9715 }
9716
chen xud6b45bd2018-10-30 22:27:10 -07009717 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009718 public int getEmergencyNumberDbVersion(int subId) {
9719 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9720
9721 final long identity = Binder.clearCallingIdentity();
9722 try {
9723 final Phone phone = getPhone(subId);
9724 if (phone == null) {
9725 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9726 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9727 }
9728 return phone.getEmergencyNumberDbVersion();
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 @Override
9735 public void notifyOtaEmergencyNumberDbInstalled() {
9736 enforceModifyPermission();
9737
9738 final long identity = Binder.clearCallingIdentity();
9739 try {
9740 for (Phone phone: PhoneFactory.getPhones()) {
9741 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9742 if (tracker != null) {
9743 tracker.updateOtaEmergencyNumberDatabase();
9744 }
9745 }
9746 } finally {
9747 Binder.restoreCallingIdentity(identity);
9748 }
9749 }
9750
9751 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009752 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009753 enforceActiveEmergencySessionPermission();
9754
9755 final long identity = Binder.clearCallingIdentity();
9756 try {
9757 for (Phone phone: PhoneFactory.getPhones()) {
9758 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9759 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009760 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9761 }
9762 }
9763 } finally {
9764 Binder.restoreCallingIdentity(identity);
9765 }
9766 }
9767
9768 @Override
9769 public void resetOtaEmergencyNumberDbFilePath() {
9770 enforceActiveEmergencySessionPermission();
9771
9772 final long identity = Binder.clearCallingIdentity();
9773 try {
9774 for (Phone phone: PhoneFactory.getPhones()) {
9775 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9776 if (tracker != null) {
9777 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009778 }
9779 }
9780 } finally {
9781 Binder.restoreCallingIdentity(identity);
9782 }
9783 }
9784
9785 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009786 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9787 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9788 Phone phone = getPhone(subId);
9789 if (phone == null) {
9790 return null;
9791 }
9792 final long identity = Binder.clearCallingIdentity();
9793 try {
9794 UiccProfile profile = UiccController.getInstance()
9795 .getUiccProfileForPhone(phone.getPhoneId());
9796 if (profile != null) {
9797 return profile.getCertsFromCarrierPrivilegeAccessRules();
9798 }
9799 } finally {
9800 Binder.restoreCallingIdentity(identity);
9801 }
9802 return null;
9803 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009804
9805 /**
9806 * Enable or disable a modem stack.
9807 */
9808 @Override
9809 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9810 enforceModifyPermission();
9811
9812 final long identity = Binder.clearCallingIdentity();
9813 try {
9814 Phone phone = PhoneFactory.getPhone(slotIndex);
9815 if (phone == null) {
9816 return false;
9817 } else {
9818 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9819 }
9820 } finally {
9821 Binder.restoreCallingIdentity(identity);
9822 }
9823 }
Michelecea4cf22018-12-21 15:00:11 -08009824
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009825 /**
9826 * Whether a modem stack is enabled or not.
9827 */
9828 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009829 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9830 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009831 Phone phone = PhoneFactory.getPhone(slotIndex);
9832 if (phone == null) return false;
9833
9834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009835 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9836 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009837 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9838 }
9839
9840 final long identity = Binder.clearCallingIdentity();
9841 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009842 try {
9843 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9844 } catch (NoSuchElementException ex) {
9845 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9846 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009847 } finally {
9848 Binder.restoreCallingIdentity(identity);
9849 }
9850 }
9851
Michelecea4cf22018-12-21 15:00:11 -08009852 @Override
Michele0ea7d782019-03-19 14:58:42 -07009853 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009854 enforceModifyPermission();
9855
9856 final long identity = Binder.clearCallingIdentity();
9857 try {
9858 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009859 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009860 .commit();
9861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 }
9865
9866 @Override
Michele0ea7d782019-03-19 14:58:42 -07009867 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009868 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009870 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9871 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009872 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009873 }
Michelecea4cf22018-12-21 15:00:11 -08009874
9875 final long identity = Binder.clearCallingIdentity();
9876 try {
Michele0ea7d782019-03-19 14:58:42 -07009877 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009882
Michele0ea7d782019-03-19 14:58:42 -07009883 @TelephonyManager.IsMultiSimSupportedResult
9884 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009885 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9886 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9887 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009888 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9889 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009890 }
9891 // Check if the hardware supports multisim functionality. If usage of multisim is not
9892 // supported by the modem, indicate that it is restricted.
9893 PhoneCapability staticCapability =
9894 mPhoneConfigurationManager.getStaticPhoneCapability();
9895 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009896 loge("isMultiSimSupportedInternal: no static configuration available");
9897 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009898 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009899 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009900 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9901 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009902 }
9903 // Check if support of multiple SIMs is restricted by carrier
9904 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009905 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009906 }
9907
Michele0ea7d782019-03-19 14:58:42 -07009908 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009909 }
9910
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009911 /**
9912 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009913 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9914 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9915 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009916 * @param numOfSims number of active sims we want to switch to
9917 */
9918 @Override
9919 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009920 if (numOfSims == 1) {
9921 enforceModifyPermission();
9922 } else {
9923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9924 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9925 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009926 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009927
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009928 try {
Michele30b57b22019-03-01 12:01:14 -08009929 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009930 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009931 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9932 return;
9933 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009934 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9935 } finally {
9936 Binder.restoreCallingIdentity(identity);
9937 }
9938 }
9939
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009940 @Override
9941 public boolean isApplicationOnUicc(int subId, int appType) {
9942 enforceReadPrivilegedPermission("isApplicationOnUicc");
9943 Phone phone = getPhone(subId);
9944 if (phone == null) {
9945 return false;
9946 }
9947 final long identity = Binder.clearCallingIdentity();
9948 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009949 UiccPort uiccPort = phone.getUiccPort();
9950 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009951 return false;
9952 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009953 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009954 if (uiccProfile == null) {
9955 return false;
9956 }
9957 if (TelephonyManager.APPTYPE_SIM <= appType
9958 && appType <= TelephonyManager.APPTYPE_ISIM) {
9959 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9960 }
9961 return false;
9962 } finally {
9963 Binder.restoreCallingIdentity(identity);
9964 }
9965 }
9966
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009967 /**
chen xub4baa772019-04-03 10:23:41 -07009968 * Get whether making changes to modem configurations will trigger reboot.
9969 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009970 */
9971 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009972 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9973 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009975 mApp, subId, callingPackage, callingFeatureId,
9976 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009977 return false;
9978 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009979 final long identity = Binder.clearCallingIdentity();
9980 try {
9981 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9982 } finally {
9983 Binder.restoreCallingIdentity(identity);
9984 }
9985 }
9986
Nathan Harold29f5f052019-02-15 13:41:57 -08009987 private void updateModemStateMetrics() {
9988 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9989 // TODO: check the state for each modem if the api is ready.
9990 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9991 }
9992
Pengquan Meng3889a572019-01-23 11:16:29 -08009993 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009994 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009995 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009996 // Verify that the callingPackage belongs to the calling UID
9997 mApp.getSystemService(AppOpsManager.class)
9998 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009999 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010000 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010001 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010002 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10003 if (slotInfos != null) {
10004 for (int i = 0; i < slotInfos.length; i++) {
10005 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10006 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10007 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10008 portInfo.getLogicalSlotIndex()));
10009 }
10010 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010011 }
10012 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010013 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010014 } finally {
10015 Binder.restoreCallingIdentity(identity);
10016 }
10017 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010018
10019 /**
10020 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010021 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010022 */
jimsunf9ec1622022-09-13 21:18:43 +080010023 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010024 @Override
10025 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010026 return getHalVersion(HAL_SERVICE_RADIO);
10027 }
10028
10029 /**
10030 * Get the HAL Version of a specific service
10031 */
10032 @Override
10033 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010034 Phone phone = getDefaultPhone();
10035 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010036 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010037 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10038 return hv.major * 100 + hv.minor;
10039 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010040
10041 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010042 * Get the current calling package name.
10043 * @return the current calling package name
10044 */
10045 @Override
10046 public String getCurrentPackageName() {
10047 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10048 }
10049
10050 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010051 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10052 * corresponding network requests on a subId.
10053 *
10054 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010055 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010056 * 2) APN is un-metered for this subscription, or
10057 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010058 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010059 *
10060 * @return whether data is allowed for a apn type.
10061 *
10062 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010063 */
10064 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010065 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010066 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10067 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010068
10069 // Now that all security checks passes, perform the operation as ourselves.
10070 final long identity = Binder.clearCallingIdentity();
10071 try {
10072 Phone phone = getPhone(subId);
10073 if (phone == null) return false;
10074
Jack Yu27422a52022-03-21 10:38:05 -070010075 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010076 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010077 isMetered = phone.getDataNetworkController().getDataConfigManager()
10078 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10079 phone.getServiceState().getDataRoaming());
10080 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010081 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010082 } finally {
10083 Binder.restoreCallingIdentity(identity);
10084 }
10085 }
10086
10087 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010088 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010089 enforceReadPrivilegedPermission("isApnMetered");
10090
10091 // Now that all security checks passes, perform the operation as ourselves.
10092 final long identity = Binder.clearCallingIdentity();
10093 try {
10094 Phone phone = getPhone(subId);
10095 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010096 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10097 DataUtils.apnTypeToNetworkCapability(apnType),
10098 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010099 } finally {
10100 Binder.restoreCallingIdentity(identity);
10101 }
10102 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010103
10104 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010105 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10106 int subscriptionId, IBooleanConsumer resultCallback) {
10107 enforceModifyPermission();
10108 long token = Binder.clearCallingIdentity();
10109 try {
10110 Phone phone = getPhone(subscriptionId);
10111 if (phone == null) {
10112 try {
10113 if (resultCallback != null) {
10114 resultCallback.accept(false);
10115 }
10116 } catch (RemoteException e) {
10117 // ignore
10118 }
10119 return;
10120 }
10121 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10122 Pair.create(specifiers, (x) -> {
10123 try {
10124 if (resultCallback != null) {
10125 resultCallback.accept(x);
10126 }
10127 } catch (RemoteException e) {
10128 // ignore
10129 }
10130 });
10131 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10132 } finally {
10133 Binder.restoreCallingIdentity(token);
10134 }
10135 }
10136
10137 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010138 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10139 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010140 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010141 mApp, subId, "getSystemSelectionChannels");
10142 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10143 final long identity = Binder.clearCallingIdentity();
10144 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010145 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10146 if (result instanceof IllegalStateException) {
10147 throw (IllegalStateException) result;
10148 }
10149 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010150 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10151 return specifiers;
10152 } finally {
10153 Binder.restoreCallingIdentity(identity);
10154 }
10155 }
10156
10157 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010158 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010159 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010160 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010161 }
10162
10163 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010164 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10165 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010166 if (callingPackage == null) {
10167 callingPackage = getCurrentPackageName();
10168 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010169 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10170 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010171 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10172 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010173 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10174 }
10175 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10176 Intent intent = new Intent();
10177 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10178 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10179 // Bring up choose default SMS subscription dialog right now
10180 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10181 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10182 mApp.startActivity(intent);
10183 }
chen xud5ca2d52019-05-28 15:20:57 -070010184
10185 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010186 public void showSwitchToManagedProfileDialog() {
10187 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010188 try {
10189 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10190 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10191 // for work telephony.
10192 Intent intent = new Intent(Intent.ACTION_SENDTO);
10193 intent.setData(Uri.parse("smsto:"));
10194 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10195 mApp.startActivity(intent);
10196 } catch (ActivityNotFoundException e) {
10197 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10198 Intent intent = new Intent();
10199 intent.setClass(mApp, ErrorDialogActivity.class);
10200 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10201 mApp.startActivity(intent);
10202 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010203 }
10204
10205 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010206 public String getMmsUAProfUrl(int subId) {
10207 //TODO investigate if this API should require proper permission check in R b/133791609
10208 final long identity = Binder.clearCallingIdentity();
10209 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010210 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10211 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10212 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10213 return carrierUAProfUrl;
10214 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010215 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10216 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010217 } finally {
10218 Binder.restoreCallingIdentity(identity);
10219 }
10220 }
10221
10222 @Override
10223 public String getMmsUserAgent(int subId) {
10224 //TODO investigate if this API should require proper permission check in R b/133791609
10225 final long identity = Binder.clearCallingIdentity();
10226 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010227 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10228 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10229 if (!TextUtils.isEmpty(carrierUserAgent)) {
10230 return carrierUserAgent;
10231 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010232 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10233 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010234 } finally {
10235 Binder.restoreCallingIdentity(identity);
10236 }
10237 }
Jack Yub07d4972019-05-28 16:12:25 -070010238
10239 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010240 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10241 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010242
Jack Yub07d4972019-05-28 16:12:25 -070010243 final long identity = Binder.clearCallingIdentity();
10244 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010245 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010246 if (phone == null) return false;
10247
Ling Maf188d502022-09-16 15:22:36 -070010248 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
10254 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010255 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010256 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010257 enforceModifyPermission();
10258
changbettyd5c246e2019-12-24 15:40:37 +080010259 final long identity = Binder.clearCallingIdentity();
10260 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010261 Phone phone = getPhone(subscriptionId);
10262 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010263
Ling Maf188d502022-09-16 15:22:36 -070010264 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010265 } finally {
10266 Binder.restoreCallingIdentity(identity);
10267 }
10268 }
10269
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010270 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010271 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010272 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10273 * otherwise.
10274 */
10275 @Override
10276 public void setCepEnabled(boolean isCepEnabled) {
10277 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10278
10279 final long identity = Binder.clearCallingIdentity();
10280 try {
10281 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10282 for (Phone phone : PhoneFactory.getPhones()) {
10283 Phone defaultPhone = phone.getImsPhone();
10284 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10285 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10286 ImsPhoneCallTracker imsPhoneCallTracker =
10287 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10288 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10289 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10290 + imsPhone.getMsisdn());
10291 }
10292 }
10293 } finally {
10294 Binder.restoreCallingIdentity(identity);
10295 }
10296 }
allenwtsu46dcc572020-01-08 18:24:03 +080010297
10298 /**
10299 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10300 *
10301 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10302 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10303 * before being read.
10304 */
10305 @Override
10306 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10307 isCompressed) {
10308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10309 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010310 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10311 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10312 }
10313 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010314 // ProvisioningManager can not handle ServiceSpecificException.
10315 // Throw the IllegalStateException and annotate ProvisioningManager.
10316 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010317 }
10318
10319 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010320 try {
Hui Wang761a6682020-10-31 05:12:53 +000010321 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10322 } finally {
10323 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010324 }
10325 }
zoey chene02881a2019-12-30 16:11:23 +080010326
10327 @Override
10328 public boolean isIccLockEnabled(int subId) {
10329 enforceReadPrivilegedPermission("isIccLockEnabled");
10330
10331 // Now that all security checks passes, perform the operation as ourselves.
10332 final long identity = Binder.clearCallingIdentity();
10333 try {
10334 Phone phone = getPhone(subId);
10335 if (phone != null && phone.getIccCard() != null) {
10336 return phone.getIccCard().getIccLockEnabled();
10337 } else {
10338 return false;
10339 }
10340 } finally {
10341 Binder.restoreCallingIdentity(identity);
10342 }
10343 }
10344
10345 /**
10346 * Set the ICC pin lock enabled or disabled.
10347 *
10348 * @return an integer representing the status of IccLock enabled or disabled in the following
10349 * three cases:
10350 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10351 * successfully.
10352 * - Positive number and zero for remaining password attempts.
10353 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10354 *
10355 */
10356 @Override
10357 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10358 enforceModifyPermission();
10359
10360 Phone phone = getPhone(subId);
10361 if (phone == null) {
10362 return 0;
10363 }
10364 // Now that all security checks passes, perform the operation as ourselves.
10365 final long identity = Binder.clearCallingIdentity();
10366 try {
10367 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10368 new Pair<Boolean, String>(enabled, password), phone, null);
10369 return attemptsRemaining;
10370
10371 } catch (Exception e) {
10372 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10373 } finally {
10374 Binder.restoreCallingIdentity(identity);
10375 }
10376 return 0;
10377 }
10378
10379 /**
10380 * Change the ICC password used in ICC pin lock.
10381 *
10382 * @return an integer representing the status of IccLock changed in the following three cases:
10383 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10384 * - Positive number and zero for remaining password attempts.
10385 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10386 *
10387 */
10388 @Override
10389 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10390 enforceModifyPermission();
10391
10392 Phone phone = getPhone(subId);
10393 if (phone == null) {
10394 return 0;
10395 }
10396 // Now that all security checks passes, perform the operation as ourselves.
10397 final long identity = Binder.clearCallingIdentity();
10398 try {
10399 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10400 new Pair<String, String>(oldPassword, newPassword), phone, null);
10401 return attemptsRemaining;
10402
10403 } catch (Exception e) {
10404 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10405 } finally {
10406 Binder.restoreCallingIdentity(identity);
10407 }
10408 return 0;
10409 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010410
10411 /**
10412 * Request for receiving user activity notification
10413 */
10414 @Override
10415 public void requestUserActivityNotification() {
10416 if (!mNotifyUserActivity.get()
10417 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10418 mNotifyUserActivity.set(true);
10419 }
10420 }
10421
10422 /**
10423 * Called when userActivity is signalled in the power manager.
10424 * This is safe to call from any thread, with any window manager locks held or not.
10425 */
10426 @Override
10427 public void userActivity() {
10428 // ***************************************
10429 // * Inherited from PhoneWindowManager *
10430 // ***************************************
10431 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10432 // WITH ITS LOCKS HELD.
10433 //
10434 // This code must be VERY careful about the locks
10435 // it acquires.
10436 // In fact, the current code acquires way too many,
10437 // and probably has lurking deadlocks.
10438
10439 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10440 throw new SecurityException("Only the OS may call notifyUserActivity()");
10441 }
10442
10443 if (mNotifyUserActivity.getAndSet(false)) {
10444 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10445 USER_ACTIVITY_NOTIFICATION_DELAY);
10446 }
10447 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010448
10449 @Override
10450 public boolean canConnectTo5GInDsdsMode() {
10451 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10452 }
Jack Yud10cdd42020-09-28 20:28:01 -070010453
10454 @Override
10455 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10456 String callingFeatureId) {
10457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10458 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10459 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10460 }
10461
10462 Phone phone = getPhone(subId);
10463 if (phone == null) {
10464 throw new RuntimeException("phone is not available");
10465 }
10466 // Now that all security checks passes, perform the operation as ourselves.
10467 final long identity = Binder.clearCallingIdentity();
10468 try {
10469 return phone.getEquivalentHomePlmns();
10470 } finally {
10471 Binder.restoreCallingIdentity(identity);
10472 }
10473 }
Daniel Bright59e67312020-11-13 11:49:37 -080010474
10475 @Override
10476 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010477 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10478 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010479 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010480 if (radioInterfaceCapabilities == null) {
10481 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010482 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010483 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010484 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010485
Hui Wang641e81c2020-10-12 12:14:23 -070010486 @Override
10487 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10488 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010489 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10490 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10491 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10492 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10493 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010494 if (DBG) {
10495 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10496 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10497 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10498 }
10499
10500 if (!SubscriptionManager.isValidSubscriptionId(subId)
10501 || appType < TelephonyManager.APPTYPE_UNKNOWN
10502 || appType > TelephonyManager.APPTYPE_ISIM
10503 || nafUrl == null || securityProtocol == null || callback == null) {
10504 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10505 if (callback != null) {
10506 try {
10507 callback.onAuthenticationFailure(
10508 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10509 } catch (RemoteException exception) {
10510 log("Fail to notify onAuthenticationFailure due to " + exception);
10511 }
10512 return;
10513 }
10514 }
10515
10516 final long token = Binder.clearCallingIdentity();
10517 try {
10518 getGbaManager(subId).bootstrapAuthenticationRequest(
10519 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010520 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010521 } finally {
10522 Binder.restoreCallingIdentity(token);
10523 }
10524 }
10525
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010526 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010527 * Attempts to set the radio power state for all phones for thermal reason.
10528 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010529 * requested radio power state will actually be set. See {@link
10530 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10531 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010532 * @param enable {@code true} if trying to turn radio on.
10533 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10534 * false}.
10535 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010536 private boolean setRadioPowerForThermal(boolean enable) {
10537 boolean isPhoneAvailable = false;
10538 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10539 Phone phone = PhoneFactory.getPhone(i);
10540 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010541 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010542 isPhoneAvailable = true;
10543 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010544 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010545
10546 // return true if successfully informed the phone object about the thermal radio power
10547 // request.
10548 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010549 }
10550
10551 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010552 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010553 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10554 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10555 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10556 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10557 throw new IllegalArgumentException("modem does not support data throttling");
10558 }
10559
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010560 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10561 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010562 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010563 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10564 }
10565
Sarah Chinecc78c42022-03-31 21:16:48 -070010566 setDataEnabledForReason(
10567 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010568
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010569 if (isDataThrottlingSupported) {
10570 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010571 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010572 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10573 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10574 } else if (thermalMitigationResult
10575 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010576 log("Modem likely does not support data throttling on secondary carrier. Data " +
10577 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10578 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010579 }
10580 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010581 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010582
10583 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010584 }
10585
Jack Nudelman644b91a2021-03-12 14:09:48 -080010586 private static List<String> getThermalMitigationAllowlist(Context context) {
10587 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10588 for (String pckg : context.getResources()
10589 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10590 sThermalMitigationAllowlistedPackages.add(pckg);
10591 }
10592 }
10593
10594 return sThermalMitigationAllowlistedPackages;
10595 }
10596
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010597 private boolean isAnyPhoneInEmergencyState() {
10598 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10599 if (tm.isInEmergencyCall()) {
10600 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10601 return true;
10602 }
10603 for (Phone phone : PhoneFactory.getPhones()) {
10604 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10605 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010606 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10607 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010608 return true;
10609 }
10610 }
10611
10612 return false;
10613 }
10614
Jack Nudelman644b91a2021-03-12 14:09:48 -080010615 /**
10616 * Used by shell commands to add an authorized package name for thermal mitigation.
10617 * @param packageName name of package to be allowlisted
10618 * @param context
10619 */
10620 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10621 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10622 sThermalMitigationAllowlistedPackages.add(packageName);
10623 }
10624
10625 /**
10626 * Used by shell commands to remove an authorized package name for thermal mitigation.
10627 * @param packageName name of package to remove from allowlist
10628 * @param context
10629 */
10630 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10631 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10632 sThermalMitigationAllowlistedPackages.remove(packageName);
10633 }
10634
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010635 /**
10636 * Thermal mitigation request to control functionalities at modem.
10637 *
10638 * @param subId the id of the subscription.
10639 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010640 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010641 *
10642 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10643 */
10644 @Override
10645 @ThermalMitigationResult
10646 public int sendThermalMitigationRequest(
10647 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010648 ThermalMitigationRequest thermalMitigationRequest,
10649 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010650 enforceModifyPermission();
10651
Jack Nudelman644b91a2021-03-12 14:09:48 -080010652 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10653 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10654 .contains(callingPackage)) {
10655 throw new SecurityException("Calling package must be configured in the device config. "
10656 + "calling package: " + callingPackage);
10657 }
10658
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010659 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10660 final long identity = Binder.clearCallingIdentity();
10661
10662 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10663 try {
10664 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10665 switch (thermalMitigationAction) {
10666 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10667 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010668 handleDataThrottlingRequest(subId,
10669 thermalMitigationRequest.getDataThrottlingRequest(),
10670 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010671 break;
10672 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10673 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10674 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10675 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10676 }
10677
10678 // Ensure that radio is on. If not able to power on due to phone being
10679 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010680 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010681 thermalMitigationResult =
10682 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10683 break;
10684 }
10685
10686 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010687 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010688 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10689 break;
10690 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10691 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10692 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10693 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10694 }
10695
10696 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10697 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010698 Phone phone = getPhone(subId);
10699 if (phone == null) {
10700 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010701 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010702 break;
10703 }
10704
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010705 TelephonyConnectionService service =
10706 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010707 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010708 Log.e(LOG_TAG, "An emergency call is pending");
10709 thermalMitigationResult =
10710 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10711 break;
10712 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010713 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010714 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010715 break;
10716 }
10717 } else {
10718 thermalMitigationResult =
10719 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10720 break;
10721 }
10722
10723 // Turn radio off. If not able to power off due to phone being unavailable,
10724 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010725 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010726 thermalMitigationResult =
10727 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10728 break;
10729 }
10730 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010731 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010732 break;
10733 default:
10734 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10735 + "not exist. Requested action: " + thermalMitigationAction);
10736 }
10737 } catch (IllegalArgumentException e) {
10738 throw e;
10739 } catch (Exception e) {
10740 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10741 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10742 } finally {
10743 Binder.restoreCallingIdentity(identity);
10744 }
10745
10746 if (DBG) {
10747 log("thermalMitigationRequest returning with thermalMitigationResult: "
10748 + thermalMitigationResult);
10749 }
10750
10751 return thermalMitigationResult;
10752 }
Hui Wang641e81c2020-10-12 12:14:23 -070010753
10754 /**
10755 * Set the GbaService Package Name that Telephony will bind to.
10756 *
10757 * @param subId The sim that the GbaService is associated with.
10758 * @param packageName The name of the package to be replaced with.
10759 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10760 */
10761 @Override
10762 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10763 enforceModifyPermission();
10764
10765 final long identity = Binder.clearCallingIdentity();
10766 try {
10767 return getGbaManager(subId).overrideServicePackage(packageName);
10768 } finally {
10769 Binder.restoreCallingIdentity(identity);
10770 }
10771 }
10772
10773 /**
10774 * Return the package name of the currently bound GbaService.
10775 *
10776 * @param subId The sim that the GbaService is associated with.
10777 * @return the package name of the GbaService configuration, null if GBA is not supported.
10778 */
10779 @Override
10780 public String getBoundGbaService(int subId) {
10781 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10782
10783 final long identity = Binder.clearCallingIdentity();
10784 try {
10785 return getGbaManager(subId).getServicePackage();
10786 } finally {
10787 Binder.restoreCallingIdentity(identity);
10788 }
10789 }
10790
10791 /**
10792 * Set the release time for telephony to unbind GbaService.
10793 *
10794 * @param subId The sim that the GbaService is associated with.
10795 * @param interval The release time to unbind GbaService by millisecond.
10796 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10797 */
10798 @Override
10799 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10800 enforceModifyPermission();
10801
10802 final long identity = Binder.clearCallingIdentity();
10803 try {
10804 return getGbaManager(subId).overrideReleaseTime(interval);
10805 } finally {
10806 Binder.restoreCallingIdentity(identity);
10807 }
10808 }
10809
10810 /**
10811 * Return the release time for telephony to unbind GbaService.
10812 *
10813 * @param subId The sim that the GbaService is associated with.
10814 * @return The release time to unbind GbaService by millisecond.
10815 */
10816 @Override
10817 public int getGbaReleaseTime(int subId) {
10818 enforceReadPrivilegedPermission("getGbaReleaseTime");
10819
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 return getGbaManager(subId).getReleaseTime();
10823 } finally {
10824 Binder.restoreCallingIdentity(identity);
10825 }
10826 }
10827
10828 private GbaManager getGbaManager(int subId) {
10829 GbaManager instance = GbaManager.getInstance(subId);
10830 if (instance == null) {
10831 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10832 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10833 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10834 }
10835 return instance;
10836 }
Hui Wang761a6682020-10-31 05:12:53 +000010837
10838 /**
10839 * indicate whether the device and the carrier can support
10840 * RCS VoLTE single registration.
10841 */
10842 @Override
10843 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010844 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10845 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10846 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10847 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010848
10849 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10850 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10851 }
10852
10853 final long identity = Binder.clearCallingIdentity();
10854 try {
10855 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10856 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010857 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10858 if (isCapable != null) {
10859 return isCapable;
10860 }
Hui Wang761a6682020-10-31 05:12:53 +000010861 }
Hui Wang67af90e2021-06-04 16:57:15 -070010862 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10863 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010864 } finally {
10865 Binder.restoreCallingIdentity(identity);
10866 }
10867 }
10868
10869 /**
10870 * Register RCS provisioning callback.
10871 */
10872 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010873 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010874 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010875 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010876 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010877 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10878 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010879
10880 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10881 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10882 }
10883 if (!isImsAvailableOnDevice()) {
10884 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10885 "IMS not available on device.");
10886 }
10887
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010890 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010891 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010892 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10893 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010894 }
Hui Wang761a6682020-10-31 05:12:53 +000010895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
10899
10900 /**
10901 * Unregister RCS provisioning callback.
10902 */
10903 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010904 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010905 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010906 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010907 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010908 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10909 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010910
10911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10912 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10913 }
10914 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010915 // operation failed silently
10916 Rlog.w(LOG_TAG, "IMS not available on device.");
10917 return;
Hui Wang761a6682020-10-31 05:12:53 +000010918 }
10919
10920 final long identity = Binder.clearCallingIdentity();
10921 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010922 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010923 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010924 } finally {
10925 Binder.restoreCallingIdentity(identity);
10926 }
10927 }
10928
10929 /**
10930 * trigger RCS reconfiguration.
10931 */
10932 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010933 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10934 "triggerRcsReconfiguration",
10935 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010936
10937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10938 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10939 }
10940 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010941 // ProvisioningManager can not handle ServiceSpecificException.
10942 // Throw the IllegalStateException and annotate ProvisioningManager.
10943 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010944 }
10945
10946 final long identity = Binder.clearCallingIdentity();
10947 try {
10948 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10949 } finally {
10950 Binder.restoreCallingIdentity(identity);
10951 }
10952 }
10953
10954 /**
10955 * Provide the client configuration parameters of the RCS application.
10956 */
10957 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010958 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10959 "setRcsClientConfiguration",
10960 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010961
10962 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10963 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10964 }
10965 if (!isImsAvailableOnDevice()) {
10966 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10967 "IMS not available on device.");
10968 }
10969
10970 final long identity = Binder.clearCallingIdentity();
10971
10972 try {
10973 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10974 if (configBinder == null) {
10975 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010976 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10977 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010978 } else {
10979 configBinder.setRcsClientConfiguration(rcc);
10980 }
joonhunshin3e154242021-09-17 06:33:39 +000010981
10982 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10983 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010984 } catch (RemoteException e) {
10985 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010986 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10987 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010988 } finally {
10989 Binder.restoreCallingIdentity(identity);
10990 }
10991 }
10992
10993 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010994 * Enables or disables the test mode for RCS VoLTE single registration.
10995 */
10996 @Override
10997 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10998 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10999 "setRcsSingleRegistrationTestModeEnabled");
11000
11001 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11002 }
11003
11004 /**
11005 * Gets the test mode for RCS VoLTE single registration.
11006 */
11007 @Override
11008 public boolean getRcsSingleRegistrationTestModeEnabled() {
11009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11010 "getRcsSingleRegistrationTestModeEnabled");
11011
11012 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11013 }
11014
11015 /**
Hui Wang761a6682020-10-31 05:12:53 +000011016 * Overrides the config of RCS VoLTE single registration enabled for the device.
11017 */
11018 @Override
11019 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11020 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11021 "setDeviceSingleRegistrationEnabledOverride");
11022 enforceModifyPermission();
11023
11024 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11025 : Boolean.parseBoolean(enabledStr);
11026 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011027 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011028 }
11029
11030 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011031 * Sends a device to device communication message. Only usable via shell.
11032 * @param message message to send.
11033 * @param value message value.
11034 */
11035 @Override
11036 public void sendDeviceToDeviceMessage(int message, int value) {
11037 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011038 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011039 enforceModifyPermission();
11040
11041 final long identity = Binder.clearCallingIdentity();
11042 try {
11043 TelephonyConnectionService service =
11044 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11045 if (service == null) {
11046 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11047 return;
11048 }
11049 service.sendTestDeviceToDeviceMessage(message, value);
11050 } finally {
11051 Binder.restoreCallingIdentity(identity);
11052 }
11053 }
11054
Tyler Gunnbabbda02021-02-10 11:05:02 -080011055 /**
11056 * Sets the specified device to device transport active.
11057 * @param transport The transport to set active.
11058 */
11059 @Override
11060 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11061 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11062 "setActiveDeviceToDeviceTransport");
11063 enforceModifyPermission();
11064
11065 final long identity = Binder.clearCallingIdentity();
11066 try {
11067 TelephonyConnectionService service =
11068 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11069 if (service == null) {
11070 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11071 return;
11072 }
11073 service.setActiveDeviceToDeviceTransport(transport);
11074 } finally {
11075 Binder.restoreCallingIdentity(identity);
11076 }
11077 }
Tyler Gunn92479152021-01-20 16:30:10 -080011078
Tyler Gunnd4339262021-05-03 14:46:49 -070011079 @Override
11080 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11081 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11082 "setDeviceToDeviceForceEnabled");
11083
11084 final long identity = Binder.clearCallingIdentity();
11085 try {
11086 Arrays.stream(PhoneFactory.getPhones()).forEach(
11087 p -> {
11088 Phone thePhone = p.getImsPhone();
11089 if (thePhone != null && thePhone instanceof ImsPhone) {
11090 ImsPhone imsPhone = (ImsPhone) thePhone;
11091 CallTracker tracker = imsPhone.getCallTracker();
11092 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11093 ImsPhoneCallTracker imsPhoneCallTracker =
11094 (ImsPhoneCallTracker) tracker;
11095 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11096 }
11097 }
11098 }
11099 );
11100 } finally {
11101 Binder.restoreCallingIdentity(identity);
11102 }
11103 }
11104
Tyler Gunn92479152021-01-20 16:30:10 -080011105 /**
Hui Wang761a6682020-10-31 05:12:53 +000011106 * Gets the config of RCS VoLTE single registration enabled for the device.
11107 */
11108 @Override
11109 public boolean getDeviceSingleRegistrationEnabled() {
11110 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11111 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11112 }
11113
11114 /**
11115 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11116 */
11117 @Override
11118 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11120 "setCarrierSingleRegistrationEnabledOverride");
11121 enforceModifyPermission();
11122
11123 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11124 : Boolean.parseBoolean(enabledStr);
11125 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11126 subId, enabled);
11127 }
11128
11129 /**
11130 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11131 */
11132 @Override
11133 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11134 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11135 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11136 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011137
11138 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011139 * Overrides the ims feature validation result
11140 */
11141 @Override
11142 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11144 "setImsFeatureValidationOverride");
11145
11146 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11147 : Boolean.parseBoolean(enabledStr);
11148 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11149 subId, enabled);
11150 }
11151
11152 /**
11153 * Gets the ims feature validation override value
11154 */
11155 @Override
11156 public boolean getImsFeatureValidationOverride(int subId) {
11157 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11158 "getImsFeatureValidationOverride");
11159 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11160 }
11161
11162 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011163 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11164 * their mobile plan.
11165 */
11166 @Override
11167 public String getMobileProvisioningUrl() {
11168 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11169 final long identity = Binder.clearCallingIdentity();
11170 try {
11171 return getDefaultPhone().getMobileProvisioningUrl();
11172 } finally {
11173 Binder.restoreCallingIdentity(identity);
11174 }
11175 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011176
James.cf Linbcdf8b32021-01-14 16:44:13 +080011177 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011178 * Get the EAB contact from the EAB database.
11179 */
11180 @Override
11181 public String getContactFromEab(String contact) {
11182 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11183 enforceModifyPermission();
11184 final long identity = Binder.clearCallingIdentity();
11185 try {
11186 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11187 } finally {
11188 Binder.restoreCallingIdentity(identity);
11189 }
11190 }
11191
11192 /**
Calvin Pana1434322021-07-01 19:27:01 +080011193 * Get the EAB capability from the EAB database.
11194 */
11195 @Override
11196 public String getCapabilityFromEab(String contact) {
11197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11198 enforceModifyPermission();
11199 final long identity = Binder.clearCallingIdentity();
11200 try {
11201 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11202 } finally {
11203 Binder.restoreCallingIdentity(identity);
11204 }
11205 }
11206
11207 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011208 * Remove the EAB contacts from the EAB database.
11209 */
11210 @Override
11211 public int removeContactFromEab(int subId, String contacts) {
11212 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11213 enforceModifyPermission();
11214 final long identity = Binder.clearCallingIdentity();
11215 try {
11216 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11217 } finally {
11218 Binder.restoreCallingIdentity(identity);
11219 }
11220 }
11221
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011222 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011223 public boolean getDeviceUceEnabled() {
11224 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11225 final long identity = Binder.clearCallingIdentity();
11226 try {
11227 return mApp.getDeviceUceEnabled();
11228 } finally {
11229 Binder.restoreCallingIdentity(identity);
11230 }
11231 }
11232
11233 @Override
11234 public void setDeviceUceEnabled(boolean isEnabled) {
11235 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11236 final long identity = Binder.clearCallingIdentity();
11237 try {
11238 mApp.setDeviceUceEnabled(isEnabled);
11239 } finally {
11240 Binder.restoreCallingIdentity(identity);
11241 }
11242 }
11243
Brad Ebinger14d467f2021-02-12 06:18:28 +000011244 /**
11245 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11246 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11247 */
11248 // Used for SHELL command only right now.
11249 @Override
11250 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11251 List<String> featureTags) {
11252 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11253 "addUceRegistrationOverrideShell");
11254 final long identity = Binder.clearCallingIdentity();
11255 try {
11256 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11257 new ArraySet<>(featureTags));
11258 } catch (ImsException e) {
11259 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11260 } finally {
11261 Binder.restoreCallingIdentity(identity);
11262 }
11263 }
11264
11265 /**
11266 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11267 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11268 */
11269 // Used for SHELL command only right now.
11270 @Override
11271 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11272 List<String> featureTags) {
11273 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11274 "removeUceRegistrationOverrideShell");
11275 final long identity = Binder.clearCallingIdentity();
11276 try {
11277 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11278 new ArraySet<>(featureTags));
11279 } catch (ImsException e) {
11280 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11281 } finally {
11282 Binder.restoreCallingIdentity(identity);
11283 }
11284 }
11285
11286 /**
11287 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11288 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11289 */
11290 // Used for SHELL command only right now.
11291 @Override
11292 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11293 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11294 "clearUceRegistrationOverrideShell");
11295 final long identity = Binder.clearCallingIdentity();
11296 try {
11297 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11298 } catch (ImsException e) {
11299 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11300 } finally {
11301 Binder.restoreCallingIdentity(identity);
11302 }
11303 }
11304
11305 /**
11306 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11307 */
11308 // Used for SHELL command only right now.
11309 @Override
11310 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11311 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11312 "getLatestRcsContactUceCapabilityShell");
11313 final long identity = Binder.clearCallingIdentity();
11314 try {
11315 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11316 } catch (ImsException e) {
11317 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11318 } finally {
11319 Binder.restoreCallingIdentity(identity);
11320 }
11321 }
11322
11323 /**
11324 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11325 * device does not have an active PUBLISH.
11326 */
11327 // Used for SHELL command only right now.
11328 @Override
11329 public String getLastUcePidfXmlShell(int subId) {
11330 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11331 final long identity = Binder.clearCallingIdentity();
11332 try {
11333 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11334 } catch (ImsException e) {
11335 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11336 } finally {
11337 Binder.restoreCallingIdentity(identity);
11338 }
11339 }
11340
James.cf Line8713a42021-04-29 16:04:26 +080011341 /**
11342 * Remove UCE requests cannot be sent to the network status.
11343 */
11344 // Used for SHELL command only right now.
11345 @Override
11346 public boolean removeUceRequestDisallowedStatus(int subId) {
11347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11348 final long identity = Binder.clearCallingIdentity();
11349 try {
11350 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11351 } catch (ImsException e) {
11352 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11353 } finally {
11354 Binder.restoreCallingIdentity(identity);
11355 }
11356 }
11357
James.cf Lin18bb9002021-05-25 01:37:38 +080011358 /**
11359 * Remove UCE requests cannot be sent to the network status.
11360 */
11361 // Used for SHELL command only.
11362 @Override
11363 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11364 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11365 final long identity = Binder.clearCallingIdentity();
11366 try {
11367 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11368 } catch (ImsException e) {
11369 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11370 } finally {
11371 Binder.restoreCallingIdentity(identity);
11372 }
11373 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011374
James.cf Lin4b784aa2021-01-31 03:25:15 +080011375 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011376 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11377 String callingPackage) {
11378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11379 mApp, subId, "setSignalStrengthUpdateRequest");
11380
11381 final int callingUid = Binder.getCallingUid();
11382 // Verify that tha callingPackage belongs to the calling UID
11383 mApp.getSystemService(AppOpsManager.class)
11384 .checkPackage(callingUid, callingPackage);
11385
Rambo Wang3607f502021-02-01 21:51:40 -080011386 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011387
11388 final long identity = Binder.clearCallingIdentity();
11389 try {
11390 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11391 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11392
11393 if (result instanceof IllegalStateException) {
11394 throw (IllegalStateException) result;
11395 }
11396 } finally {
11397 Binder.restoreCallingIdentity(identity);
11398 }
11399 }
11400
11401 @Override
11402 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11403 String callingPackage) {
11404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11405 mApp, subId, "clearSignalStrengthUpdateRequest");
11406
11407 final int callingUid = Binder.getCallingUid();
11408 // Verify that tha callingPackage belongs to the calling UID
11409 mApp.getSystemService(AppOpsManager.class)
11410 .checkPackage(callingUid, callingPackage);
11411
11412 final long identity = Binder.clearCallingIdentity();
11413 try {
11414 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11415 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11416
11417 if (result instanceof IllegalStateException) {
11418 throw (IllegalStateException) result;
11419 }
11420 } finally {
11421 Binder.restoreCallingIdentity(identity);
11422 }
11423 }
11424
Rambo Wang3607f502021-02-01 21:51:40 -080011425 private static void validateSignalStrengthUpdateRequest(Context context,
11426 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011427 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11428 // phone/system process do not have further restriction on request
11429 return;
11430 }
11431
11432 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011433 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011434 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011435 context.enforceCallingOrSelfPermission(
11436 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11437 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011438 }
11439
11440 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011441 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011442 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011443 || info.isEnabled()) {
11444 throw new IllegalArgumentException(
11445 "Only system can set hide fields in SignalThresholdInfo");
11446 }
11447
11448 // Thresholds length for each RAN need in range. This has been validated in
11449 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11450 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11451 final int[] thresholds = info.getThresholds();
11452 Objects.requireNonNull(thresholds);
11453 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11454 || thresholds.length
11455 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11456 throw new IllegalArgumentException(
11457 "thresholds length is out of range: " + thresholds.length);
11458 }
11459 }
11460 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011461
11462 /**
11463 * Gets the current phone capability.
11464 *
11465 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11466 * @return the PhoneCapability which describes the data connection capability of modem.
11467 * It's used to evaluate possible phone config change, for example from single
11468 * SIM device to multi-SIM device.
11469 */
11470 @Override
11471 public PhoneCapability getPhoneCapability() {
11472 enforceReadPrivilegedPermission("getPhoneCapability");
11473 final long identity = Binder.clearCallingIdentity();
11474 try {
11475 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11476 } finally {
11477 Binder.restoreCallingIdentity(identity);
11478 }
11479 }
Michele Berionne5e411512020-11-13 02:36:59 +000011480
11481 /**
11482 * Prepare TelephonyManager for an unattended reboot. The reboot is
11483 * required to be done shortly after the API is invoked.
11484 */
11485 @Override
11486 @TelephonyManager.PrepareUnattendedRebootResult
11487 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011489 enforceRebootPermission();
11490
11491 final long identity = Binder.clearCallingIdentity();
11492 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011493 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011494 } finally {
11495 Binder.restoreCallingIdentity(identity);
11496 }
11497 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011498
11499 /**
11500 * Request to get the current slicing configuration including URSP rules and
11501 * NSSAIs (configured, allowed and rejected).
11502 *
11503 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11504 */
11505 @Override
11506 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011507 TelephonyPermissions
11508 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11509 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011510
11511 final long identity = Binder.clearCallingIdentity();
11512 try {
11513 Phone phone = getDefaultPhone();
11514 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11515 } finally {
11516 Binder.restoreCallingIdentity(identity);
11517 }
11518 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011519
11520 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011521 * Check whether the given premium capability is available for purchase from the carrier.
11522 *
11523 * @param capability The premium capability to check.
11524 * @param subId The subId to check the premium capability for.
11525 *
11526 * @return Whether the given premium capability is available to purchase.
11527 */
11528 @Override
11529 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11530 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11531 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11532 log("Premium capability "
11533 + TelephonyManager.convertPremiumCapabilityToString(capability)
11534 + " is not available for purchase due to missing permissions.");
11535 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11536 + "permission READ_BASIC_PHONE_STATE.");
11537 }
11538
11539 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011540 if (phone == null) {
11541 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11542 return false;
11543 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011544 final long identity = Binder.clearCallingIdentity();
11545 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011546 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011547 .isPremiumCapabilityAvailableForPurchase(capability);
11548 } finally {
11549 Binder.restoreCallingIdentity(identity);
11550 }
11551 }
11552
11553 /**
11554 * Purchase the given premium capability from the carrier.
11555 *
11556 * @param capability The premium capability to purchase.
11557 * @param callback The result of the purchase request.
11558 * @param subId The subId to purchase the premium capability for.
11559 */
11560 @Override
11561 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11562 log("purchasePremiumCapability: capability="
11563 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11564 + getCurrentPackageName());
11565
11566 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11567 mApp, "purchasePremiumCapability")) {
11568 log("purchasePremiumCapability "
11569 + TelephonyManager.convertPremiumCapabilityToString(capability)
11570 + " failed due to missing permissions.");
11571 throw new SecurityException("purchasePremiumCapability requires permission "
11572 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011573 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11574 mApp, "purchasePremiumCapability")) {
11575 log("purchasePremiumCapability "
11576 + TelephonyManager.convertPremiumCapabilityToString(capability)
11577 + " failed due to missing permissions.");
11578 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011579 }
11580
11581 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011582 if (phone == null) {
11583 try {
11584 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11585 callback.accept(result);
11586 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11587 } catch (RemoteException e) {
11588 String logStr = "Purchase premium capability "
11589 + TelephonyManager.convertPremiumCapabilityToString(capability)
11590 + " failed due to RemoteException handling null phone: " + e;
11591 if (DBG) log(logStr);
11592 AnomalyReporter.reportAnomaly(
11593 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11594 }
11595 return;
11596 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011597
11598 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011599 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011600 callingProcess = mApp.getPackageManager().getApplicationInfo(
11601 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011602 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011603 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011604 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011605
11606 boolean isVisible = false;
11607 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11608 if (am != null) {
11609 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11610 if (processes != null) {
11611 for (ActivityManager.RunningAppProcessInfo process : processes) {
11612 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011613 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011614 if (process.processName.equals(callingProcess) && process.importance
11615 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11616 isVisible = true;
11617 break;
11618 }
11619 }
11620 }
11621 }
11622
11623 if (!isVisible) {
11624 try {
11625 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11626 callback.accept(result);
11627 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11628 } catch (RemoteException e) {
11629 String logStr = "Purchase premium capability "
11630 + TelephonyManager.convertPremiumCapabilityToString(capability)
11631 + " failed due to RemoteException handling background application: " + e;
11632 if (DBG) log(logStr);
11633 AnomalyReporter.reportAnomaly(
11634 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11635 }
11636 return;
11637 }
11638
Sarah Chin71b3a852022-09-28 15:54:19 -070011639 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011640 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011641 }
11642
11643 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011644 * Register an IMS connection state callback
11645 */
11646 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011647 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11648 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011649 if (feature == ImsFeature.FEATURE_MMTEL) {
11650 // ImsMmTelManager
11651 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11652 TelephonyPermissions
11653 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11654 mApp, subId, "registerImsStateCallback");
11655 } else if (feature == ImsFeature.FEATURE_RCS) {
11656 // ImsRcsManager or SipDelegateManager
11657 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11658 Binder.getCallingUid(), "registerImsStateCallback",
11659 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11660 Manifest.permission.READ_PRECISE_PHONE_STATE,
11661 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11662 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11663 }
11664
11665 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11667 "IMS not available on device.");
11668 }
11669
11670 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11671 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11672 }
11673
11674 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11675 if (controller == null) {
11676 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11677 "IMS not available on device.");
11678 }
11679
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011680 if (callingPackage == null) {
11681 callingPackage = getCurrentPackageName();
11682 }
11683
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011684 final long token = Binder.clearCallingIdentity();
11685 try {
11686 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011687 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011688 } catch (ImsException e) {
11689 throw new ServiceSpecificException(e.getCode());
11690 } finally {
11691 Binder.restoreCallingIdentity(token);
11692 }
11693 }
11694
11695 /**
11696 * Unregister an IMS connection state callback
11697 */
11698 @Override
11699 public void unregisterImsStateCallback(IImsStateCallback cb) {
11700 final long token = Binder.clearCallingIdentity();
11701 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11702 if (controller == null) {
11703 return;
11704 }
11705 try {
11706 controller.unregisterImsStateCallback(cb);
11707 } finally {
11708 Binder.restoreCallingIdentity(token);
11709 }
11710 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011711
11712 /**
11713 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11714 *
11715 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11716 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11717 * SecurityException.
11718 * If there is current registered network this value will be same as the registered cell
11719 * identity. If the device goes out of service the previous cell identity is cached and
11720 * will be returned. If the cache age of the Cell identity is more than 24 hours
11721 * it will be cleared and null will be returned.
11722 *
11723 */
11724 @Override
11725 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11726 String callingFeatureId) {
11727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11728 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11729 LocationAccessPolicy.checkLocationPermission(mApp,
11730 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11731 .setCallingPackage(callingPackage)
11732 .setCallingFeatureId(callingFeatureId)
11733 .setCallingPid(Binder.getCallingPid())
11734 .setCallingUid(Binder.getCallingUid())
11735 .setMethod("getLastKnownCellIdentity")
11736 .setLogAsInfo(true)
11737 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11738 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11739 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11740 .build());
11741
11742 boolean hasFinePermission =
11743 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11744 if (!hasFinePermission
11745 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11746 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011747 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011748 }
11749
11750 final long identity = Binder.clearCallingIdentity();
11751 try {
Ling Mac28f0212023-03-24 16:07:15 -070011752 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011753 if (sst == null) return null;
11754 return sst.getLastKnownCellIdentity();
11755 } finally {
11756 Binder.restoreCallingIdentity(identity);
11757 }
11758 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011759
jimsun3b9ccac2021-10-26 15:01:23 +080011760 /**
11761 * Sets the modem service class Name that Telephony will bind to.
11762 *
11763 * @param serviceName The class name of the modem service.
11764 * @return true if the operation is succeed, otherwise false.
11765 */
11766 public boolean setModemService(String serviceName) {
11767 Log.d(LOG_TAG, "setModemService - " + serviceName);
11768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011770 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11771 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011772 return mPhoneConfigurationManager.setModemService(serviceName);
11773 }
11774
11775 /**
11776 * Return the class name of the currently bounded modem service.
11777 *
11778 * @return the class name of the modem service.
11779 */
11780 public String getModemService() {
11781 String result;
11782 Log.d(LOG_TAG, "getModemService");
11783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11784 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011785 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011786 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11787 "getModemService");
11788 result = mPhoneConfigurationManager.getModemService();
11789 Log.d(LOG_TAG, "result = " + result);
11790 return result;
11791 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011792
11793 @Override
11794 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11795 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11796 mApp.enforceCallingOrSelfPermission(
11797 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11798 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11799
11800 final long identity = Binder.clearCallingIdentity();
11801 try {
11802 Phone phone = getPhone(subId);
11803 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011804 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11805 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011806 phone.setVoiceServiceStateOverride(hasService);
11807 } finally {
11808 Binder.restoreCallingIdentity(identity);
11809 }
11810 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011811
11812 /**
11813 * set removable eSIM as default eUICC.
11814 *
11815 * @hide
11816 */
11817 @Override
11818 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11819 enforceModifyPermission();
11820 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11821
11822 final long identity = Binder.clearCallingIdentity();
11823 try {
11824 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11825 } finally {
11826 Binder.restoreCallingIdentity(identity);
11827 }
11828 }
11829
11830 /**
11831 * Returns whether the removable eSIM is default eUICC or not.
11832 *
11833 * @hide
11834 */
11835 @Override
11836 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11837 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11839
11840 final long identity = Binder.clearCallingIdentity();
11841 try {
11842 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11843 } finally {
11844 Binder.restoreCallingIdentity(identity);
11845 }
11846 }
11847
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011848 /**
11849 * Get the component name of the default app to direct respond-via-message intent for the
11850 * user associated with this subscription, update the cache if there is no respond-via-message
11851 * application currently configured for this user.
11852 * @return component name of the app and class to direct Respond Via Message intent to, or
11853 * {@code null} if the functionality is not supported.
11854 * @hide
11855 */
11856 @Override
11857 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11858 boolean updateIfNeeded) {
11859 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011860
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011861 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11862
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011863 UserHandle userHandle = null;
11864 final long identity = Binder.clearCallingIdentity();
11865 try {
11866 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11867 } finally {
11868 Binder.restoreCallingIdentity(identity);
11869 }
11870 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11871 updateIfNeeded, userHandle);
11872 }
Jack Yuf5badd92022-12-08 00:50:53 -080011873
11874 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011875 * Set whether the device is able to connect with null ciphering or integrity
11876 * algorithms. This is a global setting and will apply to all active subscriptions
11877 * and all new subscriptions after this.
11878 *
11879 * @param enabled when true, null cipher and integrity algorithms are allowed.
11880 * @hide
11881 */
11882 @Override
11883 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11884 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11885 enforceModifyPermission();
11886 checkForNullCipherAndIntegritySupport();
11887
11888 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11889 // for listening to these preference changes and applying them immediately.
11890 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11891 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11892 editor.apply();
11893
11894 for (Phone phone: PhoneFactory.getPhones()) {
11895 phone.handleNullCipherEnabledChange();
11896 }
11897 }
11898
11899
11900 /**
11901 * Get whether the device is able to connect with null ciphering or integrity
11902 * algorithms. Note that this retrieves the phone-global preference and not
11903 * the state of the radio.
11904 *
11905 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11906 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11907 * version for this feature.
11908 * @hide
11909 */
11910 @Override
11911 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11912 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11913 enforceReadPermission();
11914 checkForNullCipherAndIntegritySupport();
11915 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11916 }
11917
11918 private void checkForNullCipherAndIntegritySupport() {
11919 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11920 throw new UnsupportedOperationException(
11921 "Null cipher and integrity operations require HAL 2.1 or above");
11922 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011923 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11924 throw new UnsupportedOperationException(
11925 "Null cipher and integrity operations unsupported by modem");
11926 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011927 }
11928
11929 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011930 * Get the SIM state for the slot index.
11931 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11932 *
11933 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11934 */
11935 @Override
11936 @SimState
11937 public int getSimStateForSlotIndex(int slotIndex) {
11938 IccCardConstants.State simState;
11939 if (slotIndex < 0) {
11940 simState = IccCardConstants.State.UNKNOWN;
11941 } else {
11942 Phone phone = null;
11943 try {
11944 phone = PhoneFactory.getPhone(slotIndex);
11945 } catch (IllegalStateException e) {
11946 // ignore
11947 }
11948 if (phone == null) {
11949 simState = IccCardConstants.State.UNKNOWN;
11950 } else {
11951 IccCard icc = phone.getIccCard();
11952 if (icc == null) {
11953 simState = IccCardConstants.State.UNKNOWN;
11954 } else {
11955 simState = icc.getState();
11956 }
11957 }
11958 }
11959 return simState.ordinal();
11960 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011961
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011962 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11963 boolean enableLogcat,
11964 long logcatStartTimestampMillis, boolean enableTelecomDump,
11965 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011966 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11967 TelephonyManager.EmergencyCallDiagnosticParams edp =
11968 new TelephonyManager.EmergencyCallDiagnosticParams();
11969 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11970 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11971 edp.setTelecomDumpSysCollection(enableTelecomDump);
11972 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11973 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
11974 Executors.newCachedThreadPool(), db,
11975 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
11976 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011977 }
11978
11979 /**
11980 * Request telephony to persist state for debugging emergency call failures.
11981 *
11982 * @param dropBoxTag Tag to use when persisting data to dropbox service.
11983 * @param enableLogcat whether to collect logcat output
11984 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
11985 * @param enableTelecomDump whether to collect telecom dumpsys
11986 * @param enableTelephonyDump whether to collect telephony dumpsys
11987 */
11988 @Override
11989 @RequiresPermission(android.Manifest.permission.DUMP)
11990 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
11991 long logcatStartTimestampMillis, boolean enableTelecomDump,
11992 boolean enableTelephonyDump) {
11993 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
11994 "persistEmergencyCallDiagnosticData");
11995 final long identity = Binder.clearCallingIdentity();
11996 try {
11997 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
11998 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
11999
12000 } finally {
12001 Binder.restoreCallingIdentity(identity);
12002 }
12003 }
12004
Hui Wang9b5793a2022-12-05 14:38:06 -060012005 /**
12006 * Get current cell broadcast ranges.
12007 */
12008 @Override
12009 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12010 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12011 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12012 "getCellBroadcastIdRanges");
12013 final long identity = Binder.clearCallingIdentity();
12014 try {
12015 return getPhone(subId).getCellBroadcastIdRanges();
12016 } finally {
12017 Binder.restoreCallingIdentity(identity);
12018 }
12019 }
12020
12021 /**
12022 * Set reception of cell broadcast messages with the list of the given ranges
12023 *
12024 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12025 */
12026 @Override
12027 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12028 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12029 @Nullable IIntegerConsumer callback) {
12030 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12031 "setCellBroadcastIdRanges");
12032 final long identity = Binder.clearCallingIdentity();
12033 try {
12034 Phone phone = getPhoneFromSubId(subId);
12035 if (DBG) {
12036 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12037 }
12038 phone.setCellBroadcastIdRanges(ranges, result -> {
12039 if (callback != null) {
12040 try {
12041 callback.accept(result);
12042 } catch (RemoteException e) {
12043 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12044 }
12045 }
12046 });
12047 } finally {
12048 Binder.restoreCallingIdentity(identity);
12049 }
12050 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012051
12052 /**
12053 * Returns whether the device supports the domain selection service.
12054 *
12055 * @return {@code true} if the device supports the domain selection service.
12056 */
12057 @Override
12058 public boolean isDomainSelectionSupported() {
12059 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12060 "isDomainSelectionSupported");
12061
12062 final long identity = Binder.clearCallingIdentity();
12063 try {
12064 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12065 } finally {
12066 Binder.restoreCallingIdentity(identity);
12067 }
12068 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012069
12070 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012071 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12072 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12073 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012074 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012075 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012076 * @param enableSatellite {@code true} to enable the satellite modem and
12077 * {@code false} to disable.
12078 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12079 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012080 *
12081 * @throws SecurityException if the caller doesn't have the required permission.
12082 */
12083 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012084 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12085 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012086 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012087 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12088 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012089 }
12090
12091 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012092 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012093 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012094 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012095 * @param result The result receiver that returns whether the satellite modem is enabled
12096 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012097 *
12098 * @throws SecurityException if the caller doesn't have the required permission.
12099 */
12100 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012101 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12102 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012103 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012104 }
12105
12106 /**
Sarah Chin43457982023-02-15 17:50:38 -080012107 * Request to get whether the satellite service demo mode is enabled.
12108 *
12109 * @param subId The subId of the subscription to check whether the satellite demo mode
12110 * is enabled for.
12111 * @param result The result receiver that returns whether the satellite demo mode is enabled
12112 * if the request is successful or an error code if the request failed.
12113 *
12114 * @throws SecurityException if the caller doesn't have the required permission.
12115 */
12116 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012117 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12118 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12119 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012120 }
12121
12122 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012123 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012124 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012125 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012126 * @param result The result receiver that returns whether the satellite service is supported on
12127 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012128 */
12129 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012130 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012131 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012132 }
12133
12134 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012135 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012136 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012137 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012138 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12139 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012140 *
12141 * @throws SecurityException if the caller doesn't have required permission.
12142 */
12143 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012144 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12145 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012146 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012147 }
12148
12149 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012150 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012151 * This can be called by the pointing UI when the user starts pointing to the satellite.
12152 * Modem should continue to report the pointing input as the device or satellite moves.
12153 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012154 * @param subId The subId of the subscription to start satellite transmission updates for.
12155 * @param resultCallback The callback to get the result of the request.
12156 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012157 *
12158 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012159 */
12160 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012161 public void startSatelliteTransmissionUpdates(int subId,
12162 @NonNull IIntegerConsumer resultCallback,
12163 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12164 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12165 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012166 }
12167
12168 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012169 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012170 * This can be called by the pointing UI when the user stops pointing to the satellite.
12171 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012172 * @param subId The subId of the subscription to stop satellite transmission updates for.
12173 * @param resultCallback The callback to get the result of the request.
12174 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12175 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012176 *
12177 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012178 */
12179 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012180 public void stopSatelliteTransmissionUpdates(int subId,
12181 @NonNull IIntegerConsumer resultCallback,
12182 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12183 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12184 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012185 }
12186
12187 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012188 * Register the subscription with a satellite provider.
12189 * This is needed to register the subscription if the provider allows dynamic registration.
12190 *
12191 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012192 * @param token The token to be used as a unique identifier for provisioning with satellite
12193 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012194 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012195 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012196 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012197 * @return The signal transport used by the caller to cancel the provision request,
12198 * or {@code null} if the request failed.
12199 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012200 * @throws SecurityException if the caller doesn't have the required permission.
12201 */
12202 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012203 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012204 @NonNull String token, @NonNull byte[] provisionData,
12205 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012206 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012207 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12208 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012209 }
12210
12211 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012212 * Unregister the device/subscription with the satellite provider.
12213 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012214 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012215 * should report as deprovisioned.
12216 *
12217 * @param subId The subId of the subscription to be deprovisioned.
12218 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012219 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012220 *
12221 * @throws SecurityException if the caller doesn't have the required permission.
12222 */
12223 @Override
12224 public void deprovisionSatelliteService(int subId,
12225 @NonNull String token, @NonNull IIntegerConsumer callback) {
12226 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012227 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012228 }
12229
12230 /**
Sarah Chin43457982023-02-15 17:50:38 -080012231 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012232 *
Sarah Chin43457982023-02-15 17:50:38 -080012233 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012234 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012235 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012236 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12237 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012238 * @throws SecurityException if the caller doesn't have the required permission.
12239 */
12240 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012241 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012242 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012243 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012244 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012245 }
12246
12247 /**
Sarah Chin43457982023-02-15 17:50:38 -080012248 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012249 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012250 *
Sarah Chin43457982023-02-15 17:50:38 -080012251 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012252 * @param callback The callback that was passed to
12253 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012254 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012255 * @throws SecurityException if the caller doesn't have the required permission.
12256 */
12257 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012258 public void unregisterForSatelliteProvisionStateChanged(
12259 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012260 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012261 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012262 }
12263
12264 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012265 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012266 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012267 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012268 * @param result The result receiver that returns whether the device is provisioned with a
12269 * satellite provider if the request is successful or an error code if the
12270 * request failed.
12271 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012272 * @throws SecurityException if the caller doesn't have the required permission.
12273 */
12274 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012275 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12276 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012277 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012278 }
12279
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012280 /**
Sarah Chin43457982023-02-15 17:50:38 -080012281 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012282 *
Sarah Chin43457982023-02-15 17:50:38 -080012283 * @param subId The subId of the subscription to register for satellite modem state changed.
12284 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012285 *
12286 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12287 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012288 * @throws SecurityException if the caller doesn't have the required permission.
12289 */
12290 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012291 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012292 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012293 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012294 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012295 }
12296
12297 /**
Sarah Chin43457982023-02-15 17:50:38 -080012298 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012299 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012300 *
Sarah Chin43457982023-02-15 17:50:38 -080012301 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012302 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012303 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012304 *
12305 * @throws SecurityException if the caller doesn't have the required permission.
12306 */
12307 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012308 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012309 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012310 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012311 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012312 }
12313
12314 /**
12315 * Register to receive incoming datagrams over satellite.
12316 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012317 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012318 * @param callback The callback to handle incoming datagrams over satellite.
12319 *
12320 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12321 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012322 * @throws SecurityException if the caller doesn't have the required permission.
12323 */
12324 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012325 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012326 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012327 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012328 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012329 }
12330
12331 /**
12332 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012333 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012334 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012335 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12336 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012337 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012338 *
12339 * @throws SecurityException if the caller doesn't have the required permission.
12340 */
12341 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012342 public void unregisterForSatelliteDatagram(int subId,
12343 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012344 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012345 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012346 }
12347
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012348 /**
12349 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012350 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012351 * This method requests modem to check if there are any pending datagrams to be received over
12352 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012353 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012354 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012355 * @param subId The subId of the subscription used for receiving datagrams.
12356 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012357 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012358 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012359 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012360 @Override
12361 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012362 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012363 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012364 }
12365
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012366 /**
12367 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012368 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012369 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12370 * input to this method. Datagram received here will be passed down to modem without any
12371 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012372 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012373 * @param subId The subId of the subscription to send satellite datagrams for.
12374 * @param datagramType datagram type indicating whether the datagram is of type
12375 * SOS_SMS or LOCATION_SHARING.
12376 * @param datagram encoded gateway datagram which is encrypted by the caller.
12377 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012378 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12379 * full screen mode.
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012380 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012381 *
12382 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012383 */
12384 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012385 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12386 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12387 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012388 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012389 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12390 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012391 }
12392
Sarah Chindf715ec2023-02-13 13:46:24 -080012393 /**
12394 * Request to get whether satellite communication is allowed for the current location.
12395 *
12396 * @param subId The subId of the subscription to check whether satellite communication is
12397 * allowed for the current location for.
12398 * @param result The result receiver that returns whether satellite communication is allowed
12399 * for the current location if the request is successful or an error code
12400 * if the request failed.
12401 *
12402 * @throws SecurityException if the caller doesn't have the required permission.
12403 */
12404 @Override
12405 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12406 @NonNull ResultReceiver result) {
12407 enforceSatelliteCommunicationPermission(
12408 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012409 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12410 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012411 }
12412
12413 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012414 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012415 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012416 * @param subId The subId to get the time after which the satellite will be visible for.
12417 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012418 * be visible if the request is successful or an error code if the request failed.
12419 *
12420 * @throws SecurityException if the caller doesn't have the required permission.
12421 */
12422 @Override
12423 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12424 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012425 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012426 }
12427
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012428 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012429 * Inform that Device is aligned to satellite for demo mode.
12430 *
12431 * @param subId The subId to get the time after which the satellite will be visible for.
12432 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12433 * {@code false} Device fails to align with the satellite for demo mode.
12434 *
12435 * @throws SecurityException if the caller doesn't have required permission.
12436 */
12437 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12438
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012439 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012440 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012441 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012442 }
12443
12444 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012445 * This API can be used by only CTS to update satellite vendor service package name.
12446 *
12447 * @param servicePackageName The package name of the satellite vendor service.
12448 * @return {@code true} if the satellite vendor service is set successfully,
12449 * {@code false} otherwise.
12450 */
12451 public boolean setSatelliteServicePackageName(String servicePackageName) {
12452 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12453 TelephonyPermissions.enforceShellOnly(
12454 Binder.getCallingUid(), "setSatelliteServicePackageName");
12455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12456 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12457 "setSatelliteServicePackageName");
12458 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12459 }
12460
12461 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012462 * This API can be used by only CTS to update satellite gateway service package name.
12463 *
12464 * @param servicePackageName The package name of the satellite gateway service.
12465 * @return {@code true} if the satellite gateway service is set successfully,
12466 * {@code false} otherwise.
12467 */
12468 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12469 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12470 TelephonyPermissions.enforceShellOnly(
12471 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12473 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12474 "setSatelliteGatewayServicePackageName");
12475 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12476 }
12477
12478 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012479 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12480 *
12481 * @param packageName The package name of the satellite pointing UI app.
12482 * @param className The class name of the satellite pointing UI app.
12483 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12484 * {@code false} otherwise.
12485 */
12486 public boolean setSatellitePointingUiClassName(
12487 @Nullable String packageName, @Nullable String className) {
12488 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12489 + ", className=" + className);
12490 TelephonyPermissions.enforceShellOnly(
12491 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12493 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12494 "setSatelliteGatewayServicePackageName");
12495 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12496 }
12497
12498 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012499 * This API can be used by only CTS to update the timeout duration in milliseconds that
12500 * satellite should stay at listening mode to wait for the next incoming page before disabling
12501 * listening mode.
12502 *
12503 * @param timeoutMillis The timeout duration in millisecond.
12504 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12505 */
12506 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12507 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12508 TelephonyPermissions.enforceShellOnly(
12509 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12511 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12512 "setSatelliteListeningTimeoutDuration");
12513 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12514 }
12515
12516 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012517 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12518 * the device is aligned with the satellite for demo mode
12519 *
12520 * @param timeoutMillis The timeout duration in millisecond.
12521 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12522 */
12523 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12524 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12525 TelephonyPermissions.enforceShellOnly(
12526 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12528 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12529 "setDeviceAlignedTimeoutDuration");
12530 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12531 }
12532
12533 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012534 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12535 *
12536 * <p>This method behaves in one of the following ways:
12537 * <ul>
12538 * <li>return true : if the calling package has the appop permission {@link
12539 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12540 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12541 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12542 * Owner device identifier access check, or the calling package has carrier privileges</>
12543 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12544 * </ul>
12545 */
12546 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12547 String callingPackage, @Nullable String callingFeatureId, String message) {
12548 for (Phone phone : PhoneFactory.getPhones()) {
12549 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12550 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12551 return true;
12552 }
12553 }
12554 return false;
12555 }
arunvoddud7401012022-12-15 16:08:12 +000012556
12557 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012558 * @return The subscription manager service instance.
12559 */
12560 public SubscriptionManagerService getSubscriptionManagerService() {
12561 return SubscriptionManagerService.getInstance();
12562 }
12563
12564 /**
arunvoddud7401012022-12-15 16:08:12 +000012565 * Class binds the consumer[callback] and carrierId.
12566 */
12567 private static class CallerCallbackInfo {
12568 private final Consumer<Integer> mConsumer;
12569 private final int mCarrierId;
12570
12571 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12572 mConsumer = consumer;
12573 mCarrierId = carrierId;
12574 }
12575
12576 public Consumer<Integer> getConsumer() {
12577 return mConsumer;
12578 }
12579
12580 public int getCarrierId() {
12581 return mCarrierId;
12582 }
12583 }
Jack Yufa8ed012023-02-11 15:42:28 -080012584}