blob: 3c7ee803d9a3342b3c8a4de039588ce710c55757 [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
2733 */
Wink Saville9de0f752013-10-22 19:04:03 -07002734 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735
2736 while (mHandler == null) {
2737 try {
2738 wait();
2739 } catch (InterruptedException e) {
2740 Thread.currentThread().interrupt();
2741 }
2742 }
2743 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2744
2745 if (puk == null) {
2746 mSimCard.supplyPin(pin, callback);
2747 } else {
2748 mSimCard.supplyPuk(puk, pin, callback);
2749 }
2750
2751 while (!mDone) {
2752 try {
2753 Log.d(LOG_TAG, "wait for done");
2754 wait();
2755 } catch (InterruptedException e) {
2756 // Restore the interrupted status
2757 Thread.currentThread().interrupt();
2758 }
2759 }
2760 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002761 int[] resultArray = new int[2];
2762 resultArray[0] = mResult;
2763 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002764
2765 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002766 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002767 }
2768
Wink Saville9de0f752013-10-22 19:04:03 -07002769 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771 }
2772
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002773 /**
2774 * This method has been removed due to privacy and stability concerns.
2775 */
2776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002778 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2779 return;
Wink Saville36469e72014-06-11 15:17:00 -07002780 }
2781
Nathan Harold1f889d82020-06-04 17:05:26 -07002782 @Override
2783 public void updateServiceLocationWithPackageName(String callingPackage) {
2784 mApp.getSystemService(AppOpsManager.class)
2785 .checkPackage(Binder.getCallingUid(), callingPackage);
2786
Nathan Haroldf096d982020-11-18 17:18:06 -08002787 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002788 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2789 // Callers targeting S have no business invoking this method.
2790 return;
2791 }
2792
2793 LocationAccessPolicy.LocationPermissionResult locationResult =
2794 LocationAccessPolicy.checkLocationPermission(mApp,
2795 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2796 .setCallingPackage(callingPackage)
2797 .setCallingFeatureId(null)
2798 .setCallingPid(Binder.getCallingPid())
2799 .setCallingUid(Binder.getCallingUid())
2800 .setMethod("updateServiceLocation")
2801 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2802 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2803 .build());
2804 // Apps that lack location permission have no business calling this method;
2805 // however, because no permission was declared in the public API, denials must
2806 // all be "soft".
2807 switch (locationResult) {
2808 case DENIED_HARD: /* fall through */
2809 case DENIED_SOFT:
2810 return;
2811 }
2812
2813 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 final long identity = Binder.clearCallingIdentity();
2815 try {
Ling Mac28f0212023-03-24 16:07:15 -07002816 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 } finally {
2818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 }
2821
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002822 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002823 @Override
2824 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 return isRadioOnWithFeature(callingPackage, null);
2826 }
2827
2828
2829 @Override
2830 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2831 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2832 callingFeatureId);
2833 }
2834
2835 @Deprecated
2836 @Override
2837 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2838 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002839 }
2840
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002842 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2843 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002845 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002846 return false;
2847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 return isRadioOnForSubscriber(subId);
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002855 }
2856
2857 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 final Phone phone = getPhone(subId);
2861 if (phone != null) {
2862 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2863 } else {
2864 return false;
2865 }
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 }
2870
2871 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002872 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 }
Wink Saville36469e72014-06-11 15:17:00 -07002874
Wink Savilleb564aae2014-10-23 10:18:09 -07002875 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 final Phone phone = getPhone(subId);
2881 if (phone != null) {
2882 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2883 }
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 }
Wink Saville36469e72014-06-11 15:17:00 -07002887 }
2888
2889 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002890 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002891 }
2892
Wink Savilleb564aae2014-10-23 10:18:09 -07002893 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002894 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 final Phone phone = getPhone(subId);
2899 if (phone == null) {
2900 return false;
2901 }
2902 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2903 toggleRadioOnOffForSubscriber(subId);
2904 }
2905 return true;
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 }
Wink Saville36469e72014-06-11 15:17:00 -07002910
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002911 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002912 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002913 /*
2914 * If any of the Radios are available, it will need to be
2915 * shutdown. So return true if any Radio is available.
2916 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2920 Phone phone = PhoneFactory.getPhone(i);
2921 if (phone != null && phone.isRadioAvailable()) return true;
2922 }
2923 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2924 return false;
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002927 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002928 }
2929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002931 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 enforceModifyPermission();
2933
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2937 logv("Shutting down Phone " + i);
2938 shutdownRadioUsingPhoneId(i);
2939 }
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002942 }
2943 }
2944
2945 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002946 Phone phone = PhoneFactory.getPhone(phoneId);
2947 if (phone != null && phone.isRadioAvailable()) {
2948 phone.shutdownRadio();
2949 }
2950 }
2951
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002953 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954
Ling Ma83dc5ea2023-01-12 15:06:04 -08002955 if (!turnOn) {
2956 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2957 }
2958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2962 if (defaultPhone != null) {
2963 defaultPhone.setRadioPower(turnOn);
2964 return true;
2965 } else {
2966 loge("There's no default phone.");
2967 return false;
2968 }
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002971 }
Wink Saville36469e72014-06-11 15:17:00 -07002972 }
2973
Wink Savilleb564aae2014-10-23 10:18:09 -07002974 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
Ling Ma83dc5ea2023-01-12 15:06:04 -08002977 if (!turnOn) {
2978 log("setRadioPowerForSubscriber off: subId=" + subId
2979 + ",callingPackage=" + getCurrentPackageName());
2980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 final Phone phone = getPhone(subId);
2984 if (phone != null) {
2985 phone.setRadioPower(turnOn);
2986 return true;
2987 } else {
2988 return false;
2989 }
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 }
2994
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002995 /**
2996 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2997 * no reason to power it off. When any of the voters want to power it off, it will be turned
2998 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2999 * powering it off, and these radio off votes will be cleared.
3000 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3001 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3002 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3003 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3004 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3005 * check its vote.
3006 *
3007 * @param subId The subscription ID.
3008 * @param reason The reason for powering off radio.
3009 * @return true on success and false on failure.
3010 */
3011 public boolean requestRadioPowerOffForReason(int subId,
3012 @TelephonyManager.RadioPowerReason int reason) {
3013 enforceModifyPermission();
3014
Ling Ma83dc5ea2023-01-12 15:06:04 -08003015 log("requestRadioPowerOffForReason: subId=" + subId
3016 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003017 final long identity = Binder.clearCallingIdentity();
3018 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003019 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003020 if (phone != null) {
3021 phone.setRadioPowerForReason(false, reason);
3022 return true;
3023 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003024 loge("requestRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003025 return false;
3026 }
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
3029 }
3030 }
3031
3032 /**
3033 * Remove the vote on powering off the radio for a reason, as requested by
3034 * {@link requestRadioPowerOffForReason}.
3035 *
3036 * @param subId The subscription ID.
3037 * @param reason The reason for powering off radio.
3038 * @return true on success and false on failure.
3039 */
3040 public boolean clearRadioPowerOffForReason(int subId,
3041 @TelephonyManager.RadioPowerReason int reason) {
3042 enforceModifyPermission();
3043
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003046 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003047 if (phone != null) {
3048 phone.setRadioPowerForReason(true, reason);
3049 return true;
3050 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003051 loge("clearRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003052 return false;
3053 }
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
3057 }
3058
3059 /**
3060 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3061 *
3062 * @param subId The subscription ID.
3063 * @param callingPackage The package making the call.
3064 * @param callingFeatureId The feature in the package.
3065 * @return List of reasons for powering off radio.
3066 */
3067 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3068 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3069
3070 final long identity = Binder.clearCallingIdentity();
3071 List result = new ArrayList();
3072 try {
3073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3074 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3075 return result;
3076 }
3077
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003078 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003079 if (phone != null) {
3080 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003081 } else {
3082 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003083 }
3084 } finally {
3085 Binder.restoreCallingIdentity(identity);
3086 }
3087 return result;
3088 }
3089
Wink Saville36469e72014-06-11 15:17:00 -07003090 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003091 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003092 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
Jack Yu285100e2022-12-02 22:48:35 -08003097 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098 final Phone phone = getPhone(subId);
3099 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003100 phone.getDataSettingsManager().setDataEnabled(
3101 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 return true;
3103 } else {
3104 return false;
3105 }
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 }
3110
Wink Saville36469e72014-06-11 15:17:00 -07003111 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003112 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003113 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115
3116 final long identity = Binder.clearCallingIdentity();
3117 try {
Jack Yu285100e2022-12-02 22:48:35 -08003118 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 final Phone phone = getPhone(subId);
3120 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003121 phone.getDataSettingsManager().setDataEnabled(
3122 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 return true;
3124 } else {
3125 return false;
3126 }
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003130 }
3131
Sanket Padawe356d7632015-06-22 14:03:32 -07003132 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003133 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 final Phone phone = getPhone(subId);
3137 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003138 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 } else {
3140 return false;
3141 }
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 }
3146
3147 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003148 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003149 }
3150
pkanwarae03a6b2016-11-06 20:37:09 -08003151 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 enforceCallPermission();
3153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3157 return;
3158 }
3159 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3160 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3161 } finally {
3162 Binder.restoreCallingIdentity(identity);
3163 }
pkanwar32d516d2016-10-14 19:37:38 -07003164 };
3165
Wink Savilleb564aae2014-10-23 10:18:09 -07003166 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168
3169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3172 return false;
3173 }
3174 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 }
3179
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003180 /**
3181 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3182 * tag on getCallState Binder call.
3183 */
3184 @Deprecated
3185 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003187 if (CompatChanges.isChangeEnabled(
3188 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3189 Binder.getCallingUid())) {
3190 // Do not allow this API to be called on API version 31+, it should only be
3191 // called on old apps using this Binder call directly.
3192 throw new SecurityException("This method can only be used for applications "
3193 + "targeting API version 30 or less.");
3194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 final long identity = Binder.clearCallingIdentity();
3196 try {
Ling Mac28f0212023-03-24 16:07:15 -07003197 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3198 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
3202 }
3203
3204 @Override
3205 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3206 if (CompatChanges.isChangeEnabled(
3207 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3208 Binder.getCallingUid())) {
3209 // Check READ_PHONE_STATE for API version 31+
3210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3211 featureId, "getCallStateForSubscription")) {
3212 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3213 + "targeting API level 31+.");
3214 }
3215 }
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3220 PhoneConstantConversions.convertCallState(phone.getState());
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
3223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 }
3225
Sanket Padawe356d7632015-06-22 14:03:32 -07003226 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003227 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003228 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003229 }
3230
3231 @Override
3232 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 final long identity = Binder.clearCallingIdentity();
3234 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003235 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003237 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 } else {
3239 return PhoneConstantConversions.convertDataState(
3240 PhoneConstants.DataState.DISCONNECTED);
3241 }
3242 } finally {
3243 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 }
3246
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003248 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003249 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003250 }
3251
3252 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003253 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 final long identity = Binder.clearCallingIdentity();
3255 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003256 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003258 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259 } else {
3260 return TelephonyManager.DATA_ACTIVITY_NONE;
3261 }
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 }
3266
3267 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003268 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003269 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003270 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003271
3272 LocationAccessPolicy.LocationPermissionResult locationResult =
3273 LocationAccessPolicy.checkLocationPermission(mApp,
3274 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3275 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003276 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003277 .setCallingPid(Binder.getCallingPid())
3278 .setCallingUid(Binder.getCallingUid())
3279 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003280 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003281 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3282 .build());
3283 switch (locationResult) {
3284 case DENIED_HARD:
3285 throw new SecurityException("Not allowed to access cell location");
3286 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003287 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3288 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003289 }
3290
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003291 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003295 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003296 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003297 } finally {
3298 Binder.restoreCallingIdentity(identity);
3299 }
Svetoslav64fad262015-04-14 14:35:21 -07003300 }
3301
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003303 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003304 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3305 // registered cell info, so return a NULL country instead.
3306 final long identity = Binder.clearCallingIdentity();
3307 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003308 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3309 // Get default phone in this case.
3310 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3311 }
Jack Yu285100e2022-12-02 22:48:35 -08003312 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003314 if (phone == null) return "";
3315 ServiceStateTracker sst = phone.getServiceStateTracker();
3316 if (sst == null) return "";
3317 LocaleTracker lt = sst.getLocaleTracker();
3318 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003319 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003323 }
3324
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003325 /**
3326 * This method was removed due to potential issues caused by performing partial
3327 * updates of service state, and lack of a credible use case.
3328 *
3329 * This has the ability to break the telephony implementation by disabling notification of
3330 * changes in device connectivity. DO NOT USE THIS!
3331 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003332 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003333 public void enableLocationUpdates() {
3334 mApp.enforceCallingOrSelfPermission(
3335 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 }
3337
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003338 /**
3339 * This method was removed due to potential issues caused by performing partial
3340 * updates of service state, and lack of a credible use case.
3341 *
3342 * This has the ability to break the telephony implementation by disabling notification of
3343 * changes in device connectivity. DO NOT USE THIS!
3344 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003345 @Override
3346 public void disableLocationUpdates() {
3347 mApp.enforceCallingOrSelfPermission(
3348 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003349 }
3350
3351 @Override
3352 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003353 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3354 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003355 try {
3356 mApp.getSystemService(AppOpsManager.class)
3357 .checkPackage(Binder.getCallingUid(), callingPackage);
3358 } catch (SecurityException e) {
3359 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3360 throw e;
3361 }
3362
Nathan Haroldf096d982020-11-18 17:18:06 -08003363 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003364 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3365 throw new SecurityException(
3366 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3367 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003368
Jordan Liu1617b712019-07-10 15:06:26 -07003369 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003370 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3371 return null;
3372 }
Svetoslav64fad262015-04-14 14:35:21 -07003373
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003374 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003375
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003376 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003377 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003378
Nathan Haroldf180aac2018-06-01 18:43:55 -07003379 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3380 for (CellInfo ci : info) {
3381 if (ci instanceof CellInfoGsm) {
3382 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3383 } else if (ci instanceof CellInfoWcdma) {
3384 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003387 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 }
3389
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003390 private List<CellInfo> getCachedCellInfo() {
3391 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3392 for (Phone phone : PhoneFactory.getPhones()) {
3393 List<CellInfo> info = phone.getAllCellInfo();
3394 if (info != null) cellInfos.addAll(info);
3395 }
3396 return cellInfos;
3397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003398
3399 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003400 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003401 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003402 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003403
3404 LocationAccessPolicy.LocationPermissionResult locationResult =
3405 LocationAccessPolicy.checkLocationPermission(mApp,
3406 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3407 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003408 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003409 .setCallingPid(Binder.getCallingPid())
3410 .setCallingUid(Binder.getCallingUid())
3411 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003412 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003413 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3414 .build());
3415 switch (locationResult) {
3416 case DENIED_HARD:
3417 throw new SecurityException("Not allowed to access cell info");
3418 case DENIED_SOFT:
3419 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003420 }
3421
Nathan Haroldf096d982020-11-18 17:18:06 -08003422 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003423 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3424 return getCachedCellInfo();
3425 }
3426
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003427 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003428 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3432 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003433 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003434 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003435 if (info != null) cellInfos.addAll(info);
3436 }
3437 return cellInfos;
3438 } finally {
3439 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 }
3441 }
3442
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003443 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003444 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3445 String callingFeatureId) {
3446 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3447 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003448 }
3449
3450 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003451 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3452 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003453 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003454 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003455 }
3456
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003457 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3458 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003459 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003460 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003461
3462 LocationAccessPolicy.LocationPermissionResult locationResult =
3463 LocationAccessPolicy.checkLocationPermission(mApp,
3464 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3465 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003466 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003467 .setCallingPid(Binder.getCallingPid())
3468 .setCallingUid(Binder.getCallingUid())
3469 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003470 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3471 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003472 .build());
3473 switch (locationResult) {
3474 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003475 if (TelephonyPermissions
3476 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003477 // Safetynet logging for b/154934934
3478 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3479 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003480 throw new SecurityException("Not allowed to access cell info");
3481 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003482 if (TelephonyPermissions
3483 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003484 // Safetynet logging for b/154934934
3485 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3486 }
Nathan Harold5320c422019-05-09 10:26:08 -07003487 try {
3488 cb.onCellInfo(new ArrayList<CellInfo>());
3489 } catch (RemoteException re) {
3490 // Drop without consequences
3491 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003492 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003493 }
3494
Nathan Harolda939a962019-05-09 10:13:47 -07003495
3496 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003497 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3498
3499 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3500 }
3501
3502 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003503 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003504 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003509 Phone phone = getPhone(subId);
3510 if (phone == null) {
3511 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3512 } else {
3513 phone.setCellInfoListRate(rateInMillis, workSource);
3514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515 } finally {
3516 Binder.restoreCallingIdentity(identity);
3517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 }
3519
Shishir Agrawala9f32182016-04-12 12:00:16 -07003520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003522 Phone phone = PhoneFactory.getPhone(slotIndex);
3523 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003524 return null;
3525 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003526 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003527 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003528 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003529 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003530 return null;
3531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 return phone.getImei();
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003539 }
3540
3541 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003542 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3543 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3544 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3545 callingFeatureId, "getPrimaryImei")) {
3546 throw new SecurityException("Caller does not have permission");
3547 }
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 for (Phone phone : PhoneFactory.getPhones()) {
3551 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3552 return phone.getImei();
3553 }
3554 }
3555 throw new UnsupportedOperationException("Operation not supported");
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
3558 }
3559 }
3560
3561 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003562 public String getTypeAllocationCodeForSlot(int slotIndex) {
3563 Phone phone = PhoneFactory.getPhone(slotIndex);
3564 String tac = null;
3565 if (phone != null) {
3566 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003567 try {
3568 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3569 } catch (IndexOutOfBoundsException e) {
3570 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3571 return null;
3572 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003573 }
3574 return tac;
3575 }
3576
3577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003578 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003579 try {
3580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3581 } catch (SecurityException se) {
3582 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3583 throw new SecurityException("Package " + callingPackage + " does not belong to "
3584 + Binder.getCallingUid());
3585 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003586 Phone phone = PhoneFactory.getPhone(slotIndex);
3587 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003588 return null;
3589 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590
Jeff Davidson913390f2018-02-23 17:11:49 -08003591 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003592 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003593 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003594 return null;
3595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596
3597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 return phone.getMeid();
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
Jack Yu2af8d712017-03-15 17:14:14 -07003603 }
3604
3605 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003606 public String getManufacturerCodeForSlot(int slotIndex) {
3607 Phone phone = PhoneFactory.getPhone(slotIndex);
3608 String manufacturerCode = null;
3609 if (phone != null) {
3610 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003611 try {
3612 manufacturerCode =
3613 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3614 } catch (IndexOutOfBoundsException e) {
3615 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3616 return null;
3617 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003618 }
3619 return manufacturerCode;
3620 }
3621
3622 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003623 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3624 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003625 Phone phone = PhoneFactory.getPhone(slotIndex);
3626 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003627 return null;
3628 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003629 int subId = phone.getSubId();
3630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003631 mApp, subId, callingPackage, callingFeatureId,
3632 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003633 return null;
3634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 return phone.getDeviceSvn();
3639 } finally {
3640 Binder.restoreCallingIdentity(identity);
3641 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003642 }
3643
fionaxu43304da2017-11-27 22:51:16 -08003644 @Override
3645 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 final Phone phone = getPhone(subId);
3649 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
fionaxu43304da2017-11-27 22:51:16 -08003653 }
3654
3655 @Override
3656 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 final long identity = Binder.clearCallingIdentity();
3658 try {
3659 final Phone phone = getPhone(subId);
3660 return phone == null ? null : phone.getCarrierName();
3661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
fionaxu43304da2017-11-27 22:51:16 -08003664 }
3665
calvinpanffe225e2018-11-01 19:43:06 +08003666 @Override
chen xu0026ca62019-03-06 15:28:50 -08003667 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 final Phone phone = getPhone(subId);
3671 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003672 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
3676 }
3677
3678 @Override
chen xu0026ca62019-03-06 15:28:50 -08003679 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003683 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
3687 }
3688
chen xu651eec72018-11-11 19:03:44 -08003689 @Override
chen xu864e11c2018-12-06 22:10:03 -08003690 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3691 if (!isSubscriptionMccMnc) {
3692 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3693 }
chen xu651eec72018-11-11 19:03:44 -08003694 final Phone phone = PhoneFactory.getPhone(slotIndex);
3695 if (phone == null) {
3696 return TelephonyManager.UNKNOWN_CARRIER_ID;
3697 }
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003706 //
3707 // Internal helper methods.
3708 //
3709
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003710 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003711 * Make sure the caller is the calling package itself
3712 *
3713 * @throws SecurityException if the caller is not the calling package
3714 */
3715 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3716 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003717 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3718 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003719 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003720 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003721 } catch (PackageManager.NameNotFoundException e) {
3722 // packageUid is -1
3723 }
3724 if (packageUid != callingUid) {
3725 throw new SecurityException(message + ": Package " + callingPackage
3726 + " does not belong to " + callingUid);
3727 }
3728 }
3729
3730 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003731 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3732 *
3733 * @throws SecurityException if the caller does not have the required permission
3734 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003735 @VisibleForTesting
3736 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003737 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3738 }
3739
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003740 /**
arunvoddud7401012022-12-15 16:08:12 +00003741 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003742 *
3743 * @throws SecurityException if the caller does not have the required permission
3744 */
3745 @VisibleForTesting
3746 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003747 enforceReadPermission(null);
3748 }
3749
3750 /**
3751 * Make sure the caller has the READ_PHONE_STATE permissions.
3752 *
3753 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3754 */
3755 @VisibleForTesting
3756 public void enforceReadPermission(String msg) {
3757 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003758 }
3759
Shuo Qian3b6ee772019-11-13 17:43:31 -08003760 private void enforceActiveEmergencySessionPermission() {
3761 mApp.enforceCallingOrSelfPermission(
3762 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3763 }
3764
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003765 /**
3766 * Make sure the caller has the CALL_PHONE permission.
3767 *
3768 * @throws SecurityException if the caller does not have the required permission
3769 */
3770 private void enforceCallPermission() {
3771 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3772 }
3773
paulhu5a773602019-08-23 19:17:33 +08003774 private void enforceSettingsPermission() {
3775 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003776 }
3777
Michele Berionne5e411512020-11-13 02:36:59 +00003778 private void enforceRebootPermission() {
3779 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3780 }
3781
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003782 /**
3783 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3784 * @param message - log message to print.
3785 * @throws SecurityException if the caller does not have the required permission
3786 */
3787 private void enforceSatelliteCommunicationPermission(String message) {
3788 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3789 }
3790
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003791 private String createTelUrl(String number) {
3792 if (TextUtils.isEmpty(number)) {
3793 return null;
3794 }
3795
Jake Hambye994d462014-02-03 13:10:13 -08003796 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003797 }
3798
Ihab Awadf9e92732013-12-05 18:02:52 -08003799 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003800 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003801 }
3802
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003803 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003804 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003805 }
3806
Ihab Awadf9e92732013-12-05 18:02:52 -08003807 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003808 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003809 }
3810
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003811 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003813 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003814 }
3815
Sanket Padawe356d7632015-06-22 14:03:32 -07003816 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003817 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 final Phone phone = PhoneFactory.getPhone(slotIndex);
3821 if (phone == null) {
3822 return PhoneConstants.PHONE_TYPE_NONE;
3823 } else {
3824 return phone.getPhoneType();
3825 }
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003829 }
3830
3831 /**
3832 * Returns the CDMA ERI icon index to display
3833 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003834 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003835 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3836 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3837 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003838 }
3839
Sanket Padawe356d7632015-06-22 14:03:32 -07003840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003841 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3842 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003844 mApp, subId, callingPackage, callingFeatureId,
3845 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003846 return -1;
3847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848
3849 final long identity = Binder.clearCallingIdentity();
3850 try {
3851 final Phone phone = getPhone(subId);
3852 if (phone != null) {
3853 return phone.getCdmaEriIconIndex();
3854 } else {
3855 return -1;
3856 }
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003860 }
3861
3862 /**
3863 * Returns the CDMA ERI icon mode,
3864 * 0 - ON
3865 * 1 - FLASHING
3866 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003867 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003868 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3869 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3870 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003871 }
3872
Sanket Padawe356d7632015-06-22 14:03:32 -07003873 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003874 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3875 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003877 mApp, subId, callingPackage, callingFeatureId,
3878 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003879 return -1;
3880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881
3882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 final Phone phone = getPhone(subId);
3885 if (phone != null) {
3886 return phone.getCdmaEriIconMode();
3887 } else {
3888 return -1;
3889 }
3890 } finally {
3891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003893 }
3894
3895 /**
3896 * Returns the CDMA ERI text,
3897 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003898 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003899 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3900 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3901 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003902 }
3903
Sanket Padawe356d7632015-06-22 14:03:32 -07003904 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003905 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3906 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003908 mApp, subId, callingPackage, callingFeatureId,
3909 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003910 return null;
3911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912
3913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 final Phone phone = getPhone(subId);
3916 if (phone != null) {
3917 return phone.getCdmaEriText();
3918 } else {
3919 return null;
3920 }
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003924 }
3925
3926 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003927 * Returns the CDMA MDN.
3928 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003929 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003930 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3932 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003937 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 return phone.getLine1Number();
3939 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003940 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 return null;
3942 }
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003945 }
3946 }
3947
3948 /**
3949 * Returns the CDMA MIN.
3950 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003951 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003952 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3954 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955
3956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 final Phone phone = getPhone(subId);
3959 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3960 return phone.getCdmaMin();
3961 } else {
3962 return null;
3963 }
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003966 }
3967 }
3968
Hall Liud892bec2018-11-30 14:51:45 -08003969 @Override
3970 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3971 INumberVerificationCallback callback, String callingPackage) {
3972 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3973 != PERMISSION_GRANTED) {
3974 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3975 }
3976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3977
3978 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3979 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003980 throw new SecurityException("Calling package must be configured in the device config: "
3981 + "calling package: " + callingPackage
3982 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003983 }
3984
3985 if (range == null) {
3986 throw new NullPointerException("Range must be non-null");
3987 }
3988
3989 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003990 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003991
3992 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3993 }
3994
Junda Liuca05d5d2014-08-14 22:36:34 -07003995 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003996 * Returns true if CDMA provisioning needs to run.
3997 */
3998 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999 final long identity = Binder.clearCallingIdentity();
4000 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004001 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002 } finally {
4003 Binder.restoreCallingIdentity(identity);
4004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004005 }
4006
4007 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004008 * Sets the voice mail number of a given subId.
4009 */
4010 @Override
4011 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004012 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4013 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014
4015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4018 new Pair<String, String>(alphaTag, number), new Integer(subId));
4019 return success;
4020 } finally {
4021 Binder.restoreCallingIdentity(identity);
4022 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004023 }
4024
Ta-wei Yen87c49842016-05-13 21:19:52 -07004025 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004026 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4027 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004028 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4029 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004030 if (!TextUtils.equals(callingPackage, systemDialer)) {
4031 throw new SecurityException("caller must be system dialer");
4032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4037 if (phoneAccountHandle == null) {
4038 return null;
4039 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041 } finally {
4042 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004043 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004044 }
4045
4046 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004047 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4048 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004051 mApp, subId, callingPackage, callingFeatureId,
4052 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004053 return null;
4054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004056 final long identity = Binder.clearCallingIdentity();
4057 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004058 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004062 }
4063
4064 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004065 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4066 VisualVoicemailSmsFilterSettings settings) {
4067 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068
4069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004072 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004076 }
4077
4078 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004079 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004085 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004089 }
4090
4091 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004092 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4093 String callingPackage, int subId) {
4094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095
4096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004099 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004103 }
4104
4105 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004106 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108
4109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004112 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004116 }
4117
4118 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004119 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4120 String callingAttributionTag, int subId, String number, int port, String text,
4121 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004122 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004123 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004124 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004125 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004126 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4127 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004128 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004129
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004130 /**
fionaxu0152e512016-11-14 13:36:14 -08004131 * Sets the voice activation state of a given subId.
4132 */
4133 @Override
4134 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4136 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 final Phone phone = getPhone(subId);
4141 if (phone != null) {
4142 phone.setVoiceActivationState(activationState);
4143 } else {
4144 loge("setVoiceActivationState fails with invalid subId: " + subId);
4145 }
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004148 }
4149 }
4150
4151 /**
4152 * Sets the data activation state of a given subId.
4153 */
4154 @Override
4155 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4157 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158
4159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 final Phone phone = getPhone(subId);
4162 if (phone != null) {
4163 phone.setDataActivationState(activationState);
4164 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004165 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 }
4167 } finally {
4168 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004169 }
4170 }
4171
4172 /**
4173 * Returns the voice activation state of a given subId.
4174 */
4175 @Override
4176 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178
fionaxu0152e512016-11-14 13:36:14 -08004179 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 if (phone != null) {
4183 return phone.getVoiceActivationState();
4184 } else {
4185 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4186 }
4187 } finally {
4188 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004189 }
4190 }
4191
4192 /**
4193 * Returns the data activation state of a given subId.
4194 */
4195 @Override
4196 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198
fionaxu0152e512016-11-14 13:36:14 -08004199 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 final long identity = Binder.clearCallingIdentity();
4201 try {
4202 if (phone != null) {
4203 return phone.getDataActivationState();
4204 } else {
4205 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4206 }
4207 } finally {
4208 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004209 }
4210 }
4211
4212 /**
Wink Saville36469e72014-06-11 15:17:00 -07004213 * Returns the unread count of voicemails for a subId
4214 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004215 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004216 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4217 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004219 mApp, subId, callingPackage, callingFeatureId,
4220 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004221 return 0;
4222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223 final long identity = Binder.clearCallingIdentity();
4224 try {
4225 final Phone phone = getPhone(subId);
4226 if (phone != null) {
4227 return phone.getVoiceMessageCount();
4228 } else {
4229 return 0;
4230 }
4231 } finally {
4232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004234 }
4235
4236 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004237 * returns true, if the device is in a state where both voice and data
4238 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004239 */
4240 @Override
4241 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
Ling Mac28f0212023-03-24 16:07:15 -07004244 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004248 }
4249
4250 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004251 * Send the dialer code if called from the current default dialer or the caller has
4252 * carrier privilege.
4253 * @param inputCode The dialer code to send
4254 */
4255 @Override
4256 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004257 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004259 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4260 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004261 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004262 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004263 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004265
4266 final long identity = Binder.clearCallingIdentity();
4267 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004268 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
fionaxu235cc5e2017-03-06 22:25:57 -08004272 }
4273
Pengquan Menga1bb6272018-09-06 09:59:22 -07004274 @Override
4275 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004276 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004277 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4278 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 if (!isActiveSubscription(subId)) {
4282 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4283 }
4284 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004287 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004288 }
4289
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004291 public boolean isInEmergencySmsMode() {
4292 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 for (Phone phone : PhoneFactory.getPhones()) {
4296 if (phone.isInEmergencySmsMode()) {
4297 return true;
4298 }
4299 }
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
4303 return false;
4304 }
4305
shilu366312e2019-12-17 09:28:10 -08004306 /**
4307 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4308 * @param subId The subscription to use to check the configuration.
4309 * @param c The callback that will be used to send the result.
4310 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004311 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004312 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4313 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004314 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004315 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004316
4317 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4318 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4319 "IMS not available on device.");
4320 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 final long token = Binder.clearCallingIdentity();
4322 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004323 int slotId = getSlotIndexOrException(subId);
4324 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004325
4326 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4327 if (controller != null) {
4328 ImsManager imsManager = controller.getImsManager(subId);
4329 if (imsManager != null) {
4330 imsManager.addRegistrationCallbackForSubscription(c, subId);
4331 } else {
4332 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4333 }
4334 } else {
4335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4336 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 } finally {
4340 Binder.restoreCallingIdentity(token);
4341 }
4342 }
4343
shilu366312e2019-12-17 09:28:10 -08004344 /**
4345 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4346 * @param subId The subscription to use to check the configuration.
4347 * @param c The callback that will be used to send the result.
4348 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004350 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004351 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004352 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4354 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4355 }
Meng Wangafbc5852019-09-19 17:37:13 -07004356 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004357
Meng Wangafbc5852019-09-19 17:37:13 -07004358 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004359 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4360 if (controller != null) {
4361 ImsManager imsManager = controller.getImsManager(subId);
4362 if (imsManager != null) {
4363 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4364 } else {
4365 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4366 + "is inactive, ignoring unregister.");
4367 // If the ImsManager is not valid, just return, since the callback
4368 // will already have been removed internally.
4369 }
4370 }
Meng Wangafbc5852019-09-19 17:37:13 -07004371 } finally {
4372 Binder.restoreCallingIdentity(token);
4373 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 }
4375
Brad Ebingera34a6c22019-10-22 17:36:18 -07004376 /**
4377 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4378 */
4379 @Override
4380 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4381 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4382 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4383 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4384 "IMS not available on device.");
4385 }
4386 final long token = Binder.clearCallingIdentity();
4387 try {
4388 Phone phone = getPhone(subId);
4389 if (phone == null) {
4390 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4391 + subId + "'");
4392 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4393 }
4394 phone.getImsRegistrationState(regState -> {
4395 try {
4396 consumer.accept((regState == null)
4397 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4398 } catch (RemoteException e) {
4399 // Ignore if the remote process is no longer available to call back.
4400 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4401 }
4402 });
4403 } finally {
4404 Binder.restoreCallingIdentity(token);
4405 }
4406 }
4407
4408 /**
4409 * Get the transport type for the IMS service registration state.
4410 */
4411 @Override
4412 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004413 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004414 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004415 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4416 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4417 "IMS not available on device.");
4418 }
4419 final long token = Binder.clearCallingIdentity();
4420 try {
4421 Phone phone = getPhone(subId);
4422 if (phone == null) {
4423 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4424 + subId + "'");
4425 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4426 }
4427 phone.getImsRegistrationTech(regTech -> {
4428 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4429 int regTechConverted = (regTech == null)
4430 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4431 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4432 regTechConverted);
4433 try {
4434 consumer.accept(regTechConverted);
4435 } catch (RemoteException e) {
4436 // Ignore if the remote process is no longer available to call back.
4437 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4438 }
4439 });
4440 } finally {
4441 Binder.restoreCallingIdentity(token);
4442 }
4443 }
4444
shilu366312e2019-12-17 09:28:10 -08004445 /**
4446 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4447 * @param subId The subscription to use to check the configuration.
4448 * @param c The callback that will be used to send the result.
4449 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004451 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4452 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004453 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004454 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004455 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4456 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4457 "IMS not available on device.");
4458 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004459 final long token = Binder.clearCallingIdentity();
4460 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004461 int slotId = getSlotIndexOrException(subId);
4462 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004463
4464 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4465 if (controller != null) {
4466 ImsManager imsManager = controller.getImsManager(subId);
4467 if (imsManager != null) {
4468 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4469 } else {
4470 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4471 }
4472 } else {
4473 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4474 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004475 } catch (ImsException e) {
4476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 } finally {
4478 Binder.restoreCallingIdentity(token);
4479 }
4480 }
4481
shilu366312e2019-12-17 09:28:10 -08004482 /**
4483 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4484 * @param subId The subscription to use to check the configuration.
4485 * @param c The callback that will be used to send the result.
4486 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004488 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004489 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004490 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004491 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4492 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4493 }
Meng Wangafbc5852019-09-19 17:37:13 -07004494
4495 final long token = Binder.clearCallingIdentity();
4496 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004497 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4498 if (controller != null) {
4499 ImsManager imsManager = controller.getImsManager(subId);
4500 if (imsManager != null) {
4501 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4502 } else {
4503 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4504 + " is inactive, ignoring unregister.");
4505 // If the ImsManager is not valid, just return, since the callback
4506 // will already have been removed internally.
4507 }
4508 }
Meng Wangafbc5852019-09-19 17:37:13 -07004509 } finally {
4510 Binder.restoreCallingIdentity(token);
4511 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 }
4513
4514 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004515 public boolean isCapable(int subId, int capability, int regTech) {
4516 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 final long token = Binder.clearCallingIdentity();
4518 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004519 int slotId = getSlotIndexOrException(subId);
4520 verifyImsMmTelConfiguredOrThrow(slotId);
4521 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4522 } catch (com.android.ims.ImsException e) {
4523 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4524 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004525 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004526 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4527 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 } finally {
4529 Binder.restoreCallingIdentity(token);
4530 }
4531 }
4532
4533 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004534 public boolean isAvailable(int subId, int capability, int regTech) {
4535 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004536 final long token = Binder.clearCallingIdentity();
4537 try {
4538 Phone phone = getPhone(subId);
4539 if (phone == null) return false;
4540 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004541 } catch (com.android.ims.ImsException e) {
4542 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4543 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 } finally {
4545 Binder.restoreCallingIdentity(token);
4546 }
4547 }
4548
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004549 /**
4550 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4551 * subscription.
4552 * @param subId The subscription to use to check the configuration.
4553 * @param callback The callback that will be used to send the result.
4554 * @param capability The MmTelFeature capability that will be used to send the result.
4555 * @param transportType The transport type of the MmTelFeature capability.
4556 */
4557 @Override
4558 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4559 int transportType) {
4560 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004561 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4562 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4563 "IMS not available on device.");
4564 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004565 final long token = Binder.clearCallingIdentity();
4566 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004567 int slotId = getSlotIndex(subId);
4568 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4569 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4570 + subId + "'");
4571 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4572 }
4573 verifyImsMmTelConfiguredOrThrow(slotId);
4574 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4575 transportType, aBoolean -> {
4576 try {
4577 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4578 } catch (RemoteException e) {
4579 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4580 + "running. Ignore");
4581 }
4582 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004583 } catch (ImsException e) {
4584 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004585 } finally {
4586 Binder.restoreCallingIdentity(token);
4587 }
4588 }
4589
shilu366312e2019-12-17 09:28:10 -08004590 /**
4591 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4592 * @param subId The subscription to use to check the configuration.
4593 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004594 @Override
4595 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004596 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004597 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004598
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 final long token = Binder.clearCallingIdentity();
4600 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004601 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004602 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004603 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (ImsException e) {
4605 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 } finally {
4607 Binder.restoreCallingIdentity(token);
4608 }
4609 }
4610
4611 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004612 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004614 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 final long identity = Binder.clearCallingIdentity();
4616 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004618 // This setting doesn't require an active ImsService connection, so do not verify. The
4619 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004620 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
4622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 } finally {
4624 Binder.restoreCallingIdentity(identity);
4625 }
4626 }
4627
shilu366312e2019-12-17 09:28:10 -08004628 /**
4629 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4630 * @param subId The subscription to use to check the configuration.
4631 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004633 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004634 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004635 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004636 final long identity = Binder.clearCallingIdentity();
4637 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004638 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004639 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004640 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004641 } catch (ImsException e) {
4642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
4646 }
4647
4648 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004649 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004651 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 final long identity = Binder.clearCallingIdentity();
4653 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004654 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004655 // This setting doesn't require an active ImsService connection, so do not verify. The
4656 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004657 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004658 } catch (ImsException e) {
4659 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004660 } finally {
4661 Binder.restoreCallingIdentity(identity);
4662 }
4663 }
4664
shilu366312e2019-12-17 09:28:10 -08004665 /**
4666 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4667 * @param subId The subscription to use to check the configuration.
4668 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004669 @Override
4670 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004671 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004672 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 final long identity = Binder.clearCallingIdentity();
4674 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004675 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004676 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004677 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004678 } catch (ImsException e) {
4679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
4685 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004686 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004688 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004689 final long identity = Binder.clearCallingIdentity();
4690 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004691 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004692 // This setting doesn't require an active ImsService connection, so do not verify. The
4693 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004694 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004695 } catch (ImsException e) {
4696 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
4700 }
4701
shilu366312e2019-12-17 09:28:10 -08004702 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004703 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4704 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4705 * @param subId The subscription to use to check the configuration.
4706 */
4707 @Override
4708 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004709 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004710 mApp, subId, "isCrossSimCallingEnabledByUser");
4711 final long identity = Binder.clearCallingIdentity();
4712 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004713 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004714 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004715 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004716 } catch (ImsException e) {
4717 throw new ServiceSpecificException(e.getCode());
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
4721 }
4722
4723 /**
4724 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4725 * Requires MODIFY_PHONE_STATE permission.
4726 * @param subId The subscription to use to check the configuration.
4727 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4728 * false otherwise
4729 */
4730 @Override
4731 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4733 "setCrossSimCallingEnabled");
4734 final long identity = Binder.clearCallingIdentity();
4735 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004736 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004737 // This setting doesn't require an active ImsService connection, so do not verify. The
4738 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004739 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004740 } catch (ImsException e) {
4741 throw new ServiceSpecificException(e.getCode());
4742 } finally {
4743 Binder.restoreCallingIdentity(identity);
4744 }
4745 }
4746
4747 /**
shilu366312e2019-12-17 09:28:10 -08004748 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4749 * @param subId The subscription to use to check the configuration.
4750 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004751 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004752
Brad Ebinger35c841c2018-10-01 10:40:55 -07004753 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004754 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004755 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004756 final long identity = Binder.clearCallingIdentity();
4757 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004758 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004759 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004760 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004761 } catch (ImsException e) {
4762 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
4766 }
4767
4768 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004769 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004771 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004772 final long identity = Binder.clearCallingIdentity();
4773 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004774 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004775 // This setting doesn't require an active ImsService connection, so do not verify. The
4776 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004777 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004778 } catch (ImsException e) {
4779 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
4783 }
4784
4785 @Override
4786 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4788 "setVoWiFiNonPersistent");
4789 final long identity = Binder.clearCallingIdentity();
4790 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004791 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004792 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004793 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004794 } catch (ImsException e) {
4795 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004796 } finally {
4797 Binder.restoreCallingIdentity(identity);
4798 }
4799 }
4800
shilu366312e2019-12-17 09:28:10 -08004801 /**
4802 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4803 * @param subId The subscription to use to check the configuration.
4804 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004805 @Override
4806 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004807 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004808 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004809 final long identity = Binder.clearCallingIdentity();
4810 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004811 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004812 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004813 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004814 } catch (ImsException e) {
4815 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
4819 }
4820
4821 @Override
4822 public void setVoWiFiModeSetting(int subId, int mode) {
4823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4824 "setVoWiFiModeSetting");
4825 final long identity = Binder.clearCallingIdentity();
4826 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004827 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004828 // This setting doesn't require an active ImsService connection, so do not verify. The
4829 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004830 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004831 } catch (ImsException e) {
4832 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
4836 }
4837
4838 @Override
4839 public int getVoWiFiRoamingModeSetting(int subId) {
4840 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4841 final long identity = Binder.clearCallingIdentity();
4842 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004843 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004844 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004845 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004846 } catch (ImsException e) {
4847 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
4851 }
4852
4853 @Override
4854 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4856 "setVoWiFiRoamingModeSetting");
4857 final long identity = Binder.clearCallingIdentity();
4858 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004859 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004860 // This setting doesn't require an active ImsService connection, so do not verify. The
4861 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004862 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004863 } catch (ImsException e) {
4864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
4868 }
4869
4870 @Override
4871 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4873 "setRttCapabilityEnabled");
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004876 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004877 // This setting doesn't require an active ImsService connection, so do not verify. The
4878 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004879 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004880 } catch (ImsException e) {
4881 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
shilu366312e2019-12-17 09:28:10 -08004887 /**
4888 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4889 * @param subId The subscription to use to check the configuration.
4890 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004891 @Override
4892 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004893 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004894 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004895 final long identity = Binder.clearCallingIdentity();
4896 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004897 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004898 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004899 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004900 } catch (ImsException e) {
4901 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
4905 }
4906
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004907 @Override
4908 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4909 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004910
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004911 final long identity = Binder.clearCallingIdentity();
4912 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004913 if (!isImsAvailableOnDevice()) {
4914 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4915 "IMS not available on device.");
4916 }
4917 int slotId = getSlotIndexOrException(subId);
4918 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004919
4920 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4921 if (controller != null) {
4922 ImsManager imsManager = controller.getImsManager(subId);
4923 if (imsManager != null) {
4924 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4925 } else {
4926 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4927 }
4928 } else {
4929 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4930 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004931 } catch (ImsException e) {
4932 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
4936 }
4937
4938 @Override
4939 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4940 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004941
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004942 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004943 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4944 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4945 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004947 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4948 if (controller != null) {
4949 ImsManager imsManager = controller.getImsManager(subId);
4950 if (imsManager != null) {
4951 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4952 } else {
4953 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4954 + " is inactive, ignoring unregister.");
4955 // If the ImsManager is not valid, just return, since the callback will already
4956 // have been removed internally.
4957 }
4958 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
4962 }
4963
joonhunshincffb7fc2021-11-28 07:32:01 +00004964 @Override
4965 public void registerFeatureProvisioningChangedCallback(int subId,
4966 IFeatureProvisioningCallback callback) {
4967 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4968 mApp, subId, "registerFeatureProvisioningChangedCallback");
4969
4970 final long identity = Binder.clearCallingIdentity();
4971 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4972 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4973 }
4974
joonhunshin91bc1952022-04-29 08:47:15 +00004975 try {
4976 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4977 if (controller == null) {
4978 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4979 "Device does not support IMS");
4980 }
4981 controller.addFeatureProvisioningChangedCallback(subId, callback);
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
4984 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004985 }
4986
4987 @Override
4988 public void unregisterFeatureProvisioningChangedCallback(int subId,
4989 IFeatureProvisioningCallback callback) {
4990 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4991 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4992
4993 final long identity = Binder.clearCallingIdentity();
4994 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4995 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4996 }
4997
joonhunshin91bc1952022-04-29 08:47:15 +00004998 try {
4999 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5000 if (controller == null) {
5001 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5002 return;
5003 }
5004 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
5007 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005008 }
allenwtsu99c623b2020-01-03 18:24:23 +08005009
5010 private void checkModifyPhoneStatePermission(int subId, String message) {
5011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5012 message);
5013 }
5014
allenwtsu99c623b2020-01-03 18:24:23 +08005015 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005016 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005017 boolean isProvisioned) {
5018 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5019
5020 final long identity = Binder.clearCallingIdentity();
5021 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005022 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5023 if (controller == null) {
5024 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5025 return;
5026 }
5027 controller.setRcsProvisioningStatusForCapability(
5028 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005029 } finally {
5030 Binder.restoreCallingIdentity(identity);
5031 }
allenwtsu99c623b2020-01-03 18:24:23 +08005032 }
5033
5034
5035 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005036 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5037 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5038 mApp, subId, "getRcsProvisioningStatusForCapability");
5039
allenwtsu99c623b2020-01-03 18:24:23 +08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005042 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5043 if (controller == null) {
5044 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5045
5046 // device does not support IMS, this method will return true always.
5047 return true;
5048 }
5049 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
5053 }
5054
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005055 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005056 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5057 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005058 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005059
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005060 final long identity = Binder.clearCallingIdentity();
5061 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005062 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5063 if (controller == null) {
5064 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5065 return;
5066 }
5067 controller.setImsProvisioningStatusForCapability(
5068 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
5072 }
5073
5074 @Override
5075 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005076 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5077 mApp, subId, "getProvisioningStatusForCapability");
5078
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005081 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5082 if (controller == null) {
5083 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005084
joonhunshin91bc1952022-04-29 08:47:15 +00005085 // device does not support IMS, this method will return true always.
5086 return true;
5087 }
5088 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
5092 }
5093
5094 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005095 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5096 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5097 mApp, subId, "isProvisioningRequiredForCapability");
5098
5099 final long identity = Binder.clearCallingIdentity();
5100 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005101 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5102 if (controller == null) {
5103 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5104
5105 // device does not support IMS, this method will return false
5106 return false;
5107 }
5108 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005109 } finally {
5110 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005111 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005112 }
5113
5114 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005115 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5116 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5117 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005118
joonhunshincffb7fc2021-11-28 07:32:01 +00005119 final long identity = Binder.clearCallingIdentity();
5120 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005121 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5122 if (controller == null) {
5123 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5124
5125 // device does not support IMS, this method will return false
5126 return false;
5127 }
5128 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005132 }
5133
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005134 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005135 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005136 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5137 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5138 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005139 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5140 mApp, subId, "getImsProvisioningInt");
5141
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005145 int slotId = getSlotIndex(subId);
5146 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5147 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5148 + subId + "' for key:" + key);
5149 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5150 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005151
joonhunshin91bc1952022-04-29 08:47:15 +00005152 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5153 if (controller == null) {
5154 loge("getImsProvisioningInt: Device does not support IMS");
5155
5156 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5157 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5158 }
5159 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005160 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5161 return retVal;
5162 }
5163
calvinpanb5a34062021-02-08 19:59:36 +08005164 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005165 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005166 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5167 + subId + "' for key:" + key);
5168 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005169 } finally {
5170 Binder.restoreCallingIdentity(identity);
5171 }
5172 }
5173
5174 @Override
5175 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5177 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5178 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5180 mApp, subId, "getImsProvisioningString");
5181
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005182 final long identity = Binder.clearCallingIdentity();
5183 try {
5184 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005185 int slotId = getSlotIndex(subId);
5186 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5187 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5188 + subId + "' for key:" + key);
5189 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5190 }
calvinpanb5a34062021-02-08 19:59:36 +08005191 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005192 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005193 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5194 + subId + "' for key:" + key);
5195 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005196 } finally {
5197 Binder.restoreCallingIdentity(identity);
5198 }
5199 }
5200
5201 @Override
5202 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005203 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5204 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5205 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5207 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005208
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005209 final long identity = Binder.clearCallingIdentity();
5210 try {
5211 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005212 int slotId = getSlotIndex(subId);
5213 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5214 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5215 + subId + "' for key:" + key);
5216 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5217 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005218
joonhunshin91bc1952022-04-29 08:47:15 +00005219 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5220 if (controller == null) {
5221 loge("setImsProvisioningInt: Device does not support IMS");
5222
5223 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5224 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5225 }
5226 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005227 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5228 return retVal;
5229 }
5230
calvinpanb5a34062021-02-08 19:59:36 +08005231 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5232 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005233 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005234 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005235 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
5239 }
5240
5241 @Override
5242 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005243 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5244 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5245 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5247 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005251 int slotId = getSlotIndex(subId);
5252 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5253 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5254 + subId + "' for key:" + key);
5255 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5256 }
calvinpanb5a34062021-02-08 19:59:36 +08005257 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5258 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005259 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005260 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005261 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005262 } finally {
5263 Binder.restoreCallingIdentity(identity);
5264 }
5265 }
5266
Brad Ebinger919631e2021-06-02 17:46:35 -07005267 /**
5268 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5269 * for the given slot ID or no ImsResolver instance has been created.
5270 * @param slotId The slot ID that the IMS service is created for.
5271 * @throws ImsException If there is no ImsService configured for this slot.
5272 */
5273 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5274 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5275 ImsFeature.FEATURE_MMTEL)) {
5276 throw new ImsException("This subscription does not support MMTEL over IMS",
5277 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5278 }
5279 }
5280
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005281 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005282 int slotId = SubscriptionManager.getSlotIndex(subId);
5283 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005284 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5285 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005286 }
5287 return slotId;
5288 }
5289
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005290 private int getSlotIndex(int subId) {
5291 int slotId = SubscriptionManager.getSlotIndex(subId);
5292 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5293 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5294 }
5295 return slotId;
5296 }
5297
Wink Saville36469e72014-06-11 15:17:00 -07005298 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005299 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005300 */
5301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005302 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5303 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005304 try {
5305 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5306 } catch (SecurityException se) {
5307 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5308 throw new SecurityException("Package " + callingPackage + " does not belong to "
5309 + Binder.getCallingUid());
5310 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005311 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005312 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005313 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005314 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005315 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005316 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005317 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005318 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5319 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 final Phone phone = getPhone(subId);
5324 if (phone != null) {
5325 return phone.getServiceState().getDataNetworkType();
5326 } else {
5327 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5328 }
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005332 }
5333
5334 /**
5335 * Returns the data network type
5336 */
5337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005338 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005339 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005340 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005341 }
5342
5343 /**
5344 * Returns the data network type for a subId
5345 */
5346 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005347 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5348 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005349 String functionName = "getDataNetworkTypeForSubscriber";
5350 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5351 mApp, functionName)) {
5352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5353 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5354 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5355 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005356 }
5357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
5360 final Phone phone = getPhone(subId);
5361 if (phone != null) {
5362 return phone.getServiceState().getDataNetworkType();
5363 } else {
5364 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5365 }
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005369 }
5370
5371 /**
Wink Saville36469e72014-06-11 15:17:00 -07005372 * Returns the Voice network type for a subId
5373 */
5374 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005375 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5376 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005377 String functionName = "getVoiceNetworkTypeForSubscriber";
5378 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5379 mApp, functionName)) {
5380 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5381 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5382 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5383 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005384 }
5385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 final Phone phone = getPhone(subId);
5389 if (phone != null) {
5390 return phone.getServiceState().getVoiceNetworkType();
5391 } else {
5392 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5393 }
5394 } finally {
5395 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005397 }
5398
5399 /**
5400 * @return true if a ICC card is present
5401 */
5402 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005403 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005404 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005405 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005406 }
5407
5408 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005409 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005410 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005411 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005412 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 final long identity = Binder.clearCallingIdentity();
5414 try {
5415 final Phone phone = PhoneFactory.getPhone(slotIndex);
5416 if (phone != null) {
5417 return phone.getIccCard().hasIccCard();
5418 } else {
5419 return false;
5420 }
5421 } finally {
5422 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005424 }
5425
5426 /**
5427 * Return if the current radio is LTE on CDMA. This
5428 * is a tri-state return value as for a period of time
5429 * the mode may be unknown.
5430 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005431 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005432 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005433 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005434 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005436 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5437 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5438 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005439 }
5440
Sanket Padawe356d7632015-06-22 14:03:32 -07005441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005442 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5443 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005444 try {
5445 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5446 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005447 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5448 }
5449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 final Phone phone = getPhone(subId);
5453 if (phone == null) {
5454 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5455 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005456 return TelephonyProperties.lte_on_cdma_device()
5457 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 }
5459 } finally {
5460 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005461 }
Wink Saville36469e72014-06-11 15:17:00 -07005462 }
5463
Wink Saville36469e72014-06-11 15:17:00 -07005464 /**
5465 * {@hide}
5466 * Returns Default subId, 0 in the case of single standby.
5467 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005468 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005469 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005470 }
5471
Shishir Agrawala9f32182016-04-12 12:00:16 -07005472 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005473 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005474 }
5475
Wink Savilleb564aae2014-10-23 10:18:09 -07005476 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005477 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005478 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005479
Pengquan Menge92a50d2018-09-21 15:54:48 -07005480 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005481 return getSubscriptionManagerService().isActiveSubId(subId,
5482 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005483 }
5484
Ihab Awadf2177b72013-11-25 13:33:23 -08005485 /**
5486 * @see android.telephony.TelephonyManager.WifiCallingChoices
5487 */
5488 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 final long identity = Binder.clearCallingIdentity();
5490 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005491 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5493 getWhenToMakeWifiCallsDefaultPreference());
5494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005497 }
5498
5499 /**
5500 * @see android.telephony.TelephonyManager.WifiCallingChoices
5501 */
5502 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 final long identity = Binder.clearCallingIdentity();
5504 try {
5505 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005506 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5508 } finally {
5509 Binder.restoreCallingIdentity(identity);
5510 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005511 }
5512
Sailesh Nepald1e68152013-12-12 19:08:02 -08005513 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005514 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005515 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005516 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005517
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005518 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5519 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5520 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005521 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005522 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005523 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005524 }
5525 return PhoneFactory.getPhone(phoneId);
5526 }
5527
Shishir Agrawal566b7612013-10-28 14:41:00 -07005528 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005529 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005530 @NonNull IccLogicalChannelRequest request) {
5531 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5532 /*message=*/ "iccOpenLogicalChannel");
5533
5534 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5535 // Verify that the callingPackage in the request belongs to the calling UID
5536 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5537
5538 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005539 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005540
Rambo Wanga1782702021-11-10 20:15:19 -08005541 private Phone getPhoneFromValidIccLogicalChannelRequest(
5542 @NonNull IccLogicalChannelRequest request, String message) {
5543 Phone phone;
5544 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5546 mApp, request.subId, message);
5547 phone = getPhoneFromSubId(request.subId);
5548 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5549 enforceModifyPermission();
5550 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5551 } else {
5552 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005553 }
Rambo Wanga1782702021-11-10 20:15:19 -08005554 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005555 }
5556
5557 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005558 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 final long identity = Binder.clearCallingIdentity();
5560 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005561 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005563 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5564 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005565 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5566 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 loge("The calling package is not allowed to access ISD-R.");
5568 throw new SecurityException(
5569 "The calling package is not allowed to access ISD-R.");
5570 }
Derek Tan740e1672017-06-27 14:56:27 -07005571 }
Derek Tan740e1672017-06-27 14:56:27 -07005572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005574 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5575 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 return response;
5577 } finally {
5578 Binder.restoreCallingIdentity(identity);
5579 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005580 }
5581
5582 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005583 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5584 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5585 /*message=*/"iccCloseLogicalChannel");
5586
5587 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5588
5589 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005590 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005591
Rambo Wanga1782702021-11-10 20:15:19 -08005592 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5593 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005594 // before this feature is enabled, this API should only return false if
5595 // the operation fails instead of throwing runtime exception for
5596 // backward-compatibility.
5597 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5598 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 final long identity = Binder.clearCallingIdentity();
5600 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005601 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005602 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 }
Chen Xue9d737e2022-01-01 23:41:31 -08005604 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005605 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005606 Boolean success = false;
5607 if (result instanceof RuntimeException) {
5608 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005609 if (shouldThrowExceptionOnFailure) {
5610 throw (RuntimeException) result;
5611 } else {
5612 return false;
5613 }
Chen Xue9d737e2022-01-01 23:41:31 -08005614 } else if (result instanceof Boolean) {
5615 success = (Boolean) result;
5616 } else {
5617 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5618 }
Rambo Wanga1782702021-11-10 20:15:19 -08005619 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 return success;
5621 } finally {
5622 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005623 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005624 }
5625
5626 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005627 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005628 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5630 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005631 if (DBG) {
5632 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5633 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5634 + p3 + " data=" + data);
5635 }
5636 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5637 command, p1, p2, p3, data);
5638 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005639
Jordan Liu4c733742019-02-28 12:03:40 -08005640 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005641 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005642 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005643 enforceModifyPermission();
5644 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005645 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005646 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5647 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005648 }
5649 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005650 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5651 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005652 }
5653
5654 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5655 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 final long identity = Binder.clearCallingIdentity();
5657 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005658 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 return "";
5660 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005663 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5664 null /* workSource */);
5665 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 // Append the returned status code to the end of the response payload.
5668 String s = Integer.toHexString(
5669 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5670 if (response.payload != null) {
5671 s = IccUtils.bytesToHexString(response.payload) + s;
5672 }
5673 return s;
5674 } finally {
5675 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005677 }
Jake Hambye994d462014-02-03 13:10:13 -08005678
Evan Charltonc66da362014-05-16 14:06:40 -07005679 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005680 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5681 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5683 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005685 if (DBG) {
5686 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5687 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5688 }
5689 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5690 cla, command, p1, p2, p3, data);
5691 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005692
Jordan Liu4c733742019-02-28 12:03:40 -08005693 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005694 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005695 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005696 enforceModifyPermission();
5697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5698 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005699 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005700 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5701 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005702 }
5703
5704 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005705 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5706 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005707 }
5708
5709 // open APDU basic channel assuming the caller has sufficient permissions
5710 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5711 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5715 && TextUtils.equals(ISDR_AID, data)) {
5716 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005717 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5718 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 if (bestComponent == null
5720 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5721 loge("The calling package is not allowed to select ISD-R.");
5722 throw new SecurityException(
5723 "The calling package is not allowed to select ISD-R.");
5724 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005725 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005728 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5729 null /* workSource */);
5730 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 // Append the returned status code to the end of the response payload.
5733 String s = Integer.toHexString(
5734 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5735 if (response.payload != null) {
5736 s = IccUtils.bytesToHexString(response.payload) + s;
5737 }
5738 return s;
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005741 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005742 }
5743
5744 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005745 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005746 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5748 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 final long identity = Binder.clearCallingIdentity();
5751 try {
5752 if (DBG) {
5753 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5754 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5755 }
5756
5757 IccIoResult response =
5758 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5759 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5760 subId);
5761
5762 if (DBG) {
5763 log("Exchange SIM_IO [R]" + response);
5764 }
5765
5766 byte[] result = null;
5767 int length = 2;
5768 if (response.payload != null) {
5769 length = 2 + response.payload.length;
5770 result = new byte[length];
5771 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5772 } else {
5773 result = new byte[length];
5774 }
5775
5776 result[length - 1] = (byte) response.sw2;
5777 result[length - 2] = (byte) response.sw1;
5778 return result;
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005781 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005782 }
5783
Nathan Haroldb3014052017-01-25 15:57:32 -08005784 /**
5785 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5786 * on a particular subscription
5787 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005788 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5789 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005791 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005792 return null;
5793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 if (appType != TelephonyManager.APPTYPE_USIM
5798 && appType != TelephonyManager.APPTYPE_SIM) {
5799 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5800 return null;
5801 }
5802 Object response = sendRequest(
5803 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5804 if (response instanceof String[]) {
5805 return (String[]) response;
5806 }
yincheng zhao2737e882019-09-06 17:06:54 -07005807 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005809 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 } finally {
5811 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005812 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005813 }
5814
yincheng zhao2737e882019-09-06 17:06:54 -07005815 /**
5816 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5817 * subscription.
5818 *
5819 * @param subId the id of the subscription.
5820 * @param appType the uicc app type, must be USIM or SIM.
5821 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5822 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005823 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005824 * @return number of fplmns that is successfully written to the SIM.
5825 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005826 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5827 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5829 mApp, subId, "setForbiddenPlmns");
5830
yincheng zhao2737e882019-09-06 17:06:54 -07005831 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5832 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5833 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5834 }
5835 if (fplmns == null) {
5836 throw new IllegalArgumentException("Fplmn List provided is null");
5837 }
5838 for (String fplmn : fplmns) {
5839 if (!CellIdentity.isValidPlmn(fplmn)) {
5840 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5841 }
5842 }
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 Object response = sendRequest(
5846 CMD_SET_FORBIDDEN_PLMNS,
5847 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5848 subId);
5849 return (int) response;
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
5853 }
5854
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005855 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005856 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5858 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5863 if (response.payload == null) {
5864 return "";
5865 }
Evan Charltonc66da362014-05-16 14:06:40 -07005866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005867 // Append the returned status code to the end of the response payload.
5868 String s = Integer.toHexString(
5869 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5870 s = IccUtils.bytesToHexString(response.payload) + s;
5871 return s;
5872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
Evan Charltonc66da362014-05-16 14:06:40 -07005875 }
5876
Jake Hambye994d462014-02-03 13:10:13 -08005877 /**
5878 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5879 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5880 *
5881 * @param itemID the ID of the item to read
5882 * @return the NV item as a String, or null on error.
5883 */
5884 @Override
5885 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5888 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889
5890 final long identity = Binder.clearCallingIdentity();
5891 try {
5892 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005893 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5895 return value;
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Jake Hambye994d462014-02-03 13:10:13 -08005899 }
5900
5901 /**
5902 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5903 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5904 *
5905 * @param itemID the ID of the item to read
5906 * @param itemValue the value to write, as a String
5907 * @return true on success; false on any failure
5908 */
5909 @Override
5910 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005911 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5913 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914
5915 final long identity = Binder.clearCallingIdentity();
5916 try {
5917 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5918 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005919 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5921 return success;
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
Jake Hambye994d462014-02-03 13:10:13 -08005925 }
5926
5927 /**
5928 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5929 * Used for device configuration by some CDMA operators.
5930 *
5931 * @param preferredRoamingList byte array containing the new PRL
5932 * @return true on success; false on any failure
5933 */
5934 @Override
5935 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5937 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938
5939 final long identity = Binder.clearCallingIdentity();
5940 try {
5941 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5942 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5943 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5944 return success;
5945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
Jake Hambye994d462014-02-03 13:10:13 -08005948 }
5949
5950 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005951 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005952 * Used for device configuration by some CDMA operators.
5953 *
chen xu6dac5ab2018-10-26 17:39:23 -07005954 * @param slotIndex - device slot.
5955 *
Jake Hambye994d462014-02-03 13:10:13 -08005956 * @return true on success; false on any failure
5957 */
5958 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005959 public boolean resetModemConfig(int slotIndex) {
5960 Phone phone = PhoneFactory.getPhone(slotIndex);
5961 if (phone != null) {
5962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5963 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964
chen xu6dac5ab2018-10-26 17:39:23 -07005965 final long identity = Binder.clearCallingIdentity();
5966 try {
5967 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5968 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5969 return success;
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 }
chen xu6dac5ab2018-10-26 17:39:23 -07005974 return false;
5975 }
5976
5977 /**
5978 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5979 *
5980 * @param slotIndex - device slot.
5981 *
5982 * @return true on success; false on any failure
5983 */
5984 @Override
5985 public boolean rebootModem(int slotIndex) {
5986 Phone phone = PhoneFactory.getPhone(slotIndex);
5987 if (phone != null) {
5988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5989 mApp, phone.getSubId(), "rebootModem");
5990
5991 final long identity = Binder.clearCallingIdentity();
5992 try {
5993 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5994 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5995 return success;
5996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
5999 }
6000 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006001 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006002
Brad Ebinger51f743a2017-01-23 13:50:20 -08006003 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006004 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6005 * {@link #disableIms(int)}.
6006 * @param slotIndex device slot.
6007 */
6008 public void resetIms(int slotIndex) {
6009 enforceModifyPermission();
6010
6011 final long identity = Binder.clearCallingIdentity();
6012 try {
6013 if (mImsResolver == null) {
6014 // may happen if the does not support IMS.
6015 return;
6016 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006017 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
6021 }
6022
6023 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006024 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6025 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006026 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006027 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006028 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029
6030 final long identity = Binder.clearCallingIdentity();
6031 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006032 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006033 // may happen if the device does not support IMS.
6034 return;
6035 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006036 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006040 }
6041
6042 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006043 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6044 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006045 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006046 public void disableIms(int slotId) {
6047 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048
6049 final long identity = Binder.clearCallingIdentity();
6050 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006052 // may happen if the device does not support IMS.
6053 return;
6054 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006055 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006059 }
6060
6061 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006062 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6063 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006064 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006065 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006066 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006067 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
6069 final long identity = Binder.clearCallingIdentity();
6070 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006071 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6073 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006074 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006075 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 } finally {
6077 Binder.restoreCallingIdentity(identity);
6078 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006079 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006080 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006081 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6082 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006083 @Override
6084 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006085 enforceModifyPermission();
6086
6087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006090 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
6094 }
6095
6096 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006097 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006098 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006099 */
6100 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6101 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102
6103 final long identity = Binder.clearCallingIdentity();
6104 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006105 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006106 // may happen if the device does not support IMS.
6107 return null;
6108 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006109 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006113 }
6114
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006115 /**
6116 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006117 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006118 */
6119 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121
6122 final long identity = Binder.clearCallingIdentity();
6123 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006124 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006125 // may happen if the device does not support IMS.
6126 return null;
6127 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006128 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006132 }
6133
Brad Ebinger884c07b2018-02-15 16:17:40 -08006134 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006135 * Sets the ImsService Package Name that Telephony will bind to.
6136 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006137 * @param slotIndex the slot ID that the ImsService should bind for.
6138 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006139 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006140 * @param featureTypes An integer array of feature types associated with a packageName.
6141 * @param packageName The name of the package that the current configuration will be replaced
6142 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006143 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006144 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006145 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6146 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006149 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 final long identity = Binder.clearCallingIdentity();
6152 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006153 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006154 // may happen if the device does not support IMS.
6155 return false;
6156 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006157 Map<Integer, String> featureConfig = new HashMap<>();
6158 for (int featureType : featureTypes) {
6159 featureConfig.put(featureType, packageName);
6160 }
6161 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6162 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006166 }
6167
6168 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006169 * Clears any carrier ImsService overrides for the slot index specified that were previously
6170 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6171 *
6172 * This should only be used for testing.
6173 *
6174 * @param slotIndex the slot ID that the ImsService should bind for.
6175 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6176 */
6177 @Override
6178 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6180 "clearCarrierImsServiceOverride");
6181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006182 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006183
6184 final long identity = Binder.clearCallingIdentity();
6185 try {
6186 if (mImsResolver == null) {
6187 // may happen if the device does not support IMS.
6188 return false;
6189 }
6190 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
6194 }
6195
6196 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006197 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006198 *
6199 * @param slotId The slot that the ImsService is associated with.
6200 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6201 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006202 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006203 * @return the package name of the ImsService configuration.
6204 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006205 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6206 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006207 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006208 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6209 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 final long identity = Binder.clearCallingIdentity();
6212 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006213 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006214 // may happen if the device does not support IMS.
6215 return "";
6216 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006217 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006218 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6219 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 } finally {
6221 Binder.restoreCallingIdentity(identity);
6222 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006223 }
6224
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006225 /**
6226 * Get the MmTelFeature state associated with the requested subscription id.
6227 * @param subId The subscription that the MmTelFeature is associated with.
6228 * @param callback A callback with an integer containing the
6229 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6230 */
6231 @Override
6232 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6233 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006234 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6235 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6236 "IMS not available on device.");
6237 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006238 final long token = Binder.clearCallingIdentity();
6239 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006240 int slotId = getSlotIndex(subId);
6241 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6242 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6243 + subId + "'");
6244 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6245 }
6246 verifyImsMmTelConfiguredOrThrow(slotId);
6247 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6248 try {
6249 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6250 } catch (RemoteException e) {
6251 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6252 + "Ignore");
6253 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006254 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006255 } catch (ImsException e) {
6256 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006257 } finally {
6258 Binder.restoreCallingIdentity(token);
6259 }
6260 }
6261
Daniel Brightbb5840b2021-01-12 15:48:18 -08006262 /**
6263 * Sets the ims registration state on all valid {@link Phone}s.
6264 */
6265 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006266 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267
6268 final long identity = Binder.clearCallingIdentity();
6269 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006270 // NOTE: Before S, this method only set the default phone.
6271 for (final Phone phone : PhoneFactory.getPhones()) {
6272 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6273 phone.setImsRegistrationState(registered);
6274 }
6275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 } finally {
6277 Binder.restoreCallingIdentity(identity);
6278 }
Wink Saville36469e72014-06-11 15:17:00 -07006279 }
6280
6281 /**
Stuart Scott54788802015-03-30 13:18:01 -07006282 * Set the network selection mode to automatic.
6283 *
6284 */
6285 @Override
6286 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6288 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289
6290 final long identity = Binder.clearCallingIdentity();
6291 try {
shilufc958392020-01-20 11:36:01 -08006292 if (!isActiveSubscription(subId)) {
6293 return;
6294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006296 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6297 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 } finally {
6299 Binder.restoreCallingIdentity(identity);
6300 }
Stuart Scott54788802015-03-30 13:18:01 -07006301 }
6302
Jack Yud10cdd42020-09-28 20:28:01 -07006303 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006304 * Ask the radio to connect to the input network and change selection mode to manual.
6305 *
6306 * @param subId the id of the subscription.
6307 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6308 * the operator to attach to.
6309 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6310 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6311 * normal network selection next time.
6312 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006313 */
6314 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006315 public boolean setNetworkSelectionModeManual(
6316 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6318 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006319
Jack Yu285100e2022-12-02 22:48:35 -08006320 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006321 if (!isActiveSubscription(subId)) {
6322 return false;
6323 }
6324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006326 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006328 if (DBG) {
6329 log("setNetworkSelectionModeManual: subId: " + subId
6330 + " operator: " + operatorInfo);
6331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006336 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006337 /**
shilu84f6e8b2019-12-19 13:58:01 -08006338 * Get the manual network selection
6339 *
6340 * @param subId the id of the subscription.
6341 *
6342 * @return the previously saved user selected PLMN
6343 */
6344 @Override
6345 public String getManualNetworkSelectionPlmn(int subId) {
6346 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006347 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6348 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006349
6350 final long identity = Binder.clearCallingIdentity();
6351 try {
6352 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006353 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006354 }
6355
6356 final Phone phone = getPhone(subId);
6357 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006358 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006359 }
6360 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6361 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006362 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006363 } finally {
6364 Binder.restoreCallingIdentity(identity);
6365 }
6366 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006367
6368 /**
6369 * Scans for available networks.
6370 */
6371 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006372 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6373 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6375 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006376 LocationAccessPolicy.LocationPermissionResult locationResult =
6377 LocationAccessPolicy.checkLocationPermission(mApp,
6378 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6379 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006380 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006381 .setCallingPid(Binder.getCallingPid())
6382 .setCallingUid(Binder.getCallingUid())
6383 .setMethod("getCellNetworkScanResults")
6384 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006385 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6386 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006387 .build());
6388 switch (locationResult) {
6389 case DENIED_HARD:
6390 throw new SecurityException("Not allowed to access scan results -- location");
6391 case DENIED_SOFT:
6392 return null;
6393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394
Pengquan Menga1bb6272018-09-06 09:59:22 -07006395 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396 try {
6397 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006398 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 } finally {
6401 Binder.restoreCallingIdentity(identity);
6402 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006403 }
6404
6405 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006406 * Get the call forwarding info, given the call forwarding reason.
6407 */
6408 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006409 public void getCallForwarding(int subId, int callForwardingReason,
6410 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006411 enforceReadPrivilegedPermission("getCallForwarding");
6412 long identity = Binder.clearCallingIdentity();
6413 try {
6414 if (DBG) {
6415 log("getCallForwarding: subId " + subId
6416 + " callForwardingReason" + callForwardingReason);
6417 }
Hall Liu27d24262020-09-18 19:04:59 -07006418
6419 Phone phone = getPhone(subId);
6420 if (phone == null) {
6421 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006422 callback.onError(
6423 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006424 } catch (RemoteException e) {
6425 // ignore
6426 }
6427 return;
6428 }
6429
6430 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6431 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6432 @Override
6433 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6434 try {
6435 callback.onCallForwardingInfoAvailable(info);
6436 } catch (RemoteException e) {
6437 // ignore
6438 }
6439 }
6440
6441 @Override
6442 public void onError(int error) {
6443 try {
6444 callback.onError(error);
6445 } catch (RemoteException e) {
6446 // ignore
6447 }
6448 }
6449 });
6450 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
6454 }
6455
6456 /**
6457 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6458 * reason, the number to forward, and the timeout before the forwarding is attempted.
6459 */
6460 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006461 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6462 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006463 enforceModifyPermission();
6464 long identity = Binder.clearCallingIdentity();
6465 try {
6466 if (DBG) {
6467 log("setCallForwarding: subId " + subId
6468 + " callForwardingInfo" + callForwardingInfo);
6469 }
Hall Liu27d24262020-09-18 19:04:59 -07006470
6471 Phone phone = getPhone(subId);
6472 if (phone == null) {
6473 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006474 callback.accept(
6475 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006476 } catch (RemoteException e) {
6477 // ignore
6478 }
6479 return;
6480 }
6481
6482 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6483 FunctionalUtils.ignoreRemoteException(callback::accept));
6484
6485 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
6491 /**
Hall Liu27d24262020-09-18 19:04:59 -07006492 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006493 */
6494 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006495 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006496 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006497 long identity = Binder.clearCallingIdentity();
6498 try {
Hall Liu27d24262020-09-18 19:04:59 -07006499 Phone phone = getPhone(subId);
6500 if (phone == null) {
6501 try {
6502 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6503 } catch (RemoteException e) {
6504 // ignore
6505 }
6506 return;
6507 }
SongFerngWang0e767992021-03-31 22:08:45 +08006508 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6509 PersistableBundle c = configManager.getConfigForSubId(subId);
6510 boolean requireUssd = c.getBoolean(
6511 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006512
Shuo Qian4a594052020-01-23 11:59:30 -08006513 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006514 if (requireUssd) {
6515 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6516 getSubscriptionCarrierId(subId));
6517 String newUssdCommand = "";
6518 try {
6519 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006520 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006521 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6522 } catch (NullPointerException e) {
6523 loge("Failed to generate USSD number" + e);
6524 }
6525 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6526 mMainThreadHandler, callback, carrierXmlParser,
6527 CarrierXmlParser.SsEntry.SSAction.QUERY);
6528 final String ussdCommand = newUssdCommand;
6529 Executors.newSingleThreadExecutor().execute(() -> {
6530 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6531 });
6532 } else {
6533 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6534 callback::accept);
6535 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6536 }
Shuo Qian4a594052020-01-23 11:59:30 -08006537 } finally {
6538 Binder.restoreCallingIdentity(identity);
6539 }
6540 }
6541
6542 /**
Hall Liu27d24262020-09-18 19:04:59 -07006543 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006544 */
6545 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006546 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006547 enforceModifyPermission();
6548 long identity = Binder.clearCallingIdentity();
6549 try {
Hall Liu27d24262020-09-18 19:04:59 -07006550 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6551
6552 Phone phone = getPhone(subId);
6553 if (phone == null) {
6554 try {
6555 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6556 } catch (RemoteException e) {
6557 // ignore
6558 }
6559 return;
6560 }
6561
SongFerngWang0e767992021-03-31 22:08:45 +08006562 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6563 PersistableBundle c = configManager.getConfigForSubId(subId);
6564 boolean requireUssd = c.getBoolean(
6565 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006566
SongFerngWang0e767992021-03-31 22:08:45 +08006567 if (DBG) log("getCallWaitingStatus: subId " + subId);
6568 if (requireUssd) {
6569 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6570 getSubscriptionCarrierId(subId));
6571 CarrierXmlParser.SsEntry.SSAction ssAction =
6572 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6573 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6574 String newUssdCommand = "";
6575 try {
6576 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006577 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006578 .makeCommand(ssAction, null);
6579 } catch (NullPointerException e) {
6580 loge("Failed to generate USSD number" + e);
6581 }
6582 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6583 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6584 final String ussdCommand = newUssdCommand;
6585 Executors.newSingleThreadExecutor().execute(() -> {
6586 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6587 });
6588 } else {
6589 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6590 FunctionalUtils.ignoreRemoteException(callback::accept));
6591
6592 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6593 }
Shuo Qian4a594052020-01-23 11:59:30 -08006594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
6597 }
6598
6599 /**
yinxub1bed742017-04-17 11:45:04 -07006600 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006601 *
yinxub1bed742017-04-17 11:45:04 -07006602 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006603 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6604 * location related information which will be sent if the caller already possess
6605 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006606 * @param request contains the radio access networks with bands/channels to scan
6607 * @param messenger callback messenger for scan results or errors
6608 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006609 * @return the id of the requested scan which can be used to stop the scan.
6610 */
6611 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006612 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6613 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006614 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6616 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006617 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006618 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6619 if (!renounceFineLocationAccess) {
6620 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006621 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6622 .setCallingPackage(callingPackage)
6623 .setCallingFeatureId(callingFeatureId)
6624 .setCallingPid(Binder.getCallingPid())
6625 .setCallingUid(Binder.getCallingUid())
6626 .setMethod("requestNetworkScan")
6627 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6628 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6629 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6630 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006631 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006632 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006633 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6634 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006635 if (e != null) {
6636 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6637 throw e;
6638 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006639 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006640 return TelephonyScanManager.INVALID_SCAN_ID;
6641 }
6642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 }
Hall Liu912dfd32019-04-25 14:02:26 -07006644 int callingUid = Binder.getCallingUid();
6645 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006649 renounceFineLocationAccess, request, messenger, binder,
6650 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006651 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006652 } finally {
6653 Binder.restoreCallingIdentity(identity);
6654 }
yinxu504e1392017-04-12 16:03:22 -07006655 }
6656
Hall Liub2ac8ef2019-02-28 15:56:23 -08006657 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006658 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006659 boolean hasCarrierPriv;
6660 final long identity = Binder.clearCallingIdentity();
6661 try {
6662 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6663 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6664 } finally {
6665 Binder.restoreCallingIdentity(identity);
6666 }
Hall Liu558027f2019-05-15 19:14:05 -07006667 boolean hasNetworkScanPermission =
6668 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006669 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006670
6671 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6672 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6673 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006674 }
6675
6676 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6677 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006678 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6679 return new SecurityException("Specific channels must not be"
6680 + " scanned without location access.");
6681 }
6682 }
6683 }
6684
Hall Liub2ac8ef2019-02-28 15:56:23 -08006685 return null;
6686 }
6687
yinxu504e1392017-04-12 16:03:22 -07006688 /**
6689 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006690 *
6691 * @param subId id of the subscription
6692 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006693 */
6694 @Override
6695 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6697 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698
Hall Liu912dfd32019-04-25 14:02:26 -07006699 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
6701 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006702 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 } finally {
6704 Binder.restoreCallingIdentity(identity);
6705 }
yinxu504e1392017-04-12 16:03:22 -07006706 }
6707
6708 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006709 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006710 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006711 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006712 */
6713 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006714 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006715 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006716 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006717 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718
6719 final long identity = Binder.clearCallingIdentity();
6720 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006721 if (DBG) log("getAllowedNetworkTypesBitmask");
6722 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6723 int networkTypesBitmask = (result != null ? result[0] : -1);
6724 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6725 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 } finally {
6727 Binder.restoreCallingIdentity(identity);
6728 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006729 }
6730
6731 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006732 * Get the allowed network types for certain reason.
6733 *
6734 * @param subId the id of the subscription.
6735 * @param reason the reason the allowed network type change is taking place
6736 * @return the allowed network types.
6737 */
6738 @Override
6739 public long getAllowedNetworkTypesForReason(int subId,
6740 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006741 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006742 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006743 final long identity = Binder.clearCallingIdentity();
6744 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006745 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
6749 }
6750
6751 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006752 * Enable/Disable E-UTRA-NR Dual Connectivity
6753 * @param subId subscription id of the sim card
6754 * @param nrDualConnectivityState expected NR dual connectivity state
6755 * This can be passed following states
6756 * <ol>
6757 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6758 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6759 * <li>Disable NR dual connectivity and force secondary cell to be released
6760 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6761 * </ol>
6762 * @return operation result.
6763 */
6764 @Override
6765 public int setNrDualConnectivityState(int subId,
6766 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6768 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006769 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006770 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6771 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6772 }
6773
Sooraj Sasindran37444802020-08-11 10:40:43 -07006774 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6775 final long identity = Binder.clearCallingIdentity();
6776 try {
6777 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6778 nrDualConnectivityState, subId,
6779 workSource);
6780 if (DBG) log("enableNRDualConnectivity result: " + result);
6781 return result;
6782 } finally {
6783 Binder.restoreCallingIdentity(identity);
6784 }
6785 }
6786
6787 /**
6788 * Is E-UTRA-NR Dual Connectivity enabled
6789 * @return true if dual connectivity is enabled else false
6790 */
6791 @Override
6792 public boolean isNrDualConnectivityEnabled(int subId) {
6793 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006794 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006795 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006796 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006797 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6798 return false;
6799 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006800 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6804 null, subId, workSource);
6805 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6806 return isEnabled;
6807 } finally {
6808 Binder.restoreCallingIdentity(identity);
6809 }
6810 }
6811
6812 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006813 * Set the allowed network types of the device and
6814 * provide the reason triggering the allowed network change.
6815 *
6816 * @param subId the id of the subscription.
6817 * @param reason the reason the allowed network type change is taking place
6818 * @param allowedNetworkTypes the allowed network types.
6819 * @return true on success; false on any failure.
6820 */
6821 @Override
6822 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006823 @TelephonyManager.AllowedNetworkTypesReason int reason,
6824 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6826 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006827 // If the caller only has carrier privileges, then they should not be able to override
6828 // any network types which were set for security reasons.
6829 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6830 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006831 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006832 throw new SecurityException(
6833 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006834 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006835 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006836 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006837 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006838 return false;
6839 }
6840 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6841 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006842 return false;
6843 }
6844
Jack Yu5b494332023-01-23 18:18:04 +00006845 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6846 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006847
Jack Yue37dd262022-12-16 11:53:37 -08006848 Phone phone = getPhone(subId);
6849 if (phone == null) {
6850 return false;
6851 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006852
Jack Yue37dd262022-12-16 11:53:37 -08006853 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006854 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006855 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006856 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006857
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006858 final long identity = Binder.clearCallingIdentity();
6859 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006860 Boolean success = (Boolean) sendRequest(
6861 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6862 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6863
6864 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6865 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
6869 }
6870
6871 /**
Miaoa84611c2019-03-15 09:21:10 +08006872 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006873 *
Miaoa84611c2019-03-15 09:21:10 +08006874 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006875 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006876 * @hide
6877 */
6878 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006879 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006882 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 try {
Miaoa84611c2019-03-15 09:21:10 +08006884 if (phone != null) {
6885 return phone.hasMatchedTetherApnSetting();
6886 } else {
6887 return false;
6888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 } finally {
6890 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006891 }
Junda Liu475951f2014-11-07 16:45:03 -08006892 }
6893
6894 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006895 * Get the user enabled state of Mobile Data.
6896 *
6897 * TODO: remove and use isUserDataEnabled.
6898 * This can't be removed now because some vendor codes
6899 * calls through ITelephony directly while they should
6900 * use TelephonyManager.
6901 *
6902 * @return true on enabled
6903 */
6904 @Override
6905 public boolean getDataEnabled(int subId) {
6906 return isUserDataEnabled(subId);
6907 }
6908
6909 /**
6910 * Get whether mobile data is enabled per user setting.
6911 *
6912 * There are other factors deciding whether mobile data is actually enabled, but they are
6913 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006914 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006915 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6916 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006917 *
6918 * @return {@code true} if data is enabled else {@code false}
6919 */
6920 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006921 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006922 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006923 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006924 try {
6925 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6926 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006927 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006928 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6929 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006930 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006932 mApp, subId, functionName);
6933
Robert Greenwalt646120a2014-05-23 11:54:03 -07006934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935
6936 final long identity = Binder.clearCallingIdentity();
6937 try {
Jack Yu285100e2022-12-02 22:48:35 -08006938 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6940 Phone phone = PhoneFactory.getPhone(phoneId);
6941 if (phone != null) {
6942 boolean retVal = phone.isUserDataEnabled();
6943 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6944 return retVal;
6945 } else {
6946 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6947 return false;
6948 }
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006951 }
6952 }
6953
6954 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006955 * Checks if the device is capable of mobile data by considering whether whether the
6956 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6957 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006958 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006959 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006960 */
6961 @Override
6962 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006963 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006964 try {
6965 try {
6966 mApp.enforceCallingOrSelfPermission(
6967 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006968 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006969 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006970 try {
6971 mApp.enforceCallingOrSelfPermission(
6972 android.Manifest.permission.READ_PHONE_STATE,
6973 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006974 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006975 mApp.enforceCallingOrSelfPermission(
6976 permission.READ_BASIC_PHONE_STATE, functionName);
6977 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006978 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006979 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006980 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982
6983 final long identity = Binder.clearCallingIdentity();
6984 try {
Jack Yu285100e2022-12-02 22:48:35 -08006985 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 Phone phone = PhoneFactory.getPhone(phoneId);
6987 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006988 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006989 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990 return retVal;
6991 } else {
6992 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6993 return false;
6994 }
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006997 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006998 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006999
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007000 /**
7001 * Check if data is enabled for a specific reason
7002 * @param subId Subscription index
7003 * @param reason the reason the data enable change is taking place
7004 * @return {@code true} if the overall data is enabled; {@code false} if not.
7005 */
7006 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007007 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007008 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007009 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007010 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007011 try {
7012 mApp.enforceCallingOrSelfPermission(
7013 android.Manifest.permission.ACCESS_NETWORK_STATE,
7014 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007015 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007016 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7017 functionName);
7018 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007019 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007020 try {
7021 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007022 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007023 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007025 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007026 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007027 }
7028
7029
7030 final long identity = Binder.clearCallingIdentity();
7031 try {
Jack Yu285100e2022-12-02 22:48:35 -08007032 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007033 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007034 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007035 + " reason=" + reason);
7036 }
7037 Phone phone = PhoneFactory.getPhone(phoneId);
7038 if (phone != null) {
7039 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007040 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007041 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007042 return retVal;
7043 } else {
7044 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007045 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007046 + subId + " retVal=false");
7047 }
7048 return false;
7049 }
7050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
7053 }
7054
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007055 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007056 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007057 // No permission needed; this only lets the caller inspect their own status.
7058 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007059 }
Junda Liu29340342014-07-10 15:23:27 -07007060
7061 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007062 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007063 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007064 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7065 }
7066
7067 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7068 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007070 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007071 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7072 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007073 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7074 if (cpt == null) {
7075 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007076 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7077 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007078 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007079 }
7080
7081 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007082 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007083 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007084 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007085 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007086 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007087 Phone phone = getPhone(subId);
7088 if (phone == null) {
7089 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7090 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7091 }
7092 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7093 if (cpt == null) {
7094 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007095 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7096 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007097 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007098 }
7099
7100 @Override
7101 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007102 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007103 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7104 }
7105
7106 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007107 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007108 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007109 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007110 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007111 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7112 Phone phone = PhoneFactory.getPhone(phoneId);
7113 if (phone == null) {
7114 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007115 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007116 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7117 if (cpt == null) {
7118 continue;
7119 }
7120 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007121 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7122 break;
7123 }
7124 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007125 return result;
Junda Liu29340342014-07-10 15:23:27 -07007126 }
Derek Tan89e89d42014-07-08 17:00:10 -07007127
7128 @Override
Junda Liue64de782015-04-16 17:19:16 -07007129 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007130 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007131 Phone phone = PhoneFactory.getPhone(phoneId);
7132 if (phone == null) {
7133 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007134 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007135 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7136 if (cpt == null) {
7137 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007138 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007139 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007140 }
7141
Amith Yamasani6e118872016-02-19 12:53:51 -08007142 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007143 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007144 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007145 Phone phone = PhoneFactory.getPhone(phoneId);
7146 if (phone == null) {
7147 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007148 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007149 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7150 if (cpt == null) {
7151 return Collections.emptyList();
7152 }
7153 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007154 }
7155
chen xuf7e9fe82019-05-09 19:31:02 -07007156 @Override
7157 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007158 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007159 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007160 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007161 try {
7162 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7163 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7164 }
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007167 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007168 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007169 }
7170
Rambo Wang6812ffb2022-03-15 16:54:17 -07007171 @Override
7172 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7173 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7174
7175 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7176 if (phone == null) {
7177 return null;
7178 }
7179 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7180 if (cpt == null) {
7181 return null;
7182 }
7183 return cpt.getCarrierServicePackageName();
7184 }
7185
Wink Savilleb564aae2014-10-23 10:18:09 -07007186 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007187 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007188 UiccPort port = phone == null ? null : phone.getUiccPort();
7189 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007190 return null;
7191 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007192 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007193 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007194 return null;
7195 }
7196 return iccId;
7197 }
7198
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007199 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007200 public void setCallComposerStatus(int subId, int status) {
7201 enforceModifyPermission();
7202
7203 final long identity = Binder.clearCallingIdentity();
7204 try {
7205 Phone phone = getPhone(subId);
7206 if (phone != null) {
7207 Phone defaultPhone = phone.getImsPhone();
7208 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7209 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7210 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007211 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7212 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007213 }
7214 }
Shuo Qian284ae752020-12-22 19:10:14 -08007215 } catch (ImsException e) {
7216 throw new ServiceSpecificException(e.getCode());
7217 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007218 Binder.restoreCallingIdentity(identity);
7219 }
7220 }
7221
7222 @Override
7223 public int getCallComposerStatus(int subId) {
7224 enforceReadPrivilegedPermission("getCallComposerStatus");
7225
7226 final long identity = Binder.clearCallingIdentity();
7227 try {
7228 Phone phone = getPhone(subId);
7229 if (phone != null) {
7230 Phone defaultPhone = phone.getImsPhone();
7231 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7232 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7233 return imsPhone.getCallComposerStatus();
7234 }
7235 }
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
7239 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7240 }
7241
7242 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007243 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7244 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007245 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007246 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 final String iccId = getIccId(subId);
7251 final Phone phone = getPhone(subId);
7252 if (phone == null) {
7253 return false;
7254 }
7255 final String subscriberId = phone.getSubscriberId();
7256
7257 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007258 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 + subscriberId + " to " + number);
7260 }
7261
7262 if (TextUtils.isEmpty(iccId)) {
7263 return false;
7264 }
7265
7266 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7267
7268 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7269 if (alphaTag == null) {
7270 editor.remove(alphaTagPrefKey);
7271 } else {
7272 editor.putString(alphaTagPrefKey, alphaTag);
7273 }
7274
7275 // Record both the line number and IMSI for this ICCID, since we need to
7276 // track all merged IMSIs based on line number
7277 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7278 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7279 if (number == null) {
7280 editor.remove(numberPrefKey);
7281 editor.remove(subscriberPrefKey);
7282 } else {
7283 editor.putString(numberPrefKey, number);
7284 editor.putString(subscriberPrefKey, subscriberId);
7285 }
7286
7287 editor.commit();
7288 return true;
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007291 }
Derek Tan7226c842014-07-02 17:42:23 -07007292 }
7293
7294 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007295 public String getLine1NumberForDisplay(int subId, String callingPackage,
7296 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007297 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007299 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007300 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007301 return null;
7302 }
Derek Tan97ebb422014-09-05 16:55:38 -07007303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304 final long identity = Binder.clearCallingIdentity();
7305 try {
7306 String iccId = getIccId(subId);
7307 if (iccId != null) {
7308 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7309 if (DBG_MERGE) {
7310 log("getLine1NumberForDisplay returning "
7311 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7312 }
7313 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7316 return null;
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007319 }
Derek Tan7226c842014-07-02 17:42:23 -07007320 }
7321
7322 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007323 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7324 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007326 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007327 return null;
7328 }
Derek Tan97ebb422014-09-05 16:55:38 -07007329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 final long identity = Binder.clearCallingIdentity();
7331 try {
7332 String iccId = getIccId(subId);
7333 if (iccId != null) {
7334 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7335 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7336 }
7337 return null;
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007340 }
Derek Tan7226c842014-07-02 17:42:23 -07007341 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007342
7343 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007344 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7345 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007346 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7347 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007349 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007350 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007351 return null;
7352 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007353
Jordan Liub49b04b2019-05-06 14:45:15 -07007354 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7355 // the process, where TelephonyManager was instantiated.
7356 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007357 final long identity = Binder.clearCallingIdentity();
7358 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007359 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 final TelephonyManager tele = TelephonyManager.from(context);
7361 final SubscriptionManager sub = SubscriptionManager.from(context);
7362
7363 // Figure out what subscribers are currently active
7364 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365
Jordan Liub49b04b2019-05-06 14:45:15 -07007366 // Only consider subs which match the current subId
7367 // This logic can be simplified. See b/131189269 for progress.
7368 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007369 activeSubscriberIds.add(tele.getSubscriberId(subId));
7370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371
7372 // First pass, find a number override for an active subscriber
7373 String mergeNumber = null;
7374 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7375 for (String key : prefs.keySet()) {
7376 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7377 final String subscriberId = (String) prefs.get(key);
7378 if (activeSubscriberIds.contains(subscriberId)) {
7379 final String iccId = key.substring(
7380 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7381 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7382 mergeNumber = (String) prefs.get(numberKey);
7383 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007384 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 + " for active subscriber " + subscriberId);
7386 }
7387 if (!TextUtils.isEmpty(mergeNumber)) {
7388 break;
7389 }
7390 }
7391 }
7392 }
7393
7394 // Shortcut when no active merged subscribers
7395 if (TextUtils.isEmpty(mergeNumber)) {
7396 return null;
7397 }
7398
7399 // Second pass, find all subscribers under that line override
7400 final ArraySet<String> result = new ArraySet<>();
7401 for (String key : prefs.keySet()) {
7402 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7403 final String number = (String) prefs.get(key);
7404 if (mergeNumber.equals(number)) {
7405 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7406 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7407 final String subscriberId = (String) prefs.get(subscriberKey);
7408 if (!TextUtils.isEmpty(subscriberId)) {
7409 result.add(subscriberId);
7410 }
7411 }
7412 }
7413 }
7414
7415 final String[] resultArray = result.toArray(new String[result.size()]);
7416 Arrays.sort(resultArray);
7417 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007418 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7420 }
7421 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007422 } finally {
7423 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007424 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007425 }
7426
7427 @Override
zoey chen38003472019-12-13 17:16:31 +08007428 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7429 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007430
7431 final long identity = Binder.clearCallingIdentity();
7432 try {
7433 final TelephonyManager telephonyManager = mApp.getSystemService(
7434 TelephonyManager.class);
7435 String subscriberId = telephonyManager.getSubscriberId(subId);
7436 if (subscriberId == null) {
7437 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007438 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007439 + subId);
7440 }
7441 return null;
7442 }
7443
Jack Yu3beaf9d2023-04-14 09:17:27 -07007444 final SubscriptionInfo info = getSubscriptionManagerService()
7445 .getSubscriptionInfo(subId);
7446 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007447 // If it doesn't belong to any group, return just subscriberId of itself.
7448 if (groupUuid == null) {
7449 return new String[]{subscriberId};
7450 }
7451
7452 // Get all subscriberIds from the group.
7453 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007454 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7455 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7456 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007457 for (SubscriptionInfo subInfo : groupInfos) {
7458 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7459 if (subscriberId != null) {
7460 mergedSubscriberIds.add(subscriberId);
7461 }
7462 }
7463
7464 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467
7468 }
7469 }
7470
7471 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007472 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007473 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007474 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475
7476 final long identity = Binder.clearCallingIdentity();
7477 try {
7478 final Phone phone = getPhone(subId);
7479 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007483 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007484
7485 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007486 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007487 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7488 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007489 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7490 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
7494 final Phone phone = getPhone(subId);
7495 if (phone == null) {
7496 return false;
7497 }
7498 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7499 cdmaNonRoamingList);
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007502 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007503 }
7504
7505 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007506 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007507 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007508 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007509 if (phone == null) {
7510 return raf;
7511 }
7512
Shuo Qiandee53402020-05-29 14:08:15 -07007513 try {
7514 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007515 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007516 mApp, phone.getSubId(), "getRadioAccessFamily");
7517 } catch (SecurityException e) {
7518 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7519 throw e;
7520 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 final long identity = Binder.clearCallingIdentity();
7523 try {
chen xub97461a2018-10-26 14:17:57 -07007524 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
chen xub97461a2018-10-26 14:17:57 -07007528 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007529 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007530
7531 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007532 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007533 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007534 try {
7535 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7536 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007537 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007538 }
7539 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007540 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007541 }
7542 RoleManager rm = mApp.getSystemService(RoleManager.class);
7543 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7544 if (!dialerRoleHolders.contains(callingPackage)) {
7545 throw new SecurityException("App must be the dialer role holder to"
7546 + " upload a call composer pic");
7547 }
7548
7549 Executors.newSingleThreadExecutor().execute(() -> {
7550 ByteArrayOutputStream output = new ByteArrayOutputStream(
7551 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7552 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7553 boolean readUntilEnd = false;
7554 int totalBytesRead = 0;
7555 byte[] buffer = new byte[16 * 1024];
7556 while (true) {
7557 int numRead;
7558 try {
7559 numRead = input.read(buffer);
7560 } catch (IOException e) {
7561 try {
7562 fd.checkError();
7563 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7564 null);
7565 } catch (IOException e1) {
7566 // This means that the other side closed explicitly with an error. If this
7567 // happens, log and ignore.
7568 loge("Remote end of call composer picture pipe closed: " + e1);
7569 }
7570 break;
7571 }
7572 if (numRead == -1) {
7573 readUntilEnd = true;
7574 break;
7575 }
7576 totalBytesRead += numRead;
7577 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7578 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7579 try {
7580 input.close();
7581 } catch (IOException e) {
7582 // ignore
7583 }
7584 break;
7585 }
7586 output.write(buffer, 0, numRead);
7587 }
7588 // Generally, the remote end will close the file descriptors. The only case where we
7589 // close is above, where the picture size is too big.
7590
7591 try {
7592 fd.checkError();
7593 } catch (IOException e) {
7594 loge("Remote end for call composer closed with an error: " + e);
7595 return;
7596 }
7597
Hall Liuaa4211e2021-01-20 15:43:39 -08007598 if (!readUntilEnd) {
7599 loge("Did not finish reading entire image; aborting");
7600 return;
7601 }
Hall Liu82694d52020-12-11 18:22:04 -08007602
Hall Liuaa4211e2021-01-20 15:43:39 -08007603 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7604 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7605 new CallComposerPictureTransfer.Factory() {},
7606 imageData,
7607 (result) -> {
7608 if (result.first != null) {
7609 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7610 Bundle outputResult = new Bundle();
7611 outputResult.putParcelable(
7612 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7613 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7614 outputResult);
7615 } else {
7616 callback.send(result.second, null);
7617 }
7618 }
7619 );
Hall Liu82694d52020-12-11 18:22:04 -08007620 });
7621 }
7622
7623 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007624 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007625 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007626 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007627
7628 final long identity = Binder.clearCallingIdentity();
7629 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007630 ImsManager.getInstance(defaultPhone.getContext(),
7631 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632 } finally {
7633 Binder.restoreCallingIdentity(identity);
7634 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007635 }
7636
7637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007638 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007639 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7641 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007642 return false;
7643 }
Svet Ganovb320e182015-04-16 12:30:10 -07007644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 // Check the user preference and the system-level IMS setting. Even if the user has
7648 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7649 // In the long run, we may instead need to check if there exists a connection service
7650 // which can support video calling.
7651 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007652 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653 return imsManager.isVtEnabledByPlatform()
7654 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7655 && imsManager.isVtEnabledByUser();
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007659 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007660
Andrew Leea1239f22015-03-02 17:44:07 -08007661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007662 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7663 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007665 mApp, subId, callingPackage, callingFeatureId,
7666 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 return false;
7668 }
7669
7670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 CarrierConfigManager configManager =
7673 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007674 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
7678 }
Andrew Leea1239f22015-03-02 17:44:07 -08007679 }
7680
7681 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007682 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007684 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 return false;
7686 }
7687
7688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 CarrierConfigManager configManager =
7691 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007692 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
7696 }
Andrew Leea1239f22015-03-02 17:44:07 -08007697 }
7698
Andrew Lee9431b832015-03-09 18:46:45 -07007699 @Override
7700 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007701 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007702 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007703 }
7704
7705 @Override
7706 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 final long identity = Binder.clearCallingIdentity();
7708 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007709 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 } finally {
7711 Binder.restoreCallingIdentity(identity);
7712 }
Andrew Lee9431b832015-03-09 18:46:45 -07007713 }
7714
Hall Liuf6668912018-10-31 17:05:23 -07007715 /**
7716 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7717 * support for the feature and device firmware support.
7718 *
7719 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7720 */
7721 @Override
7722 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007724 final Phone phone = getPhone(subscriptionId);
7725 if (phone == null) {
7726 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7727 return false;
7728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007730 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7732 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007733 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 return isCarrierSupported && isDeviceSupported;
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
7737 }
Hall Liu98187582018-01-22 19:15:32 -08007738 }
7739
Hall Liuf6668912018-10-31 17:05:23 -07007740 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007741 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7742 * RTT setting, will return true if the device and carrier both support RTT.
7743 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007744 */
7745 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 final long identity = Binder.clearCallingIdentity();
7747 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007748 boolean isRttSupported = isRttSupported(subscriptionId);
7749 boolean isUserRttSettingOn = Settings.Secure.getInt(
7750 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7751 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7752 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7753 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007757 }
7758
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007759 @Deprecated
7760 @Override
7761 public String getDeviceId(String callingPackage) {
7762 return getDeviceIdWithFeature(callingPackage, null);
7763 }
7764
Sanket Padawe7310cc72015-01-14 09:53:20 -08007765 /**
7766 * Returns the unique device ID of phone, for example, the IMEI for
7767 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7768 *
7769 * <p>Requires Permission:
7770 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7771 */
7772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007773 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007774 try {
7775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7776 } catch (SecurityException se) {
7777 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7778 throw new SecurityException("Package " + callingPackage + " does not belong to "
7779 + Binder.getCallingUid());
7780 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007781 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007782 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007783 return null;
7784 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007785 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007786 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007787 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007788 return null;
7789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790
7791 final long identity = Binder.clearCallingIdentity();
7792 try {
7793 return phone.getDeviceId();
7794 } finally {
7795 Binder.restoreCallingIdentity(identity);
7796 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007797 }
7798
Ping Sunc67b7c22016-03-02 19:16:45 +08007799 /**
7800 * {@hide}
7801 * Returns the IMS Registration Status on a particular subid
7802 *
7803 * @param subId
7804 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007805 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007806 Phone phone = getPhone(subId);
7807 if (phone != null) {
7808 return phone.isImsRegistered();
7809 } else {
7810 return false;
7811 }
7812 }
7813
Santos Cordon7a1885b2015-02-03 11:15:19 -08007814 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007815 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007816 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007817 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007818 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007819 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7820 }
7821 final long identity = Binder.clearCallingIdentity();
7822 try {
7823 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
7827 }
7828
7829 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007830 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007831 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007832 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007833 mApp,
7834 subscriptionId,
7835 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7836 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007837 final long identity = Binder.clearCallingIdentity();
7838 try {
7839 Phone phone = getPhone(subscriptionId);
7840 if (phone == null) {
7841 return null;
7842 }
7843 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 }
7848
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007849 /**
7850 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007851 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007852 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 Phone phone = getPhone(subId);
7856 if (phone != null) {
7857 return phone.isWifiCallingEnabled();
7858 } else {
7859 return false;
7860 }
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007863 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007864 }
7865
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007866 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007867 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007868 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007869 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 Phone phone = getPhone(subId);
7873 if (phone != null) {
7874 return phone.isVideoEnabled();
7875 } else {
7876 return false;
7877 }
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007880 }
7881 }
7882
7883 /**
7884 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7885 * defined in {@link ImsRegistrationImplBase}.
7886 */
7887 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 final long identity = Binder.clearCallingIdentity();
7889 try {
7890 Phone phone = getPhone(subId);
7891 if (phone != null) {
7892 return phone.getImsRegistrationTech();
7893 } else {
7894 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7895 }
7896 } finally {
7897 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007898 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007899 }
7900
Stuart Scott8eef64f2015-04-08 15:13:54 -07007901 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007902 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007903 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007904 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7905 return;
7906 }
Kai Shif70f46f2021-03-03 13:59:46 -08007907 Phone defaultPhone = getDefaultPhone();
7908 if (defaultPhone != null) {
7909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7910 mApp, getDefaultPhone().getSubId(), "factoryReset");
7911 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007912 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007913
Svet Ganovcc087f82015-05-12 20:35:54 -07007914 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007915 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7916 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007917 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007918 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007919 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007920 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007921 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007922 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007923 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007924 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007925 // There has been issues when Sms raw table somehow stores orphan
7926 // fragments. They lead to garbled message when new fragments come
7927 // in and combined with those stale ones. In case this happens again,
7928 // user can reset all network settings which will clean up this table.
7929 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007930 // Clean up IMS settings as well here.
7931 int slotId = getSlotIndex(subId);
7932 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7933 ImsManager.getInstance(mApp, slotId).factoryReset();
7934 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007935
Kai Shif70f46f2021-03-03 13:59:46 -08007936 if (defaultPhone == null) {
7937 return;
7938 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007939 // Erase modem config if erase modem on network setting is enabled.
7940 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7941 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7942 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007943 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007944 }
Kai Shif70f46f2021-03-03 13:59:46 -08007945
7946 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007947 } finally {
7948 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007949 }
7950 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007951
SongFerngWangfd89b102021-05-27 22:44:54 +08007952 @VisibleForTesting
7953 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7954 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7955 return;
7956 }
7957 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7958 RILConstants.PREFERRED_NETWORK_MODE);
7959 SubscriptionManager.setSubscriptionProperty(subId,
7960 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7961 "user=" + defaultNetworkType);
7962 phone.loadAllowedNetworksFromSubscriptionDatabase();
7963 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7964 defaultNetworkType, null);
7965 }
7966
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007967 private void cleanUpSmsRawTable(Context context) {
7968 ContentResolver resolver = context.getContentResolver();
7969 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7970 resolver.delete(uri, null, null);
7971 }
7972
Narayan Kamath1c496c22015-04-16 14:40:19 +01007973 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007974 public String getSimLocaleForSubscriber(int subId) {
7975 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7976 final Phone phone = getPhone(subId);
7977 if (phone == null) {
7978 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007979 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 final long identity = Binder.clearCallingIdentity();
7982 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07007983 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
7984 phone.getContext().getOpPackageName(),
7985 phone.getContext().getAttributionTag());
7986 if (info == null) {
7987 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7988 return null;
chen xu6291c472019-02-04 12:55:53 -08007989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 // Try and fetch the locale from the carrier properties or from the SIM language
7991 // preferences (EF-PL and EF-LI)...
7992 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007994 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7995 if (localeFromDefaultSim != null) {
7996 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7997 if (DBG) log("Using locale from subId: " + subId + " locale: "
7998 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007999 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008000 } else {
8001 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 }
8003 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 // The SIM language preferences only store a language (e.g. fr = French), not an
8006 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8007 // the SIM and carrier preferences does not include a country we add the country
8008 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008009 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008011 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008012 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 }
8014
8015 if (DBG) log("No locale found - returning null");
8016 return null;
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008020 }
8021
tom hsu0b59d292022-09-29 23:49:21 +08008022 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008023 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008024 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008025 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008026 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008027 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8028 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008029 Locale.forLanguageTag(localeTag).getCountry())) {
8030 return localeTag;
8031 }
8032 }
8033 return inputLocale.toLanguageTag();
8034 }
8035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 /**
8037 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8038 */
8039 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008040 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
8041 mApp.getOpPackageName(), mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008042 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008043
Gary Jian3aa9a762022-01-24 16:41:19 +08008044 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8045 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008046
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008047 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008048 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8049 * representing the state of the modem.
8050 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008051 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8052 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008053 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008054 */
8055 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008056 public void requestModemActivityInfo(ResultReceiver result) {
8057 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059
8060 final long identity = Binder.clearCallingIdentity();
8061 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008062 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 } finally {
8064 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008065 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008066 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008067
Gary Jian76280a42022-12-07 16:18:33 +08008068 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008069 // less than total activity duration.
8070 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8071 if (info == null) {
8072 return false;
8073 }
8074 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008075 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008076 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8077
Hall Liu49656c02020-10-09 19:00:11 -07008078 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8079
Siddharth Rayb8114062018-06-17 15:02:38 -07008080 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008081 && (info.getSleepTimeMillis() <= activityDurationMs)
8082 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008083 }
8084
Gary Jian3aa9a762022-01-24 16:41:19 +08008085 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8086 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8087 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8088 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8089
8090 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8091 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8092 }
8093
8094 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8095 mLastModemActivityInfo.setReceiveTimeMillis(
8096 rat,
8097 freq,
8098 info.getReceiveTimeMillis(rat, freq)
8099 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8100 }
8101
8102 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8103 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8104 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8105 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8106
8107 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8108 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8109 }
8110 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8111 mLastModemActivityInfo.setReceiveTimeMillis(
8112 rat,
8113 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8114 }
8115
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008116 /**
8117 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8118 * @param info recent ModemActivityInfo
8119 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008120 private void mergeModemActivityInfo(ModemActivityInfo info) {
8121 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008122 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008123 boolean matched;
8124 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8125 matched = false;
8126 int rat = info.getSpecificInfoRat(i);
8127 int freq = info.getSpecificInfoFrequencyRange(i);
8128 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8129 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8130 //if it already exists
8131 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8132 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8133 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8134 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8135 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8136 updateLastModemActivityInfo(info, rat, freq);
8137 matched = true;
8138 }
8139 } else {
8140 updateLastModemActivityInfo(info, rat);
8141 matched = true;
8142 }
8143 }
8144 }
8145
8146 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008147 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008148 new ActivityStatsTechSpecificInfo(
8149 rat,
8150 freq,
8151 info.getTransmitTimeMillis(rat, freq),
8152 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008153 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008154 }
8155 }
8156 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8157 mLastModemActivitySpecificInfo =
8158 new ActivityStatsTechSpecificInfo[merged.size()];
8159 merged.toArray(mLastModemActivitySpecificInfo);
8160
8161 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8162 mLastModemActivityInfo.setSleepTimeMillis(
8163 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008164 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008165 mLastModemActivityInfo.setIdleTimeMillis(
8166 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008167 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008168
8169 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008170 new ModemActivityInfo(
8171 mLastModemActivityInfo.getTimestampMillis(),
8172 mLastModemActivityInfo.getSleepTimeMillis(),
8173 mLastModemActivityInfo.getIdleTimeMillis(),
8174 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008175 }
8176
8177 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8178 ActivityStatsTechSpecificInfo[] info) {
8179 int infoSize = info.length;
8180 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8181 for (int i = 0; i < infoSize; i++) {
8182 ret[i] = new ActivityStatsTechSpecificInfo(
8183 info[i].getRat(), info[i].getFrequencyRange(),
8184 info[i].getTransmitTimeMillis(),
8185 (int) info[i].getReceiveTimeMillis());
8186 }
8187 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008188 }
8189
Jack Yu85bd38a2015-11-09 11:34:32 -08008190 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008191 * Returns the service state information on specified subscription.
8192 */
8193 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008194 public ServiceState getServiceStateForSubscriber(int subId,
8195 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8196 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008198 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008199 return null;
8200 }
8201
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008202 boolean hasFinePermission = false;
8203 boolean hasCoarsePermission = false;
8204 if (!renounceFineLocationAccess) {
8205 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8206 LocationAccessPolicy.checkLocationPermission(mApp,
8207 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8208 .setCallingPackage(callingPackage)
8209 .setCallingFeatureId(callingFeatureId)
8210 .setCallingPid(Binder.getCallingPid())
8211 .setCallingUid(Binder.getCallingUid())
8212 .setMethod("getServiceStateForSubscriber")
8213 .setLogAsInfo(true)
8214 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8215 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8216 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8217 .build());
8218 hasFinePermission =
8219 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8220 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008221
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008222 if (!renounceCoarseLocationAccess) {
8223 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8224 LocationAccessPolicy.checkLocationPermission(mApp,
8225 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8226 .setCallingPackage(callingPackage)
8227 .setCallingFeatureId(callingFeatureId)
8228 .setCallingPid(Binder.getCallingPid())
8229 .setCallingUid(Binder.getCallingUid())
8230 .setMethod("getServiceStateForSubscriber")
8231 .setLogAsInfo(true)
8232 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8233 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8234 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8235 .build());
8236 hasCoarsePermission =
8237 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8238 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008239
Jack Yu479f40e2020-10-27 21:29:25 -07008240 final Phone phone = getPhone(subId);
8241 if (phone == null) {
8242 return null;
8243 }
8244
Jordan Liu0f2bc442020-11-18 16:47:37 -08008245 final long identity = Binder.clearCallingIdentity();
8246
Jack Yu479f40e2020-10-27 21:29:25 -07008247 boolean isCallingPackageDataService = phone.getDataServicePackages()
8248 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008250 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008251 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8252 .getSubscriptionInfoInternal(subId);
8253 if (subInfo == null || !subInfo.isActive()) {
8254 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8255 + "subId=" + subId);
8256 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008257 }
8258
Hall Liuf19c44f2018-11-27 14:38:17 -08008259 ServiceState ss = phone.getServiceState();
8260
8261 // Scrub out the location info in ServiceState depending on what level of access
8262 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008263 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008264 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8265 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 } finally {
8267 Binder.restoreCallingIdentity(identity);
8268 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008269 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008270
8271 /**
8272 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8273 *
8274 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8275 * voicemail ringtone.
8276 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8277 * PhoneAccount.
8278 */
8279 @Override
8280 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 final long identity = Binder.clearCallingIdentity();
8282 try {
8283 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8284 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008285 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008292 }
8293
8294 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008295 * Sets the per-account voicemail ringtone.
8296 *
8297 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8298 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8299 *
8300 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8301 * voicemail ringtone.
8302 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8303 * PhoneAccount.
8304 */
8305 @Override
8306 public void setVoicemailRingtoneUri(String callingPackage,
8307 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008308 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008309 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008310 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8311 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8313 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8314 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316
8317 final long identity = Binder.clearCallingIdentity();
8318 try {
8319 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8320 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008321 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 }
8323 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008326 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008327 }
8328
8329 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008330 * Returns whether vibration is set for voicemail notification in Phone settings.
8331 *
8332 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8333 * voicemail vibration setting.
8334 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8335 */
8336 @Override
8337 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8341 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008342 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8346 } finally {
8347 Binder.restoreCallingIdentity(identity);
8348 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008349 }
8350
Youhan Wange64578a2016-05-02 15:32:42 -07008351 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008352 * Sets the per-account voicemail vibration.
8353 *
8354 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8355 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8356 *
8357 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8358 * voicemail vibration setting.
8359 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8360 * specific PhoneAccount.
8361 */
8362 @Override
8363 public void setVoicemailVibrationEnabled(String callingPackage,
8364 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008365 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008366 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008367 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8368 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8370 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8371 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008372 }
8373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8377 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008378 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 }
8380 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8381 } finally {
8382 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008383 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008384 }
8385
8386 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008387 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8388 *
8389 * @throws SecurityException if the caller does not have the required permission
8390 */
arunvoddud7401012022-12-15 16:08:12 +00008391 @VisibleForTesting
8392 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008393 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008394 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008395 }
8396
8397 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008398 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8399 * permission.
8400 *
8401 * @throws SecurityException if the caller does not have the required permission
8402 */
8403 private void enforceSendSmsPermission() {
8404 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8405 }
8406
8407 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008408 * Make sure either called from same process as self (phone) or IPC caller has interact across
8409 * users permission.
8410 *
8411 * @throws SecurityException if the caller does not have the required permission
8412 */
8413 private void enforceInteractAcrossUsersPermission(String message) {
8414 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8415 }
8416
8417 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008418 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008419 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008420 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008421 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008422 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 final long identity = Binder.clearCallingIdentity();
8424 try {
8425 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008426 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008427 if (componentName == null) {
8428 throw new SecurityException(
8429 "Caller not current active visual voicemail package[null]");
8430 }
8431 String vvmPackage = componentName.getPackageName();
8432 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008433 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 }
8435 } finally {
8436 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008437 }
8438 }
8439
8440 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008441 * Return the application ID for the app type.
8442 *
8443 * @param subId the subscription ID that this request applies to.
8444 * @param appType the uicc app type.
8445 * @return Application ID for specificied app type, or null if no uicc.
8446 */
8447 @Override
8448 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008449 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008450 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451
8452 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008453 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454 if (phone == null) {
8455 return null;
8456 }
8457 String aid = null;
8458 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008459 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008460 .getApplicationByType(appType).getAid();
8461 } catch (Exception e) {
8462 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8463 }
8464 return aid;
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008467 }
Youhan Wange64578a2016-05-02 15:32:42 -07008468 }
8469
Youhan Wang4001d252016-05-11 10:29:41 -07008470 /**
8471 * Return the Electronic Serial Number.
8472 *
8473 * @param subId the subscription ID that this request applies to.
8474 * @return ESN or null if error.
8475 */
8476 @Override
8477 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008478 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008479 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480
8481 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008482 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008483 if (phone == null) {
8484 return null;
8485 }
8486 String esn = null;
8487 try {
8488 esn = phone.getEsn();
8489 } catch (Exception e) {
8490 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8491 }
8492 return esn;
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008495 }
Youhan Wang4001d252016-05-11 10:29:41 -07008496 }
8497
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008498 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008499 * Return the Preferred Roaming List Version.
8500 *
8501 * @param subId the subscription ID that this request applies to.
8502 * @return PRLVersion or null if error.
8503 */
8504 @Override
8505 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008506 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008507 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508
8509 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008510 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008511 if (phone == null) {
8512 return null;
8513 }
8514 String cdmaPrlVersion = null;
8515 try {
8516 cdmaPrlVersion = phone.getCdmaPrlVersion();
8517 } catch (Exception e) {
8518 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8519 }
8520 return cdmaPrlVersion;
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008523 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008524 }
8525
8526 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008527 * Get snapshot of Telephony histograms
8528 * @return List of Telephony histograms
8529 * @hide
8530 */
8531 @Override
8532 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8534 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535
8536 final long identity = Binder.clearCallingIdentity();
8537 try {
8538 return RIL.getTelephonyRILTimingHistograms();
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
8541 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008542 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008543
8544 /**
8545 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008546 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8547 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008548 * Require system privileges. In the future we may add this to carrier APIs.
8549 *
Michele Berionne482f8202018-11-27 18:57:59 -08008550 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008551 */
8552 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008553 @TelephonyManager.SetCarrierRestrictionResult
8554 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008555 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008557
Michele Berionne482f8202018-11-27 18:57:59 -08008558 if (carrierRestrictionRules == null) {
8559 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008560 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008562 final long identity = Binder.clearCallingIdentity();
8563 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008564 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008565 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008566 } finally {
8567 Binder.restoreCallingIdentity(identity);
8568 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008569 }
8570
8571 /**
8572 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008573 * Get the allowed carrier list and the excluded carrier list, including the priority between
8574 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008575 * Require system privileges. In the future we may add this to carrier APIs.
8576 *
Michele Berionne482f8202018-11-27 18:57:59 -08008577 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008578 */
8579 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008580 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008581 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008582 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583
8584 final long identity = Binder.clearCallingIdentity();
8585 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008586 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8587 if (response instanceof CarrierRestrictionRules) {
8588 return (CarrierRestrictionRules) response;
8589 }
8590 // Response is an Exception of some kind,
8591 // which is signalled to the user as a NULL retval
8592 return null;
8593 } catch (Exception e) {
8594 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8595 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 } finally {
8597 Binder.restoreCallingIdentity(identity);
8598 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008599 }
8600
fionaxu59545b42016-05-25 15:53:37 -07008601 /**
arunvoddud7401012022-12-15 16:08:12 +00008602 * Fetches the carrier restriction status of the device and sends the status to the caller
8603 * through the callback.
8604 *
8605 * @param callback The callback that will be used to send the result.
8606 * @throws SecurityException if the caller does not have the required permission/privileges or
8607 * the caller is not allowlisted.
8608 */
8609 @Override
8610 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8611 enforceReadPermission("getCarrierRestrictionStatus");
8612 int carrierId = validateCallerAndGetCarrierId(packageName);
8613 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8614 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8615 throw new SecurityException("Not an authorized caller");
8616 }
8617 final long identity = Binder.clearCallingIdentity();
8618 try {
8619 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8620 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8621 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8622 } finally {
8623 Binder.restoreCallingIdentity(identity);
8624 }
8625 }
8626
arunvoddu567f2b42023-04-25 17:22:00 +00008627 @Override
8628 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8629 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8630 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8631 return allowListInfo.getShaIdList(pkgName, carrierId);
8632 }
8633
arunvoddud7401012022-12-15 16:08:12 +00008634 @VisibleForTesting
8635 public int validateCallerAndGetCarrierId(String packageName) {
8636 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8637 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8638 }
8639
8640 /**
fionaxu59545b42016-05-25 15:53:37 -07008641 * Action set from carrier signalling broadcast receivers to enable/disable radio
8642 * @param subId the subscription ID that this action applies to.
8643 * @param enabled control enable or disable radio.
8644 * {@hide}
8645 */
8646 @Override
8647 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8648 enforceModifyPermission();
8649 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008650
8651 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008652 if (phone == null) {
8653 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8654 return;
8655 }
8656 try {
8657 phone.carrierActionSetRadioEnabled(enabled);
8658 } catch (Exception e) {
8659 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008660 } finally {
8661 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008662 }
8663 }
8664
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008665 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008666 * Enable or disable Voice over NR (VoNR)
8667 * @param subId the subscription ID that this action applies to.
8668 * @param enabled enable or disable VoNR.
8669 * @return operation result.
8670 */
8671 @Override
8672 public int setVoNrEnabled(int subId, boolean enabled) {
8673 enforceModifyPermission();
8674 final Phone phone = getPhone(subId);
8675
8676 final long identity = Binder.clearCallingIdentity();
8677 if (phone == null) {
8678 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8679 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8680 }
8681
8682 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8683 try {
8684 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8685 workSource);
8686 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008687
8688 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8689 if (DBG) {
8690 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8691 }
8692 SubscriptionManager.setSubscriptionProperty(
8693 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8694 (enabled ? "1" : "0"));
8695 }
8696
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008697 return result;
8698 } finally {
8699 Binder.restoreCallingIdentity(identity);
8700 }
8701 }
8702
8703 /**
8704 * Is voice over NR enabled
8705 * @return true if VoNR is enabled else false
8706 */
8707 @Override
8708 public boolean isVoNrEnabled(int subId) {
8709 enforceReadPrivilegedPermission("isVoNrEnabled");
8710 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
8713 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8714 null, subId, workSource);
8715 if (DBG) log("isVoNrEnabled: " + isEnabled);
8716 return isEnabled;
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 }
8721
8722 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008723 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8724 * network status based on which carrier apps could apply actions accordingly,
8725 * enable/disable default url handler for example.
8726 *
8727 * @param subId the subscription ID that this action applies to.
8728 * @param report control start/stop reporting the default network status.
8729 * {@hide}
8730 */
8731 @Override
8732 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8733 enforceModifyPermission();
8734 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008735
8736 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008737 if (phone == null) {
8738 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8739 return;
8740 }
8741 try {
8742 phone.carrierActionReportDefaultNetworkStatus(report);
8743 } catch (Exception e) {
8744 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008745 } finally {
8746 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008747 }
8748 }
8749
8750 /**
fionaxud9622282017-07-17 17:51:30 -07008751 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8752 * @param subId the subscription ID that this action applies to.
8753 * {@hide}
8754 */
8755 @Override
8756 public void carrierActionResetAll(int subId) {
8757 enforceModifyPermission();
8758 final Phone phone = getPhone(subId);
8759 if (phone == null) {
8760 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8761 return;
8762 }
8763 try {
8764 phone.carrierActionResetAll();
8765 } catch (Exception e) {
8766 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8767 }
8768 }
8769
8770 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008771 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8772 * bug report is being generated.
8773 */
8774 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008775 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008776 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8777 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008778 writer.println("Permission Denial: can't dump Phone from pid="
8779 + Binder.getCallingPid()
8780 + ", uid=" + Binder.getCallingUid()
8781 + "without permission "
8782 + android.Manifest.permission.DUMP);
8783 return;
8784 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008785 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008786 }
Jack Yueb89b242016-06-22 13:27:47 -07008787
Brad Ebingerdac2f002018-04-03 15:17:52 -07008788 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008789 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8790 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8791 @NonNull String[] args) {
8792 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8793 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008794 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008795 }
8796
Jack Yueb89b242016-06-22 13:27:47 -07008797 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008798 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008799 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008800 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008801 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008802 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008803 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008804 */
8805 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008806 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008807 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008808 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8809 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8810 try {
8811 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008812 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008813 } catch (SecurityException se) {
8814 enforceModifyPermission();
8815 }
8816 } else {
8817 enforceModifyPermission();
8818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008819
8820 final long identity = Binder.clearCallingIdentity();
8821 try {
8822 Phone phone = getPhone(subId);
8823 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008824 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8825 phone.carrierActionSetMeteredApnsEnabled(enabled);
8826 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008827 phone.getDataSettingsManager().setDataEnabled(
8828 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008830 }
8831 } finally {
8832 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008833 }
8834 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008835
8836 /**
8837 * Get Client request stats
8838 * @return List of Client Request Stats
8839 * @hide
8840 */
8841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008842 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8843 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008845 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008846 return null;
8847 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008848 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008850 final long identity = Binder.clearCallingIdentity();
8851 try {
8852 if (phone != null) {
8853 return phone.getClientRequestStats();
8854 }
8855
8856 return null;
8857 } finally {
8858 Binder.restoreCallingIdentity(identity);
8859 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008860 }
8861
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008862 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008863 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008864 if (uid == Process.ROOT_UID && packageName == null) {
8865 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8866 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8867 // exception. ROOT_UID seems not to have a valid package name returned by
8868 // PackageManager, so just fake it here to avoid issues when running telephony shell
8869 // commands that plumb through the RIL as root, like so:
8870 // $ adb root
8871 // $ adb shell cmd phone ...
8872 packageName = "root";
8873 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008874 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008875 }
Jack Yueb4124c2017-02-16 15:32:43 -08008876
8877 /**
Grace Chen70990072017-03-24 17:21:30 -07008878 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008879 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008880 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008881 * @param state State of SIM (power down, power up, pass through)
8882 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8883 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8884 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008885 *
8886 **/
8887 @Override
Grace Chen70990072017-03-24 17:21:30 -07008888 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008889 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008890 Phone phone = PhoneFactory.getPhone(slotIndex);
8891
vagdeviaf9a5b92018-08-15 16:01:53 -07008892 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008894 final long identity = Binder.clearCallingIdentity();
8895 try {
8896 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008897 phone.setSimPowerState(state, null, workSource);
8898 }
8899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
8902 }
8903
8904 /**
8905 * Set SIM card power state.
8906 *
8907 * @param slotIndex SIM slot id.
8908 * @param state State of SIM (power down, power up, pass through)
8909 * @param callback callback to trigger after success or failure
8910 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8911 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8912 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8913 *
8914 **/
8915 @Override
8916 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8917 IIntegerConsumer callback) {
8918 enforceModifyPermission();
8919 Phone phone = PhoneFactory.getPhone(slotIndex);
8920
8921 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8922
8923 final long identity = Binder.clearCallingIdentity();
8924 try {
8925 if (phone != null) {
8926 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8927 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008928 }
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008931 }
8932 }
Shuo Qiandd210312017-04-12 22:11:33 +00008933
Tyler Gunn65d45c22017-06-05 11:22:26 -07008934 private boolean isUssdApiAllowed(int subId) {
8935 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008936 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008937 if (configManager == null) {
8938 return false;
8939 }
8940 PersistableBundle pb = configManager.getConfigForSubId(subId);
8941 if (pb == null) {
8942 return false;
8943 }
8944 return pb.getBoolean(
8945 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8946 }
8947
Shuo Qiandd210312017-04-12 22:11:33 +00008948 /**
Ling Mac28f0212023-03-24 16:07:15 -07008949 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008950 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008951 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008952 */
goneil9c5f4872017-12-05 14:07:56 -08008953 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008954 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008955 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 final long identity = Binder.clearCallingIdentity();
8957 try {
Ling Mac28f0212023-03-24 16:07:15 -07008958 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959 } finally {
8960 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008961 }
8962 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008963
8964 /**
8965 * Get the current signal strength information for the given subscription.
8966 * Because this information is not updated when the device is in a low power state
8967 * it should not be relied-upon to be current.
8968 * @param subId Subscription index
8969 * @return the most recent cached signal strength info from the modem
8970 */
8971 @Override
8972 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008973 final long identity = Binder.clearCallingIdentity();
8974 try {
8975 Phone p = getPhone(subId);
8976 if (p == null) {
8977 return null;
8978 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 return p.getSignalStrength();
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008984 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008985
Pengquan Meng77b7f132018-08-22 14:49:57 -07008986 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008987 * Get the current modem radio state for the given slot.
8988 * @param slotIndex slot index.
8989 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008990 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008991 * @return the current radio power state from the modem
8992 */
8993 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008994 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008995 Phone phone = PhoneFactory.getPhone(slotIndex);
8996 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8998 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008999 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9000 }
9001
9002 final long identity = Binder.clearCallingIdentity();
9003 try {
9004 return phone.getRadioPowerState();
9005 } finally {
9006 Binder.restoreCallingIdentity(identity);
9007 }
9008 }
9009 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9010 }
9011
9012 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009013 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9014 *
9015 * <p>Requires one of the following permissions:
9016 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009017 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009018 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9019 * privileges.
9020 *
9021 * @param subId subscription id
9022 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9023 * {@code false}.
9024 */
9025 @Override
9026 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009027 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009028 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009029 try {
9030 mApp.enforceCallingOrSelfPermission(
9031 android.Manifest.permission.ACCESS_NETWORK_STATE,
9032 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009033 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009034 mApp.enforceCallingOrSelfPermission(
9035 permission.READ_BASIC_PHONE_STATE, functionName);
9036 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009037 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009038 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009039 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009040 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009041
Pengquan Menga1bb6272018-09-06 09:59:22 -07009042 boolean isEnabled = false;
9043 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009044 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009045 Phone phone = getPhone(subId);
9046 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009047 } finally {
9048 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009049 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009050 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009051 }
9052
9053
9054 /**
9055 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9056 *
9057 * <p> Requires permission:
9058 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9059 * privileges.
9060 *
9061 * @param subId subscription id
9062 * @param isEnabled {@code true} means enable, {@code false} means disable.
9063 */
9064 @Override
9065 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9067 mApp, subId, "setDataRoamingEnabled");
9068
Pengquan Menga1bb6272018-09-06 09:59:22 -07009069 final long identity = Binder.clearCallingIdentity();
9070 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009071 Phone phone = getPhone(subId);
9072 if (phone != null) {
9073 phone.setDataRoamingEnabled(isEnabled);
9074 }
9075 } finally {
9076 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009077 }
9078 }
9079
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009080 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009081 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009082 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009083 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009084 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009085
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009086 boolean isAllowed = true;
9087 final long identity = Binder.clearCallingIdentity();
9088 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009089 Phone phone = getPhone(subId);
9090 if (phone != null) {
9091 isAllowed = phone.isCspPlmnEnabled();
9092 }
9093 } finally {
9094 Binder.restoreCallingIdentity(identity);
9095 }
9096 return isAllowed;
9097 }
9098
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009099 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9100 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009101 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009102 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009103 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009104 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9105 if (phone == null) {
9106 return false;
9107 }
9108 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9109 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9110 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009111 }
9112
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009113 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009114 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009115 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009116 mApp.getSystemService(AppOpsManager.class)
9117 .checkPackage(Binder.getCallingUid(), callingPackage);
9118
Jordan Liu1e142fc2019-04-22 15:10:43 -07009119 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009120 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009121 try {
9122 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009123 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009124 } catch (SecurityException e) {
9125 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9126 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009127 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009128 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009129 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009130 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009131 }
sandeepjsb6c87872021-09-27 15:34:44 +00009132 // checking compatibility, if calling app's target SDK is T and beyond.
9133 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9134 Binder.getCallingUid())) {
9135 isIccIdAccessRestricted = true;
9136 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009137 final long identity = Binder.clearCallingIdentity();
9138 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009139 UiccController uiccController = UiccController.getInstance();
9140 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009141 if (hasReadPermission) {
9142 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009143 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009144
9145 // Remove private info if the caller doesn't have access
9146 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9147 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009148 //setting the value after compatibility check
9149 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009150 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9151 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009152 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009153 if (card == null) {
9154 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009155 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009156 continue;
9157 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009158 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9159 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009160 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009161 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009162 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009163 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9164 for (UiccPortInfo portInfo : portInfos) {
9165 UiccPort port = uiccController.getUiccPortForSlot(
9166 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9167 if (port == null) {
9168 // assume no access if port is null
9169 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9170 continue;
9171 }
9172 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9173 uiccPortInfos.add(portInfo);
9174 } else {
9175 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9176 }
9177 }
9178 filteredInfos.add(new UiccCardInfo(
9179 cardInfo.isEuicc(),
9180 cardInfo.getCardId(),
9181 null,
9182 cardInfo.getPhysicalSlotIndex(),
9183 cardInfo.isRemovable(),
9184 cardInfo.isMultipleEnabledProfilesSupported(),
9185 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009186 }
9187 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
9192
sandeepjsb6c87872021-09-27 15:34:44 +00009193 /**
9194 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9195 * generally private and require carrier privileges to view.
9196 *
9197 * @hide
9198 */
9199 @NonNull
9200 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9201 List<UiccPortInfo> portinfo = new ArrayList<>();
9202 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9203 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9204 }
9205 return new UiccCardInfo(
9206 cardInfo.isEuicc(),
9207 cardInfo.getCardId(),
9208 null,
9209 cardInfo.getPhysicalSlotIndex(),
9210 cardInfo.isRemovable(),
9211 cardInfo.isMultipleEnabledProfilesSupported(),
9212 portinfo
9213 );
9214 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009215
sandeepjsb6c87872021-09-27 15:34:44 +00009216 /**
9217 * @hide
9218 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9219 * These values are generally private and require carrier privileges to view.
9220 */
9221 @NonNull
9222 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9223 return new UiccPortInfo(
9224 UiccPortInfo.ICCID_REDACTED,
9225 portInfo.getPortIndex(),
9226 portInfo.getLogicalSlotIndex(),
9227 portInfo.isActive()
9228 );
9229 }
9230 @Override
9231 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009232 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009233 mApp.getSystemService(AppOpsManager.class)
9234 .checkPackage(Binder.getCallingUid(), callingPackage);
9235
sandeepjsb6c87872021-09-27 15:34:44 +00009236 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009237
Aman Guptaf3c90b32022-03-17 04:54:16 +00009238 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9239 // we are reading iccId which is PII data.
9240 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009241
9242 // checking compatibility, if calling app's target SDK is T and beyond.
9243 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9244 Binder.getCallingUid())) {
9245 isLogicalSlotAccessRestricted = true;
9246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009250 if (slots == null || slots.length == 0) {
9251 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009252 return null;
9253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009254 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9255 for (int i = 0; i < slots.length; i++) {
9256 UiccSlot slot = slots[i];
9257 if (slot == null) {
9258 continue;
9259 }
9260
Jordan Liu7be7e652019-05-06 18:55:02 +00009261 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009262 UiccCard card = slot.getUiccCard();
9263 if (card != null) {
9264 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009265 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009266 cardId = slot.getEid();
9267 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009268 // If cardId is null, use iccId of default port as cardId.
9269 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009271 }
9272
Jordan Liu857451f2019-05-09 16:35:35 -07009273 if (cardId != null) {
9274 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9275 // if cardId is an EID, it's all digits so this is fine
9276 cardId = IccUtils.stripTrailingFs(cardId);
9277 }
9278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009279 int cardState = 0;
9280 switch (slot.getCardState()) {
9281 case CARDSTATE_ABSENT:
9282 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9283 break;
9284 case CARDSTATE_PRESENT:
9285 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9286 break;
9287 case CARDSTATE_ERROR:
9288 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9289 break;
9290 case CARDSTATE_RESTRICTED:
9291 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9292 break;
9293 default:
9294 break;
9295
9296 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009297 List<UiccPortInfo> portInfos = new ArrayList<>();
9298 int[] portIndexes = slot.getPortList();
9299 for (int portIdx : portIndexes) {
9300 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009301 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009302 portInfos.add(new UiccPortInfo(iccId, portIdx,
9303 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009305 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009306 slot.isEuicc(),
9307 cardId,
9308 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009309 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009310 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009311 //setting the value after compatibility check
9312 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009313 }
9314 return infos;
9315 } finally {
9316 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009317 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009318 }
9319
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009320 /* Returns null if doesn't have read permission or carrier privilege access. */
9321 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9322 boolean hasReadPermission) {
9323 String iccId = slot.getIccId(portIndex);
9324 if (hasReadPermission) { // if has read permission
9325 return iccId;
9326 } else {
9327 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9328 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9329 // if no read permission, checking carrier privilege access
9330 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9331 return iccId;
9332 }
9333 }
9334 }
9335 // No read permission or carrier privilege access.
9336 return UiccPortInfo.ICCID_REDACTED;
9337 }
9338
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009339 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009340 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009341 public boolean switchSlots(int[] physicalSlots) {
9342 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009343
9344 final long identity = Binder.clearCallingIdentity();
9345 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009346 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9347 for (int i = 0; i < physicalSlots.length; i++) {
9348 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9349 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9350 physicalSlots[i], i));
9351 }
9352 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009356 }
Jack Yu4c988042018-02-27 15:30:01 -08009357
9358 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009359 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9360 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9361 enforceModifyPermission();
9362
9363 final long identity = Binder.clearCallingIdentity();
9364 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009365 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009366 } finally {
9367 Binder.restoreCallingIdentity(identity);
9368 }
9369 }
9370
9371 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009372 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009373 final long identity = Binder.clearCallingIdentity();
9374 try {
9375 return UiccController.getInstance().getCardIdForDefaultEuicc();
9376 } finally {
9377 Binder.restoreCallingIdentity(identity);
9378 }
9379 }
9380
Pengquan Meng85728fb2018-03-12 16:31:21 -07009381 /**
goneil47ffb6e2018-04-06 15:40:58 -07009382 * A test API to reload the UICC profile.
9383 *
9384 * <p>Requires that the calling app has permission
9385 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9386 * @hide
9387 */
9388 @Override
9389 public void refreshUiccProfile(int subId) {
9390 enforceModifyPermission();
9391
9392 final long identity = Binder.clearCallingIdentity();
9393 try {
9394 Phone phone = getPhone(subId);
9395 if (phone == null) {
9396 return;
9397 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009398 UiccPort uiccPort = phone.getUiccPort();
9399 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009400 return;
9401 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009402 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009403 if (uiccProfile == null) {
9404 return;
9405 }
9406 uiccProfile.refresh();
9407 } finally {
9408 Binder.restoreCallingIdentity(identity);
9409 }
9410 }
9411
9412 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009413 * Returns false if the mobile data is disabled by default, otherwise return true.
9414 */
9415 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009416 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009417 }
9418
9419 /**
9420 * Returns true if the data roaming is enabled by default, i.e the system property
9421 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9422 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9423 */
9424 private boolean getDefaultDataRoamingEnabled(int subId) {
9425 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009426 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009427 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009428 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9429 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9430 return isDataRoamingEnabled;
9431 }
9432
9433 /**
9434 * Returns the default network type for the given {@code subId}, if the default network type is
9435 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9436 */
9437 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009438 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009439 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009440 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9441 return list.get(phoneId);
9442 }
9443 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009444 }
fionaxua13278b2018-03-21 00:08:13 -07009445
9446 @Override
9447 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009448 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009449 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009450
9451 final long identity = Binder.clearCallingIdentity();
9452 try {
9453 final Phone phone = getPhone(subId);
9454 if (phone == null) {
9455 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9456 return;
9457 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009458 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9459 if (cpt != null) {
9460 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9461 }
9462 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009463 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9464 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009465 if (carrierPrivilegeRules == null) {
9466 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9467 } else {
9468 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009470 } finally {
9471 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009472 }
fionaxua13278b2018-03-21 00:08:13 -07009473 }
9474
9475 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009476 public void setCarrierServicePackageOverride(
9477 int subId, String carrierServicePackage, String callingPackage) {
9478 TelephonyPermissions.enforceShellOnly(
9479 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9480
9481 // Verify that the callingPackage belongs to the calling UID
9482 mApp.getSystemService(AppOpsManager.class)
9483 .checkPackage(Binder.getCallingUid(), callingPackage);
9484
9485 final long identity = Binder.clearCallingIdentity();
9486 try {
9487 final Phone phone = getPhone(subId);
9488 if (phone == null || phone.getSubId() != subId) {
9489 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9490 throw new IllegalArgumentException("No phone for subid");
9491 }
9492 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9493 if (cpt == null) {
9494 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9495 throw new IllegalStateException("No CPT for phone");
9496 }
9497 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9498 } finally {
9499 Binder.restoreCallingIdentity(identity);
9500 }
9501 }
9502
9503 @Override
fionaxua13278b2018-03-21 00:08:13 -07009504 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009505 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009506
9507 final long identity = Binder.clearCallingIdentity();
9508 try {
9509 final Phone phone = getPhone(subId);
9510 if (phone == null) {
9511 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9512 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9513 }
9514 return phone.getCarrierIdListVersion();
9515 } finally {
9516 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009517 }
fionaxua13278b2018-03-21 00:08:13 -07009518 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009519
9520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009521 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9522 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009524 mApp, subId, callingPackage, callingFeatureId,
9525 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009526 return -1;
9527 }
9528
9529 final long identity = Binder.clearCallingIdentity();
9530 try {
9531 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
9534 }
9535 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009536
9537 @Override
9538 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009539 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009540 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009541 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009542
9543 final long identity = Binder.clearCallingIdentity();
9544 try {
9545 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9546 } finally {
9547 Binder.restoreCallingIdentity(identity);
9548 }
9549 }
9550
9551 @Override
9552 public boolean setCdmaRoamingMode(int subId, int mode) {
9553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9554 mApp, subId, "setCdmaRoamingMode");
9555
9556 final long identity = Binder.clearCallingIdentity();
9557 try {
9558 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
9563
9564 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009565 public int getCdmaSubscriptionMode(int subId) {
9566 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009567 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009568 mApp, subId, "getCdmaSubscriptionMode");
9569
9570 final long identity = Binder.clearCallingIdentity();
9571 try {
9572 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9573 } finally {
9574 Binder.restoreCallingIdentity(identity);
9575 }
9576 }
9577
9578 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009579 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9581 mApp, subId, "setCdmaSubscriptionMode");
9582
9583 final long identity = Binder.clearCallingIdentity();
9584 try {
9585 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009590
sqianc5eccab2018-10-19 18:46:41 -07009591 @Override
sqian8c685422019-02-22 15:55:18 -08009592 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009593 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009595 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9596 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009597 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9598 }
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
sqian854d44b2018-12-12 16:48:18 -08009601 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9602 for (Phone phone: PhoneFactory.getPhones()) {
9603 if (phone.getEmergencyNumberTracker() != null
9604 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9605 emergencyNumberListInternal.put(
9606 phone.getSubId(),
9607 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9608 }
sqian11b7a0e2018-12-05 18:48:28 -08009609 }
sqian854d44b2018-12-12 16:48:18 -08009610 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009611 } finally {
9612 Binder.restoreCallingIdentity(identity);
9613 }
sqianc5eccab2018-10-19 18:46:41 -07009614 }
9615
9616 @Override
sqian8c685422019-02-22 15:55:18 -08009617 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009618 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009619 if (!exactMatch) {
9620 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009621 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009622 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009623 }
9624 final long identity = Binder.clearCallingIdentity();
9625 try {
sqian854d44b2018-12-12 16:48:18 -08009626 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009627 //Note: we ignore passed in param exactMatch. We can remove it once
9628 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009629 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009630 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009631 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009632 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009633 }
sqian11b7a0e2018-12-05 18:48:28 -08009634 }
9635 return false;
9636 } finally {
9637 Binder.restoreCallingIdentity(identity);
9638 }
9639 }
9640
sqianf4ca7ed2019-01-15 18:32:07 -08009641 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009642 * Start emergency callback mode for GsmCdmaPhone for testing.
9643 */
9644 @Override
9645 public void startEmergencyCallbackMode() {
9646 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9647 "startEmergencyCallbackMode");
9648 enforceModifyPermission();
9649 final long identity = Binder.clearCallingIdentity();
9650 try {
9651 for (Phone phone : PhoneFactory.getPhones()) {
9652 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9653 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9654 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9655 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9656 gsmCdmaPhone.obtainMessage(
9657 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9658 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9659 }
9660 }
9661 } finally {
9662 Binder.restoreCallingIdentity(identity);
9663 }
9664 }
9665
9666 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009667 * Update emergency number list for test mode.
9668 */
9669 @Override
9670 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9671 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9672 "updateEmergencyNumberListTestMode");
9673
9674 final long identity = Binder.clearCallingIdentity();
9675 try {
9676 for (Phone phone: PhoneFactory.getPhones()) {
9677 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9678 if (tracker != null) {
9679 tracker.executeEmergencyNumberTestModeCommand(action, num);
9680 }
9681 }
9682 } finally {
9683 Binder.restoreCallingIdentity(identity);
9684 }
9685 }
9686
9687 /**
9688 * Get the full emergency number list for test mode.
9689 */
9690 @Override
9691 public List<String> getEmergencyNumberListTestMode() {
9692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9693 "getEmergencyNumberListTestMode");
9694
9695 final long identity = Binder.clearCallingIdentity();
9696 try {
9697 Set<String> emergencyNumbers = new HashSet<>();
9698 for (Phone phone: PhoneFactory.getPhones()) {
9699 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9700 if (tracker != null) {
9701 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9702 emergencyNumbers.add(num.getNumber());
9703 }
9704 }
9705 }
9706 return new ArrayList<>(emergencyNumbers);
9707 } finally {
9708 Binder.restoreCallingIdentity(identity);
9709 }
9710 }
9711
chen xud6b45bd2018-10-30 22:27:10 -07009712 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009713 public int getEmergencyNumberDbVersion(int subId) {
9714 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9715
9716 final long identity = Binder.clearCallingIdentity();
9717 try {
9718 final Phone phone = getPhone(subId);
9719 if (phone == null) {
9720 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9721 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9722 }
9723 return phone.getEmergencyNumberDbVersion();
9724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
9728
9729 @Override
9730 public void notifyOtaEmergencyNumberDbInstalled() {
9731 enforceModifyPermission();
9732
9733 final long identity = Binder.clearCallingIdentity();
9734 try {
9735 for (Phone phone: PhoneFactory.getPhones()) {
9736 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9737 if (tracker != null) {
9738 tracker.updateOtaEmergencyNumberDatabase();
9739 }
9740 }
9741 } finally {
9742 Binder.restoreCallingIdentity(identity);
9743 }
9744 }
9745
9746 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009747 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009748 enforceActiveEmergencySessionPermission();
9749
9750 final long identity = Binder.clearCallingIdentity();
9751 try {
9752 for (Phone phone: PhoneFactory.getPhones()) {
9753 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9754 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009755 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9756 }
9757 }
9758 } finally {
9759 Binder.restoreCallingIdentity(identity);
9760 }
9761 }
9762
9763 @Override
9764 public void resetOtaEmergencyNumberDbFilePath() {
9765 enforceActiveEmergencySessionPermission();
9766
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
9769 for (Phone phone: PhoneFactory.getPhones()) {
9770 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9771 if (tracker != null) {
9772 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009773 }
9774 }
9775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
9779
9780 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009781 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9782 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9783 Phone phone = getPhone(subId);
9784 if (phone == null) {
9785 return null;
9786 }
9787 final long identity = Binder.clearCallingIdentity();
9788 try {
9789 UiccProfile profile = UiccController.getInstance()
9790 .getUiccProfileForPhone(phone.getPhoneId());
9791 if (profile != null) {
9792 return profile.getCertsFromCarrierPrivilegeAccessRules();
9793 }
9794 } finally {
9795 Binder.restoreCallingIdentity(identity);
9796 }
9797 return null;
9798 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009799
9800 /**
9801 * Enable or disable a modem stack.
9802 */
9803 @Override
9804 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9805 enforceModifyPermission();
9806
9807 final long identity = Binder.clearCallingIdentity();
9808 try {
9809 Phone phone = PhoneFactory.getPhone(slotIndex);
9810 if (phone == null) {
9811 return false;
9812 } else {
9813 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9814 }
9815 } finally {
9816 Binder.restoreCallingIdentity(identity);
9817 }
9818 }
Michelecea4cf22018-12-21 15:00:11 -08009819
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009820 /**
9821 * Whether a modem stack is enabled or not.
9822 */
9823 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009824 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9825 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009826 Phone phone = PhoneFactory.getPhone(slotIndex);
9827 if (phone == null) return false;
9828
9829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009830 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9831 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009832 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9833 }
9834
9835 final long identity = Binder.clearCallingIdentity();
9836 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009837 try {
9838 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9839 } catch (NoSuchElementException ex) {
9840 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9841 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
9846
Michelecea4cf22018-12-21 15:00:11 -08009847 @Override
Michele0ea7d782019-03-19 14:58:42 -07009848 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009849 enforceModifyPermission();
9850
9851 final long identity = Binder.clearCallingIdentity();
9852 try {
9853 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009854 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009855 .commit();
9856 } finally {
9857 Binder.restoreCallingIdentity(identity);
9858 }
9859 }
9860
9861 @Override
Michele0ea7d782019-03-19 14:58:42 -07009862 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009863 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009865 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9866 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009867 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009868 }
Michelecea4cf22018-12-21 15:00:11 -08009869
9870 final long identity = Binder.clearCallingIdentity();
9871 try {
Michele0ea7d782019-03-19 14:58:42 -07009872 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009873 } finally {
9874 Binder.restoreCallingIdentity(identity);
9875 }
9876 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009877
Michele0ea7d782019-03-19 14:58:42 -07009878 @TelephonyManager.IsMultiSimSupportedResult
9879 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009880 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9881 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9882 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009883 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9884 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009885 }
9886 // Check if the hardware supports multisim functionality. If usage of multisim is not
9887 // supported by the modem, indicate that it is restricted.
9888 PhoneCapability staticCapability =
9889 mPhoneConfigurationManager.getStaticPhoneCapability();
9890 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009891 loge("isMultiSimSupportedInternal: no static configuration available");
9892 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009893 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009894 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009895 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9896 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009897 }
9898 // Check if support of multiple SIMs is restricted by carrier
9899 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009900 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009901 }
9902
Michele0ea7d782019-03-19 14:58:42 -07009903 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009904 }
9905
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009906 /**
9907 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009908 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9909 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9910 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009911 * @param numOfSims number of active sims we want to switch to
9912 */
9913 @Override
9914 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009915 if (numOfSims == 1) {
9916 enforceModifyPermission();
9917 } else {
9918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9919 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9920 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009921 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009922
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009923 try {
Michele30b57b22019-03-01 12:01:14 -08009924 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009925 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009926 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9927 return;
9928 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009929 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9930 } finally {
9931 Binder.restoreCallingIdentity(identity);
9932 }
9933 }
9934
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009935 @Override
9936 public boolean isApplicationOnUicc(int subId, int appType) {
9937 enforceReadPrivilegedPermission("isApplicationOnUicc");
9938 Phone phone = getPhone(subId);
9939 if (phone == null) {
9940 return false;
9941 }
9942 final long identity = Binder.clearCallingIdentity();
9943 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009944 UiccPort uiccPort = phone.getUiccPort();
9945 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009946 return false;
9947 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009948 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009949 if (uiccProfile == null) {
9950 return false;
9951 }
9952 if (TelephonyManager.APPTYPE_SIM <= appType
9953 && appType <= TelephonyManager.APPTYPE_ISIM) {
9954 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9955 }
9956 return false;
9957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960 }
9961
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009962 /**
chen xub4baa772019-04-03 10:23:41 -07009963 * Get whether making changes to modem configurations will trigger reboot.
9964 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009965 */
9966 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009967 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9968 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009970 mApp, subId, callingPackage, callingFeatureId,
9971 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009972 return false;
9973 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009974 final long identity = Binder.clearCallingIdentity();
9975 try {
9976 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9977 } finally {
9978 Binder.restoreCallingIdentity(identity);
9979 }
9980 }
9981
Nathan Harold29f5f052019-02-15 13:41:57 -08009982 private void updateModemStateMetrics() {
9983 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9984 // TODO: check the state for each modem if the api is ready.
9985 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9986 }
9987
Pengquan Meng3889a572019-01-23 11:16:29 -08009988 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009989 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009990 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009991 // Verify that the callingPackage belongs to the calling UID
9992 mApp.getSystemService(AppOpsManager.class)
9993 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009994 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009995 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009996 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009997 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9998 if (slotInfos != null) {
9999 for (int i = 0; i < slotInfos.length; i++) {
10000 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10001 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10002 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10003 portInfo.getLogicalSlotIndex()));
10004 }
10005 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010006 }
10007 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010008 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010009 } finally {
10010 Binder.restoreCallingIdentity(identity);
10011 }
10012 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010013
10014 /**
10015 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010016 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010017 */
jimsunf9ec1622022-09-13 21:18:43 +080010018 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010019 @Override
10020 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010021 return getHalVersion(HAL_SERVICE_RADIO);
10022 }
10023
10024 /**
10025 * Get the HAL Version of a specific service
10026 */
10027 @Override
10028 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010029 Phone phone = getDefaultPhone();
10030 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010031 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010032 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10033 return hv.major * 100 + hv.minor;
10034 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010035
10036 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010037 * Get the current calling package name.
10038 * @return the current calling package name
10039 */
10040 @Override
10041 public String getCurrentPackageName() {
10042 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10043 }
10044
10045 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010046 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10047 * corresponding network requests on a subId.
10048 *
10049 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010050 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010051 * 2) APN is un-metered for this subscription, or
10052 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010053 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010054 *
10055 * @return whether data is allowed for a apn type.
10056 *
10057 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010058 */
10059 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010060 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010061 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10062 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010063
10064 // Now that all security checks passes, perform the operation as ourselves.
10065 final long identity = Binder.clearCallingIdentity();
10066 try {
10067 Phone phone = getPhone(subId);
10068 if (phone == null) return false;
10069
Jack Yu27422a52022-03-21 10:38:05 -070010070 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010071 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010072 isMetered = phone.getDataNetworkController().getDataConfigManager()
10073 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10074 phone.getServiceState().getDataRoaming());
10075 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010076 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 }
10081
10082 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010083 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010084 enforceReadPrivilegedPermission("isApnMetered");
10085
10086 // Now that all security checks passes, perform the operation as ourselves.
10087 final long identity = Binder.clearCallingIdentity();
10088 try {
10089 Phone phone = getPhone(subId);
10090 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010091 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10092 DataUtils.apnTypeToNetworkCapability(apnType),
10093 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010094 } finally {
10095 Binder.restoreCallingIdentity(identity);
10096 }
10097 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010098
10099 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010100 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10101 int subscriptionId, IBooleanConsumer resultCallback) {
10102 enforceModifyPermission();
10103 long token = Binder.clearCallingIdentity();
10104 try {
10105 Phone phone = getPhone(subscriptionId);
10106 if (phone == null) {
10107 try {
10108 if (resultCallback != null) {
10109 resultCallback.accept(false);
10110 }
10111 } catch (RemoteException e) {
10112 // ignore
10113 }
10114 return;
10115 }
10116 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10117 Pair.create(specifiers, (x) -> {
10118 try {
10119 if (resultCallback != null) {
10120 resultCallback.accept(x);
10121 }
10122 } catch (RemoteException e) {
10123 // ignore
10124 }
10125 });
10126 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10127 } finally {
10128 Binder.restoreCallingIdentity(token);
10129 }
10130 }
10131
10132 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010133 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10134 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010135 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010136 mApp, subId, "getSystemSelectionChannels");
10137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10138 final long identity = Binder.clearCallingIdentity();
10139 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010140 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10141 if (result instanceof IllegalStateException) {
10142 throw (IllegalStateException) result;
10143 }
10144 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010145 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10146 return specifiers;
10147 } finally {
10148 Binder.restoreCallingIdentity(identity);
10149 }
10150 }
10151
10152 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010153 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010154 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010155 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010156 }
10157
10158 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010159 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10160 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010161 if (callingPackage == null) {
10162 callingPackage = getCurrentPackageName();
10163 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010164 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10165 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010166 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10167 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010168 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10169 }
10170 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10171 Intent intent = new Intent();
10172 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10173 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10174 // Bring up choose default SMS subscription dialog right now
10175 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10176 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10177 mApp.startActivity(intent);
10178 }
chen xud5ca2d52019-05-28 15:20:57 -070010179
10180 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010181 public void showSwitchToManagedProfileDialog() {
10182 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010183 try {
10184 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10185 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10186 // for work telephony.
10187 Intent intent = new Intent(Intent.ACTION_SENDTO);
10188 intent.setData(Uri.parse("smsto:"));
10189 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10190 mApp.startActivity(intent);
10191 } catch (ActivityNotFoundException e) {
10192 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10193 Intent intent = new Intent();
10194 intent.setClass(mApp, ErrorDialogActivity.class);
10195 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10196 mApp.startActivity(intent);
10197 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010198 }
10199
10200 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010201 public String getMmsUAProfUrl(int subId) {
10202 //TODO investigate if this API should require proper permission check in R b/133791609
10203 final long identity = Binder.clearCallingIdentity();
10204 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010205 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10206 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10207 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10208 return carrierUAProfUrl;
10209 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010210 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10211 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 @Override
10218 public String getMmsUserAgent(int subId) {
10219 //TODO investigate if this API should require proper permission check in R b/133791609
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010222 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10223 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10224 if (!TextUtils.isEmpty(carrierUserAgent)) {
10225 return carrierUserAgent;
10226 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010227 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10228 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010229 } finally {
10230 Binder.restoreCallingIdentity(identity);
10231 }
10232 }
Jack Yub07d4972019-05-28 16:12:25 -070010233
10234 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010235 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10236 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010237
Jack Yub07d4972019-05-28 16:12:25 -070010238 final long identity = Binder.clearCallingIdentity();
10239 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010240 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010241 if (phone == null) return false;
10242
Ling Maf188d502022-09-16 15:22:36 -070010243 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010244 } finally {
10245 Binder.restoreCallingIdentity(identity);
10246 }
10247 }
10248
10249 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010250 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010251 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010252 enforceModifyPermission();
10253
changbettyd5c246e2019-12-24 15:40:37 +080010254 final long identity = Binder.clearCallingIdentity();
10255 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010256 Phone phone = getPhone(subscriptionId);
10257 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010258
Ling Maf188d502022-09-16 15:22:36 -070010259 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010260 } finally {
10261 Binder.restoreCallingIdentity(identity);
10262 }
10263 }
10264
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010265 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010266 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010267 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10268 * otherwise.
10269 */
10270 @Override
10271 public void setCepEnabled(boolean isCepEnabled) {
10272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10273
10274 final long identity = Binder.clearCallingIdentity();
10275 try {
10276 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10277 for (Phone phone : PhoneFactory.getPhones()) {
10278 Phone defaultPhone = phone.getImsPhone();
10279 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10280 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10281 ImsPhoneCallTracker imsPhoneCallTracker =
10282 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10283 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10284 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10285 + imsPhone.getMsisdn());
10286 }
10287 }
10288 } finally {
10289 Binder.restoreCallingIdentity(identity);
10290 }
10291 }
allenwtsu46dcc572020-01-08 18:24:03 +080010292
10293 /**
10294 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10295 *
10296 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10297 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10298 * before being read.
10299 */
10300 @Override
10301 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10302 isCompressed) {
10303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10304 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010305 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10306 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10307 }
10308 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010309 // ProvisioningManager can not handle ServiceSpecificException.
10310 // Throw the IllegalStateException and annotate ProvisioningManager.
10311 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010312 }
10313
10314 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010315 try {
Hui Wang761a6682020-10-31 05:12:53 +000010316 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10317 } finally {
10318 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010319 }
10320 }
zoey chene02881a2019-12-30 16:11:23 +080010321
10322 @Override
10323 public boolean isIccLockEnabled(int subId) {
10324 enforceReadPrivilegedPermission("isIccLockEnabled");
10325
10326 // Now that all security checks passes, perform the operation as ourselves.
10327 final long identity = Binder.clearCallingIdentity();
10328 try {
10329 Phone phone = getPhone(subId);
10330 if (phone != null && phone.getIccCard() != null) {
10331 return phone.getIccCard().getIccLockEnabled();
10332 } else {
10333 return false;
10334 }
10335 } finally {
10336 Binder.restoreCallingIdentity(identity);
10337 }
10338 }
10339
10340 /**
10341 * Set the ICC pin lock enabled or disabled.
10342 *
10343 * @return an integer representing the status of IccLock enabled or disabled in the following
10344 * three cases:
10345 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10346 * successfully.
10347 * - Positive number and zero for remaining password attempts.
10348 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10349 *
10350 */
10351 @Override
10352 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10353 enforceModifyPermission();
10354
10355 Phone phone = getPhone(subId);
10356 if (phone == null) {
10357 return 0;
10358 }
10359 // Now that all security checks passes, perform the operation as ourselves.
10360 final long identity = Binder.clearCallingIdentity();
10361 try {
10362 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10363 new Pair<Boolean, String>(enabled, password), phone, null);
10364 return attemptsRemaining;
10365
10366 } catch (Exception e) {
10367 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10368 } finally {
10369 Binder.restoreCallingIdentity(identity);
10370 }
10371 return 0;
10372 }
10373
10374 /**
10375 * Change the ICC password used in ICC pin lock.
10376 *
10377 * @return an integer representing the status of IccLock changed in the following three cases:
10378 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10379 * - Positive number and zero for remaining password attempts.
10380 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10381 *
10382 */
10383 @Override
10384 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10385 enforceModifyPermission();
10386
10387 Phone phone = getPhone(subId);
10388 if (phone == null) {
10389 return 0;
10390 }
10391 // Now that all security checks passes, perform the operation as ourselves.
10392 final long identity = Binder.clearCallingIdentity();
10393 try {
10394 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10395 new Pair<String, String>(oldPassword, newPassword), phone, null);
10396 return attemptsRemaining;
10397
10398 } catch (Exception e) {
10399 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10400 } finally {
10401 Binder.restoreCallingIdentity(identity);
10402 }
10403 return 0;
10404 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010405
10406 /**
10407 * Request for receiving user activity notification
10408 */
10409 @Override
10410 public void requestUserActivityNotification() {
10411 if (!mNotifyUserActivity.get()
10412 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10413 mNotifyUserActivity.set(true);
10414 }
10415 }
10416
10417 /**
10418 * Called when userActivity is signalled in the power manager.
10419 * This is safe to call from any thread, with any window manager locks held or not.
10420 */
10421 @Override
10422 public void userActivity() {
10423 // ***************************************
10424 // * Inherited from PhoneWindowManager *
10425 // ***************************************
10426 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10427 // WITH ITS LOCKS HELD.
10428 //
10429 // This code must be VERY careful about the locks
10430 // it acquires.
10431 // In fact, the current code acquires way too many,
10432 // and probably has lurking deadlocks.
10433
10434 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10435 throw new SecurityException("Only the OS may call notifyUserActivity()");
10436 }
10437
10438 if (mNotifyUserActivity.getAndSet(false)) {
10439 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10440 USER_ACTIVITY_NOTIFICATION_DELAY);
10441 }
10442 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010443
10444 @Override
10445 public boolean canConnectTo5GInDsdsMode() {
10446 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10447 }
Jack Yud10cdd42020-09-28 20:28:01 -070010448
10449 @Override
10450 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10451 String callingFeatureId) {
10452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10453 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10454 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10455 }
10456
10457 Phone phone = getPhone(subId);
10458 if (phone == null) {
10459 throw new RuntimeException("phone is not available");
10460 }
10461 // Now that all security checks passes, perform the operation as ourselves.
10462 final long identity = Binder.clearCallingIdentity();
10463 try {
10464 return phone.getEquivalentHomePlmns();
10465 } finally {
10466 Binder.restoreCallingIdentity(identity);
10467 }
10468 }
Daniel Bright59e67312020-11-13 11:49:37 -080010469
10470 @Override
10471 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010472 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10473 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010474 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010475 if (radioInterfaceCapabilities == null) {
10476 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010477 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010478 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010479 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010480
Hui Wang641e81c2020-10-12 12:14:23 -070010481 @Override
10482 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10483 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010484 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10485 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10486 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10487 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10488 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010489 if (DBG) {
10490 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10491 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10492 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10493 }
10494
10495 if (!SubscriptionManager.isValidSubscriptionId(subId)
10496 || appType < TelephonyManager.APPTYPE_UNKNOWN
10497 || appType > TelephonyManager.APPTYPE_ISIM
10498 || nafUrl == null || securityProtocol == null || callback == null) {
10499 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10500 if (callback != null) {
10501 try {
10502 callback.onAuthenticationFailure(
10503 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10504 } catch (RemoteException exception) {
10505 log("Fail to notify onAuthenticationFailure due to " + exception);
10506 }
10507 return;
10508 }
10509 }
10510
10511 final long token = Binder.clearCallingIdentity();
10512 try {
10513 getGbaManager(subId).bootstrapAuthenticationRequest(
10514 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010515 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010516 } finally {
10517 Binder.restoreCallingIdentity(token);
10518 }
10519 }
10520
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010521 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010522 * Attempts to set the radio power state for all phones for thermal reason.
10523 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010524 * requested radio power state will actually be set. See {@link
10525 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10526 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010527 * @param enable {@code true} if trying to turn radio on.
10528 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10529 * false}.
10530 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010531 private boolean setRadioPowerForThermal(boolean enable) {
10532 boolean isPhoneAvailable = false;
10533 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10534 Phone phone = PhoneFactory.getPhone(i);
10535 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010536 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010537 isPhoneAvailable = true;
10538 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010539 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010540
10541 // return true if successfully informed the phone object about the thermal radio power
10542 // request.
10543 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010544 }
10545
10546 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010547 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010548 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10549 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10550 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10551 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10552 throw new IllegalArgumentException("modem does not support data throttling");
10553 }
10554
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010555 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10556 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010557 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010558 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10559 }
10560
Sarah Chinecc78c42022-03-31 21:16:48 -070010561 setDataEnabledForReason(
10562 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010563
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010564 if (isDataThrottlingSupported) {
10565 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010566 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010567 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10568 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10569 } else if (thermalMitigationResult
10570 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010571 log("Modem likely does not support data throttling on secondary carrier. Data " +
10572 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10573 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010574 }
10575 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010576 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010577
10578 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010579 }
10580
Jack Nudelman644b91a2021-03-12 14:09:48 -080010581 private static List<String> getThermalMitigationAllowlist(Context context) {
10582 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10583 for (String pckg : context.getResources()
10584 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10585 sThermalMitigationAllowlistedPackages.add(pckg);
10586 }
10587 }
10588
10589 return sThermalMitigationAllowlistedPackages;
10590 }
10591
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010592 private boolean isAnyPhoneInEmergencyState() {
10593 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10594 if (tm.isInEmergencyCall()) {
10595 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10596 return true;
10597 }
10598 for (Phone phone : PhoneFactory.getPhones()) {
10599 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10600 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010601 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10602 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010603 return true;
10604 }
10605 }
10606
10607 return false;
10608 }
10609
Jack Nudelman644b91a2021-03-12 14:09:48 -080010610 /**
10611 * Used by shell commands to add an authorized package name for thermal mitigation.
10612 * @param packageName name of package to be allowlisted
10613 * @param context
10614 */
10615 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10616 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10617 sThermalMitigationAllowlistedPackages.add(packageName);
10618 }
10619
10620 /**
10621 * Used by shell commands to remove an authorized package name for thermal mitigation.
10622 * @param packageName name of package to remove from allowlist
10623 * @param context
10624 */
10625 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10626 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10627 sThermalMitigationAllowlistedPackages.remove(packageName);
10628 }
10629
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010630 /**
10631 * Thermal mitigation request to control functionalities at modem.
10632 *
10633 * @param subId the id of the subscription.
10634 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010635 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010636 *
10637 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10638 */
10639 @Override
10640 @ThermalMitigationResult
10641 public int sendThermalMitigationRequest(
10642 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010643 ThermalMitigationRequest thermalMitigationRequest,
10644 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010645 enforceModifyPermission();
10646
Jack Nudelman644b91a2021-03-12 14:09:48 -080010647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10648 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10649 .contains(callingPackage)) {
10650 throw new SecurityException("Calling package must be configured in the device config. "
10651 + "calling package: " + callingPackage);
10652 }
10653
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10655 final long identity = Binder.clearCallingIdentity();
10656
10657 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10658 try {
10659 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10660 switch (thermalMitigationAction) {
10661 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10662 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010663 handleDataThrottlingRequest(subId,
10664 thermalMitigationRequest.getDataThrottlingRequest(),
10665 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010666 break;
10667 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10668 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10669 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10670 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10671 }
10672
10673 // Ensure that radio is on. If not able to power on due to phone being
10674 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010675 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010676 thermalMitigationResult =
10677 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10678 break;
10679 }
10680
10681 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010682 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010683 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10684 break;
10685 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10686 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10687 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10688 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10689 }
10690
10691 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10692 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010693 Phone phone = getPhone(subId);
10694 if (phone == null) {
10695 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010696 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010697 break;
10698 }
10699
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010700 TelephonyConnectionService service =
10701 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010702 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010703 Log.e(LOG_TAG, "An emergency call is pending");
10704 thermalMitigationResult =
10705 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10706 break;
10707 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010708 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010709 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010710 break;
10711 }
10712 } else {
10713 thermalMitigationResult =
10714 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10715 break;
10716 }
10717
10718 // Turn radio off. If not able to power off due to phone being unavailable,
10719 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010720 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010721 thermalMitigationResult =
10722 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10723 break;
10724 }
10725 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010726 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010727 break;
10728 default:
10729 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10730 + "not exist. Requested action: " + thermalMitigationAction);
10731 }
10732 } catch (IllegalArgumentException e) {
10733 throw e;
10734 } catch (Exception e) {
10735 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10736 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10737 } finally {
10738 Binder.restoreCallingIdentity(identity);
10739 }
10740
10741 if (DBG) {
10742 log("thermalMitigationRequest returning with thermalMitigationResult: "
10743 + thermalMitigationResult);
10744 }
10745
10746 return thermalMitigationResult;
10747 }
Hui Wang641e81c2020-10-12 12:14:23 -070010748
10749 /**
10750 * Set the GbaService Package Name that Telephony will bind to.
10751 *
10752 * @param subId The sim that the GbaService is associated with.
10753 * @param packageName The name of the package to be replaced with.
10754 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10755 */
10756 @Override
10757 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10758 enforceModifyPermission();
10759
10760 final long identity = Binder.clearCallingIdentity();
10761 try {
10762 return getGbaManager(subId).overrideServicePackage(packageName);
10763 } finally {
10764 Binder.restoreCallingIdentity(identity);
10765 }
10766 }
10767
10768 /**
10769 * Return the package name of the currently bound GbaService.
10770 *
10771 * @param subId The sim that the GbaService is associated with.
10772 * @return the package name of the GbaService configuration, null if GBA is not supported.
10773 */
10774 @Override
10775 public String getBoundGbaService(int subId) {
10776 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10777
10778 final long identity = Binder.clearCallingIdentity();
10779 try {
10780 return getGbaManager(subId).getServicePackage();
10781 } finally {
10782 Binder.restoreCallingIdentity(identity);
10783 }
10784 }
10785
10786 /**
10787 * Set the release time for telephony to unbind GbaService.
10788 *
10789 * @param subId The sim that the GbaService is associated with.
10790 * @param interval The release time to unbind GbaService by millisecond.
10791 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10792 */
10793 @Override
10794 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10795 enforceModifyPermission();
10796
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 return getGbaManager(subId).overrideReleaseTime(interval);
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
10804
10805 /**
10806 * Return the release time for telephony to unbind GbaService.
10807 *
10808 * @param subId The sim that the GbaService is associated with.
10809 * @return The release time to unbind GbaService by millisecond.
10810 */
10811 @Override
10812 public int getGbaReleaseTime(int subId) {
10813 enforceReadPrivilegedPermission("getGbaReleaseTime");
10814
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 return getGbaManager(subId).getReleaseTime();
10818 } finally {
10819 Binder.restoreCallingIdentity(identity);
10820 }
10821 }
10822
10823 private GbaManager getGbaManager(int subId) {
10824 GbaManager instance = GbaManager.getInstance(subId);
10825 if (instance == null) {
10826 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10827 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10828 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10829 }
10830 return instance;
10831 }
Hui Wang761a6682020-10-31 05:12:53 +000010832
10833 /**
10834 * indicate whether the device and the carrier can support
10835 * RCS VoLTE single registration.
10836 */
10837 @Override
10838 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010839 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10840 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10841 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10842 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010843
10844 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10845 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10846 }
10847
10848 final long identity = Binder.clearCallingIdentity();
10849 try {
10850 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10851 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010852 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10853 if (isCapable != null) {
10854 return isCapable;
10855 }
Hui Wang761a6682020-10-31 05:12:53 +000010856 }
Hui Wang67af90e2021-06-04 16:57:15 -070010857 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10858 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010859 } finally {
10860 Binder.restoreCallingIdentity(identity);
10861 }
10862 }
10863
10864 /**
10865 * Register RCS provisioning callback.
10866 */
10867 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010868 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010869 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010870 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010871 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010872 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10873 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010874
10875 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10876 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10877 }
10878 if (!isImsAvailableOnDevice()) {
10879 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10880 "IMS not available on device.");
10881 }
10882
10883 final long identity = Binder.clearCallingIdentity();
10884 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010885 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010886 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010887 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10888 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010889 }
Hui Wang761a6682020-10-31 05:12:53 +000010890 } finally {
10891 Binder.restoreCallingIdentity(identity);
10892 }
10893 }
10894
10895 /**
10896 * Unregister RCS provisioning callback.
10897 */
10898 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010899 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010900 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010901 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010902 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010903 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10904 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010905
10906 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10907 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10908 }
10909 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010910 // operation failed silently
10911 Rlog.w(LOG_TAG, "IMS not available on device.");
10912 return;
Hui Wang761a6682020-10-31 05:12:53 +000010913 }
10914
10915 final long identity = Binder.clearCallingIdentity();
10916 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010917 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010918 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010919 } finally {
10920 Binder.restoreCallingIdentity(identity);
10921 }
10922 }
10923
10924 /**
10925 * trigger RCS reconfiguration.
10926 */
10927 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010928 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10929 "triggerRcsReconfiguration",
10930 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010931
10932 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10933 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10934 }
10935 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010936 // ProvisioningManager can not handle ServiceSpecificException.
10937 // Throw the IllegalStateException and annotate ProvisioningManager.
10938 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010939 }
10940
10941 final long identity = Binder.clearCallingIdentity();
10942 try {
10943 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10944 } finally {
10945 Binder.restoreCallingIdentity(identity);
10946 }
10947 }
10948
10949 /**
10950 * Provide the client configuration parameters of the RCS application.
10951 */
10952 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010953 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10954 "setRcsClientConfiguration",
10955 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010956
10957 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10958 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10959 }
10960 if (!isImsAvailableOnDevice()) {
10961 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10962 "IMS not available on device.");
10963 }
10964
10965 final long identity = Binder.clearCallingIdentity();
10966
10967 try {
10968 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10969 if (configBinder == null) {
10970 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010971 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10972 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010973 } else {
10974 configBinder.setRcsClientConfiguration(rcc);
10975 }
joonhunshin3e154242021-09-17 06:33:39 +000010976
10977 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10978 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010979 } catch (RemoteException e) {
10980 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010981 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10982 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010983 } finally {
10984 Binder.restoreCallingIdentity(identity);
10985 }
10986 }
10987
10988 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010989 * Enables or disables the test mode for RCS VoLTE single registration.
10990 */
10991 @Override
10992 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10994 "setRcsSingleRegistrationTestModeEnabled");
10995
10996 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10997 }
10998
10999 /**
11000 * Gets the test mode for RCS VoLTE single registration.
11001 */
11002 @Override
11003 public boolean getRcsSingleRegistrationTestModeEnabled() {
11004 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11005 "getRcsSingleRegistrationTestModeEnabled");
11006
11007 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11008 }
11009
11010 /**
Hui Wang761a6682020-10-31 05:12:53 +000011011 * Overrides the config of RCS VoLTE single registration enabled for the device.
11012 */
11013 @Override
11014 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11015 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11016 "setDeviceSingleRegistrationEnabledOverride");
11017 enforceModifyPermission();
11018
11019 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11020 : Boolean.parseBoolean(enabledStr);
11021 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011022 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011023 }
11024
11025 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011026 * Sends a device to device communication message. Only usable via shell.
11027 * @param message message to send.
11028 * @param value message value.
11029 */
11030 @Override
11031 public void sendDeviceToDeviceMessage(int message, int value) {
11032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011033 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011034 enforceModifyPermission();
11035
11036 final long identity = Binder.clearCallingIdentity();
11037 try {
11038 TelephonyConnectionService service =
11039 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11040 if (service == null) {
11041 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11042 return;
11043 }
11044 service.sendTestDeviceToDeviceMessage(message, value);
11045 } finally {
11046 Binder.restoreCallingIdentity(identity);
11047 }
11048 }
11049
Tyler Gunnbabbda02021-02-10 11:05:02 -080011050 /**
11051 * Sets the specified device to device transport active.
11052 * @param transport The transport to set active.
11053 */
11054 @Override
11055 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11057 "setActiveDeviceToDeviceTransport");
11058 enforceModifyPermission();
11059
11060 final long identity = Binder.clearCallingIdentity();
11061 try {
11062 TelephonyConnectionService service =
11063 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11064 if (service == null) {
11065 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11066 return;
11067 }
11068 service.setActiveDeviceToDeviceTransport(transport);
11069 } finally {
11070 Binder.restoreCallingIdentity(identity);
11071 }
11072 }
Tyler Gunn92479152021-01-20 16:30:10 -080011073
Tyler Gunnd4339262021-05-03 14:46:49 -070011074 @Override
11075 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11076 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11077 "setDeviceToDeviceForceEnabled");
11078
11079 final long identity = Binder.clearCallingIdentity();
11080 try {
11081 Arrays.stream(PhoneFactory.getPhones()).forEach(
11082 p -> {
11083 Phone thePhone = p.getImsPhone();
11084 if (thePhone != null && thePhone instanceof ImsPhone) {
11085 ImsPhone imsPhone = (ImsPhone) thePhone;
11086 CallTracker tracker = imsPhone.getCallTracker();
11087 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11088 ImsPhoneCallTracker imsPhoneCallTracker =
11089 (ImsPhoneCallTracker) tracker;
11090 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11091 }
11092 }
11093 }
11094 );
11095 } finally {
11096 Binder.restoreCallingIdentity(identity);
11097 }
11098 }
11099
Tyler Gunn92479152021-01-20 16:30:10 -080011100 /**
Hui Wang761a6682020-10-31 05:12:53 +000011101 * Gets the config of RCS VoLTE single registration enabled for the device.
11102 */
11103 @Override
11104 public boolean getDeviceSingleRegistrationEnabled() {
11105 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11106 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11107 }
11108
11109 /**
11110 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11111 */
11112 @Override
11113 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11115 "setCarrierSingleRegistrationEnabledOverride");
11116 enforceModifyPermission();
11117
11118 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11119 : Boolean.parseBoolean(enabledStr);
11120 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11121 subId, enabled);
11122 }
11123
11124 /**
11125 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11126 */
11127 @Override
11128 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11129 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11130 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11131 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011132
11133 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011134 * Overrides the ims feature validation result
11135 */
11136 @Override
11137 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11139 "setImsFeatureValidationOverride");
11140
11141 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11142 : Boolean.parseBoolean(enabledStr);
11143 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11144 subId, enabled);
11145 }
11146
11147 /**
11148 * Gets the ims feature validation override value
11149 */
11150 @Override
11151 public boolean getImsFeatureValidationOverride(int subId) {
11152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11153 "getImsFeatureValidationOverride");
11154 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11155 }
11156
11157 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011158 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11159 * their mobile plan.
11160 */
11161 @Override
11162 public String getMobileProvisioningUrl() {
11163 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11164 final long identity = Binder.clearCallingIdentity();
11165 try {
11166 return getDefaultPhone().getMobileProvisioningUrl();
11167 } finally {
11168 Binder.restoreCallingIdentity(identity);
11169 }
11170 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011171
James.cf Linbcdf8b32021-01-14 16:44:13 +080011172 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011173 * Get the EAB contact from the EAB database.
11174 */
11175 @Override
11176 public String getContactFromEab(String contact) {
11177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11178 enforceModifyPermission();
11179 final long identity = Binder.clearCallingIdentity();
11180 try {
11181 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11182 } finally {
11183 Binder.restoreCallingIdentity(identity);
11184 }
11185 }
11186
11187 /**
Calvin Pana1434322021-07-01 19:27:01 +080011188 * Get the EAB capability from the EAB database.
11189 */
11190 @Override
11191 public String getCapabilityFromEab(String contact) {
11192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11193 enforceModifyPermission();
11194 final long identity = Binder.clearCallingIdentity();
11195 try {
11196 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11197 } finally {
11198 Binder.restoreCallingIdentity(identity);
11199 }
11200 }
11201
11202 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011203 * Remove the EAB contacts from the EAB database.
11204 */
11205 @Override
11206 public int removeContactFromEab(int subId, String contacts) {
11207 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11208 enforceModifyPermission();
11209 final long identity = Binder.clearCallingIdentity();
11210 try {
11211 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11212 } finally {
11213 Binder.restoreCallingIdentity(identity);
11214 }
11215 }
11216
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011217 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011218 public boolean getDeviceUceEnabled() {
11219 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11220 final long identity = Binder.clearCallingIdentity();
11221 try {
11222 return mApp.getDeviceUceEnabled();
11223 } finally {
11224 Binder.restoreCallingIdentity(identity);
11225 }
11226 }
11227
11228 @Override
11229 public void setDeviceUceEnabled(boolean isEnabled) {
11230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11231 final long identity = Binder.clearCallingIdentity();
11232 try {
11233 mApp.setDeviceUceEnabled(isEnabled);
11234 } finally {
11235 Binder.restoreCallingIdentity(identity);
11236 }
11237 }
11238
Brad Ebinger14d467f2021-02-12 06:18:28 +000011239 /**
11240 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11241 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11242 */
11243 // Used for SHELL command only right now.
11244 @Override
11245 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11246 List<String> featureTags) {
11247 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11248 "addUceRegistrationOverrideShell");
11249 final long identity = Binder.clearCallingIdentity();
11250 try {
11251 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11252 new ArraySet<>(featureTags));
11253 } catch (ImsException e) {
11254 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11255 } finally {
11256 Binder.restoreCallingIdentity(identity);
11257 }
11258 }
11259
11260 /**
11261 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11262 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11263 */
11264 // Used for SHELL command only right now.
11265 @Override
11266 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11267 List<String> featureTags) {
11268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11269 "removeUceRegistrationOverrideShell");
11270 final long identity = Binder.clearCallingIdentity();
11271 try {
11272 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11273 new ArraySet<>(featureTags));
11274 } catch (ImsException e) {
11275 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11276 } finally {
11277 Binder.restoreCallingIdentity(identity);
11278 }
11279 }
11280
11281 /**
11282 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11283 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11284 */
11285 // Used for SHELL command only right now.
11286 @Override
11287 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11289 "clearUceRegistrationOverrideShell");
11290 final long identity = Binder.clearCallingIdentity();
11291 try {
11292 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11293 } catch (ImsException e) {
11294 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11295 } finally {
11296 Binder.restoreCallingIdentity(identity);
11297 }
11298 }
11299
11300 /**
11301 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11302 */
11303 // Used for SHELL command only right now.
11304 @Override
11305 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11306 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11307 "getLatestRcsContactUceCapabilityShell");
11308 final long identity = Binder.clearCallingIdentity();
11309 try {
11310 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11311 } catch (ImsException e) {
11312 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11313 } finally {
11314 Binder.restoreCallingIdentity(identity);
11315 }
11316 }
11317
11318 /**
11319 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11320 * device does not have an active PUBLISH.
11321 */
11322 // Used for SHELL command only right now.
11323 @Override
11324 public String getLastUcePidfXmlShell(int subId) {
11325 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11326 final long identity = Binder.clearCallingIdentity();
11327 try {
11328 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11329 } catch (ImsException e) {
11330 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11331 } finally {
11332 Binder.restoreCallingIdentity(identity);
11333 }
11334 }
11335
James.cf Line8713a42021-04-29 16:04:26 +080011336 /**
11337 * Remove UCE requests cannot be sent to the network status.
11338 */
11339 // Used for SHELL command only right now.
11340 @Override
11341 public boolean removeUceRequestDisallowedStatus(int subId) {
11342 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11343 final long identity = Binder.clearCallingIdentity();
11344 try {
11345 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11346 } catch (ImsException e) {
11347 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11348 } finally {
11349 Binder.restoreCallingIdentity(identity);
11350 }
11351 }
11352
James.cf Lin18bb9002021-05-25 01:37:38 +080011353 /**
11354 * Remove UCE requests cannot be sent to the network status.
11355 */
11356 // Used for SHELL command only.
11357 @Override
11358 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11359 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11360 final long identity = Binder.clearCallingIdentity();
11361 try {
11362 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11363 } catch (ImsException e) {
11364 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11365 } finally {
11366 Binder.restoreCallingIdentity(identity);
11367 }
11368 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011369
James.cf Lin4b784aa2021-01-31 03:25:15 +080011370 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011371 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11372 String callingPackage) {
11373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11374 mApp, subId, "setSignalStrengthUpdateRequest");
11375
11376 final int callingUid = Binder.getCallingUid();
11377 // Verify that tha callingPackage belongs to the calling UID
11378 mApp.getSystemService(AppOpsManager.class)
11379 .checkPackage(callingUid, callingPackage);
11380
Rambo Wang3607f502021-02-01 21:51:40 -080011381 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011382
11383 final long identity = Binder.clearCallingIdentity();
11384 try {
11385 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11386 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11387
11388 if (result instanceof IllegalStateException) {
11389 throw (IllegalStateException) result;
11390 }
11391 } finally {
11392 Binder.restoreCallingIdentity(identity);
11393 }
11394 }
11395
11396 @Override
11397 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11398 String callingPackage) {
11399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11400 mApp, subId, "clearSignalStrengthUpdateRequest");
11401
11402 final int callingUid = Binder.getCallingUid();
11403 // Verify that tha callingPackage belongs to the calling UID
11404 mApp.getSystemService(AppOpsManager.class)
11405 .checkPackage(callingUid, callingPackage);
11406
11407 final long identity = Binder.clearCallingIdentity();
11408 try {
11409 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11410 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11411
11412 if (result instanceof IllegalStateException) {
11413 throw (IllegalStateException) result;
11414 }
11415 } finally {
11416 Binder.restoreCallingIdentity(identity);
11417 }
11418 }
11419
Rambo Wang3607f502021-02-01 21:51:40 -080011420 private static void validateSignalStrengthUpdateRequest(Context context,
11421 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011422 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11423 // phone/system process do not have further restriction on request
11424 return;
11425 }
11426
11427 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011428 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011429 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011430 context.enforceCallingOrSelfPermission(
11431 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11432 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011433 }
11434
11435 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011436 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011437 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011438 || info.isEnabled()) {
11439 throw new IllegalArgumentException(
11440 "Only system can set hide fields in SignalThresholdInfo");
11441 }
11442
11443 // Thresholds length for each RAN need in range. This has been validated in
11444 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11445 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11446 final int[] thresholds = info.getThresholds();
11447 Objects.requireNonNull(thresholds);
11448 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11449 || thresholds.length
11450 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11451 throw new IllegalArgumentException(
11452 "thresholds length is out of range: " + thresholds.length);
11453 }
11454 }
11455 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011456
11457 /**
11458 * Gets the current phone capability.
11459 *
11460 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11461 * @return the PhoneCapability which describes the data connection capability of modem.
11462 * It's used to evaluate possible phone config change, for example from single
11463 * SIM device to multi-SIM device.
11464 */
11465 @Override
11466 public PhoneCapability getPhoneCapability() {
11467 enforceReadPrivilegedPermission("getPhoneCapability");
11468 final long identity = Binder.clearCallingIdentity();
11469 try {
11470 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11471 } finally {
11472 Binder.restoreCallingIdentity(identity);
11473 }
11474 }
Michele Berionne5e411512020-11-13 02:36:59 +000011475
11476 /**
11477 * Prepare TelephonyManager for an unattended reboot. The reboot is
11478 * required to be done shortly after the API is invoked.
11479 */
11480 @Override
11481 @TelephonyManager.PrepareUnattendedRebootResult
11482 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011483 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011484 enforceRebootPermission();
11485
11486 final long identity = Binder.clearCallingIdentity();
11487 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011488 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011489 } finally {
11490 Binder.restoreCallingIdentity(identity);
11491 }
11492 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011493
11494 /**
11495 * Request to get the current slicing configuration including URSP rules and
11496 * NSSAIs (configured, allowed and rejected).
11497 *
11498 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11499 */
11500 @Override
11501 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011502 TelephonyPermissions
11503 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11504 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011505
11506 final long identity = Binder.clearCallingIdentity();
11507 try {
11508 Phone phone = getDefaultPhone();
11509 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11510 } finally {
11511 Binder.restoreCallingIdentity(identity);
11512 }
11513 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011514
11515 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011516 * Check whether the given premium capability is available for purchase from the carrier.
11517 *
11518 * @param capability The premium capability to check.
11519 * @param subId The subId to check the premium capability for.
11520 *
11521 * @return Whether the given premium capability is available to purchase.
11522 */
11523 @Override
11524 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11525 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11526 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11527 log("Premium capability "
11528 + TelephonyManager.convertPremiumCapabilityToString(capability)
11529 + " is not available for purchase due to missing permissions.");
11530 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11531 + "permission READ_BASIC_PHONE_STATE.");
11532 }
11533
11534 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011535 if (phone == null) {
11536 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11537 return false;
11538 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011539 final long identity = Binder.clearCallingIdentity();
11540 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011541 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011542 .isPremiumCapabilityAvailableForPurchase(capability);
11543 } finally {
11544 Binder.restoreCallingIdentity(identity);
11545 }
11546 }
11547
11548 /**
11549 * Purchase the given premium capability from the carrier.
11550 *
11551 * @param capability The premium capability to purchase.
11552 * @param callback The result of the purchase request.
11553 * @param subId The subId to purchase the premium capability for.
11554 */
11555 @Override
11556 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11557 log("purchasePremiumCapability: capability="
11558 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11559 + getCurrentPackageName());
11560
11561 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11562 mApp, "purchasePremiumCapability")) {
11563 log("purchasePremiumCapability "
11564 + TelephonyManager.convertPremiumCapabilityToString(capability)
11565 + " failed due to missing permissions.");
11566 throw new SecurityException("purchasePremiumCapability requires permission "
11567 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011568 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11569 mApp, "purchasePremiumCapability")) {
11570 log("purchasePremiumCapability "
11571 + TelephonyManager.convertPremiumCapabilityToString(capability)
11572 + " failed due to missing permissions.");
11573 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011574 }
11575
11576 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011577 if (phone == null) {
11578 try {
11579 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11580 callback.accept(result);
11581 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11582 } catch (RemoteException e) {
11583 String logStr = "Purchase premium capability "
11584 + TelephonyManager.convertPremiumCapabilityToString(capability)
11585 + " failed due to RemoteException handling null phone: " + e;
11586 if (DBG) log(logStr);
11587 AnomalyReporter.reportAnomaly(
11588 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11589 }
11590 return;
11591 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011592
11593 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011594 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011595 callingProcess = mApp.getPackageManager().getApplicationInfo(
11596 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011597 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011598 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011599 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011600
11601 boolean isVisible = false;
11602 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11603 if (am != null) {
11604 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11605 if (processes != null) {
11606 for (ActivityManager.RunningAppProcessInfo process : processes) {
11607 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011608 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011609 if (process.processName.equals(callingProcess) && process.importance
11610 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11611 isVisible = true;
11612 break;
11613 }
11614 }
11615 }
11616 }
11617
11618 if (!isVisible) {
11619 try {
11620 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11621 callback.accept(result);
11622 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11623 } catch (RemoteException e) {
11624 String logStr = "Purchase premium capability "
11625 + TelephonyManager.convertPremiumCapabilityToString(capability)
11626 + " failed due to RemoteException handling background application: " + e;
11627 if (DBG) log(logStr);
11628 AnomalyReporter.reportAnomaly(
11629 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11630 }
11631 return;
11632 }
11633
Sarah Chin71b3a852022-09-28 15:54:19 -070011634 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011635 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011636 }
11637
11638 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011639 * Register an IMS connection state callback
11640 */
11641 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011642 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11643 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011644 if (feature == ImsFeature.FEATURE_MMTEL) {
11645 // ImsMmTelManager
11646 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11647 TelephonyPermissions
11648 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11649 mApp, subId, "registerImsStateCallback");
11650 } else if (feature == ImsFeature.FEATURE_RCS) {
11651 // ImsRcsManager or SipDelegateManager
11652 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11653 Binder.getCallingUid(), "registerImsStateCallback",
11654 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11655 Manifest.permission.READ_PRECISE_PHONE_STATE,
11656 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11657 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11658 }
11659
11660 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11661 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11662 "IMS not available on device.");
11663 }
11664
11665 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11666 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11667 }
11668
11669 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11670 if (controller == null) {
11671 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11672 "IMS not available on device.");
11673 }
11674
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011675 if (callingPackage == null) {
11676 callingPackage = getCurrentPackageName();
11677 }
11678
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011679 final long token = Binder.clearCallingIdentity();
11680 try {
11681 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011682 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011683 } catch (ImsException e) {
11684 throw new ServiceSpecificException(e.getCode());
11685 } finally {
11686 Binder.restoreCallingIdentity(token);
11687 }
11688 }
11689
11690 /**
11691 * Unregister an IMS connection state callback
11692 */
11693 @Override
11694 public void unregisterImsStateCallback(IImsStateCallback cb) {
11695 final long token = Binder.clearCallingIdentity();
11696 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11697 if (controller == null) {
11698 return;
11699 }
11700 try {
11701 controller.unregisterImsStateCallback(cb);
11702 } finally {
11703 Binder.restoreCallingIdentity(token);
11704 }
11705 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011706
11707 /**
11708 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11709 *
11710 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11711 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11712 * SecurityException.
11713 * If there is current registered network this value will be same as the registered cell
11714 * identity. If the device goes out of service the previous cell identity is cached and
11715 * will be returned. If the cache age of the Cell identity is more than 24 hours
11716 * it will be cleared and null will be returned.
11717 *
11718 */
11719 @Override
11720 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11721 String callingFeatureId) {
11722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11723 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11724 LocationAccessPolicy.checkLocationPermission(mApp,
11725 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11726 .setCallingPackage(callingPackage)
11727 .setCallingFeatureId(callingFeatureId)
11728 .setCallingPid(Binder.getCallingPid())
11729 .setCallingUid(Binder.getCallingUid())
11730 .setMethod("getLastKnownCellIdentity")
11731 .setLogAsInfo(true)
11732 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11733 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11734 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11735 .build());
11736
11737 boolean hasFinePermission =
11738 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11739 if (!hasFinePermission
11740 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11741 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011742 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011743 }
11744
11745 final long identity = Binder.clearCallingIdentity();
11746 try {
Ling Mac28f0212023-03-24 16:07:15 -070011747 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011748 if (sst == null) return null;
11749 return sst.getLastKnownCellIdentity();
11750 } finally {
11751 Binder.restoreCallingIdentity(identity);
11752 }
11753 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011754
jimsun3b9ccac2021-10-26 15:01:23 +080011755 /**
11756 * Sets the modem service class Name that Telephony will bind to.
11757 *
11758 * @param serviceName The class name of the modem service.
11759 * @return true if the operation is succeed, otherwise false.
11760 */
11761 public boolean setModemService(String serviceName) {
11762 Log.d(LOG_TAG, "setModemService - " + serviceName);
11763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011765 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11766 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011767 return mPhoneConfigurationManager.setModemService(serviceName);
11768 }
11769
11770 /**
11771 * Return the class name of the currently bounded modem service.
11772 *
11773 * @return the class name of the modem service.
11774 */
11775 public String getModemService() {
11776 String result;
11777 Log.d(LOG_TAG, "getModemService");
11778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11779 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011780 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011781 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11782 "getModemService");
11783 result = mPhoneConfigurationManager.getModemService();
11784 Log.d(LOG_TAG, "result = " + result);
11785 return result;
11786 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011787
11788 @Override
11789 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11790 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11791 mApp.enforceCallingOrSelfPermission(
11792 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11794
11795 final long identity = Binder.clearCallingIdentity();
11796 try {
11797 Phone phone = getPhone(subId);
11798 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011799 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11800 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011801 phone.setVoiceServiceStateOverride(hasService);
11802 } finally {
11803 Binder.restoreCallingIdentity(identity);
11804 }
11805 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011806
11807 /**
11808 * set removable eSIM as default eUICC.
11809 *
11810 * @hide
11811 */
11812 @Override
11813 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11814 enforceModifyPermission();
11815 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11816
11817 final long identity = Binder.clearCallingIdentity();
11818 try {
11819 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11820 } finally {
11821 Binder.restoreCallingIdentity(identity);
11822 }
11823 }
11824
11825 /**
11826 * Returns whether the removable eSIM is default eUICC or not.
11827 *
11828 * @hide
11829 */
11830 @Override
11831 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11832 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11833 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11834
11835 final long identity = Binder.clearCallingIdentity();
11836 try {
11837 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11838 } finally {
11839 Binder.restoreCallingIdentity(identity);
11840 }
11841 }
11842
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011843 /**
11844 * Get the component name of the default app to direct respond-via-message intent for the
11845 * user associated with this subscription, update the cache if there is no respond-via-message
11846 * application currently configured for this user.
11847 * @return component name of the app and class to direct Respond Via Message intent to, or
11848 * {@code null} if the functionality is not supported.
11849 * @hide
11850 */
11851 @Override
11852 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11853 boolean updateIfNeeded) {
11854 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011855
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011856 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11857
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011858 UserHandle userHandle = null;
11859 final long identity = Binder.clearCallingIdentity();
11860 try {
11861 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11862 } finally {
11863 Binder.restoreCallingIdentity(identity);
11864 }
11865 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11866 updateIfNeeded, userHandle);
11867 }
Jack Yuf5badd92022-12-08 00:50:53 -080011868
11869 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011870 * Set whether the device is able to connect with null ciphering or integrity
11871 * algorithms. This is a global setting and will apply to all active subscriptions
11872 * and all new subscriptions after this.
11873 *
11874 * @param enabled when true, null cipher and integrity algorithms are allowed.
11875 * @hide
11876 */
11877 @Override
11878 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11879 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11880 enforceModifyPermission();
11881 checkForNullCipherAndIntegritySupport();
11882
11883 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11884 // for listening to these preference changes and applying them immediately.
11885 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11886 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11887 editor.apply();
11888
11889 for (Phone phone: PhoneFactory.getPhones()) {
11890 phone.handleNullCipherEnabledChange();
11891 }
11892 }
11893
11894
11895 /**
11896 * Get whether the device is able to connect with null ciphering or integrity
11897 * algorithms. Note that this retrieves the phone-global preference and not
11898 * the state of the radio.
11899 *
11900 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11901 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11902 * version for this feature.
11903 * @hide
11904 */
11905 @Override
11906 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11907 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11908 enforceReadPermission();
11909 checkForNullCipherAndIntegritySupport();
11910 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11911 }
11912
11913 private void checkForNullCipherAndIntegritySupport() {
11914 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11915 throw new UnsupportedOperationException(
11916 "Null cipher and integrity operations require HAL 2.1 or above");
11917 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011918 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11919 throw new UnsupportedOperationException(
11920 "Null cipher and integrity operations unsupported by modem");
11921 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011922 }
11923
11924 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011925 * Get the SIM state for the slot index.
11926 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11927 *
11928 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11929 */
11930 @Override
11931 @SimState
11932 public int getSimStateForSlotIndex(int slotIndex) {
11933 IccCardConstants.State simState;
11934 if (slotIndex < 0) {
11935 simState = IccCardConstants.State.UNKNOWN;
11936 } else {
11937 Phone phone = null;
11938 try {
11939 phone = PhoneFactory.getPhone(slotIndex);
11940 } catch (IllegalStateException e) {
11941 // ignore
11942 }
11943 if (phone == null) {
11944 simState = IccCardConstants.State.UNKNOWN;
11945 } else {
11946 IccCard icc = phone.getIccCard();
11947 if (icc == null) {
11948 simState = IccCardConstants.State.UNKNOWN;
11949 } else {
11950 simState = icc.getState();
11951 }
11952 }
11953 }
11954 return simState.ordinal();
11955 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011956
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011957 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11958 boolean enableLogcat,
11959 long logcatStartTimestampMillis, boolean enableTelecomDump,
11960 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011961 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11962 TelephonyManager.EmergencyCallDiagnosticParams edp =
11963 new TelephonyManager.EmergencyCallDiagnosticParams();
11964 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11965 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11966 edp.setTelecomDumpSysCollection(enableTelecomDump);
11967 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11968 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
11969 Executors.newCachedThreadPool(), db,
11970 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
11971 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011972 }
11973
11974 /**
11975 * Request telephony to persist state for debugging emergency call failures.
11976 *
11977 * @param dropBoxTag Tag to use when persisting data to dropbox service.
11978 * @param enableLogcat whether to collect logcat output
11979 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
11980 * @param enableTelecomDump whether to collect telecom dumpsys
11981 * @param enableTelephonyDump whether to collect telephony dumpsys
11982 */
11983 @Override
11984 @RequiresPermission(android.Manifest.permission.DUMP)
11985 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
11986 long logcatStartTimestampMillis, boolean enableTelecomDump,
11987 boolean enableTelephonyDump) {
11988 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
11989 "persistEmergencyCallDiagnosticData");
11990 final long identity = Binder.clearCallingIdentity();
11991 try {
11992 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
11993 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
11994
11995 } finally {
11996 Binder.restoreCallingIdentity(identity);
11997 }
11998 }
11999
Hui Wang9b5793a2022-12-05 14:38:06 -060012000 /**
12001 * Get current cell broadcast ranges.
12002 */
12003 @Override
12004 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12005 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12006 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12007 "getCellBroadcastIdRanges");
12008 final long identity = Binder.clearCallingIdentity();
12009 try {
12010 return getPhone(subId).getCellBroadcastIdRanges();
12011 } finally {
12012 Binder.restoreCallingIdentity(identity);
12013 }
12014 }
12015
12016 /**
12017 * Set reception of cell broadcast messages with the list of the given ranges
12018 *
12019 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12020 */
12021 @Override
12022 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12023 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12024 @Nullable IIntegerConsumer callback) {
12025 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12026 "setCellBroadcastIdRanges");
12027 final long identity = Binder.clearCallingIdentity();
12028 try {
12029 Phone phone = getPhoneFromSubId(subId);
12030 if (DBG) {
12031 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12032 }
12033 phone.setCellBroadcastIdRanges(ranges, result -> {
12034 if (callback != null) {
12035 try {
12036 callback.accept(result);
12037 } catch (RemoteException e) {
12038 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12039 }
12040 }
12041 });
12042 } finally {
12043 Binder.restoreCallingIdentity(identity);
12044 }
12045 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012046
12047 /**
12048 * Returns whether the device supports the domain selection service.
12049 *
12050 * @return {@code true} if the device supports the domain selection service.
12051 */
12052 @Override
12053 public boolean isDomainSelectionSupported() {
12054 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12055 "isDomainSelectionSupported");
12056
12057 final long identity = Binder.clearCallingIdentity();
12058 try {
12059 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12060 } finally {
12061 Binder.restoreCallingIdentity(identity);
12062 }
12063 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012064
12065 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012066 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12067 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12068 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012069 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012070 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012071 * @param enableSatellite {@code true} to enable the satellite modem and
12072 * {@code false} to disable.
12073 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12074 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012075 *
12076 * @throws SecurityException if the caller doesn't have the required permission.
12077 */
12078 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012079 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12080 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012081 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012082 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12083 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012084 }
12085
12086 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012087 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012088 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012089 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012090 * @param result The result receiver that returns whether the satellite modem is enabled
12091 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012092 *
12093 * @throws SecurityException if the caller doesn't have the required permission.
12094 */
12095 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012096 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12097 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012098 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012099 }
12100
12101 /**
Sarah Chin43457982023-02-15 17:50:38 -080012102 * Request to get whether the satellite service demo mode is enabled.
12103 *
12104 * @param subId The subId of the subscription to check whether the satellite demo mode
12105 * is enabled for.
12106 * @param result The result receiver that returns whether the satellite demo mode is enabled
12107 * if the request is successful or an error code if the request failed.
12108 *
12109 * @throws SecurityException if the caller doesn't have the required permission.
12110 */
12111 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012112 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12113 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12114 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012115 }
12116
12117 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012118 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012119 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012120 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012121 * @param result The result receiver that returns whether the satellite service is supported on
12122 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012123 */
12124 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012125 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012126 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012127 }
12128
12129 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012130 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012131 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012132 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012133 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12134 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012135 *
12136 * @throws SecurityException if the caller doesn't have required permission.
12137 */
12138 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012139 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12140 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012141 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012142 }
12143
12144 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012145 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012146 * This can be called by the pointing UI when the user starts pointing to the satellite.
12147 * Modem should continue to report the pointing input as the device or satellite moves.
12148 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012149 * @param subId The subId of the subscription to start satellite transmission updates for.
12150 * @param resultCallback The callback to get the result of the request.
12151 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012152 *
12153 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012154 */
12155 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012156 public void startSatelliteTransmissionUpdates(int subId,
12157 @NonNull IIntegerConsumer resultCallback,
12158 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12159 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12160 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012161 }
12162
12163 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012164 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012165 * This can be called by the pointing UI when the user stops pointing to the satellite.
12166 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012167 * @param subId The subId of the subscription to stop satellite transmission updates for.
12168 * @param resultCallback The callback to get the result of the request.
12169 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12170 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012171 *
12172 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012173 */
12174 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012175 public void stopSatelliteTransmissionUpdates(int subId,
12176 @NonNull IIntegerConsumer resultCallback,
12177 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12178 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12179 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012180 }
12181
12182 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012183 * Register the subscription with a satellite provider.
12184 * This is needed to register the subscription if the provider allows dynamic registration.
12185 *
12186 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012187 * @param token The token to be used as a unique identifier for provisioning with satellite
12188 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012189 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012190 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012191 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012192 * @return The signal transport used by the caller to cancel the provision request,
12193 * or {@code null} if the request failed.
12194 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012195 * @throws SecurityException if the caller doesn't have the required permission.
12196 */
12197 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012198 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012199 @NonNull String token, @NonNull byte[] provisionData,
12200 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012201 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012202 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12203 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012204 }
12205
12206 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012207 * Unregister the device/subscription with the satellite provider.
12208 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012209 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012210 * should report as deprovisioned.
12211 *
12212 * @param subId The subId of the subscription to be deprovisioned.
12213 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012214 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012215 *
12216 * @throws SecurityException if the caller doesn't have the required permission.
12217 */
12218 @Override
12219 public void deprovisionSatelliteService(int subId,
12220 @NonNull String token, @NonNull IIntegerConsumer callback) {
12221 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012222 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012223 }
12224
12225 /**
Sarah Chin43457982023-02-15 17:50:38 -080012226 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012227 *
Sarah Chin43457982023-02-15 17:50:38 -080012228 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012229 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012230 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012231 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12232 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012233 * @throws SecurityException if the caller doesn't have the required permission.
12234 */
12235 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012236 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012237 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012238 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012239 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012240 }
12241
12242 /**
Sarah Chin43457982023-02-15 17:50:38 -080012243 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012244 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012245 *
Sarah Chin43457982023-02-15 17:50:38 -080012246 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012247 * @param callback The callback that was passed to
12248 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012249 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012250 * @throws SecurityException if the caller doesn't have the required permission.
12251 */
12252 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012253 public void unregisterForSatelliteProvisionStateChanged(
12254 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012255 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012256 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012257 }
12258
12259 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012260 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012261 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012262 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012263 * @param result The result receiver that returns whether the device is provisioned with a
12264 * satellite provider if the request is successful or an error code if the
12265 * request failed.
12266 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012267 * @throws SecurityException if the caller doesn't have the required permission.
12268 */
12269 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012270 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12271 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012272 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012273 }
12274
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012275 /**
Sarah Chin43457982023-02-15 17:50:38 -080012276 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012277 *
Sarah Chin43457982023-02-15 17:50:38 -080012278 * @param subId The subId of the subscription to register for satellite modem state changed.
12279 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012280 *
12281 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12282 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012283 * @throws SecurityException if the caller doesn't have the required permission.
12284 */
12285 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012286 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012287 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012288 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012289 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012290 }
12291
12292 /**
Sarah Chin43457982023-02-15 17:50:38 -080012293 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012294 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012295 *
Sarah Chin43457982023-02-15 17:50:38 -080012296 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012297 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012298 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012299 *
12300 * @throws SecurityException if the caller doesn't have the required permission.
12301 */
12302 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012303 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012304 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012305 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012306 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012307 }
12308
12309 /**
12310 * Register to receive incoming datagrams over satellite.
12311 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012312 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012313 * @param callback The callback to handle incoming datagrams over satellite.
12314 *
12315 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12316 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012317 * @throws SecurityException if the caller doesn't have the required permission.
12318 */
12319 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012320 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012321 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012322 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012323 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012324 }
12325
12326 /**
12327 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012328 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012329 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012330 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12331 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012332 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012333 *
12334 * @throws SecurityException if the caller doesn't have the required permission.
12335 */
12336 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012337 public void unregisterForSatelliteDatagram(int subId,
12338 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012339 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012340 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012341 }
12342
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012343 /**
12344 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012345 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012346 * This method requests modem to check if there are any pending datagrams to be received over
12347 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012348 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012349 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012350 * @param subId The subId of the subscription used for receiving datagrams.
12351 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012352 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012353 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012354 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012355 @Override
12356 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012357 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012358 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012359 }
12360
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012361 /**
12362 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012363 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012364 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12365 * input to this method. Datagram received here will be passed down to modem without any
12366 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012367 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012368 * @param subId The subId of the subscription to send satellite datagrams for.
12369 * @param datagramType datagram type indicating whether the datagram is of type
12370 * SOS_SMS or LOCATION_SHARING.
12371 * @param datagram encoded gateway datagram which is encrypted by the caller.
12372 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012373 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12374 * full screen mode.
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012375 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012376 *
12377 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012378 */
12379 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012380 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12381 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12382 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012383 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012384 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12385 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012386 }
12387
Sarah Chindf715ec2023-02-13 13:46:24 -080012388 /**
12389 * Request to get whether satellite communication is allowed for the current location.
12390 *
12391 * @param subId The subId of the subscription to check whether satellite communication is
12392 * allowed for the current location for.
12393 * @param result The result receiver that returns whether satellite communication is allowed
12394 * for the current location if the request is successful or an error code
12395 * if the request failed.
12396 *
12397 * @throws SecurityException if the caller doesn't have the required permission.
12398 */
12399 @Override
12400 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12401 @NonNull ResultReceiver result) {
12402 enforceSatelliteCommunicationPermission(
12403 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012404 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12405 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012406 }
12407
12408 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012409 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012410 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012411 * @param subId The subId to get the time after which the satellite will be visible for.
12412 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012413 * be visible if the request is successful or an error code if the request failed.
12414 *
12415 * @throws SecurityException if the caller doesn't have the required permission.
12416 */
12417 @Override
12418 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12419 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012420 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012421 }
12422
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012423 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012424 * Inform that Device is aligned to satellite for demo mode.
12425 *
12426 * @param subId The subId to get the time after which the satellite will be visible for.
12427 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12428 * {@code false} Device fails to align with the satellite for demo mode.
12429 *
12430 * @throws SecurityException if the caller doesn't have required permission.
12431 */
12432 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12433
12434 public void onDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
12435 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
12436 mSatelliteController.onDeviceAlignedWithSatellite(subId, isAligned);
12437 }
12438
12439 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012440 * This API can be used by only CTS to update satellite vendor service package name.
12441 *
12442 * @param servicePackageName The package name of the satellite vendor service.
12443 * @return {@code true} if the satellite vendor service is set successfully,
12444 * {@code false} otherwise.
12445 */
12446 public boolean setSatelliteServicePackageName(String servicePackageName) {
12447 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12448 TelephonyPermissions.enforceShellOnly(
12449 Binder.getCallingUid(), "setSatelliteServicePackageName");
12450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12451 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12452 "setSatelliteServicePackageName");
12453 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12454 }
12455
12456 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012457 * This API can be used by only CTS to update satellite gateway service package name.
12458 *
12459 * @param servicePackageName The package name of the satellite gateway service.
12460 * @return {@code true} if the satellite gateway service is set successfully,
12461 * {@code false} otherwise.
12462 */
12463 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12464 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12465 TelephonyPermissions.enforceShellOnly(
12466 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12468 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12469 "setSatelliteGatewayServicePackageName");
12470 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12471 }
12472
12473 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012474 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12475 *
12476 * @param packageName The package name of the satellite pointing UI app.
12477 * @param className The class name of the satellite pointing UI app.
12478 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12479 * {@code false} otherwise.
12480 */
12481 public boolean setSatellitePointingUiClassName(
12482 @Nullable String packageName, @Nullable String className) {
12483 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12484 + ", className=" + className);
12485 TelephonyPermissions.enforceShellOnly(
12486 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12488 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12489 "setSatelliteGatewayServicePackageName");
12490 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12491 }
12492
12493 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012494 * This API can be used by only CTS to update the timeout duration in milliseconds that
12495 * satellite should stay at listening mode to wait for the next incoming page before disabling
12496 * listening mode.
12497 *
12498 * @param timeoutMillis The timeout duration in millisecond.
12499 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12500 */
12501 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12502 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12503 TelephonyPermissions.enforceShellOnly(
12504 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12506 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12507 "setSatelliteListeningTimeoutDuration");
12508 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12509 }
12510
12511 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012512 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12513 * the device is aligned with the satellite for demo mode
12514 *
12515 * @param timeoutMillis The timeout duration in millisecond.
12516 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12517 */
12518 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12519 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12520 TelephonyPermissions.enforceShellOnly(
12521 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12523 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12524 "setDeviceAlignedTimeoutDuration");
12525 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12526 }
12527
12528 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012529 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12530 *
12531 * <p>This method behaves in one of the following ways:
12532 * <ul>
12533 * <li>return true : if the calling package has the appop permission {@link
12534 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12535 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12536 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12537 * Owner device identifier access check, or the calling package has carrier privileges</>
12538 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12539 * </ul>
12540 */
12541 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12542 String callingPackage, @Nullable String callingFeatureId, String message) {
12543 for (Phone phone : PhoneFactory.getPhones()) {
12544 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12545 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12546 return true;
12547 }
12548 }
12549 return false;
12550 }
arunvoddud7401012022-12-15 16:08:12 +000012551
12552 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012553 * @return The subscription manager service instance.
12554 */
12555 public SubscriptionManagerService getSubscriptionManagerService() {
12556 return SubscriptionManagerService.getInstance();
12557 }
12558
12559 /**
arunvoddud7401012022-12-15 16:08:12 +000012560 * Class binds the consumer[callback] and carrierId.
12561 */
12562 private static class CallerCallbackInfo {
12563 private final Consumer<Integer> mConsumer;
12564 private final int mCarrierId;
12565
12566 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12567 mConsumer = consumer;
12568 mCarrierId = carrierId;
12569 }
12570
12571 public Consumer<Integer> getConsumer() {
12572 return mConsumer;
12573 }
12574
12575 public int getCarrierId() {
12576 return mCarrierId;
12577 }
12578 }
Jack Yufa8ed012023-02-11 15:42:28 -080012579}