blob: 21862fb5786aab7a412331cdb3961c58922b08df [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;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000299 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
300 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700301 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
302 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
303 private static final int CMD_EXCHANGE_SIM_IO = 31;
304 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800305 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
306 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700307 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
308 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700309 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
310 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700311 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
312 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
313 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
314 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700315 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
316 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
317 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
318 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700319 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800320 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
321 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000322 private static final int CMD_SWITCH_SLOTS = 50;
323 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700324 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
325 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
326 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
327 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
328 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
329 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
330 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
331 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700332 private static final int CMD_GET_ALL_CELL_INFO = 60;
333 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
334 private static final int CMD_GET_CELL_LOCATION = 62;
335 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700336 private static final int CMD_MODEM_REBOOT = 64;
337 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700338 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
339 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800340 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
341 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700342 private static final int CMD_GET_MODEM_STATUS = 70;
343 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700344 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
345 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700346 private static final int CMD_ERASE_MODEM_CONFIG = 74;
347 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800348 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
349 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
350 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
351 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800352 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
353 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800354 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800355 private static final int CMD_GET_CALL_FORWARDING = 83;
356 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
357 private static final int CMD_SET_CALL_FORWARDING = 85;
358 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
359 private static final int CMD_GET_CALL_WAITING = 87;
360 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
361 private static final int CMD_SET_CALL_WAITING = 89;
362 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700363 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
364 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
365 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
366 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700367 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
368 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800369 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
370 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800371 private static final int CMD_SET_DATA_THROTTLING = 99;
372 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800373 private static final int CMD_SET_SIM_POWER = 101;
374 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800375 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
376 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
377 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
378 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800379 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
380 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000381 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800382 private static final int CMD_GET_SLICING_CONFIG = 110;
383 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800384 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700385 private static final int CMD_ENABLE_VONR = 113;
386 private static final int EVENT_ENABLE_VONR_DONE = 114;
387 private static final int CMD_IS_VONR_ENABLED = 115;
388 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700389 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
390 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000391
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800392 // Parameters of select command.
393 private static final int SELECT_COMMAND = 0xA4;
394 private static final int SELECT_P1 = 0x04;
395 private static final int SELECT_P2 = 0;
396 private static final int SELECT_P3 = 0x10;
397
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000398 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
399 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 /** The singleton instance. */
402 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800403 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
Sarah Chin4beb2b72023-02-14 14:47:54 -0800405 private final PhoneGlobals mApp;
406 private final CallManager mCM;
407 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000408
409 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800410 private final UserManager mUserManager;
411 private final AppOpsManager mAppOps;
412 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800413 private final SharedPreferences mTelephonySharedPreferences;
414 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800415 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
Peter Wangdafb9ac2020-01-15 14:13:38 -0800417 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800418 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800419 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
420
Sarah Chin4beb2b72023-02-14 14:47:54 -0800421 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800422
Derek Tan97ebb422014-09-05 16:55:38 -0700423 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
424 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800425 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800426 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700427
Michelecea4cf22018-12-21 15:00:11 -0800428 // String to store multi SIM allowed
429 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
430
Derek Tan740e1672017-06-27 14:56:27 -0700431 // The AID of ISD-R.
432 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
433
yinxub1bed742017-04-17 11:45:04 -0700434 private NetworkScanRequestTracker mNetworkScanRequestTracker;
435
David Kelly5e06a7f2018-03-12 14:10:59 +0000436 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
437 private static final int MANUFACTURER_CODE_LENGTH = 8;
438
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800439 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800440 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800441
Sarah Chin2ec39f62022-08-31 17:03:26 -0700442 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
443 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
444
Derek Tan89e89d42014-07-08 17:00:10 -0700445 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700446 * Experiment flag to enable erase modem config on reset network, default value is false
447 */
448 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
449 "reset_network_erase_modem_config_enabled";
450
Rambo Wang0f050d82021-02-12 11:43:36 -0800451 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800452
Gary Jian76280a42022-12-07 16:18:33 +0800453 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
454
sandeepjsb6c87872021-09-27 15:34:44 +0000455 /**
456 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
457 * one ICCID active at the same time.
458 * Apps should use below API signatures if targeting SDK is T and beyond.
459 *
460 * @hide
461 */
462 @ChangeId
463 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
464 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800465
Naina Nallurid63128d2019-09-17 14:10:30 -0700466 /**
Chen Xu540470b2021-12-14 17:15:47 -0800467 * Apps targeting on Android T and beyond will get exception whenever icc close channel
468 * operation fails.
469 */
470 @ChangeId
471 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
472 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
473
474 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 * A request object to use for transmitting data to an ICC.
476 */
477 private static final class IccAPDUArgument {
478 public int channel, cla, command, p1, p2, p3;
479 public String data;
480
481 public IccAPDUArgument(int channel, int cla, int command,
482 int p1, int p2, int p3, String data) {
483 this.channel = channel;
484 this.cla = cla;
485 this.command = command;
486 this.p1 = p1;
487 this.p2 = p2;
488 this.p3 = p3;
489 this.data = data;
490 }
491 }
492
493 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700494 * A request object to use for transmitting data to an ICC.
495 */
496 private static final class ManualNetworkSelectionArgument {
497 public OperatorInfo operatorInfo;
498 public boolean persistSelection;
499
500 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
501 this.operatorInfo = operatorInfo;
502 this.persistSelection = persistSelection;
503 }
504 }
505
Sarah Chin71b3a852022-09-28 15:54:19 -0700506 private static final class PurchasePremiumCapabilityArgument {
507 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700508 public @NonNull IIntegerConsumer callback;
509
510 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800511 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700512 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 this.callback = callback;
514 }
515 }
516
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700517 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
519 * request after sending. The main thread will notify the request when it is complete.
520 */
521 private static final class MainThreadRequest {
522 /** The argument to use for the request */
523 public Object argument;
524 /** The result of the request that is run on the main thread */
525 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800526 // The subscriber id that this request applies to. Defaults to
527 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
528 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529
Nathan Harold92bed182018-10-12 18:16:49 -0700530 // In cases where subId is unavailable, the caller needs to specify the phone.
531 public Phone phone;
532
vagdeviaf9a5b92018-08-15 16:01:53 -0700533 public WorkSource workSource;
534
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 public MainThreadRequest(Object argument) {
536 this.argument = argument;
537 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800538
Nathan Harold92bed182018-10-12 18:16:49 -0700539 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
540 this.argument = argument;
541 if (phone != null) {
542 this.phone = phone;
543 }
544 this.workSource = workSource;
545 }
546
vagdeviaf9a5b92018-08-15 16:01:53 -0700547 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800548 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800549 if (subId != null) {
550 this.subId = subId;
551 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700552 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554 }
555
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800556 private static final class IncomingThirdPartyCallArgs {
557 public final ComponentName component;
558 public final String callId;
559 public final String callerDisplayName;
560
561 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
562 String callerDisplayName) {
563 this.component = component;
564 this.callId = callId;
565 this.callerDisplayName = callerDisplayName;
566 }
567 }
568
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 /**
570 * A handler that processes messages on the main thread in the phone process. Since many
571 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
572 * inbound binder threads to the main thread in the phone process. The Binder thread
573 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
574 * on, which will be notified when the operation completes and will contain the result of the
575 * request.
576 *
577 * <p>If a MainThreadRequest object is provided in the msg.obj field,
578 * note that request.result must be set to something non-null for the calling thread to
579 * unblock.
580 */
581 private final class MainThreadHandler extends Handler {
582 @Override
583 public void handleMessage(Message msg) {
584 MainThreadRequest request;
585 Message onCompleted;
586 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000587 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800589 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700590
591 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 case CMD_HANDLE_USSD_REQUEST: {
593 request = (MainThreadRequest) msg.obj;
594 final Phone phone = getPhoneFromRequest(request);
595 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800596 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700598
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 if (!isUssdApiAllowed(request.subId)) {
600 // Carrier does not support use of this API, return failure.
601 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
602 UssdResponse response = new UssdResponse(ussdRequest, null);
603 Bundle returnData = new Bundle();
604 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
605 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700606
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 request.result = true;
608 notifyRequester(request);
609 return;
610 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700611
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 try {
613 request.result = phone != null
614 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
615 } catch (CallStateException cse) {
616 request.result = false;
617 }
618 // Wake up the requesting thread
619 notifyRequester(request);
620 break;
pkanwar32d516d2016-10-14 19:37:38 -0700621 }
622
Yorke Lee716f67e2015-06-17 15:39:16 -0700623 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700625 final Phone phone = getPhoneFromRequest(request);
626 request.result = phone != null ?
627 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
628 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700633
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000637 uiccPort = getUiccPortFromRequest(request);
638 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800640 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800644 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000645 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800646 iccArgument.channel, iccArgument.cla, iccArgument.command,
647 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
648 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 ar = (AsyncResult) msg.obj;
654 request = (MainThreadRequest) ar.userObj;
655 if (ar.exception == null && ar.result != null) {
656 request.result = ar.result;
657 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800658 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 if (ar.result == null) {
660 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800661 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800663 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
665 loge("iccTransmitApduLogicalChannel: Unknown exception");
666 }
667 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
672 request = (MainThreadRequest) msg.obj;
673 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000674 uiccPort = getUiccPortFromRequest(request);
675 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800677 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 } else {
680 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800681 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000682 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800683 iccArgument.cla, iccArgument.command, iccArgument.p1,
684 iccArgument.p2,
685 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 }
687 break;
688
689 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
692 if (ar.exception == null && ar.result != null) {
693 request.result = ar.result;
694 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800695 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 if (ar.result == null) {
697 loge("iccTransmitApduBasicChannel: Empty response");
698 } else if (ar.exception instanceof CommandException) {
699 loge("iccTransmitApduBasicChannel: CommandException: " +
700 ar.exception);
701 } else {
702 loge("iccTransmitApduBasicChannel: Unknown exception");
703 }
704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 break;
707
708 case CMD_EXCHANGE_SIM_IO:
709 request = (MainThreadRequest) msg.obj;
710 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000711 uiccPort = getUiccPortFromRequest(request);
712 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800714 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 } else {
717 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
718 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000719 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
721 iccArgument.data, onCompleted);
722 }
723 break;
724
725 case EVENT_EXCHANGE_SIM_IO_DONE:
726 ar = (AsyncResult) msg.obj;
727 request = (MainThreadRequest) ar.userObj;
728 if (ar.exception == null && ar.result != null) {
729 request.result = ar.result;
730 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800731 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700732 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 break;
735
Derek Tan4d5e5c12014-02-04 11:54:58 -0800736 case CMD_SEND_ENVELOPE:
737 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000738 uiccPort = getUiccPortFromRequest(request);
739 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700740 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800741 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700743 } else {
744 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800745 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800747 break;
748
749 case EVENT_SEND_ENVELOPE_DONE:
750 ar = (AsyncResult) msg.obj;
751 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700752 if (ar.exception == null && ar.result != null) {
753 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800754 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800755 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700756 if (ar.result == null) {
757 loge("sendEnvelopeWithStatus: Empty response");
758 } else if (ar.exception instanceof CommandException) {
759 loge("sendEnvelopeWithStatus: CommandException: " +
760 ar.exception);
761 } else {
762 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
763 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800766 break;
767
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 case CMD_OPEN_CHANNEL:
769 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000770 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800771 IccLogicalChannelRequest openChannelRequest =
772 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000773 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800775 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800776 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700777 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700778 } else {
779 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800780 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
781 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 break;
784
785 case EVENT_OPEN_CHANNEL_DONE:
786 ar = (AsyncResult) msg.obj;
787 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700788 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700789 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700790 int[] result = (int[]) ar.result;
791 int channelId = result[0];
792 byte[] selectResponse = null;
793 if (result.length > 1) {
794 selectResponse = new byte[result.length - 1];
795 for (int i = 1; i < result.length; ++i) {
796 selectResponse[i - 1] = (byte) result[i];
797 }
798 }
799 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800800 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800801
802 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700803 if (uiccPort == null) {
804 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
805 } else {
806 IccLogicalChannelRequest channelRequest =
807 (IccLogicalChannelRequest) request.argument;
808 channelRequest.channel = channelId;
809 uiccPort.onLogicalChannelOpened(channelRequest);
810 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 if (ar.result == null) {
813 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700814 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700815 if (ar.exception != null) {
816 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
817 }
818
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700819 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700820 if (ar.exception instanceof CommandException) {
821 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800822 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700823 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700824 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700825 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700826 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700827 }
828 }
829 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800830 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700831 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700832 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700833 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 break;
835
836 case CMD_CLOSE_CHANNEL:
837 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000838 uiccPort = getUiccPortFromRequest(request);
839 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700840 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800841 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800842 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800843 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700844 } else {
845 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000846 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700847 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 break;
849
850 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null) {
854 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800855 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700856 if (uiccPort == null) {
857 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
858 } else {
859 final int channelId = (Integer) request.argument;
860 uiccPort.onLogicalChannelClosed(channelId);
861 }
Chen Xu540470b2021-12-14 17:15:47 -0800862 } else {
863 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800864 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800865 if (ar.exception instanceof CommandException) {
866 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
867 CommandException.Error error =
868 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800869 if (error == CommandException.Error.INVALID_ARGUMENTS) {
870 // should only throw exceptions from the binder threads.
871 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800872 "iccCloseLogicalChannel: invalid argument ");
873 }
874 } else {
875 loge("iccCloseLogicalChannel: Unknown exception");
876 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800877 request.result = (exception != null) ? exception :
878 new IllegalStateException(
879 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800880 }
881 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800882 break;
883
884 case CMD_NV_READ_ITEM:
885 request = (MainThreadRequest) msg.obj;
886 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800887 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
888 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800889 break;
890
891 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700896 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800897 request.result = "";
898 if (ar.result == null) {
899 loge("nvReadItem: Empty response");
900 } else if (ar.exception instanceof CommandException) {
901 loge("nvReadItem: CommandException: " +
902 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700903 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800904 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700905 }
906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700908 break;
909
Jake Hambye994d462014-02-03 13:10:13 -0800910 case CMD_NV_WRITE_ITEM:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
913 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800914 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700915 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
918 case EVENT_NV_WRITE_ITEM_DONE:
919 handleNullReturnEvent(msg, "nvWriteItem");
920 break;
921
922 case CMD_NV_WRITE_CDMA_PRL:
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800925 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800926 break;
927
928 case EVENT_NV_WRITE_CDMA_PRL_DONE:
929 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
930 break;
931
chen xu6dac5ab2018-10-26 17:39:23 -0700932 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800933 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700934 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800935 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800936 break;
937
chen xu6dac5ab2018-10-26 17:39:23 -0700938 case EVENT_RESET_MODEM_CONFIG_DONE:
939 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800940 break;
941
Sooraj Sasindran37444802020-08-11 10:40:43 -0700942 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
945 request);
946 Phone phone = getPhoneFromRequest(request);
947 if (phone != null) {
948 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
949 } else {
950 loge("isNRDualConnectivityEnabled: No phone object");
951 request.result = false;
952 notifyRequester(request);
953 }
954 break;
955 }
956
957 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
958 ar = (AsyncResult) msg.obj;
959 request = (MainThreadRequest) ar.userObj;
960 if (ar.exception == null && ar.result != null) {
961 request.result = ar.result;
962 } else {
963 // request.result must be set to something non-null
964 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700965 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700966 request.result = ar.result;
967 } else {
968 request.result = false;
969 }
970 if (ar.result == null) {
971 loge("isNRDualConnectivityEnabled: Empty response");
972 } else if (ar.exception instanceof CommandException) {
973 loge("isNRDualConnectivityEnabled: CommandException: "
974 + ar.exception);
975 } else {
976 loge("isNRDualConnectivityEnabled: Unknown exception");
977 }
978 }
979 notifyRequester(request);
980 break;
981
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700982 case CMD_IS_VONR_ENABLED: {
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
985 request);
986 Phone phone = getPhoneFromRequest(request);
987 if (phone != null) {
988 phone.isVoNrEnabled(onCompleted, request.workSource);
989 } else {
990 loge("isVoNrEnabled: No phone object");
991 request.result = false;
992 notifyRequester(request);
993 }
994 break;
995 }
996
997 case EVENT_IS_VONR_ENABLED_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception == null && ar.result != null) {
1001 request.result = ar.result;
1002 } else {
1003 // request.result must be set to something non-null
1004 // for the calling thread to unblock
1005 if (ar.result != null) {
1006 request.result = ar.result;
1007 } else {
1008 request.result = false;
1009 }
1010 if (ar.result == null) {
1011 loge("isVoNrEnabled: Empty response");
1012 } else if (ar.exception instanceof CommandException) {
1013 loge("isVoNrEnabled: CommandException: "
1014 + ar.exception);
1015 } else {
1016 loge("isVoNrEnabled: Unknown exception");
1017 }
1018 }
1019 notifyRequester(request);
1020 break;
1021
Sooraj Sasindran37444802020-08-11 10:40:43 -07001022 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1025 Phone phone = getPhoneFromRequest(request);
1026 if (phone != null) {
1027 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1028 request.workSource);
1029 } else {
1030 loge("enableNrDualConnectivity: No phone object");
1031 request.result =
1032 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1033 notifyRequester(request);
1034 }
1035 break;
1036 }
1037
1038 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
1041 if (ar.exception == null) {
1042 request.result =
1043 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1044 } else {
1045 request.result =
1046 TelephonyManager
1047 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1048 if (ar.exception instanceof CommandException) {
1049 CommandException.Error error =
1050 ((CommandException) (ar.exception)).getCommandError();
1051 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1052 request.result =
1053 TelephonyManager
1054 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001055 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1056 request.result =
1057 TelephonyManager
1058 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001059 }
1060 loge("enableNrDualConnectivity" + ": CommandException: "
1061 + ar.exception);
1062 } else {
1063 loge("enableNrDualConnectivity" + ": Unknown exception");
1064 }
1065 }
1066 notifyRequester(request);
1067 break;
1068 }
1069
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001070 case CMD_ENABLE_VONR: {
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1073 Phone phone = getPhoneFromRequest(request);
1074 if (phone != null) {
1075 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1076 request.workSource);
1077 } else {
1078 loge("setVoNrEnabled: No phone object");
1079 request.result =
1080 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1081 notifyRequester(request);
1082 }
1083 break;
1084 }
1085
1086 case EVENT_ENABLE_VONR_DONE: {
1087 ar = (AsyncResult) msg.obj;
1088 request = (MainThreadRequest) ar.userObj;
1089 if (ar.exception == null) {
1090 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1091 } else {
1092 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1093 if (ar.exception instanceof CommandException) {
1094 CommandException.Error error =
1095 ((CommandException) (ar.exception)).getCommandError();
1096 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1097 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1098 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1099 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1100 } else {
1101 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1102 }
1103 loge("setVoNrEnabled" + ": CommandException: "
1104 + ar.exception);
1105 } else {
1106 loge("setVoNrEnabled" + ": Unknown exception");
1107 }
1108 }
1109 notifyRequester(request);
1110 break;
1111 }
1112
SongFerngWang3ef3e072020-12-21 16:41:52 +08001113 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1116 request);
1117 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001118 break;
1119
SongFerngWang3ef3e072020-12-21 16:41:52 +08001120 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001121 ar = (AsyncResult) msg.obj;
1122 request = (MainThreadRequest) ar.userObj;
1123 if (ar.exception == null && ar.result != null) {
1124 request.result = ar.result; // Integer
1125 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301126 // request.result must be set to something non-null
1127 // for the calling thread to unblock
1128 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001129 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001130 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001132 loge("getAllowedNetworkTypesBitmask: CommandException: "
1133 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001134 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001135 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 }
1137 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001138 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 break;
1140
SongFerngWang3ef3e072020-12-21 16:41:52 +08001141 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1144 request);
1145 Pair<Integer, Long> reasonWithNetworkTypes =
1146 (Pair<Integer, Long>) request.argument;
1147 getPhoneFromRequest(request).setAllowedNetworkTypes(
1148 reasonWithNetworkTypes.first,
1149 reasonWithNetworkTypes.second,
1150 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 break;
1152
SongFerngWang3ef3e072020-12-21 16:41:52 +08001153 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1154 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001155 break;
1156
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001157 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1158 request = (MainThreadRequest)msg.obj;
1159 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001160 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001161 break;
1162
1163 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1164 ar = (AsyncResult)msg.obj;
1165 request = (MainThreadRequest)ar.userObj;
1166 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001168 break;
1169
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001170 case CMD_SET_VOICEMAIL_NUMBER:
1171 request = (MainThreadRequest) msg.obj;
1172 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1173 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001174 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1175 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001176 break;
1177
1178 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1179 handleNullReturnEvent(msg, "setVoicemailNumber");
1180 break;
1181
Stuart Scott54788802015-03-30 13:18:01 -07001182 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1185 request);
1186 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1187 break;
1188
1189 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1190 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1191 break;
1192
Shishir Agrawal302c8692015-06-19 13:49:39 -07001193 case CMD_PERFORM_NETWORK_SCAN:
1194 request = (MainThreadRequest) msg.obj;
1195 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1196 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1197 break;
1198
Hall Liu27d24262020-09-18 19:04:59 -07001199 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001202 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1203 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1204 request.argument;
1205 int callForwardingReason = args.first;
1206 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001207 break;
Hall Liu27d24262020-09-18 19:04:59 -07001208 }
1209 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001210 ar = (AsyncResult) msg.obj;
1211 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001212 TelephonyManager.CallForwardingInfoCallback callback =
1213 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1214 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001215 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001216 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1218 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1219 // Service Class is a bit mask per 3gpp 27.007. Search for
1220 // any service for voice call.
1221 if ((callForwardInfo.serviceClass
1222 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001223 callForwardingInfo = new CallForwardingInfo(
1224 callForwardInfo.status
1225 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001226 callForwardInfo.reason,
1227 callForwardInfo.number,
1228 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001229 break;
1230 }
1231 }
1232 // Didn't find a call forward info for voice call.
1233 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001234 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1235 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001236 }
Hall Liu27d24262020-09-18 19:04:59 -07001237 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001238 } else {
1239 if (ar.result == null) {
1240 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1241 }
1242 if (ar.exception != null) {
1243 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1244 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001245 int errorCode = TelephonyManager
1246 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001247 if (ar.exception instanceof CommandException) {
1248 CommandException.Error error =
1249 ((CommandException) (ar.exception)).getCommandError();
1250 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001251 errorCode = TelephonyManager
1252 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001253 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 errorCode = TelephonyManager
1255 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 }
1257 }
Hall Liu27d24262020-09-18 19:04:59 -07001258 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260 break;
Hall Liu27d24262020-09-18 19:04:59 -07001261 }
Shuo Qian4a594052020-01-23 11:59:30 -08001262
Hall Liu27d24262020-09-18 19:04:59 -07001263 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001264 request = (MainThreadRequest) msg.obj;
1265 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001266 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001268 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1269 request.argument).first;
1270 request.phone.setCallForwardingOption(
1271 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001272 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001273 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001274 callForwardingInfoToSet.getReason(),
1275 callForwardingInfoToSet.getNumber(),
1276 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1277 break;
Hall Liu27d24262020-09-18 19:04:59 -07001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279
Hall Liu27d24262020-09-18 19:04:59 -07001280 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001281 ar = (AsyncResult) msg.obj;
1282 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001283 Consumer<Integer> callback =
1284 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1285 request.argument).second;
1286 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001287 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001288 int errorCode = TelephonyManager.CallForwardingInfoCallback
1289 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001290 if (ar.exception instanceof CommandException) {
1291 CommandException.Error error =
1292 ((CommandException) (ar.exception)).getCommandError();
1293 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001294 errorCode = TelephonyManager.CallForwardingInfoCallback
1295 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001296 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001297 errorCode = TelephonyManager.CallForwardingInfoCallback
1298 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001299 }
1300 }
1301 callback.accept(errorCode);
1302 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001303 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 }
Shuo Qian4a594052020-01-23 11:59:30 -08001305 break;
Hall Liu27d24262020-09-18 19:04:59 -07001306 }
Shuo Qian4a594052020-01-23 11:59:30 -08001307
Hall Liu27d24262020-09-18 19:04:59 -07001308 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001309 request = (MainThreadRequest) msg.obj;
1310 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1311 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1312 break;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314
Hall Liu27d24262020-09-18 19:04:59 -07001315 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001318 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001319 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001320 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001321 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001322 // Service Class is a bit mask per 3gpp 27.007.
1323 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001324 if (callForwardResults.length > 1
1325 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001326 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001327 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001328 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1329 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001330 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001331 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001332 }
1333 } else {
1334 if (ar.result == null) {
1335 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1336 }
1337 if (ar.exception != null) {
1338 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1339 }
1340 if (ar.exception instanceof CommandException) {
1341 CommandException.Error error =
1342 ((CommandException) (ar.exception)).getCommandError();
1343 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001344 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001345 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001346 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1347 callWaitingStatus =
1348 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001349 }
1350 }
1351 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001352 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001353 break;
Hall Liu27d24262020-09-18 19:04:59 -07001354 }
Shuo Qian4a594052020-01-23 11:59:30 -08001355
Hall Liu27d24262020-09-18 19:04:59 -07001356 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001357 request = (MainThreadRequest) msg.obj;
1358 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001359 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1360 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001361 break;
Hall Liu27d24262020-09-18 19:04:59 -07001362 }
Shuo Qian4a594052020-01-23 11:59:30 -08001363
Hall Liu27d24262020-09-18 19:04:59 -07001364 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001367 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1368 Consumer<Integer> callback =
1369 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1370 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001371 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001372 if (ar.exception instanceof CommandException) {
1373 CommandException.Error error =
1374 ((CommandException) (ar.exception)).getCommandError();
1375 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1376 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001377 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1378 callback.accept(
1379 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001380 } else {
1381 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1382 }
1383 } else {
1384 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1385 }
1386 } else {
1387 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1388 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001389 }
Shuo Qian4a594052020-01-23 11:59:30 -08001390 break;
Hall Liu27d24262020-09-18 19:04:59 -07001391 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001392 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 CellNetworkScanResult cellScanResult;
1396 if (ar.exception == null && ar.result != null) {
1397 cellScanResult = new CellNetworkScanResult(
1398 CellNetworkScanResult.STATUS_SUCCESS,
1399 (List<OperatorInfo>) ar.result);
1400 } else {
1401 if (ar.result == null) {
1402 loge("getCellNetworkScanResults: Empty response");
1403 }
1404 if (ar.exception != null) {
1405 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1406 }
1407 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1408 if (ar.exception instanceof CommandException) {
1409 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001410 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001411 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1412 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1413 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1414 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1415 }
1416 }
1417 cellScanResult = new CellNetworkScanResult(errorCode, null);
1418 }
1419 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001420 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001421 break;
1422
1423 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1424 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001425 ManualNetworkSelectionArgument selArg =
1426 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001427 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1428 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001429 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1430 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001431 break;
1432
1433 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001434 ar = (AsyncResult) msg.obj;
1435 request = (MainThreadRequest) ar.userObj;
1436 if (ar.exception == null) {
1437 request.result = true;
1438 } else {
1439 request.result = false;
1440 loge("setNetworkSelectionModeManual " + ar.exception);
1441 }
1442 notifyRequester(request);
1443 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001444 break;
1445
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 case CMD_GET_MODEM_ACTIVITY_INFO:
1447 request = (MainThreadRequest) msg.obj;
1448 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001449 if (defaultPhone != null) {
1450 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001451 } else {
1452 ResultReceiver result = (ResultReceiver) request.argument;
1453 Bundle bundle = new Bundle();
1454 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001455 new ModemActivityInfo(0, 0, 0,
1456 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001458 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 break;
1460
Hall Liud0f208c2020-10-14 16:54:44 -07001461 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001462 ar = (AsyncResult) msg.obj;
1463 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001464 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001465 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001466 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001467 if (mLastModemActivityInfo == null) {
1468 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1469 mLastModemActivitySpecificInfo[0] =
1470 new ActivityStatsTechSpecificInfo(
1471 0,
1472 0,
1473 new int[ModemActivityInfo.getNumTxPowerLevels()],
1474 0);
1475 mLastModemActivityInfo =
1476 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1477 }
1478
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001479 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001480 // Update the last modem activity info and the result of the request.
1481 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1482 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001483 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001484 } else {
1485 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001486 }
Kai Shi917fdc62022-11-28 14:01:02 -08001487 // This is needed to decouple ret from mLastModemActivityInfo
1488 // We don't want to return mLastModemActivityInfo which is updated
1489 // inside mergeModemActivityInfo()
1490 ret = new ModemActivityInfo(
1491 mLastModemActivityInfo.getTimestampMillis(),
1492 mLastModemActivityInfo.getSleepTimeMillis(),
1493 mLastModemActivityInfo.getIdleTimeMillis(),
1494 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001495
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001496 } else {
1497 if (ar.result == null) {
1498 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001499 error = TelephonyManager.ModemActivityInfoException
1500 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001501 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001502 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001503 error = TelephonyManager.ModemActivityInfoException
1504 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505 } else {
1506 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001507 error = TelephonyManager.ModemActivityInfoException
1508 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001509 }
1510 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001511 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001512 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001513 bundle.putParcelable(
1514 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001515 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001516 } else {
1517 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1518 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001519 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001520 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001521 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001522 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001523
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001524 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001526 CarrierRestrictionRules argument =
1527 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001528 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001529 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001530 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001531 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001532
1533 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1534 ar = (AsyncResult) msg.obj;
1535 request = (MainThreadRequest) ar.userObj;
1536 if (ar.exception == null && ar.result != null) {
1537 request.result = ar.result;
1538 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001539 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1540 if (ar.exception instanceof CommandException) {
1541 loge("setAllowedCarriers: CommandException: " + ar.exception);
1542 CommandException.Error error =
1543 ((CommandException) (ar.exception)).getCommandError();
1544 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1545 request.result =
1546 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1547 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001548 } else {
1549 loge("setAllowedCarriers: Unknown exception");
1550 }
1551 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001552 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001553 break;
1554
1555 case CMD_GET_ALLOWED_CARRIERS:
1556 request = (MainThreadRequest) msg.obj;
1557 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001558 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001559 break;
1560
1561 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1562 ar = (AsyncResult) msg.obj;
1563 request = (MainThreadRequest) ar.userObj;
1564 if (ar.exception == null && ar.result != null) {
1565 request.result = ar.result;
1566 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001567 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001568 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001569 if (ar.result == null) {
1570 loge("getAllowedCarriers: Empty response");
1571 } else if (ar.exception instanceof CommandException) {
1572 loge("getAllowedCarriers: CommandException: " +
1573 ar.exception);
1574 } else {
1575 loge("getAllowedCarriers: Unknown exception");
1576 }
1577 }
arunvoddud7401012022-12-15 16:08:12 +00001578 if (request.argument != null) {
1579 // This is for the implementation of carrierRestrictionStatus.
1580 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1581 Consumer<Integer> callback = callbackInfo.getConsumer();
1582 int callerCarrierId = callbackInfo.getCarrierId();
1583 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1584 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1585 CarrierRestrictionRules carrierRestrictionRules =
1586 (CarrierRestrictionRules) ar.result;
1587 int carrierId = -1;
1588 try {
1589 CarrierIdentifier carrierIdentifier =
1590 carrierRestrictionRules.getAllowedCarriers().get(0);
1591 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1592 carrierIdentifier);
1593 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1594 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1595 }
1596 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1597 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1598 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001599 lockStatus = TelephonyManager
1600 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001601 }
1602 } else {
1603 Rlog.e(LOG_TAG,
1604 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1605 }
1606 callback.accept(lockStatus);
1607 } else {
1608 // This is for the implementation of getAllowedCarriers.
1609 notifyRequester(request);
1610 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001611 break;
1612
Nathan Haroldb3014052017-01-25 15:57:32 -08001613 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 if (ar.exception == null && ar.result != null) {
1617 request.result = ar.result;
1618 } else {
1619 request.result = new IllegalArgumentException(
1620 "Failed to retrieve Forbidden Plmns");
1621 if (ar.result == null) {
1622 loge("getForbiddenPlmns: Empty response");
1623 } else {
1624 loge("getForbiddenPlmns: Unknown exception");
1625 }
1626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001627 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001628 break;
1629
1630 case CMD_GET_FORBIDDEN_PLMNS:
1631 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001632 uiccPort = getUiccPortFromRequest(request);
1633 if (uiccPort == null) {
1634 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001635 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001636 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001637 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001638 break;
1639 }
1640 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001641 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001642 if (uiccApp == null) {
1643 loge("getForbiddenPlmns() no app with specified type -- "
1644 + appType);
1645 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 break;
1648 } else {
1649 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1650 + " specified type -- " + appType);
1651 }
1652 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1653 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001654 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001655 break;
1656
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001657 case CMD_SWITCH_SLOTS:
1658 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001659 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001660 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001661 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001662 break;
1663
1664 case EVENT_SWITCH_SLOTS_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
1667 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001668 notifyRequester(request);
1669 break;
1670 case CMD_GET_NETWORK_SELECTION_MODE:
1671 request = (MainThreadRequest) msg.obj;
1672 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1673 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1674 break;
1675
1676 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1677 ar = (AsyncResult) msg.obj;
1678 request = (MainThreadRequest) ar.userObj;
1679 if (ar.exception != null) {
1680 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1681 } else {
1682 int mode = ((int[]) ar.result)[0];
1683 if (mode == 0) {
1684 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1685 } else {
1686 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1687 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001689 notifyRequester(request);
1690 break;
1691 case CMD_GET_CDMA_ROAMING_MODE:
1692 request = (MainThreadRequest) msg.obj;
1693 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1694 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1695 break;
1696 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1697 ar = (AsyncResult) msg.obj;
1698 request = (MainThreadRequest) ar.userObj;
1699 if (ar.exception != null) {
1700 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1701 } else {
1702 request.result = ((int[]) ar.result)[0];
1703 }
1704 notifyRequester(request);
1705 break;
1706 case CMD_SET_CDMA_ROAMING_MODE:
1707 request = (MainThreadRequest) msg.obj;
1708 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1709 int mode = (int) request.argument;
1710 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1711 break;
1712 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 request.result = ar.exception == null;
1716 notifyRequester(request);
1717 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001718 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1719 request = (MainThreadRequest) msg.obj;
1720 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1721 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1722 break;
1723 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1724 ar = (AsyncResult) msg.obj;
1725 request = (MainThreadRequest) ar.userObj;
1726 if (ar.exception != null) {
1727 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1728 } else {
1729 request.result = ((int[]) ar.result)[0];
1730 }
1731 notifyRequester(request);
1732 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001733 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1734 request = (MainThreadRequest) msg.obj;
1735 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1736 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001737 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1738 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001739 break;
1740 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 request.result = ar.exception == null;
1744 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001745 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001746 case CMD_GET_ALL_CELL_INFO:
1747 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001748 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001749 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001750 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001751 case EVENT_GET_ALL_CELL_INFO_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001754 // If a timeout occurs, the response will be null
1755 request.result = (ar.exception == null && ar.result != null)
1756 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001757 synchronized (request) {
1758 request.notifyAll();
1759 }
1760 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001761 case CMD_REQUEST_CELL_INFO_UPDATE:
1762 request = (MainThreadRequest) msg.obj;
1763 request.phone.requestCellInfoUpdate(request.workSource,
1764 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1765 break;
1766 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1767 ar = (AsyncResult) msg.obj;
1768 request = (MainThreadRequest) ar.userObj;
1769 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1770 try {
1771 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001772 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001773 cb.onError(
1774 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1775 ar.exception.getClass().getName(),
1776 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001777 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001779 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001780 } else {
1781 // use the result as returned
1782 cb.onCellInfo((List<CellInfo>) ar.result);
1783 }
1784 } catch (RemoteException re) {
1785 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1786 }
1787 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001788 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001789 request = (MainThreadRequest) msg.obj;
1790 WorkSource ws = (WorkSource) request.argument;
1791 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001792 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001793 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001794 }
1795 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001796 ar = (AsyncResult) msg.obj;
1797 request = (MainThreadRequest) ar.userObj;
1798 if (ar.exception == null) {
1799 request.result = ar.result;
1800 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001801 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001802 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001803 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001804 }
1805
1806 synchronized (request) {
1807 request.notifyAll();
1808 }
1809 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 }
chen xu6dac5ab2018-10-26 17:39:23 -07001811 case CMD_MODEM_REBOOT:
1812 request = (MainThreadRequest) msg.obj;
1813 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001814 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001815 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001816 case EVENT_CMD_MODEM_REBOOT_DONE:
1817 handleNullReturnEvent(msg, "rebootModem");
1818 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001819 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001820 request = (MainThreadRequest) msg.obj;
1821 boolean enable = (boolean) request.argument;
1822 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001823 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001824 PhoneConfigurationManager.getInstance()
1825 .enablePhone(request.phone, enable, onCompleted);
1826 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001827 }
Michele Berionne5e411512020-11-13 02:36:59 +00001828 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001829 ar = (AsyncResult) msg.obj;
1830 request = (MainThreadRequest) ar.userObj;
1831 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001832 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001833 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001834 if ((boolean) request.result) {
1835 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1836 updateModemStateMetrics();
1837 } else {
1838 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1839 + ar.exception);
1840 }
1841 notifyRequester(request);
1842 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001843 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001844 case CMD_GET_MODEM_STATUS:
1845 request = (MainThreadRequest) msg.obj;
1846 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1847 PhoneConfigurationManager.getInstance()
1848 .getPhoneStatusFromModem(request.phone, onCompleted);
1849 break;
1850 case EVENT_GET_MODEM_STATUS_DONE:
1851 ar = (AsyncResult) msg.obj;
1852 request = (MainThreadRequest) ar.userObj;
1853 int id = request.phone.getPhoneId();
1854 if (ar.exception == null && ar.result != null) {
1855 request.result = ar.result;
1856 //update the cache as modem status has changed
1857 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1858 (boolean) request.result);
1859 } else {
1860 // Return true if modem status cannot be retrieved. For most cases,
1861 // modem status is on. And for older version modems, GET_MODEM_STATUS
1862 // and disable modem are not supported. Modem is always on.
1863 // TODO: this should be fixed in R to support a third
1864 // status UNKNOWN b/131631629
1865 request.result = true;
1866 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1867 + ar.exception);
1868 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001869 notifyRequester(request);
1870 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001871 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1872 request = (MainThreadRequest) msg.obj;
1873 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1874 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1875 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1876 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1877 break;
1878 }
1879 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1880 ar = (AsyncResult) msg.obj;
1881 request = (MainThreadRequest) ar.userObj;
1882 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1883 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1884 args.second.accept(ar.exception == null);
1885 notifyRequester(request);
1886 break;
1887 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001888 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1891 Phone phone = getPhoneFromRequest(request);
1892 if (phone != null) {
1893 phone.getSystemSelectionChannels(onCompleted);
1894 } else {
1895 loge("getSystemSelectionChannels: No phone object");
1896 request.result = new ArrayList<RadioAccessSpecifier>();
1897 notifyRequester(request);
1898 }
1899 break;
1900 }
1901 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1902 ar = (AsyncResult) msg.obj;
1903 request = (MainThreadRequest) ar.userObj;
1904 if (ar.exception == null && ar.result != null) {
1905 request.result = ar.result;
1906 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001907 request.result = new IllegalStateException(
1908 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001909 if (ar.result == null) {
1910 loge("getSystemSelectionChannels: Empty response");
1911 } else {
1912 loge("getSystemSelectionChannels: Unknown exception");
1913 }
1914 }
1915 notifyRequester(request);
1916 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001917 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1918 ar = (AsyncResult) msg.obj;
1919 request = (MainThreadRequest) ar.userObj;
1920 if (ar.exception == null && ar.result != null) {
1921 request.result = ar.result;
1922 } else {
1923 request.result = -1;
1924 loge("Failed to set Forbidden Plmns");
1925 if (ar.result == null) {
1926 loge("setForbidenPlmns: Empty response");
1927 } else if (ar.exception != null) {
1928 loge("setForbiddenPlmns: Exception: " + ar.exception);
1929 request.result = -1;
1930 } else {
1931 loge("setForbiddenPlmns: Unknown exception");
1932 }
1933 }
1934 notifyRequester(request);
1935 break;
1936 case CMD_SET_FORBIDDEN_PLMNS:
1937 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001938 uiccPort = getUiccPortFromRequest(request);
1939 if (uiccPort == null) {
1940 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001941 request.result = -1;
1942 notifyRequester(request);
1943 break;
1944 }
1945 Pair<Integer, List<String>> setFplmnsArgs =
1946 (Pair<Integer, List<String>>) request.argument;
1947 appType = setFplmnsArgs.first;
1948 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001949 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001950 if (uiccApp == null) {
1951 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1952 request.result = -1;
1953 loge("Failed to get UICC App");
1954 notifyRequester(request);
1955 } else {
1956 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1957 ((SIMRecords) uiccApp.getIccRecords())
1958 .setForbiddenPlmns(onCompleted, fplmns);
1959 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001960 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001961 case CMD_ERASE_MODEM_CONFIG:
1962 request = (MainThreadRequest) msg.obj;
1963 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1964 defaultPhone.eraseModemConfig(onCompleted);
1965 break;
1966 case EVENT_ERASE_MODEM_CONFIG_DONE:
1967 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001968 break;
zoey chene02881a2019-12-30 16:11:23 +08001969
Kai Shif70f46f2021-03-03 13:59:46 -08001970 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1971 request = (MainThreadRequest) msg.obj;
1972 request.result = defaultPhone.eraseDataInSharedPreferences();
1973 notifyRequester(request);
1974 break;
1975
zoey chene02881a2019-12-30 16:11:23 +08001976 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1977 request = (MainThreadRequest) msg.obj;
1978 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1979 Pair<String, String> changed = (Pair<String, String>) request.argument;
1980 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1981 changed.first, changed.second, onCompleted);
1982 break;
1983 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1984 ar = (AsyncResult) msg.obj;
1985 request = (MainThreadRequest) ar.userObj;
1986 if (ar.exception == null) {
1987 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001988 // If the operation is successful, update the PIN storage
1989 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1990 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001991 UiccController.getInstance().getPinStorage()
1992 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001993 } else {
1994 request.result = msg.arg1;
1995 }
1996 notifyRequester(request);
1997 break;
1998
Michele Berionne5e411512020-11-13 02:36:59 +00001999 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002000 request = (MainThreadRequest) msg.obj;
2001 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2002 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2003 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2004 enabled.first, enabled.second, onCompleted);
2005 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002006 }
zoey chene02881a2019-12-30 16:11:23 +08002007 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2008 ar = (AsyncResult) msg.obj;
2009 request = (MainThreadRequest) ar.userObj;
2010 if (ar.exception == null) {
2011 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002012 // If the operation is successful, update the PIN storage
2013 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2014 int phoneId = getPhoneFromRequest(request).getPhoneId();
2015 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002016 UiccController.getInstance().getPinStorage()
2017 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002018 } else {
2019 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2020 }
zoey chene02881a2019-12-30 16:11:23 +08002021 } else {
2022 request.result = msg.arg1;
2023 }
Michele Berionne5e411512020-11-13 02:36:59 +00002024
2025
zoey chene02881a2019-12-30 16:11:23 +08002026 notifyRequester(request);
2027 break;
2028
Peter Wangdafb9ac2020-01-15 14:13:38 -08002029 case MSG_NOTIFY_USER_ACTIVITY:
2030 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002031 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002032 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2033 getDefaultPhone().getContext().sendBroadcastAsUser(
2034 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2035 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002036
2037 case CMD_SET_DATA_THROTTLING: {
2038 request = (MainThreadRequest) msg.obj;
2039 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2040 DataThrottlingRequest dataThrottlingRequest =
2041 (DataThrottlingRequest) request.argument;
2042 Phone phone = getPhoneFromRequest(request);
2043 if (phone != null) {
2044 phone.setDataThrottling(onCompleted,
2045 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2046 dataThrottlingRequest.getCompletionDurationMillis());
2047 } else {
2048 loge("setDataThrottling: No phone object");
2049 request.result =
2050 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2051 notifyRequester(request);
2052 }
2053
2054 break;
2055 }
2056 case EVENT_SET_DATA_THROTTLING_DONE:
2057 ar = (AsyncResult) msg.obj;
2058 request = (MainThreadRequest) ar.userObj;
2059
2060 if (ar.exception == null) {
2061 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2062 } else if (ar.exception instanceof CommandException) {
2063 loge("setDataThrottling: CommandException: " + ar.exception);
2064 CommandException.Error error =
2065 ((CommandException) (ar.exception)).getCommandError();
2066
2067 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2068 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002069 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002070 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2071 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002072 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2073 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002074 } else {
2075 request.result =
2076 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2077 }
2078 } else {
2079 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2080 }
2081 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2082 notifyRequester(request);
2083 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002084
2085 case CMD_SET_SIM_POWER: {
2086 request = (MainThreadRequest) msg.obj;
2087 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2088 request = (MainThreadRequest) msg.obj;
2089 int stateToSet =
2090 ((Pair<Integer, IIntegerConsumer>)
2091 request.argument).first;
2092 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2093 break;
2094 }
2095 case EVENT_SET_SIM_POWER_DONE: {
2096 ar = (AsyncResult) msg.obj;
2097 request = (MainThreadRequest) ar.userObj;
2098 IIntegerConsumer callback =
2099 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2100 if (ar.exception != null) {
2101 loge("setSimPower exception: " + ar.exception);
2102 int errorCode = TelephonyManager.CallForwardingInfoCallback
2103 .RESULT_ERROR_UNKNOWN;
2104 if (ar.exception instanceof CommandException) {
2105 CommandException.Error error =
2106 ((CommandException) (ar.exception)).getCommandError();
2107 if (error == CommandException.Error.SIM_ERR) {
2108 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2109 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2110 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2111 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2112 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2113 } else {
2114 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2115 }
2116 }
2117 try {
2118 callback.accept(errorCode);
2119 } catch (RemoteException e) {
2120 // Ignore if the remote process is no longer available to call back.
2121 Log.w(LOG_TAG, "setSimPower: callback not available.");
2122 }
2123 } else {
2124 try {
2125 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2126 } catch (RemoteException e) {
2127 // Ignore if the remote process is no longer available to call back.
2128 Log.w(LOG_TAG, "setSimPower: callback not available.");
2129 }
2130 }
2131 break;
2132 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002133 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2134 request = (MainThreadRequest) msg.obj;
2135
2136 final Phone phone = getPhoneFromRequest(request);
2137 if (phone == null || phone.getServiceStateTracker() == null) {
2138 request.result = new IllegalStateException("Phone or SST is null");
2139 notifyRequester(request);
2140 break;
2141 }
2142
2143 Pair<Integer, SignalStrengthUpdateRequest> pair =
2144 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2145 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2146 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002147 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002148 request.subId, pair.first /*callingUid*/,
2149 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002150 break;
2151 }
2152 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2153 ar = (AsyncResult) msg.obj;
2154 request = (MainThreadRequest) ar.userObj;
2155 // request.result will be the exception of ar if present, true otherwise.
2156 // Be cautious not to leave result null which will wait() forever
2157 request.result = ar.exception != null ? ar.exception : true;
2158 notifyRequester(request);
2159 break;
2160 }
2161 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2162 request = (MainThreadRequest) msg.obj;
2163
2164 Phone phone = getPhoneFromRequest(request);
2165 if (phone == null || phone.getServiceStateTracker() == null) {
2166 request.result = new IllegalStateException("Phone or SST is null");
2167 notifyRequester(request);
2168 break;
2169 }
2170
2171 Pair<Integer, SignalStrengthUpdateRequest> pair =
2172 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2173 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2174 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002175 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002176 request.subId, pair.first /*callingUid*/,
2177 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002178 break;
2179 }
2180 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2181 ar = (AsyncResult) msg.obj;
2182 request = (MainThreadRequest) ar.userObj;
2183 request.result = ar.exception != null ? ar.exception : true;
2184 notifyRequester(request);
2185 break;
2186 }
Jordan Liu109698e2020-11-24 14:50:34 -08002187
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002188 case CMD_GET_SLICING_CONFIG: {
2189 request = (MainThreadRequest) msg.obj;
2190 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2191 request.phone.getSlicingConfig(onCompleted);
2192 break;
2193 }
2194 case EVENT_GET_SLICING_CONFIG_DONE: {
2195 ar = (AsyncResult) msg.obj;
2196 request = (MainThreadRequest) ar.userObj;
2197 ResultReceiver result = (ResultReceiver) request.argument;
2198
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002199 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002200 Bundle bundle = new Bundle();
2201 int resultCode = 0;
2202 if (ar.exception != null) {
2203 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2204 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002205 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002206 } else if (ar.result == null) {
2207 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002208 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002209 } else {
2210 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002211 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2212 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002213 }
2214
2215 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002216 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002217 }
2218 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2219 result.send(resultCode, bundle);
2220 notifyRequester(request);
2221 break;
2222 }
2223
Sarah Chin71b3a852022-09-28 15:54:19 -07002224 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002225 request = (MainThreadRequest) msg.obj;
2226 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002227 PurchasePremiumCapabilityArgument arg =
2228 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002229 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002230 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002231 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002232 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002233
Sarah Chin71b3a852022-09-28 15:54:19 -07002234 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002235 ar = (AsyncResult) msg.obj;
2236 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002237 PurchasePremiumCapabilityArgument arg =
2238 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002239 try {
2240 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244 + ", result= "
2245 + TelephonyManager.convertPurchaseResultToString(result));
2246 } catch (RemoteException e) {
2247 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249 + " failed: " + e;
2250 if (DBG) log(logStr);
2251 AnomalyReporter.reportAnomaly(
2252 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2253 }
2254 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256
Michele Berionne5e411512020-11-13 02:36:59 +00002257 case CMD_PREPARE_UNATTENDED_REBOOT:
2258 request = (MainThreadRequest) msg.obj;
2259 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002260 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002261 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002262 notifyRequester(request);
2263 break;
2264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 default:
2266 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2267 break;
2268 }
2269 }
Jake Hambye994d462014-02-03 13:10:13 -08002270
Pengquan Menga1bb6272018-09-06 09:59:22 -07002271 private void notifyRequester(MainThreadRequest request) {
2272 synchronized (request) {
2273 request.notifyAll();
2274 }
2275 }
2276
Jake Hambye994d462014-02-03 13:10:13 -08002277 private void handleNullReturnEvent(Message msg, String command) {
2278 AsyncResult ar = (AsyncResult) msg.obj;
2279 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2280 if (ar.exception == null) {
2281 request.result = true;
2282 } else {
2283 request.result = false;
2284 if (ar.exception instanceof CommandException) {
2285 loge(command + ": CommandException: " + ar.exception);
2286 } else {
2287 loge(command + ": Unknown exception");
2288 }
2289 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002290 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
2294 /**
2295 * Posts the specified command to be executed on the main thread,
2296 * waits for the request to complete, and returns the result.
2297 * @see #sendRequestAsync
2298 */
2299 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002300 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2301 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002302 }
2303
2304 /**
2305 * Posts the specified command to be executed on the main thread,
2306 * waits for the request to complete, and returns the result.
2307 * @see #sendRequestAsync
2308 */
2309 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2310 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002311 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002312 }
2313
2314 /**
2315 * Posts the specified command to be executed on the main thread,
2316 * waits for the request to complete, and returns the result.
2317 * @see #sendRequestAsync
2318 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002319 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002320 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2321 }
2322
2323 /**
2324 * Posts the specified command to be executed on the main thread,
2325 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2326 * if not timeout or null otherwise.
2327 * @see #sendRequestAsync
2328 */
2329 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2330 long timeoutInMs) {
2331 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002332 }
2333
2334 /**
2335 * Posts the specified command to be executed on the main thread,
2336 * waits for the request to complete, and returns the result.
2337 * @see #sendRequestAsync
2338 */
Nathan Harold92bed182018-10-12 18:16:49 -07002339 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002340 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002341 }
2342
2343 /**
2344 * Posts the specified command to be executed on the main thread,
2345 * waits for the request to complete, and returns the result.
2346 * @see #sendRequestAsync
2347 */
2348 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002349 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2350 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002351 }
2352
2353 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002354 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2355 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2356 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002357 * @see #sendRequestAsync
2358 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002359 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2360 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2362 throw new RuntimeException("This method will deadlock if called from the main thread.");
2363 }
2364
Nathan Harold92bed182018-10-12 18:16:49 -07002365 MainThreadRequest request = null;
2366 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2367 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2368 } else if (phone != null) {
2369 request = new MainThreadRequest(argument, phone, workSource);
2370 } else {
2371 request = new MainThreadRequest(argument, subId, workSource);
2372 }
2373
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 Message msg = mMainThreadHandler.obtainMessage(command, request);
2375 msg.sendToTarget();
2376
Rambo Wang0f050d82021-02-12 11:43:36 -08002377
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002379 if (timeoutInMs >= 0) {
2380 // Wait for at least timeoutInMs before returning null request result
2381 long now = SystemClock.elapsedRealtime();
2382 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002383 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002384 try {
2385 request.wait(deadline - now);
2386 } catch (InterruptedException e) {
2387 // Do nothing, go back and check if request is completed or timeout
2388 } finally {
2389 now = SystemClock.elapsedRealtime();
2390 }
2391 }
2392 } else {
2393 // Wait for the request to complete
2394 while (request.result == null) {
2395 try {
2396 request.wait();
2397 } catch (InterruptedException e) {
2398 // Do nothing, go back and wait until the request is complete
2399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 }
2401 }
2402 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002403 if (request.result == null) {
2404 Log.wtf(LOG_TAG,
2405 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 return request.result;
2408 }
2409
2410 /**
2411 * Asynchronous ("fire and forget") version of sendRequest():
2412 * Posts the specified command to be executed on the main thread, and
2413 * returns immediately.
2414 * @see #sendRequest
2415 */
2416 private void sendRequestAsync(int command) {
2417 mMainThreadHandler.sendEmptyMessage(command);
2418 }
2419
2420 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002421 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002422 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002423 */
2424 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002425 sendRequestAsync(command, argument, null, null);
2426 }
2427
2428 /**
2429 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2430 * @see {@link #sendRequest(int,Object)}
2431 */
2432 private void sendRequestAsync(
2433 int command, Object argument, Phone phone, WorkSource workSource) {
2434 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002435 Message msg = mMainThreadHandler.obtainMessage(command, request);
2436 msg.sendToTarget();
2437 }
2438
2439 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 * Initialize the singleton PhoneInterfaceManager instance.
2441 * This is only done once, at startup, from PhoneApp.onCreate().
2442 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002443 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 synchronized (PhoneInterfaceManager.class) {
2445 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002446 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 } else {
2448 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2449 }
2450 return sInstance;
2451 }
2452 }
2453
2454 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002455 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002458 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002459 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002460 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2462 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002463 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002464 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002465 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002466 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002467 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002468 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 publish();
arunvoddud7401012022-12-15 16:08:12 +00002470 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 }
2472
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002473 @VisibleForTesting
2474 public SharedPreferences getSharedPreferences() {
2475 return mTelephonySharedPreferences;
2476 }
2477
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002478 /**
2479 * Get the default phone for this device.
2480 */
2481 @VisibleForTesting
2482 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002483 Phone thePhone = getPhone(getDefaultSubscription());
2484 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2485 }
2486
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 private void publish() {
2488 if (DBG) log("publish: " + this);
2489
Peter Wangc035ce42020-01-08 21:00:22 -08002490 TelephonyFrameworkInitializer
2491 .getTelephonyServiceManager()
2492 .getTelephonyServiceRegisterer()
2493 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 }
2495
Stuart Scott584921c2015-01-15 17:10:34 -08002496 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002497 if (request.phone != null) {
2498 return request.phone;
2499 } else {
2500 return getPhoneFromSubId(request.subId);
2501 }
2502 }
2503
2504 private Phone getPhoneFromSubId(int subId) {
2505 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2506 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002507 }
2508
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002509 /**
2510 * Get phone object associated with a subscription.
2511 * Return default phone if phone object associated with subscription is null
2512 * @param subId - subscriptionId
2513 * @return phone object associated with a subscription or default phone if null.
2514 */
Ling Mac28f0212023-03-24 16:07:15 -07002515 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002516 Phone phone = getPhoneFromSubId(subId);
2517 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002518 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002519 phone = getDefaultPhone();
2520 }
2521 return phone;
2522 }
2523
Rambo Wange53e07d2022-05-10 13:01:13 -07002524 @Nullable
2525 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002526 Phone phone = getPhoneFromRequest(request);
2527 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002528 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002529 }
2530
Ling Mac28f0212023-03-24 16:07:15 -07002531 /**
2532 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2533 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2534 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2535 * @return The Phone associated the sub Id
2536 */
2537 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002538 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540
Kai Shif70f46f2021-03-03 13:59:46 -08002541 private void sendEraseModemConfig(@NonNull Phone phone) {
2542 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2543 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2544 }
2545
2546 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2547 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2548 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002549 }
2550
Peter Wang44b186e2020-01-13 23:33:09 -08002551 private boolean isImsAvailableOnDevice() {
2552 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2553 if (pm == null) {
2554 // For some reason package manger is not available.. This will fail internally anyway,
2555 // so do not throw error and allow.
2556 return true;
2557 }
2558 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2559 }
2560
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002562 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002563 }
2564
Wink Savilleb564aae2014-10-23 10:18:09 -07002565 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 if (DBG) log("dial: " + number);
2567 // No permission check needed here: This is just a wrapper around the
2568 // ACTION_DIAL intent, which is available to any app since it puts up
2569 // the UI before it does anything.
2570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 String url = createTelUrl(number);
2574 if (url == null) {
2575 return;
2576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578 // PENDING: should we just silently fail if phone is offhook or ringing?
2579 PhoneConstants.State state = mCM.getState(subId);
2580 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2581 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2582 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2583 mApp.startActivity(intent);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 }
2588 }
2589
2590 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002591 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002592 }
2593
Wink Savilleb564aae2014-10-23 10:18:09 -07002594 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 if (DBG) log("call: " + number);
2596
2597 // This is just a wrapper around the ACTION_CALL intent, but we still
2598 // need to do a permission check since we're calling startActivity()
2599 // from the context of the phone app.
2600 enforceCallPermission();
2601
Jordan Liu1617b712019-07-10 15:06:26 -07002602 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 != AppOpsManager.MODE_ALLOWED) {
2604 return;
2605 }
2606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 String url = createTelUrl(number);
2610 if (url == null) {
2611 return;
2612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 boolean isValid = false;
2615 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2616 if (slist != null) {
2617 for (SubscriptionInfo subInfoRecord : slist) {
2618 if (subInfoRecord.getSubscriptionId() == subId) {
2619 isValid = true;
2620 break;
2621 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002622 }
Wink Saville08874612014-08-31 19:19:58 -07002623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 if (!isValid) {
2625 return;
2626 }
Wink Saville08874612014-08-31 19:19:58 -07002627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2629 intent.putExtra(SUBSCRIPTION_KEY, subId);
2630 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2631 mApp.startActivity(intent);
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 }
2636
Wink Savilleb564aae2014-10-23 10:18:09 -07002637 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002638 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002639 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2640 }
2641
Wink Savilleb564aae2014-10-23 10:18:09 -07002642 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002643 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002644 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2645 }
2646
Wink Savilleb564aae2014-10-23 10:18:09 -07002647 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649
2650 final long identity = Binder.clearCallingIdentity();
2651 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002652 Phone phone = getPhone(subId);
2653 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 checkSimPin.start();
2655 return checkSimPin.unlockSim(null, pin);
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
Wink Savilleb564aae2014-10-23 10:18:09 -07002661 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002666 Phone phone = getPhone(subId);
2667 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 checkSimPuk.start();
2669 return checkSimPuk.unlockSim(puk, pin);
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 }
2674
2675 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002676 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 * a synchronous one.
2678 */
2679 private static class UnlockSim extends Thread {
2680
2681 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002682 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683
2684 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002685 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2686 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687
2688 // For replies from SimCard interface
2689 private Handler mHandler;
2690
2691 // For async handler to identify request type
2692 private static final int SUPPLY_PIN_COMPLETE = 100;
2693
Michele Berionne5e411512020-11-13 02:36:59 +00002694 UnlockSim(int phoneId, IccCard simCard) {
2695 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 mSimCard = simCard;
2697 }
2698
2699 @Override
2700 public void run() {
2701 Looper.prepare();
2702 synchronized (UnlockSim.this) {
2703 mHandler = new Handler() {
2704 @Override
2705 public void handleMessage(Message msg) {
2706 AsyncResult ar = (AsyncResult) msg.obj;
2707 switch (msg.what) {
2708 case SUPPLY_PIN_COMPLETE:
2709 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2710 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002711 mRetryCount = msg.arg1;
2712 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002713 CommandException.Error error = null;
2714 if (ar.exception instanceof CommandException) {
2715 error = ((CommandException) (ar.exception))
2716 .getCommandError();
2717 }
2718 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002719 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002720 } else if (error == CommandException.Error.ABORTED) {
2721 /* When UiccCardApp dispose, handle message and return
2722 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002723 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002724 } else {
2725 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2726 }
2727 } else {
2728 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 mDone = true;
2731 UnlockSim.this.notifyAll();
2732 }
2733 break;
2734 }
2735 }
2736 };
2737 UnlockSim.this.notifyAll();
2738 }
2739 Looper.loop();
2740 }
2741
2742 /*
2743 * Use PIN or PUK to unlock SIM card
2744 *
2745 * If PUK is null, unlock SIM card with PIN
2746 *
2747 * If PUK is not null, unlock SIM card with PUK and set PIN code
2748 */
Wink Saville9de0f752013-10-22 19:04:03 -07002749 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750
2751 while (mHandler == null) {
2752 try {
2753 wait();
2754 } catch (InterruptedException e) {
2755 Thread.currentThread().interrupt();
2756 }
2757 }
2758 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2759
2760 if (puk == null) {
2761 mSimCard.supplyPin(pin, callback);
2762 } else {
2763 mSimCard.supplyPuk(puk, pin, callback);
2764 }
2765
2766 while (!mDone) {
2767 try {
2768 Log.d(LOG_TAG, "wait for done");
2769 wait();
2770 } catch (InterruptedException e) {
2771 // Restore the interrupted status
2772 Thread.currentThread().interrupt();
2773 }
2774 }
2775 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002776 int[] resultArray = new int[2];
2777 resultArray[0] = mResult;
2778 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002779
2780 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002781 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002782 }
2783
Wink Saville9de0f752013-10-22 19:04:03 -07002784 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002785 }
2786 }
2787
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002788 /**
2789 * This method has been removed due to privacy and stability concerns.
2790 */
2791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002793 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2794 return;
Wink Saville36469e72014-06-11 15:17:00 -07002795 }
2796
Nathan Harold1f889d82020-06-04 17:05:26 -07002797 @Override
2798 public void updateServiceLocationWithPackageName(String callingPackage) {
2799 mApp.getSystemService(AppOpsManager.class)
2800 .checkPackage(Binder.getCallingUid(), callingPackage);
2801
Nathan Haroldf096d982020-11-18 17:18:06 -08002802 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002803 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2804 // Callers targeting S have no business invoking this method.
2805 return;
2806 }
2807
2808 LocationAccessPolicy.LocationPermissionResult locationResult =
2809 LocationAccessPolicy.checkLocationPermission(mApp,
2810 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2811 .setCallingPackage(callingPackage)
2812 .setCallingFeatureId(null)
2813 .setCallingPid(Binder.getCallingPid())
2814 .setCallingUid(Binder.getCallingUid())
2815 .setMethod("updateServiceLocation")
2816 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2817 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2818 .build());
2819 // Apps that lack location permission have no business calling this method;
2820 // however, because no permission was declared in the public API, denials must
2821 // all be "soft".
2822 switch (locationResult) {
2823 case DENIED_HARD: /* fall through */
2824 case DENIED_SOFT:
2825 return;
2826 }
2827
2828 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 final long identity = Binder.clearCallingIdentity();
2830 try {
Ling Mac28f0212023-03-24 16:07:15 -07002831 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832 } finally {
2833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 }
2836
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002837 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002838 @Override
2839 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002840 return isRadioOnWithFeature(callingPackage, null);
2841 }
2842
2843
2844 @Override
2845 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2846 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2847 callingFeatureId);
2848 }
2849
2850 @Deprecated
2851 @Override
2852 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2853 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002854 }
2855
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002856 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002857 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2858 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002860 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002861 return false;
2862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 return isRadioOnForSubscriber(subId);
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002870 }
2871
2872 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 final Phone phone = getPhone(subId);
2876 if (phone != null) {
2877 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2878 } else {
2879 return false;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
2886 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002887 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 }
Wink Saville36469e72014-06-11 15:17:00 -07002889
Wink Savilleb564aae2014-10-23 10:18:09 -07002890 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 final Phone phone = getPhone(subId);
2896 if (phone != null) {
2897 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Wink Saville36469e72014-06-11 15:17:00 -07002902 }
2903
2904 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002905 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002906 }
2907
Wink Savilleb564aae2014-10-23 10:18:09 -07002908 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002909 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 final Phone phone = getPhone(subId);
2914 if (phone == null) {
2915 return false;
2916 }
2917 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2918 toggleRadioOnOffForSubscriber(subId);
2919 }
2920 return true;
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 }
Wink Saville36469e72014-06-11 15:17:00 -07002925
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002926 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002927 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002928 /*
2929 * If any of the Radios are available, it will need to be
2930 * shutdown. So return true if any Radio is available.
2931 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2935 Phone phone = PhoneFactory.getPhone(i);
2936 if (phone != null && phone.isRadioAvailable()) return true;
2937 }
2938 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2939 return false;
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002942 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002943 }
2944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002946 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947 enforceModifyPermission();
2948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2952 logv("Shutting down Phone " + i);
2953 shutdownRadioUsingPhoneId(i);
2954 }
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002957 }
2958 }
2959
2960 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002961 Phone phone = PhoneFactory.getPhone(phoneId);
2962 if (phone != null && phone.isRadioAvailable()) {
2963 phone.shutdownRadio();
2964 }
2965 }
2966
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969
Ling Ma83dc5ea2023-01-12 15:06:04 -08002970 if (!turnOn) {
2971 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2972 }
2973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2977 if (defaultPhone != null) {
2978 defaultPhone.setRadioPower(turnOn);
2979 return true;
2980 } else {
2981 loge("There's no default phone.");
2982 return false;
2983 }
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002986 }
Wink Saville36469e72014-06-11 15:17:00 -07002987 }
2988
Wink Savilleb564aae2014-10-23 10:18:09 -07002989 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991
Ling Ma83dc5ea2023-01-12 15:06:04 -08002992 if (!turnOn) {
2993 log("setRadioPowerForSubscriber off: subId=" + subId
2994 + ",callingPackage=" + getCurrentPackageName());
2995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 final Phone phone = getPhone(subId);
2999 if (phone != null) {
3000 phone.setRadioPower(turnOn);
3001 return true;
3002 } else {
3003 return false;
3004 }
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 }
3009
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003010 /**
3011 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3012 * no reason to power it off. When any of the voters want to power it off, it will be turned
3013 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3014 * powering it off, and these radio off votes will be cleared.
3015 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3016 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3017 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3018 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3019 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3020 * check its vote.
3021 *
3022 * @param subId The subscription ID.
3023 * @param reason The reason for powering off radio.
3024 * @return true on success and false on failure.
3025 */
3026 public boolean requestRadioPowerOffForReason(int subId,
3027 @TelephonyManager.RadioPowerReason int reason) {
3028 enforceModifyPermission();
3029
Ling Ma83dc5ea2023-01-12 15:06:04 -08003030 log("requestRadioPowerOffForReason: subId=" + subId
3031 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003032 final long identity = Binder.clearCallingIdentity();
3033 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003034 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003035 if (phone != null) {
3036 phone.setRadioPowerForReason(false, reason);
3037 return true;
3038 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003039 loge("requestRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003040 return false;
3041 }
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
3045 }
3046
3047 /**
3048 * Remove the vote on powering off the radio for a reason, as requested by
3049 * {@link requestRadioPowerOffForReason}.
3050 *
3051 * @param subId The subscription ID.
3052 * @param reason The reason for powering off radio.
3053 * @return true on success and false on failure.
3054 */
3055 public boolean clearRadioPowerOffForReason(int subId,
3056 @TelephonyManager.RadioPowerReason int reason) {
3057 enforceModifyPermission();
3058
3059 final long identity = Binder.clearCallingIdentity();
3060 try {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003061 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003062 if (phone != null) {
3063 phone.setRadioPowerForReason(true, reason);
3064 return true;
3065 } else {
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003066 loge("clearRadioPowerOffForReason: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003067 return false;
3068 }
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 /**
3075 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3076 *
3077 * @param subId The subscription ID.
3078 * @param callingPackage The package making the call.
3079 * @param callingFeatureId The feature in the package.
3080 * @return List of reasons for powering off radio.
3081 */
3082 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3083 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3084
3085 final long identity = Binder.clearCallingIdentity();
3086 List result = new ArrayList();
3087 try {
3088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3089 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3090 return result;
3091 }
3092
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003093 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 if (phone != null) {
3095 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003096 } else {
3097 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003098 }
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
3102 return result;
3103 }
3104
Wink Saville36469e72014-06-11 15:17:00 -07003105 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003106 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003107 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
Jack Yu285100e2022-12-02 22:48:35 -08003112 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final Phone phone = getPhone(subId);
3114 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003115 phone.getDataSettingsManager().setDataEnabled(
3116 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 return true;
3118 } else {
3119 return false;
3120 }
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124 }
3125
Wink Saville36469e72014-06-11 15:17:00 -07003126 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003127 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003128 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
Jack Yu285100e2022-12-02 22:48:35 -08003133 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 final Phone phone = getPhone(subId);
3135 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003136 phone.getDataSettingsManager().setDataEnabled(
3137 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 return true;
3139 } else {
3140 return false;
3141 }
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 }
3146
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003148 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 final Phone phone = getPhone(subId);
3152 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003153 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003154 } else {
3155 return false;
3156 }
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
3162 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003163 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003164 }
3165
pkanwarae03a6b2016-11-06 20:37:09 -08003166 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 enforceCallPermission();
3168
3169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3172 return;
3173 }
3174 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3175 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3176 } finally {
3177 Binder.restoreCallingIdentity(identity);
3178 }
pkanwar32d516d2016-10-14 19:37:38 -07003179 };
3180
Wink Savilleb564aae2014-10-23 10:18:09 -07003181 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3187 return false;
3188 }
3189 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3190 } finally {
3191 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 }
3194
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003195 /**
3196 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3197 * tag on getCallState Binder call.
3198 */
3199 @Deprecated
3200 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003202 if (CompatChanges.isChangeEnabled(
3203 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3204 Binder.getCallingUid())) {
3205 // Do not allow this API to be called on API version 31+, it should only be
3206 // called on old apps using this Binder call directly.
3207 throw new SecurityException("This method can only be used for applications "
3208 + "targeting API version 30 or less.");
3209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
Ling Mac28f0212023-03-24 16:07:15 -07003212 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3213 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
3220 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3221 if (CompatChanges.isChangeEnabled(
3222 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3223 Binder.getCallingUid())) {
3224 // Check READ_PHONE_STATE for API version 31+
3225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3226 featureId, "getCallStateForSubscription")) {
3227 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3228 + "targeting API level 31+.");
3229 }
3230 }
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3235 PhoneConstantConversions.convertCallState(phone.getState());
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 }
3240
Sanket Padawe356d7632015-06-22 14:03:32 -07003241 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003242 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003243 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003244 }
3245
3246 @Override
3247 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003252 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 } else {
3254 return PhoneConstantConversions.convertDataState(
3255 PhoneConstants.DataState.DISCONNECTED);
3256 }
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003260 }
3261
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003263 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003264 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003265 }
3266
3267 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003268 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003271 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003273 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 } else {
3275 return TelephonyManager.DATA_ACTIVITY_NONE;
3276 }
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
3282 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003283 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003284 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003285 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003286
3287 LocationAccessPolicy.LocationPermissionResult locationResult =
3288 LocationAccessPolicy.checkLocationPermission(mApp,
3289 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3290 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003291 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003292 .setCallingPid(Binder.getCallingPid())
3293 .setCallingUid(Binder.getCallingUid())
3294 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003295 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003296 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3297 .build());
3298 switch (locationResult) {
3299 case DENIED_HARD:
3300 throw new SecurityException("Not allowed to access cell location");
3301 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003302 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3303 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 }
3305
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003306 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003310 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003311 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
Svetoslav64fad262015-04-14 14:35:21 -07003315 }
3316
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003318 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003319 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3320 // registered cell info, so return a NULL country instead.
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003323 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3324 // Get default phone in this case.
3325 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3326 }
Jack Yu285100e2022-12-02 22:48:35 -08003327 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003329 if (phone == null) return "";
3330 ServiceStateTracker sst = phone.getServiceStateTracker();
3331 if (sst == null) return "";
3332 LocaleTracker lt = sst.getLocaleTracker();
3333 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003334 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003338 }
3339
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003340 /**
3341 * This method was removed due to potential issues caused by performing partial
3342 * updates of service state, and lack of a credible use case.
3343 *
3344 * This has the ability to break the telephony implementation by disabling notification of
3345 * changes in device connectivity. DO NOT USE THIS!
3346 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003347 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 public void enableLocationUpdates() {
3349 mApp.enforceCallingOrSelfPermission(
3350 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003351 }
3352
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003353 /**
3354 * This method was removed due to potential issues caused by performing partial
3355 * updates of service state, and lack of a credible use case.
3356 *
3357 * This has the ability to break the telephony implementation by disabling notification of
3358 * changes in device connectivity. DO NOT USE THIS!
3359 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003360 @Override
3361 public void disableLocationUpdates() {
3362 mApp.enforceCallingOrSelfPermission(
3363 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 }
3365
3366 @Override
3367 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003368 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3369 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003370 try {
3371 mApp.getSystemService(AppOpsManager.class)
3372 .checkPackage(Binder.getCallingUid(), callingPackage);
3373 } catch (SecurityException e) {
3374 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3375 throw e;
3376 }
3377
Nathan Haroldf096d982020-11-18 17:18:06 -08003378 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003379 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3380 throw new SecurityException(
3381 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3382 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003383
Jordan Liu1617b712019-07-10 15:06:26 -07003384 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003385 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3386 return null;
3387 }
Svetoslav64fad262015-04-14 14:35:21 -07003388
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003389 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003391 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003392 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393
Nathan Haroldf180aac2018-06-01 18:43:55 -07003394 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3395 for (CellInfo ci : info) {
3396 if (ci instanceof CellInfoGsm) {
3397 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3398 } else if (ci instanceof CellInfoWcdma) {
3399 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003402 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 }
3404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 private List<CellInfo> getCachedCellInfo() {
3406 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3407 for (Phone phone : PhoneFactory.getPhones()) {
3408 List<CellInfo> info = phone.getAllCellInfo();
3409 if (info != null) cellInfos.addAll(info);
3410 }
3411 return cellInfos;
3412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413
3414 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003415 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003416 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003417 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003418
3419 LocationAccessPolicy.LocationPermissionResult locationResult =
3420 LocationAccessPolicy.checkLocationPermission(mApp,
3421 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3422 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003423 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003424 .setCallingPid(Binder.getCallingPid())
3425 .setCallingUid(Binder.getCallingUid())
3426 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003427 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003428 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3429 .build());
3430 switch (locationResult) {
3431 case DENIED_HARD:
3432 throw new SecurityException("Not allowed to access cell info");
3433 case DENIED_SOFT:
3434 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 }
3436
Nathan Haroldf096d982020-11-18 17:18:06 -08003437 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003438 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3439 return getCachedCellInfo();
3440 }
3441
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003442 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3447 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003448 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003449 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 if (info != null) cellInfos.addAll(info);
3451 }
3452 return cellInfos;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456 }
3457
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003459 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3460 String callingFeatureId) {
3461 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3462 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003463 }
3464
3465 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003466 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3467 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003468 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003469 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003470 }
3471
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003472 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3473 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003475 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003476
3477 LocationAccessPolicy.LocationPermissionResult locationResult =
3478 LocationAccessPolicy.checkLocationPermission(mApp,
3479 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3480 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003481 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003482 .setCallingPid(Binder.getCallingPid())
3483 .setCallingUid(Binder.getCallingUid())
3484 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003485 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3486 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003487 .build());
3488 switch (locationResult) {
3489 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003490 if (TelephonyPermissions
3491 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003492 // Safetynet logging for b/154934934
3493 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3494 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003495 throw new SecurityException("Not allowed to access cell info");
3496 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003497 if (TelephonyPermissions
3498 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003499 // Safetynet logging for b/154934934
3500 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3501 }
Nathan Harold5320c422019-05-09 10:26:08 -07003502 try {
3503 cb.onCellInfo(new ArrayList<CellInfo>());
3504 } catch (RemoteException re) {
3505 // Drop without consequences
3506 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003507 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003508 }
3509
Nathan Harolda939a962019-05-09 10:13:47 -07003510
3511 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003512 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3513
3514 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3515 }
3516
3517 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003518 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003519 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003524 Phone phone = getPhone(subId);
3525 if (phone == null) {
3526 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3527 } else {
3528 phone.setCellInfoListRate(rateInMillis, workSource);
3529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
Shishir Agrawala9f32182016-04-12 12:00:16 -07003535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003536 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 return null;
3540 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003542 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003543 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003544 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003545 return null;
3546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 return phone.getImei();
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003554 }
3555
3556 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003557 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3558 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3559 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3560 callingFeatureId, "getPrimaryImei")) {
3561 throw new SecurityException("Caller does not have permission");
3562 }
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 for (Phone phone : PhoneFactory.getPhones()) {
3566 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3567 return phone.getImei();
3568 }
3569 }
3570 throw new UnsupportedOperationException("Operation not supported");
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 }
3575
3576 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003577 public String getTypeAllocationCodeForSlot(int slotIndex) {
3578 Phone phone = PhoneFactory.getPhone(slotIndex);
3579 String tac = null;
3580 if (phone != null) {
3581 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003582 try {
3583 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3584 } catch (IndexOutOfBoundsException e) {
3585 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3586 return null;
3587 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003588 }
3589 return tac;
3590 }
3591
3592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003593 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003594 try {
3595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3596 } catch (SecurityException se) {
3597 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3598 throw new SecurityException("Package " + callingPackage + " does not belong to "
3599 + Binder.getCallingUid());
3600 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003601 Phone phone = PhoneFactory.getPhone(slotIndex);
3602 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003603 return null;
3604 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605
Jeff Davidson913390f2018-02-23 17:11:49 -08003606 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003607 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003608 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003609 return null;
3610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611
3612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 return phone.getMeid();
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
Jack Yu2af8d712017-03-15 17:14:14 -07003618 }
3619
3620 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003621 public String getManufacturerCodeForSlot(int slotIndex) {
3622 Phone phone = PhoneFactory.getPhone(slotIndex);
3623 String manufacturerCode = null;
3624 if (phone != null) {
3625 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003626 try {
3627 manufacturerCode =
3628 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3629 } catch (IndexOutOfBoundsException e) {
3630 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3631 return null;
3632 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003633 }
3634 return manufacturerCode;
3635 }
3636
3637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3639 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 Phone phone = PhoneFactory.getPhone(slotIndex);
3641 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 return null;
3643 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 int subId = phone.getSubId();
3645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003646 mApp, subId, callingPackage, callingFeatureId,
3647 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003648 return null;
3649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 return phone.getDeviceSvn();
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003657 }
3658
fionaxu43304da2017-11-27 22:51:16 -08003659 @Override
3660 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = getPhone(subId);
3664 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
fionaxu43304da2017-11-27 22:51:16 -08003668 }
3669
3670 @Override
3671 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 final Phone phone = getPhone(subId);
3675 return phone == null ? null : phone.getCarrierName();
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
fionaxu43304da2017-11-27 22:51:16 -08003679 }
3680
calvinpanffe225e2018-11-01 19:43:06 +08003681 @Override
chen xu0026ca62019-03-06 15:28:50 -08003682 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003687 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
chen xu0026ca62019-03-06 15:28:50 -08003694 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003698 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
3702 }
3703
chen xu651eec72018-11-11 19:03:44 -08003704 @Override
chen xu864e11c2018-12-06 22:10:03 -08003705 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3706 if (!isSubscriptionMccMnc) {
3707 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3708 }
chen xu651eec72018-11-11 19:03:44 -08003709 final Phone phone = PhoneFactory.getPhone(slotIndex);
3710 if (phone == null) {
3711 return TelephonyManager.UNKNOWN_CARRIER_ID;
3712 }
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
3719 }
3720
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 //
3722 // Internal helper methods.
3723 //
3724
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003725 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003726 * Make sure the caller is the calling package itself
3727 *
3728 * @throws SecurityException if the caller is not the calling package
3729 */
3730 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3731 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003732 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3733 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003734 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003735 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003736 } catch (PackageManager.NameNotFoundException e) {
3737 // packageUid is -1
3738 }
3739 if (packageUid != callingUid) {
3740 throw new SecurityException(message + ": Package " + callingPackage
3741 + " does not belong to " + callingUid);
3742 }
3743 }
3744
3745 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003746 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3747 *
3748 * @throws SecurityException if the caller does not have the required permission
3749 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003750 @VisibleForTesting
3751 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003752 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3753 }
3754
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003755 /**
arunvoddud7401012022-12-15 16:08:12 +00003756 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003757 *
3758 * @throws SecurityException if the caller does not have the required permission
3759 */
3760 @VisibleForTesting
3761 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003762 enforceReadPermission(null);
3763 }
3764
3765 /**
3766 * Make sure the caller has the READ_PHONE_STATE permissions.
3767 *
3768 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3769 */
3770 @VisibleForTesting
3771 public void enforceReadPermission(String msg) {
3772 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003773 }
3774
Shuo Qian3b6ee772019-11-13 17:43:31 -08003775 private void enforceActiveEmergencySessionPermission() {
3776 mApp.enforceCallingOrSelfPermission(
3777 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3778 }
3779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003780 /**
3781 * Make sure the caller has the CALL_PHONE permission.
3782 *
3783 * @throws SecurityException if the caller does not have the required permission
3784 */
3785 private void enforceCallPermission() {
3786 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3787 }
3788
paulhu5a773602019-08-23 19:17:33 +08003789 private void enforceSettingsPermission() {
3790 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003791 }
3792
Michele Berionne5e411512020-11-13 02:36:59 +00003793 private void enforceRebootPermission() {
3794 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3795 }
3796
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003797 /**
3798 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3799 * @param message - log message to print.
3800 * @throws SecurityException if the caller does not have the required permission
3801 */
3802 private void enforceSatelliteCommunicationPermission(String message) {
3803 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3804 }
3805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003806 private String createTelUrl(String number) {
3807 if (TextUtils.isEmpty(number)) {
3808 return null;
3809 }
3810
Jake Hambye994d462014-02-03 13:10:13 -08003811 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 }
3813
Ihab Awadf9e92732013-12-05 18:02:52 -08003814 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003815 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003818 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003819 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003820 }
3821
Ihab Awadf9e92732013-12-05 18:02:52 -08003822 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003823 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003824 }
3825
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003827 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003828 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003829 }
3830
Sanket Padawe356d7632015-06-22 14:03:32 -07003831 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003832 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 final Phone phone = PhoneFactory.getPhone(slotIndex);
3836 if (phone == null) {
3837 return PhoneConstants.PHONE_TYPE_NONE;
3838 } else {
3839 return phone.getPhoneType();
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003844 }
3845
3846 /**
3847 * Returns the CDMA ERI icon index to display
3848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003850 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3851 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3852 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003853 }
3854
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 mApp, subId, callingPackage, callingFeatureId,
3860 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003861 return -1;
3862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863
3864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 final Phone phone = getPhone(subId);
3867 if (phone != null) {
3868 return phone.getCdmaEriIconIndex();
3869 } else {
3870 return -1;
3871 }
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 }
3876
3877 /**
3878 * Returns the CDMA ERI icon mode,
3879 * 0 - ON
3880 * 1 - FLASHING
3881 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003883 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3884 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3885 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003886 }
3887
Sanket Padawe356d7632015-06-22 14:03:32 -07003888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003889 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3890 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003892 mApp, subId, callingPackage, callingFeatureId,
3893 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003894 return -1;
3895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896
3897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 final Phone phone = getPhone(subId);
3900 if (phone != null) {
3901 return phone.getCdmaEriIconMode();
3902 } else {
3903 return -1;
3904 }
3905 } finally {
3906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003908 }
3909
3910 /**
3911 * Returns the CDMA ERI text,
3912 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003913 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003914 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3915 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3916 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003917 }
3918
Sanket Padawe356d7632015-06-22 14:03:32 -07003919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003920 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3921 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003923 mApp, subId, callingPackage, callingFeatureId,
3924 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003925 return null;
3926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 final Phone phone = getPhone(subId);
3931 if (phone != null) {
3932 return phone.getCdmaEriText();
3933 } else {
3934 return null;
3935 }
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 }
3940
3941 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003942 * Returns the CDMA MDN.
3943 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003944 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003945 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3947 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 return phone.getLine1Number();
3954 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 return null;
3957 }
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003960 }
3961 }
3962
3963 /**
3964 * Returns the CDMA MIN.
3965 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003966 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003967 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3969 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 final Phone phone = getPhone(subId);
3974 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3975 return phone.getCdmaMin();
3976 } else {
3977 return null;
3978 }
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003981 }
3982 }
3983
Hall Liud892bec2018-11-30 14:51:45 -08003984 @Override
3985 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3986 INumberVerificationCallback callback, String callingPackage) {
3987 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3988 != PERMISSION_GRANTED) {
3989 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3990 }
3991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3992
3993 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3994 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003995 throw new SecurityException("Calling package must be configured in the device config: "
3996 + "calling package: " + callingPackage
3997 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003998 }
3999
4000 if (range == null) {
4001 throw new NullPointerException("Range must be non-null");
4002 }
4003
4004 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004005 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004006
4007 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4008 }
4009
Junda Liuca05d5d2014-08-14 22:36:34 -07004010 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004011 * Returns true if CDMA provisioning needs to run.
4012 */
4013 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004016 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 }
4021
4022 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004023 * Sets the voice mail number of a given subId.
4024 */
4025 @Override
4026 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4028 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029
4030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4033 new Pair<String, String>(alphaTag, number), new Integer(subId));
4034 return success;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004038 }
4039
Ta-wei Yen87c49842016-05-13 21:19:52 -07004040 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004041 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004043 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4044 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004045 if (!TextUtils.equals(callingPackage, systemDialer)) {
4046 throw new SecurityException("caller must be system dialer");
4047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4052 if (phoneAccountHandle == null) {
4053 return null;
4054 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 } finally {
4057 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004058 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004059 }
4060
4061 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004062 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4063 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 mApp, subId, callingPackage, callingFeatureId,
4067 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004068 return null;
4069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004071 final long identity = Binder.clearCallingIdentity();
4072 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004073 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004077 }
4078
4079 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004080 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4081 VisualVoicemailSmsFilterSettings settings) {
4082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004091 }
4092
4093 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004094 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4095 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004100 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004104 }
4105
4106 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004107 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4108 String callingPackage, int subId) {
4109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 } finally {
4116 Binder.restoreCallingIdentity(identity);
4117 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004118 }
4119
4120 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004121 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004127 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004131 }
4132
4133 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004134 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4135 String callingAttributionTag, int subId, String number, int port, String text,
4136 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004138 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004139 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004140 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004141 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4142 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004143 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004144
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004145 /**
fionaxu0152e512016-11-14 13:36:14 -08004146 * Sets the voice activation state of a given subId.
4147 */
4148 @Override
4149 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4151 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 final Phone phone = getPhone(subId);
4156 if (phone != null) {
4157 phone.setVoiceActivationState(activationState);
4158 } else {
4159 loge("setVoiceActivationState fails with invalid subId: " + subId);
4160 }
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004163 }
4164 }
4165
4166 /**
4167 * Sets the data activation state of a given subId.
4168 */
4169 @Override
4170 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4172 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 final Phone phone = getPhone(subId);
4177 if (phone != null) {
4178 phone.setDataActivationState(activationState);
4179 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004180 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 }
4182 } finally {
4183 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004184 }
4185 }
4186
4187 /**
4188 * Returns the voice activation state of a given subId.
4189 */
4190 @Override
4191 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193
fionaxu0152e512016-11-14 13:36:14 -08004194 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 if (phone != null) {
4198 return phone.getVoiceActivationState();
4199 } else {
4200 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4201 }
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004204 }
4205 }
4206
4207 /**
4208 * Returns the data activation state of a given subId.
4209 */
4210 @Override
4211 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
fionaxu0152e512016-11-14 13:36:14 -08004214 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 if (phone != null) {
4218 return phone.getDataActivationState();
4219 } else {
4220 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4221 }
4222 } finally {
4223 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004224 }
4225 }
4226
4227 /**
Wink Saville36469e72014-06-11 15:17:00 -07004228 * Returns the unread count of voicemails for a subId
4229 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004231 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4232 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 mApp, subId, callingPackage, callingFeatureId,
4235 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004236 return 0;
4237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 final long identity = Binder.clearCallingIdentity();
4239 try {
4240 final Phone phone = getPhone(subId);
4241 if (phone != null) {
4242 return phone.getVoiceMessageCount();
4243 } else {
4244 return 0;
4245 }
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004249 }
4250
4251 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004252 * returns true, if the device is in a state where both voice and data
4253 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004254 */
4255 @Override
4256 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
Ling Mac28f0212023-03-24 16:07:15 -07004259 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004263 }
4264
4265 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004266 * Send the dialer code if called from the current default dialer or the caller has
4267 * carrier privilege.
4268 * @param inputCode The dialer code to send
4269 */
4270 @Override
4271 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004274 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4275 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004276 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004277 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004283 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
fionaxu235cc5e2017-03-06 22:25:57 -08004287 }
4288
Pengquan Menga1bb6272018-09-06 09:59:22 -07004289 @Override
4290 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004291 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004292 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4293 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 if (!isActiveSubscription(subId)) {
4297 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4298 }
4299 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004303 }
4304
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004306 public boolean isInEmergencySmsMode() {
4307 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 for (Phone phone : PhoneFactory.getPhones()) {
4311 if (phone.isInEmergencySmsMode()) {
4312 return true;
4313 }
4314 }
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
4318 return false;
4319 }
4320
shilu366312e2019-12-17 09:28:10 -08004321 /**
4322 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4323 * @param subId The subscription to use to check the configuration.
4324 * @param c The callback that will be used to send the result.
4325 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004326 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004327 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4328 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004329 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004330 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004331
4332 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4334 "IMS not available on device.");
4335 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 final long token = Binder.clearCallingIdentity();
4337 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004338 int slotId = getSlotIndexOrException(subId);
4339 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004340
4341 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4342 if (controller != null) {
4343 ImsManager imsManager = controller.getImsManager(subId);
4344 if (imsManager != null) {
4345 imsManager.addRegistrationCallbackForSubscription(c, subId);
4346 } else {
4347 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4348 }
4349 } else {
4350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4351 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004352 } catch (ImsException e) {
4353 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 } finally {
4355 Binder.restoreCallingIdentity(token);
4356 }
4357 }
4358
shilu366312e2019-12-17 09:28:10 -08004359 /**
4360 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4361 * @param subId The subscription to use to check the configuration.
4362 * @param c The callback that will be used to send the result.
4363 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004365 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004366 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004367 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004368 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4369 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4370 }
Meng Wangafbc5852019-09-19 17:37:13 -07004371 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004372
Meng Wangafbc5852019-09-19 17:37:13 -07004373 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004374 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4375 if (controller != null) {
4376 ImsManager imsManager = controller.getImsManager(subId);
4377 if (imsManager != null) {
4378 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4379 } else {
4380 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4381 + "is inactive, ignoring unregister.");
4382 // If the ImsManager is not valid, just return, since the callback
4383 // will already have been removed internally.
4384 }
4385 }
Meng Wangafbc5852019-09-19 17:37:13 -07004386 } finally {
4387 Binder.restoreCallingIdentity(token);
4388 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 }
4390
Brad Ebingera34a6c22019-10-22 17:36:18 -07004391 /**
4392 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4393 */
4394 @Override
4395 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4396 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4397 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4398 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4399 "IMS not available on device.");
4400 }
4401 final long token = Binder.clearCallingIdentity();
4402 try {
4403 Phone phone = getPhone(subId);
4404 if (phone == null) {
4405 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4406 + subId + "'");
4407 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4408 }
4409 phone.getImsRegistrationState(regState -> {
4410 try {
4411 consumer.accept((regState == null)
4412 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4413 } catch (RemoteException e) {
4414 // Ignore if the remote process is no longer available to call back.
4415 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4416 }
4417 });
4418 } finally {
4419 Binder.restoreCallingIdentity(token);
4420 }
4421 }
4422
4423 /**
4424 * Get the transport type for the IMS service registration state.
4425 */
4426 @Override
4427 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004428 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004429 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004430 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4431 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4432 "IMS not available on device.");
4433 }
4434 final long token = Binder.clearCallingIdentity();
4435 try {
4436 Phone phone = getPhone(subId);
4437 if (phone == null) {
4438 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4439 + subId + "'");
4440 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4441 }
4442 phone.getImsRegistrationTech(regTech -> {
4443 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4444 int regTechConverted = (regTech == null)
4445 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4446 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4447 regTechConverted);
4448 try {
4449 consumer.accept(regTechConverted);
4450 } catch (RemoteException e) {
4451 // Ignore if the remote process is no longer available to call back.
4452 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4453 }
4454 });
4455 } finally {
4456 Binder.restoreCallingIdentity(token);
4457 }
4458 }
4459
shilu366312e2019-12-17 09:28:10 -08004460 /**
4461 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4462 * @param subId The subscription to use to check the configuration.
4463 * @param c The callback that will be used to send the result.
4464 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004466 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4467 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004468 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004469 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004470 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4471 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4472 "IMS not available on device.");
4473 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004474 final long token = Binder.clearCallingIdentity();
4475 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004476 int slotId = getSlotIndexOrException(subId);
4477 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004478
4479 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4480 if (controller != null) {
4481 ImsManager imsManager = controller.getImsManager(subId);
4482 if (imsManager != null) {
4483 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4484 } else {
4485 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4486 }
4487 } else {
4488 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4489 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (ImsException e) {
4491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 } finally {
4493 Binder.restoreCallingIdentity(token);
4494 }
4495 }
4496
shilu366312e2019-12-17 09:28:10 -08004497 /**
4498 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4499 * @param subId The subscription to use to check the configuration.
4500 * @param c The callback that will be used to send the result.
4501 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004503 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004504 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004505 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004506 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4507 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4508 }
Meng Wangafbc5852019-09-19 17:37:13 -07004509
4510 final long token = Binder.clearCallingIdentity();
4511 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004512 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4513 if (controller != null) {
4514 ImsManager imsManager = controller.getImsManager(subId);
4515 if (imsManager != null) {
4516 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4517 } else {
4518 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4519 + " is inactive, ignoring unregister.");
4520 // If the ImsManager is not valid, just return, since the callback
4521 // will already have been removed internally.
4522 }
4523 }
Meng Wangafbc5852019-09-19 17:37:13 -07004524 } finally {
4525 Binder.restoreCallingIdentity(token);
4526 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 }
4528
4529 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004530 public boolean isCapable(int subId, int capability, int regTech) {
4531 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 final long token = Binder.clearCallingIdentity();
4533 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004534 int slotId = getSlotIndexOrException(subId);
4535 verifyImsMmTelConfiguredOrThrow(slotId);
4536 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4537 } catch (com.android.ims.ImsException e) {
4538 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4539 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004540 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004541 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4542 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 } finally {
4544 Binder.restoreCallingIdentity(token);
4545 }
4546 }
4547
4548 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004549 public boolean isAvailable(int subId, int capability, int regTech) {
4550 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004551 final long token = Binder.clearCallingIdentity();
4552 try {
4553 Phone phone = getPhone(subId);
4554 if (phone == null) return false;
4555 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004556 } catch (com.android.ims.ImsException e) {
4557 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4558 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004559 } finally {
4560 Binder.restoreCallingIdentity(token);
4561 }
4562 }
4563
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004564 /**
4565 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4566 * subscription.
4567 * @param subId The subscription to use to check the configuration.
4568 * @param callback The callback that will be used to send the result.
4569 * @param capability The MmTelFeature capability that will be used to send the result.
4570 * @param transportType The transport type of the MmTelFeature capability.
4571 */
4572 @Override
4573 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4574 int transportType) {
4575 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004576 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4577 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4578 "IMS not available on device.");
4579 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004580 final long token = Binder.clearCallingIdentity();
4581 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004582 int slotId = getSlotIndex(subId);
4583 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4584 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4585 + subId + "'");
4586 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4587 }
4588 verifyImsMmTelConfiguredOrThrow(slotId);
4589 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4590 transportType, aBoolean -> {
4591 try {
4592 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4593 } catch (RemoteException e) {
4594 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4595 + "running. Ignore");
4596 }
4597 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004598 } catch (ImsException e) {
4599 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004600 } finally {
4601 Binder.restoreCallingIdentity(token);
4602 }
4603 }
4604
shilu366312e2019-12-17 09:28:10 -08004605 /**
4606 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4607 * @param subId The subscription to use to check the configuration.
4608 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004609 @Override
4610 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004611 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004612 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004613
Brad Ebinger35c841c2018-10-01 10:40:55 -07004614 final long token = Binder.clearCallingIdentity();
4615 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004616 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004617 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004618 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004619 } catch (ImsException e) {
4620 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 } finally {
4622 Binder.restoreCallingIdentity(token);
4623 }
4624 }
4625
4626 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004627 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004629 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 final long identity = Binder.clearCallingIdentity();
4631 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004632 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004633 // This setting doesn't require an active ImsService connection, so do not verify. The
4634 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004635 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004636 } catch (ImsException e) {
4637 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
4641 }
4642
shilu366312e2019-12-17 09:28:10 -08004643 /**
4644 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4645 * @param subId The subscription to use to check the configuration.
4646 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004647 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004648 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004649 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004650 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004651 final long identity = Binder.clearCallingIdentity();
4652 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004653 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004654 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004655 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004656 } catch (ImsException e) {
4657 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 } finally {
4659 Binder.restoreCallingIdentity(identity);
4660 }
4661 }
4662
4663 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004664 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004666 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 final long identity = Binder.clearCallingIdentity();
4668 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004669 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004670 // This setting doesn't require an active ImsService connection, so do not verify. The
4671 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004672 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004673 } catch (ImsException e) {
4674 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
4678 }
4679
shilu366312e2019-12-17 09:28:10 -08004680 /**
4681 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4682 * @param subId The subscription to use to check the configuration.
4683 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004684 @Override
4685 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004686 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004687 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004688 final long identity = Binder.clearCallingIdentity();
4689 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004691 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 } catch (ImsException e) {
4694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
4700 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004701 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004703 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004704 final long identity = Binder.clearCallingIdentity();
4705 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004706 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004707 // This setting doesn't require an active ImsService connection, so do not verify. The
4708 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004709 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004710 } catch (ImsException e) {
4711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
4715 }
4716
shilu366312e2019-12-17 09:28:10 -08004717 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004718 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4719 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4720 * @param subId The subscription to use to check the configuration.
4721 */
4722 @Override
4723 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004724 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004725 mApp, subId, "isCrossSimCallingEnabledByUser");
4726 final long identity = Binder.clearCallingIdentity();
4727 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004728 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004729 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004730 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004731 } catch (ImsException e) {
4732 throw new ServiceSpecificException(e.getCode());
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
4736 }
4737
4738 /**
4739 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4740 * Requires MODIFY_PHONE_STATE permission.
4741 * @param subId The subscription to use to check the configuration.
4742 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4743 * false otherwise
4744 */
4745 @Override
4746 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4748 "setCrossSimCallingEnabled");
4749 final long identity = Binder.clearCallingIdentity();
4750 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004751 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004752 // This setting doesn't require an active ImsService connection, so do not verify. The
4753 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004754 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004755 } catch (ImsException e) {
4756 throw new ServiceSpecificException(e.getCode());
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
4762 /**
shilu366312e2019-12-17 09:28:10 -08004763 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4764 * @param subId The subscription to use to check the configuration.
4765 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004766 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004767
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004769 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004770 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 final long identity = Binder.clearCallingIdentity();
4772 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004773 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004774 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004775 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004776 } catch (ImsException e) {
4777 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 } finally {
4779 Binder.restoreCallingIdentity(identity);
4780 }
4781 }
4782
4783 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004784 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004786 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004787 final long identity = Binder.clearCallingIdentity();
4788 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004789 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004790 // This setting doesn't require an active ImsService connection, so do not verify. The
4791 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004792 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004793 } catch (ImsException e) {
4794 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004795 } finally {
4796 Binder.restoreCallingIdentity(identity);
4797 }
4798 }
4799
4800 @Override
4801 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4803 "setVoWiFiNonPersistent");
4804 final long identity = Binder.clearCallingIdentity();
4805 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004806 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004807 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004808 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004809 } catch (ImsException e) {
4810 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004811 } finally {
4812 Binder.restoreCallingIdentity(identity);
4813 }
4814 }
4815
shilu366312e2019-12-17 09:28:10 -08004816 /**
4817 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4818 * @param subId The subscription to use to check the configuration.
4819 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004820 @Override
4821 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004822 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004823 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004824 final long identity = Binder.clearCallingIdentity();
4825 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004826 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004827 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004828 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004829 } catch (ImsException e) {
4830 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
4834 }
4835
4836 @Override
4837 public void setVoWiFiModeSetting(int subId, int mode) {
4838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4839 "setVoWiFiModeSetting");
4840 final long identity = Binder.clearCallingIdentity();
4841 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004842 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004843 // This setting doesn't require an active ImsService connection, so do not verify. The
4844 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004845 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*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 int getVoWiFiRoamingModeSetting(int subId) {
4855 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4856 final long identity = Binder.clearCallingIdentity();
4857 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004858 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004859 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004860 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004861 } catch (ImsException e) {
4862 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
4866 }
4867
4868 @Override
4869 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4871 "setVoWiFiRoamingModeSetting");
4872 final long identity = Binder.clearCallingIdentity();
4873 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004874 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004875 // This setting doesn't require an active ImsService connection, so do not verify. The
4876 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004877 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004878 } catch (ImsException e) {
4879 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
4883 }
4884
4885 @Override
4886 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4888 "setRttCapabilityEnabled");
4889 final long identity = Binder.clearCallingIdentity();
4890 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004891 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004892 // This setting doesn't require an active ImsService connection, so do not verify. The
4893 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004894 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004895 } catch (ImsException e) {
4896 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
4900 }
4901
shilu366312e2019-12-17 09:28:10 -08004902 /**
4903 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4904 * @param subId The subscription to use to check the configuration.
4905 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004906 @Override
4907 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004908 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004909 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004910 final long identity = Binder.clearCallingIdentity();
4911 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004912 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004913 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004914 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004915 } catch (ImsException e) {
4916 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
4920 }
4921
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 @Override
4923 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4924 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004925
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004926 final long identity = Binder.clearCallingIdentity();
4927 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004928 if (!isImsAvailableOnDevice()) {
4929 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4930 "IMS not available on device.");
4931 }
4932 int slotId = getSlotIndexOrException(subId);
4933 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004934
4935 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4936 if (controller != null) {
4937 ImsManager imsManager = controller.getImsManager(subId);
4938 if (imsManager != null) {
4939 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4940 } else {
4941 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4942 }
4943 } else {
4944 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4945 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004946 } catch (ImsException e) {
4947 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
4951 }
4952
4953 @Override
4954 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4955 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004956
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004957 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004958 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4959 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4960 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004961 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004962 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4963 if (controller != null) {
4964 ImsManager imsManager = controller.getImsManager(subId);
4965 if (imsManager != null) {
4966 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4967 } else {
4968 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4969 + " is inactive, ignoring unregister.");
4970 // If the ImsManager is not valid, just return, since the callback will already
4971 // have been removed internally.
4972 }
4973 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
4977 }
4978
joonhunshincffb7fc2021-11-28 07:32:01 +00004979 @Override
4980 public void registerFeatureProvisioningChangedCallback(int subId,
4981 IFeatureProvisioningCallback callback) {
4982 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4983 mApp, subId, "registerFeatureProvisioningChangedCallback");
4984
4985 final long identity = Binder.clearCallingIdentity();
4986 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4987 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4988 }
4989
joonhunshin91bc1952022-04-29 08:47:15 +00004990 try {
4991 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4992 if (controller == null) {
4993 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4994 "Device does not support IMS");
4995 }
4996 controller.addFeatureProvisioningChangedCallback(subId, callback);
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005000 }
5001
5002 @Override
5003 public void unregisterFeatureProvisioningChangedCallback(int subId,
5004 IFeatureProvisioningCallback callback) {
5005 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5006 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5007
5008 final long identity = Binder.clearCallingIdentity();
5009 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5010 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5011 }
5012
joonhunshin91bc1952022-04-29 08:47:15 +00005013 try {
5014 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5015 if (controller == null) {
5016 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5017 return;
5018 }
5019 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005023 }
allenwtsu99c623b2020-01-03 18:24:23 +08005024
5025 private void checkModifyPhoneStatePermission(int subId, String message) {
5026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5027 message);
5028 }
5029
allenwtsu99c623b2020-01-03 18:24:23 +08005030 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005031 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005032 boolean isProvisioned) {
5033 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5034
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005037 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5038 if (controller == null) {
5039 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5040 return;
5041 }
5042 controller.setRcsProvisioningStatusForCapability(
5043 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
allenwtsu99c623b2020-01-03 18:24:23 +08005047 }
5048
5049
5050 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005051 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5052 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5053 mApp, subId, "getRcsProvisioningStatusForCapability");
5054
allenwtsu99c623b2020-01-03 18:24:23 +08005055 final long identity = Binder.clearCallingIdentity();
5056 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005057 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5058 if (controller == null) {
5059 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5060
5061 // device does not support IMS, this method will return true always.
5062 return true;
5063 }
5064 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
5068 }
5069
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005070 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005071 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5072 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005073 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005074
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005075 final long identity = Binder.clearCallingIdentity();
5076 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005077 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5078 if (controller == null) {
5079 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5080 return;
5081 }
5082 controller.setImsProvisioningStatusForCapability(
5083 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005084 } finally {
5085 Binder.restoreCallingIdentity(identity);
5086 }
5087 }
5088
5089 @Override
5090 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005091 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5092 mApp, subId, "getProvisioningStatusForCapability");
5093
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005096 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5097 if (controller == null) {
5098 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005099
joonhunshin91bc1952022-04-29 08:47:15 +00005100 // device does not support IMS, this method will return true always.
5101 return true;
5102 }
5103 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
5107 }
5108
5109 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005110 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5111 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5112 mApp, subId, "isProvisioningRequiredForCapability");
5113
5114 final long identity = Binder.clearCallingIdentity();
5115 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005116 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5117 if (controller == null) {
5118 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5119
5120 // device does not support IMS, this method will return false
5121 return false;
5122 }
5123 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005126 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005127 }
5128
5129 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005130 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5131 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5132 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005133
joonhunshincffb7fc2021-11-28 07:32:01 +00005134 final long identity = Binder.clearCallingIdentity();
5135 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005136 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5137 if (controller == null) {
5138 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5139
5140 // device does not support IMS, this method will return false
5141 return false;
5142 }
5143 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005147 }
5148
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005149 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005150 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005151 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5152 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5153 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005154 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5155 mApp, subId, "getImsProvisioningInt");
5156
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005160 int slotId = getSlotIndex(subId);
5161 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5162 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5163 + subId + "' for key:" + key);
5164 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5165 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005166
joonhunshin91bc1952022-04-29 08:47:15 +00005167 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5168 if (controller == null) {
5169 loge("getImsProvisioningInt: Device does not support IMS");
5170
5171 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5172 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5173 }
5174 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005175 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5176 return retVal;
5177 }
5178
calvinpanb5a34062021-02-08 19:59:36 +08005179 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005180 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005181 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5182 + subId + "' for key:" + key);
5183 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
5187 }
5188
5189 @Override
5190 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005191 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5192 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5193 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005194 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5195 mApp, subId, "getImsProvisioningString");
5196
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005197 final long identity = Binder.clearCallingIdentity();
5198 try {
5199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005200 int slotId = getSlotIndex(subId);
5201 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5202 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5203 + subId + "' for key:" + key);
5204 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5205 }
calvinpanb5a34062021-02-08 19:59:36 +08005206 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005207 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005208 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5209 + subId + "' for key:" + key);
5210 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
5214 }
5215
5216 @Override
5217 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005218 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5219 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5220 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5222 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005223
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005227 int slotId = getSlotIndex(subId);
5228 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5229 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5230 + subId + "' for key:" + key);
5231 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5232 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005233
joonhunshin91bc1952022-04-29 08:47:15 +00005234 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5235 if (controller == null) {
5236 loge("setImsProvisioningInt: Device does not support IMS");
5237
5238 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5239 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5240 }
5241 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005242 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5243 return retVal;
5244 }
5245
calvinpanb5a34062021-02-08 19:59:36 +08005246 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5247 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005248 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005249 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005250 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
5254 }
5255
5256 @Override
5257 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005258 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5259 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5260 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5262 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005266 int slotId = getSlotIndex(subId);
5267 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5268 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5269 + subId + "' for key:" + key);
5270 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5271 }
calvinpanb5a34062021-02-08 19:59:36 +08005272 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5273 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005274 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005275 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005276 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
5280 }
5281
Brad Ebinger919631e2021-06-02 17:46:35 -07005282 /**
5283 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5284 * for the given slot ID or no ImsResolver instance has been created.
5285 * @param slotId The slot ID that the IMS service is created for.
5286 * @throws ImsException If there is no ImsService configured for this slot.
5287 */
5288 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5289 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5290 ImsFeature.FEATURE_MMTEL)) {
5291 throw new ImsException("This subscription does not support MMTEL over IMS",
5292 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5293 }
5294 }
5295
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005296 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005297 int slotId = SubscriptionManager.getSlotIndex(subId);
5298 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005299 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5300 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005301 }
5302 return slotId;
5303 }
5304
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005305 private int getSlotIndex(int subId) {
5306 int slotId = SubscriptionManager.getSlotIndex(subId);
5307 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5308 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5309 }
5310 return slotId;
5311 }
5312
Wink Saville36469e72014-06-11 15:17:00 -07005313 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005314 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005315 */
5316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005317 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5318 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005319 try {
5320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5321 } catch (SecurityException se) {
5322 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5323 throw new SecurityException("Package " + callingPackage + " does not belong to "
5324 + Binder.getCallingUid());
5325 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005326 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005327 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005328 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005329 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005330 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005331 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005332 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005333 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5334 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 final Phone phone = getPhone(subId);
5339 if (phone != null) {
5340 return phone.getServiceState().getDataNetworkType();
5341 } else {
5342 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5343 }
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005347 }
5348
5349 /**
5350 * Returns the data network type
5351 */
5352 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005353 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005354 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005355 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005356 }
5357
5358 /**
5359 * Returns the data network type for a subId
5360 */
5361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005362 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5363 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005364 String functionName = "getDataNetworkTypeForSubscriber";
5365 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5366 mApp, functionName)) {
5367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5368 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5369 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5370 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005371 }
5372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
5375 final Phone phone = getPhone(subId);
5376 if (phone != null) {
5377 return phone.getServiceState().getDataNetworkType();
5378 } else {
5379 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5380 }
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005384 }
5385
5386 /**
Wink Saville36469e72014-06-11 15:17:00 -07005387 * Returns the Voice network type for a subId
5388 */
5389 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005390 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5391 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005392 String functionName = "getVoiceNetworkTypeForSubscriber";
5393 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5394 mApp, functionName)) {
5395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5396 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5397 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5398 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005399 }
5400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 final Phone phone = getPhone(subId);
5404 if (phone != null) {
5405 return phone.getServiceState().getVoiceNetworkType();
5406 } else {
5407 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5408 }
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005412 }
5413
5414 /**
5415 * @return true if a ICC card is present
5416 */
5417 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005418 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005419 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005420 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005421 }
5422
5423 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005424 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005425 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005426 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005427 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
5430 final Phone phone = PhoneFactory.getPhone(slotIndex);
5431 if (phone != null) {
5432 return phone.getIccCard().hasIccCard();
5433 } else {
5434 return false;
5435 }
5436 } finally {
5437 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005439 }
5440
5441 /**
5442 * Return if the current radio is LTE on CDMA. This
5443 * is a tri-state return value as for a period of time
5444 * the mode may be unknown.
5445 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005446 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005447 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005448 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005449 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005450 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005451 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5452 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5453 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005454 }
5455
Sanket Padawe356d7632015-06-22 14:03:32 -07005456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005457 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5458 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005459 try {
5460 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5461 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005462 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5463 }
5464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 final Phone phone = getPhone(subId);
5468 if (phone == null) {
5469 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5470 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005471 return TelephonyProperties.lte_on_cdma_device()
5472 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 }
5474 } finally {
5475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005476 }
Wink Saville36469e72014-06-11 15:17:00 -07005477 }
5478
Wink Saville36469e72014-06-11 15:17:00 -07005479 /**
5480 * {@hide}
5481 * Returns Default subId, 0 in the case of single standby.
5482 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005483 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005484 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005485 }
5486
Shishir Agrawala9f32182016-04-12 12:00:16 -07005487 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005488 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005489 }
5490
Wink Savilleb564aae2014-10-23 10:18:09 -07005491 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005492 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005493 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005494
Pengquan Menge92a50d2018-09-21 15:54:48 -07005495 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005496 return getSubscriptionManagerService().isActiveSubId(subId,
5497 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005498 }
5499
Ihab Awadf2177b72013-11-25 13:33:23 -08005500 /**
5501 * @see android.telephony.TelephonyManager.WifiCallingChoices
5502 */
5503 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 final long identity = Binder.clearCallingIdentity();
5505 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005506 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5508 getWhenToMakeWifiCallsDefaultPreference());
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005512 }
5513
5514 /**
5515 * @see android.telephony.TelephonyManager.WifiCallingChoices
5516 */
5517 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 final long identity = Binder.clearCallingIdentity();
5519 try {
5520 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005521 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005526 }
5527
Sailesh Nepald1e68152013-12-12 19:08:02 -08005528 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005529 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005530 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005531 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005532
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005533 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5534 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5535 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005536 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005537 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005538 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005539 }
5540 return PhoneFactory.getPhone(phoneId);
5541 }
5542
Shishir Agrawal566b7612013-10-28 14:41:00 -07005543 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005544 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005545 @NonNull IccLogicalChannelRequest request) {
5546 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5547 /*message=*/ "iccOpenLogicalChannel");
5548
5549 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5550 // Verify that the callingPackage in the request belongs to the calling UID
5551 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5552
5553 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005554 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005555
Rambo Wanga1782702021-11-10 20:15:19 -08005556 private Phone getPhoneFromValidIccLogicalChannelRequest(
5557 @NonNull IccLogicalChannelRequest request, String message) {
5558 Phone phone;
5559 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5561 mApp, request.subId, message);
5562 phone = getPhoneFromSubId(request.subId);
5563 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5564 enforceModifyPermission();
5565 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5566 } else {
5567 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005568 }
Rambo Wanga1782702021-11-10 20:15:19 -08005569 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005570 }
5571
5572 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005573 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
5575 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005576 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005578 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5579 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005580 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5581 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 loge("The calling package is not allowed to access ISD-R.");
5583 throw new SecurityException(
5584 "The calling package is not allowed to access ISD-R.");
5585 }
Derek Tan740e1672017-06-27 14:56:27 -07005586 }
Derek Tan740e1672017-06-27 14:56:27 -07005587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005589 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5590 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 return response;
5592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005595 }
5596
5597 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005598 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5599 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5600 /*message=*/"iccCloseLogicalChannel");
5601
5602 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5603
5604 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005606
Rambo Wanga1782702021-11-10 20:15:19 -08005607 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5608 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005609 // before this feature is enabled, this API should only return false if
5610 // the operation fails instead of throwing runtime exception for
5611 // backward-compatibility.
5612 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5613 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 final long identity = Binder.clearCallingIdentity();
5615 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005616 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005617 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 }
Chen Xue9d737e2022-01-01 23:41:31 -08005619 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005620 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005621 Boolean success = false;
5622 if (result instanceof RuntimeException) {
5623 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005624 if (shouldThrowExceptionOnFailure) {
5625 throw (RuntimeException) result;
5626 } else {
5627 return false;
5628 }
Chen Xue9d737e2022-01-01 23:41:31 -08005629 } else if (result instanceof Boolean) {
5630 success = (Boolean) result;
5631 } else {
5632 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5633 }
Rambo Wanga1782702021-11-10 20:15:19 -08005634 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 return success;
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005638 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005639 }
5640
5641 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005642 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005643 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5645 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005646 if (DBG) {
5647 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5648 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5649 + p3 + " data=" + data);
5650 }
5651 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5652 command, p1, p2, p3, data);
5653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005654
Jordan Liu4c733742019-02-28 12:03:40 -08005655 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005656 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005657 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005658 enforceModifyPermission();
5659 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005660 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005661 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5662 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005663 }
5664 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005665 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5666 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005667 }
5668
5669 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5670 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 final long identity = Binder.clearCallingIdentity();
5672 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005673 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 return "";
5675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005678 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5679 null /* workSource */);
5680 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 // Append the returned status code to the end of the response payload.
5683 String s = Integer.toHexString(
5684 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5685 if (response.payload != null) {
5686 s = IccUtils.bytesToHexString(response.payload) + s;
5687 }
5688 return s;
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005691 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005692 }
Jake Hambye994d462014-02-03 13:10:13 -08005693
Evan Charltonc66da362014-05-16 14:06:40 -07005694 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005695 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5696 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5698 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005700 if (DBG) {
5701 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5702 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5703 }
5704 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5705 cla, command, p1, p2, p3, data);
5706 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005707
Jordan Liu4c733742019-02-28 12:03:40 -08005708 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005709 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005710 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005711 enforceModifyPermission();
5712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5713 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005714 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005715 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5716 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005717 }
5718
5719 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005720 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5721 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005722 }
5723
5724 // open APDU basic channel assuming the caller has sufficient permissions
5725 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5726 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 final long identity = Binder.clearCallingIdentity();
5728 try {
5729 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5730 && TextUtils.equals(ISDR_AID, data)) {
5731 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005732 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5733 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 if (bestComponent == null
5735 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5736 loge("The calling package is not allowed to select ISD-R.");
5737 throw new SecurityException(
5738 "The calling package is not allowed to select ISD-R.");
5739 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005740 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005743 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5744 null /* workSource */);
5745 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 // Append the returned status code to the end of the response payload.
5748 String s = Integer.toHexString(
5749 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5750 if (response.payload != null) {
5751 s = IccUtils.bytesToHexString(response.payload) + s;
5752 }
5753 return s;
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005756 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005757 }
5758
5759 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005760 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005761 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5763 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 if (DBG) {
5768 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5769 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5770 }
5771
5772 IccIoResult response =
5773 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5774 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5775 subId);
5776
5777 if (DBG) {
5778 log("Exchange SIM_IO [R]" + response);
5779 }
5780
5781 byte[] result = null;
5782 int length = 2;
5783 if (response.payload != null) {
5784 length = 2 + response.payload.length;
5785 result = new byte[length];
5786 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5787 } else {
5788 result = new byte[length];
5789 }
5790
5791 result[length - 1] = (byte) response.sw2;
5792 result[length - 2] = (byte) response.sw1;
5793 return result;
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005796 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005797 }
5798
Nathan Haroldb3014052017-01-25 15:57:32 -08005799 /**
5800 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5801 * on a particular subscription
5802 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005803 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5804 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005806 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005807 return null;
5808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809
5810 final long identity = Binder.clearCallingIdentity();
5811 try {
5812 if (appType != TelephonyManager.APPTYPE_USIM
5813 && appType != TelephonyManager.APPTYPE_SIM) {
5814 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5815 return null;
5816 }
5817 Object response = sendRequest(
5818 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5819 if (response instanceof String[]) {
5820 return (String[]) response;
5821 }
yincheng zhao2737e882019-09-06 17:06:54 -07005822 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005824 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 } finally {
5826 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005827 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005828 }
5829
yincheng zhao2737e882019-09-06 17:06:54 -07005830 /**
5831 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5832 * subscription.
5833 *
5834 * @param subId the id of the subscription.
5835 * @param appType the uicc app type, must be USIM or SIM.
5836 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5837 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005838 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005839 * @return number of fplmns that is successfully written to the SIM.
5840 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005841 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5842 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5844 mApp, subId, "setForbiddenPlmns");
5845
yincheng zhao2737e882019-09-06 17:06:54 -07005846 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5847 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5848 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5849 }
5850 if (fplmns == null) {
5851 throw new IllegalArgumentException("Fplmn List provided is null");
5852 }
5853 for (String fplmn : fplmns) {
5854 if (!CellIdentity.isValidPlmn(fplmn)) {
5855 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5856 }
5857 }
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 Object response = sendRequest(
5861 CMD_SET_FORBIDDEN_PLMNS,
5862 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5863 subId);
5864 return (int) response;
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
5869
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005870 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005871 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5873 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 final long identity = Binder.clearCallingIdentity();
5876 try {
5877 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5878 if (response.payload == null) {
5879 return "";
5880 }
Evan Charltonc66da362014-05-16 14:06:40 -07005881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 // Append the returned status code to the end of the response payload.
5883 String s = Integer.toHexString(
5884 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5885 s = IccUtils.bytesToHexString(response.payload) + s;
5886 return s;
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
Evan Charltonc66da362014-05-16 14:06:40 -07005890 }
5891
Jake Hambye994d462014-02-03 13:10:13 -08005892 /**
5893 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5894 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5895 *
5896 * @param itemID the ID of the item to read
5897 * @return the NV item as a String, or null on error.
5898 */
5899 @Override
5900 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005901 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5903 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904
5905 final long identity = Binder.clearCallingIdentity();
5906 try {
5907 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005908 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5910 return value;
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
Jake Hambye994d462014-02-03 13:10:13 -08005914 }
5915
5916 /**
5917 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5918 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5919 *
5920 * @param itemID the ID of the item to read
5921 * @param itemValue the value to write, as a String
5922 * @return true on success; false on any failure
5923 */
5924 @Override
5925 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5928 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5933 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005934 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5936 return success;
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Jake Hambye994d462014-02-03 13:10:13 -08005940 }
5941
5942 /**
5943 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5944 * Used for device configuration by some CDMA operators.
5945 *
5946 * @param preferredRoamingList byte array containing the new PRL
5947 * @return true on success; false on any failure
5948 */
5949 @Override
5950 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5952 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5957 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5958 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5959 return success;
5960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
Jake Hambye994d462014-02-03 13:10:13 -08005963 }
5964
5965 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005966 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005967 * Used for device configuration by some CDMA operators.
5968 *
chen xu6dac5ab2018-10-26 17:39:23 -07005969 * @param slotIndex - device slot.
5970 *
Jake Hambye994d462014-02-03 13:10:13 -08005971 * @return true on success; false on any failure
5972 */
5973 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005974 public boolean resetModemConfig(int slotIndex) {
5975 Phone phone = PhoneFactory.getPhone(slotIndex);
5976 if (phone != null) {
5977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5978 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979
chen xu6dac5ab2018-10-26 17:39:23 -07005980 final long identity = Binder.clearCallingIdentity();
5981 try {
5982 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5983 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5984 return success;
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
5987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 }
chen xu6dac5ab2018-10-26 17:39:23 -07005989 return false;
5990 }
5991
5992 /**
5993 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5994 *
5995 * @param slotIndex - device slot.
5996 *
5997 * @return true on success; false on any failure
5998 */
5999 @Override
6000 public boolean rebootModem(int slotIndex) {
6001 Phone phone = PhoneFactory.getPhone(slotIndex);
6002 if (phone != null) {
6003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, phone.getSubId(), "rebootModem");
6005
6006 final long identity = Binder.clearCallingIdentity();
6007 try {
6008 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6009 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6010 return success;
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
6014 }
6015 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006016 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006017
Brad Ebinger51f743a2017-01-23 13:50:20 -08006018 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006019 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6020 * {@link #disableIms(int)}.
6021 * @param slotIndex device slot.
6022 */
6023 public void resetIms(int slotIndex) {
6024 enforceModifyPermission();
6025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 if (mImsResolver == null) {
6029 // may happen if the does not support IMS.
6030 return;
6031 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006032 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
6036 }
6037
6038 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006039 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6040 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006041 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006042 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006047 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006048 // may happen if the device does not support IMS.
6049 return;
6050 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 } finally {
6053 Binder.restoreCallingIdentity(identity);
6054 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006055 }
6056
6057 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006058 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6059 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006060 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006061 public void disableIms(int slotId) {
6062 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063
6064 final long identity = Binder.clearCallingIdentity();
6065 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006066 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006067 // may happen if the device does not support IMS.
6068 return;
6069 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006070 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006074 }
6075
6076 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006077 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6078 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006079 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006080 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006081 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006082 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083
6084 final long identity = Binder.clearCallingIdentity();
6085 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006086 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006087 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6088 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006089 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006090 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006094 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006095 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006096 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6097 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006098 @Override
6099 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006100 enforceModifyPermission();
6101
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006105 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006106 } finally {
6107 Binder.restoreCallingIdentity(identity);
6108 }
6109 }
6110
6111 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006112 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006113 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006114 */
6115 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117
6118 final long identity = Binder.clearCallingIdentity();
6119 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006120 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006121 // may happen if the device does not support IMS.
6122 return null;
6123 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006124 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006128 }
6129
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006130 /**
6131 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006132 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006133 */
6134 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136
6137 final long identity = Binder.clearCallingIdentity();
6138 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006139 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006140 // may happen if the device does not support IMS.
6141 return null;
6142 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006143 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006147 }
6148
Brad Ebinger884c07b2018-02-15 16:17:40 -08006149 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006150 * Sets the ImsService Package Name that Telephony will bind to.
6151 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006152 * @param slotIndex the slot ID that the ImsService should bind for.
6153 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006154 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006155 * @param featureTypes An integer array of feature types associated with a packageName.
6156 * @param packageName The name of the package that the current configuration will be replaced
6157 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006158 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006159 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006160 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6161 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006164 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 final long identity = Binder.clearCallingIdentity();
6167 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006168 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006169 // may happen if the device does not support IMS.
6170 return false;
6171 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006172 Map<Integer, String> featureConfig = new HashMap<>();
6173 for (int featureType : featureTypes) {
6174 featureConfig.put(featureType, packageName);
6175 }
6176 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6177 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006181 }
6182
6183 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006184 * Clears any carrier ImsService overrides for the slot index specified that were previously
6185 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6186 *
6187 * This should only be used for testing.
6188 *
6189 * @param slotIndex the slot ID that the ImsService should bind for.
6190 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6191 */
6192 @Override
6193 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6195 "clearCarrierImsServiceOverride");
6196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006197 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006198
6199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 if (mImsResolver == null) {
6202 // may happen if the device does not support IMS.
6203 return false;
6204 }
6205 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
6209 }
6210
6211 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006212 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006213 *
6214 * @param slotId The slot that the ImsService is associated with.
6215 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6216 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006217 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006218 * @return the package name of the ImsService configuration.
6219 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006220 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6221 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006222 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006223 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6224 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 final long identity = Binder.clearCallingIdentity();
6227 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006228 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006229 // may happen if the device does not support IMS.
6230 return "";
6231 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006232 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006233 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6234 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 } finally {
6236 Binder.restoreCallingIdentity(identity);
6237 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006238 }
6239
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006240 /**
6241 * Get the MmTelFeature state associated with the requested subscription id.
6242 * @param subId The subscription that the MmTelFeature is associated with.
6243 * @param callback A callback with an integer containing the
6244 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6245 */
6246 @Override
6247 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6248 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006249 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6250 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6251 "IMS not available on device.");
6252 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006253 final long token = Binder.clearCallingIdentity();
6254 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006255 int slotId = getSlotIndex(subId);
6256 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6257 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6258 + subId + "'");
6259 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6260 }
6261 verifyImsMmTelConfiguredOrThrow(slotId);
6262 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6263 try {
6264 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6265 } catch (RemoteException e) {
6266 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6267 + "Ignore");
6268 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006269 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006270 } catch (ImsException e) {
6271 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006272 } finally {
6273 Binder.restoreCallingIdentity(token);
6274 }
6275 }
6276
Daniel Brightbb5840b2021-01-12 15:48:18 -08006277 /**
6278 * Sets the ims registration state on all valid {@link Phone}s.
6279 */
6280 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006281 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282
6283 final long identity = Binder.clearCallingIdentity();
6284 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006285 // NOTE: Before S, this method only set the default phone.
6286 for (final Phone phone : PhoneFactory.getPhones()) {
6287 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6288 phone.setImsRegistrationState(registered);
6289 }
6290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 } finally {
6292 Binder.restoreCallingIdentity(identity);
6293 }
Wink Saville36469e72014-06-11 15:17:00 -07006294 }
6295
6296 /**
Stuart Scott54788802015-03-30 13:18:01 -07006297 * Set the network selection mode to automatic.
6298 *
6299 */
6300 @Override
6301 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6303 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304
6305 final long identity = Binder.clearCallingIdentity();
6306 try {
shilufc958392020-01-20 11:36:01 -08006307 if (!isActiveSubscription(subId)) {
6308 return;
6309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006311 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6312 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 } finally {
6314 Binder.restoreCallingIdentity(identity);
6315 }
Stuart Scott54788802015-03-30 13:18:01 -07006316 }
6317
Jack Yud10cdd42020-09-28 20:28:01 -07006318 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006319 * Ask the radio to connect to the input network and change selection mode to manual.
6320 *
6321 * @param subId the id of the subscription.
6322 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6323 * the operator to attach to.
6324 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6325 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6326 * normal network selection next time.
6327 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006328 */
6329 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006330 public boolean setNetworkSelectionModeManual(
6331 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6333 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006334
Jack Yu285100e2022-12-02 22:48:35 -08006335 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006336 if (!isActiveSubscription(subId)) {
6337 return false;
6338 }
6339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006341 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006343 if (DBG) {
6344 log("setNetworkSelectionModeManual: subId: " + subId
6345 + " operator: " + operatorInfo);
6346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006351 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006352 /**
shilu84f6e8b2019-12-19 13:58:01 -08006353 * Get the manual network selection
6354 *
6355 * @param subId the id of the subscription.
6356 *
6357 * @return the previously saved user selected PLMN
6358 */
6359 @Override
6360 public String getManualNetworkSelectionPlmn(int subId) {
6361 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006362 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6363 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006364
6365 final long identity = Binder.clearCallingIdentity();
6366 try {
6367 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006368 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006369 }
6370
6371 final Phone phone = getPhone(subId);
6372 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006373 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006374 }
6375 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6376 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006377 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
6381 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006382
6383 /**
6384 * Scans for available networks.
6385 */
6386 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006387 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6388 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6390 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006391 LocationAccessPolicy.LocationPermissionResult locationResult =
6392 LocationAccessPolicy.checkLocationPermission(mApp,
6393 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6394 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006395 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006396 .setCallingPid(Binder.getCallingPid())
6397 .setCallingUid(Binder.getCallingUid())
6398 .setMethod("getCellNetworkScanResults")
6399 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006400 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6401 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006402 .build());
6403 switch (locationResult) {
6404 case DENIED_HARD:
6405 throw new SecurityException("Not allowed to access scan results -- location");
6406 case DENIED_SOFT:
6407 return null;
6408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
Pengquan Menga1bb6272018-09-06 09:59:22 -07006410 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 try {
6412 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006413 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 } finally {
6416 Binder.restoreCallingIdentity(identity);
6417 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006418 }
6419
6420 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006421 * Get the call forwarding info, given the call forwarding reason.
6422 */
6423 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006424 public void getCallForwarding(int subId, int callForwardingReason,
6425 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006426 enforceReadPrivilegedPermission("getCallForwarding");
6427 long identity = Binder.clearCallingIdentity();
6428 try {
6429 if (DBG) {
6430 log("getCallForwarding: subId " + subId
6431 + " callForwardingReason" + callForwardingReason);
6432 }
Hall Liu27d24262020-09-18 19:04:59 -07006433
6434 Phone phone = getPhone(subId);
6435 if (phone == null) {
6436 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006437 callback.onError(
6438 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006439 } catch (RemoteException e) {
6440 // ignore
6441 }
6442 return;
6443 }
6444
6445 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6446 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6447 @Override
6448 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6449 try {
6450 callback.onCallForwardingInfoAvailable(info);
6451 } catch (RemoteException e) {
6452 // ignore
6453 }
6454 }
6455
6456 @Override
6457 public void onError(int error) {
6458 try {
6459 callback.onError(error);
6460 } catch (RemoteException e) {
6461 // ignore
6462 }
6463 }
6464 });
6465 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
6471 /**
6472 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6473 * reason, the number to forward, and the timeout before the forwarding is attempted.
6474 */
6475 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006476 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6477 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006478 enforceModifyPermission();
6479 long identity = Binder.clearCallingIdentity();
6480 try {
6481 if (DBG) {
6482 log("setCallForwarding: subId " + subId
6483 + " callForwardingInfo" + callForwardingInfo);
6484 }
Hall Liu27d24262020-09-18 19:04:59 -07006485
6486 Phone phone = getPhone(subId);
6487 if (phone == null) {
6488 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006489 callback.accept(
6490 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006491 } catch (RemoteException e) {
6492 // ignore
6493 }
6494 return;
6495 }
6496
6497 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6498 FunctionalUtils.ignoreRemoteException(callback::accept));
6499
6500 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
6504 }
6505
6506 /**
Hall Liu27d24262020-09-18 19:04:59 -07006507 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006508 */
6509 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006510 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006511 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006512 long identity = Binder.clearCallingIdentity();
6513 try {
Hall Liu27d24262020-09-18 19:04:59 -07006514 Phone phone = getPhone(subId);
6515 if (phone == null) {
6516 try {
6517 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6518 } catch (RemoteException e) {
6519 // ignore
6520 }
6521 return;
6522 }
SongFerngWang0e767992021-03-31 22:08:45 +08006523 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6524 PersistableBundle c = configManager.getConfigForSubId(subId);
6525 boolean requireUssd = c.getBoolean(
6526 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006527
Shuo Qian4a594052020-01-23 11:59:30 -08006528 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006529 if (requireUssd) {
6530 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6531 getSubscriptionCarrierId(subId));
6532 String newUssdCommand = "";
6533 try {
6534 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006535 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006536 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6537 } catch (NullPointerException e) {
6538 loge("Failed to generate USSD number" + e);
6539 }
6540 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6541 mMainThreadHandler, callback, carrierXmlParser,
6542 CarrierXmlParser.SsEntry.SSAction.QUERY);
6543 final String ussdCommand = newUssdCommand;
6544 Executors.newSingleThreadExecutor().execute(() -> {
6545 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6546 });
6547 } else {
6548 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6549 callback::accept);
6550 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6551 }
Shuo Qian4a594052020-01-23 11:59:30 -08006552 } finally {
6553 Binder.restoreCallingIdentity(identity);
6554 }
6555 }
6556
6557 /**
Hall Liu27d24262020-09-18 19:04:59 -07006558 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006559 */
6560 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006561 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006562 enforceModifyPermission();
6563 long identity = Binder.clearCallingIdentity();
6564 try {
Hall Liu27d24262020-09-18 19:04:59 -07006565 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6566
6567 Phone phone = getPhone(subId);
6568 if (phone == null) {
6569 try {
6570 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6571 } catch (RemoteException e) {
6572 // ignore
6573 }
6574 return;
6575 }
6576
SongFerngWang0e767992021-03-31 22:08:45 +08006577 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6578 PersistableBundle c = configManager.getConfigForSubId(subId);
6579 boolean requireUssd = c.getBoolean(
6580 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006581
SongFerngWang0e767992021-03-31 22:08:45 +08006582 if (DBG) log("getCallWaitingStatus: subId " + subId);
6583 if (requireUssd) {
6584 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6585 getSubscriptionCarrierId(subId));
6586 CarrierXmlParser.SsEntry.SSAction ssAction =
6587 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6588 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6589 String newUssdCommand = "";
6590 try {
6591 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006592 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006593 .makeCommand(ssAction, null);
6594 } catch (NullPointerException e) {
6595 loge("Failed to generate USSD number" + e);
6596 }
6597 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6598 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6599 final String ussdCommand = newUssdCommand;
6600 Executors.newSingleThreadExecutor().execute(() -> {
6601 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6602 });
6603 } else {
6604 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6605 FunctionalUtils.ignoreRemoteException(callback::accept));
6606
6607 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6608 }
Shuo Qian4a594052020-01-23 11:59:30 -08006609 } finally {
6610 Binder.restoreCallingIdentity(identity);
6611 }
6612 }
6613
6614 /**
yinxub1bed742017-04-17 11:45:04 -07006615 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006616 *
yinxub1bed742017-04-17 11:45:04 -07006617 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006618 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6619 * location related information which will be sent if the caller already possess
6620 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006621 * @param request contains the radio access networks with bands/channels to scan
6622 * @param messenger callback messenger for scan results or errors
6623 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006624 * @return the id of the requested scan which can be used to stop the scan.
6625 */
6626 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006627 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6628 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006629 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6631 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006632 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006633 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6634 if (!renounceFineLocationAccess) {
6635 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006636 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6637 .setCallingPackage(callingPackage)
6638 .setCallingFeatureId(callingFeatureId)
6639 .setCallingPid(Binder.getCallingPid())
6640 .setCallingUid(Binder.getCallingUid())
6641 .setMethod("requestNetworkScan")
6642 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6643 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6644 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6645 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006646 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006647 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006648 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6649 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006650 if (e != null) {
6651 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6652 throw e;
6653 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006654 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006655 return TelephonyScanManager.INVALID_SCAN_ID;
6656 }
6657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 }
Hall Liu912dfd32019-04-25 14:02:26 -07006659 int callingUid = Binder.getCallingUid();
6660 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006661 final long identity = Binder.clearCallingIdentity();
6662 try {
6663 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006664 renounceFineLocationAccess, request, messenger, binder,
6665 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006666 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006667 } finally {
6668 Binder.restoreCallingIdentity(identity);
6669 }
yinxu504e1392017-04-12 16:03:22 -07006670 }
6671
Hall Liub2ac8ef2019-02-28 15:56:23 -08006672 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006673 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006674 boolean hasCarrierPriv;
6675 final long identity = Binder.clearCallingIdentity();
6676 try {
6677 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6678 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
Hall Liu558027f2019-05-15 19:14:05 -07006682 boolean hasNetworkScanPermission =
6683 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006684 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006685
6686 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6687 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6688 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006689 }
6690
6691 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6692 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006693 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6694 return new SecurityException("Specific channels must not be"
6695 + " scanned without location access.");
6696 }
6697 }
6698 }
6699
Hall Liub2ac8ef2019-02-28 15:56:23 -08006700 return null;
6701 }
6702
yinxu504e1392017-04-12 16:03:22 -07006703 /**
6704 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006705 *
6706 * @param subId id of the subscription
6707 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006708 */
6709 @Override
6710 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6712 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713
Hall Liu912dfd32019-04-25 14:02:26 -07006714 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
6716 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006717 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 } finally {
6719 Binder.restoreCallingIdentity(identity);
6720 }
yinxu504e1392017-04-12 16:03:22 -07006721 }
6722
6723 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006724 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006725 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006726 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006727 */
6728 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006729 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006730 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006731 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006732 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733
6734 final long identity = Binder.clearCallingIdentity();
6735 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006736 if (DBG) log("getAllowedNetworkTypesBitmask");
6737 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6738 int networkTypesBitmask = (result != null ? result[0] : -1);
6739 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6740 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 } finally {
6742 Binder.restoreCallingIdentity(identity);
6743 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006744 }
6745
6746 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006747 * Get the allowed network types for certain reason.
6748 *
6749 * @param subId the id of the subscription.
6750 * @param reason the reason the allowed network type change is taking place
6751 * @return the allowed network types.
6752 */
6753 @Override
6754 public long getAllowedNetworkTypesForReason(int subId,
6755 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006756 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006757 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006758 final long identity = Binder.clearCallingIdentity();
6759 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006760 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
6764 }
6765
6766 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006767 * Enable/Disable E-UTRA-NR Dual Connectivity
6768 * @param subId subscription id of the sim card
6769 * @param nrDualConnectivityState expected NR dual connectivity state
6770 * This can be passed following states
6771 * <ol>
6772 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6773 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6774 * <li>Disable NR dual connectivity and force secondary cell to be released
6775 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6776 * </ol>
6777 * @return operation result.
6778 */
6779 @Override
6780 public int setNrDualConnectivityState(int subId,
6781 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6783 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006784 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006785 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6786 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6787 }
6788
Sooraj Sasindran37444802020-08-11 10:40:43 -07006789 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6793 nrDualConnectivityState, subId,
6794 workSource);
6795 if (DBG) log("enableNRDualConnectivity result: " + result);
6796 return result;
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
6800 }
6801
6802 /**
6803 * Is E-UTRA-NR Dual Connectivity enabled
6804 * @return true if dual connectivity is enabled else false
6805 */
6806 @Override
6807 public boolean isNrDualConnectivityEnabled(int subId) {
6808 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006809 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006810 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006811 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006812 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6813 return false;
6814 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6819 null, subId, workSource);
6820 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6821 return isEnabled;
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
6825 }
6826
6827 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006828 * Set the allowed network types of the device and
6829 * provide the reason triggering the allowed network change.
6830 *
6831 * @param subId the id of the subscription.
6832 * @param reason the reason the allowed network type change is taking place
6833 * @param allowedNetworkTypes the allowed network types.
6834 * @return true on success; false on any failure.
6835 */
6836 @Override
6837 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006838 @TelephonyManager.AllowedNetworkTypesReason int reason,
6839 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6841 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006842 // If the caller only has carrier privileges, then they should not be able to override
6843 // any network types which were set for security reasons.
6844 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6845 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006846 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006847 throw new SecurityException(
6848 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006849 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006850 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006851 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006852 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006853 return false;
6854 }
6855 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6856 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006857 return false;
6858 }
6859
Jack Yu5b494332023-01-23 18:18:04 +00006860 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6861 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006862
Jack Yue37dd262022-12-16 11:53:37 -08006863 Phone phone = getPhone(subId);
6864 if (phone == null) {
6865 return false;
6866 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006867
Jack Yue37dd262022-12-16 11:53:37 -08006868 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006869 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006870 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006871 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006872
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006873 final long identity = Binder.clearCallingIdentity();
6874 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006875 Boolean success = (Boolean) sendRequest(
6876 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6877 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6878
6879 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6880 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006881 } finally {
6882 Binder.restoreCallingIdentity(identity);
6883 }
6884 }
6885
6886 /**
Miaoa84611c2019-03-15 09:21:10 +08006887 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006888 *
Miaoa84611c2019-03-15 09:21:10 +08006889 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006890 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006891 * @hide
6892 */
6893 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006894 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006897 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 try {
Miaoa84611c2019-03-15 09:21:10 +08006899 if (phone != null) {
6900 return phone.hasMatchedTetherApnSetting();
6901 } else {
6902 return false;
6903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 } finally {
6905 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006906 }
Junda Liu475951f2014-11-07 16:45:03 -08006907 }
6908
6909 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006910 * Get the user enabled state of Mobile Data.
6911 *
6912 * TODO: remove and use isUserDataEnabled.
6913 * This can't be removed now because some vendor codes
6914 * calls through ITelephony directly while they should
6915 * use TelephonyManager.
6916 *
6917 * @return true on enabled
6918 */
6919 @Override
6920 public boolean getDataEnabled(int subId) {
6921 return isUserDataEnabled(subId);
6922 }
6923
6924 /**
6925 * Get whether mobile data is enabled per user setting.
6926 *
6927 * There are other factors deciding whether mobile data is actually enabled, but they are
6928 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006929 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006930 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6931 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006932 *
6933 * @return {@code true} if data is enabled else {@code false}
6934 */
6935 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006936 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006937 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006938 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006939 try {
6940 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6941 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006942 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006943 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6944 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006945 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006947 mApp, subId, functionName);
6948
Robert Greenwalt646120a2014-05-23 11:54:03 -07006949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
Jack Yu285100e2022-12-02 22:48:35 -08006953 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6955 Phone phone = PhoneFactory.getPhone(phoneId);
6956 if (phone != null) {
6957 boolean retVal = phone.isUserDataEnabled();
6958 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6959 return retVal;
6960 } else {
6961 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6962 return false;
6963 }
6964 } finally {
6965 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006966 }
6967 }
6968
6969 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006970 * Checks if the device is capable of mobile data by considering whether whether the
6971 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6972 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006973 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006974 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006975 */
6976 @Override
6977 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006978 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006979 try {
6980 try {
6981 mApp.enforceCallingOrSelfPermission(
6982 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006983 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006984 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006985 try {
6986 mApp.enforceCallingOrSelfPermission(
6987 android.Manifest.permission.READ_PHONE_STATE,
6988 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006989 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006990 mApp.enforceCallingOrSelfPermission(
6991 permission.READ_BASIC_PHONE_STATE, functionName);
6992 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006993 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006994 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006995 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997
6998 final long identity = Binder.clearCallingIdentity();
6999 try {
Jack Yu285100e2022-12-02 22:48:35 -08007000 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 Phone phone = PhoneFactory.getPhone(phoneId);
7002 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007003 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007004 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 return retVal;
7006 } else {
7007 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7008 return false;
7009 }
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007012 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007013 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007014
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007015 /**
7016 * Check if data is enabled for a specific reason
7017 * @param subId Subscription index
7018 * @param reason the reason the data enable change is taking place
7019 * @return {@code true} if the overall data is enabled; {@code false} if not.
7020 */
7021 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007022 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007023 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007024 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007025 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007026 try {
7027 mApp.enforceCallingOrSelfPermission(
7028 android.Manifest.permission.ACCESS_NETWORK_STATE,
7029 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007030 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007031 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7032 functionName);
7033 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007034 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007035 try {
7036 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007037 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007038 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007040 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007041 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007042 }
7043
7044
7045 final long identity = Binder.clearCallingIdentity();
7046 try {
Jack Yu285100e2022-12-02 22:48:35 -08007047 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007048 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007049 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007050 + " reason=" + reason);
7051 }
7052 Phone phone = PhoneFactory.getPhone(phoneId);
7053 if (phone != null) {
7054 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007055 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007056 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007057 return retVal;
7058 } else {
7059 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007060 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007061 + subId + " retVal=false");
7062 }
7063 return false;
7064 }
7065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
7068 }
7069
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007070 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007071 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007072 // No permission needed; this only lets the caller inspect their own status.
7073 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007074 }
Junda Liu29340342014-07-10 15:23:27 -07007075
7076 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007077 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007078 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007079 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7080 }
7081
7082 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7083 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007085 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007086 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7087 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007088 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7089 if (cpt == null) {
7090 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007091 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7092 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007093 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007094 }
7095
7096 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007097 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007098 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007099 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007101 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007102 Phone phone = getPhone(subId);
7103 if (phone == null) {
7104 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7105 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7106 }
7107 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7108 if (cpt == null) {
7109 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007110 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7111 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007112 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007113 }
7114
7115 @Override
7116 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007117 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007118 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7119 }
7120
7121 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007122 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007123 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007124 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007125 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007126 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7127 Phone phone = PhoneFactory.getPhone(phoneId);
7128 if (phone == null) {
7129 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007130 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007131 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7132 if (cpt == null) {
7133 continue;
7134 }
7135 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007136 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7137 break;
7138 }
7139 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007140 return result;
Junda Liu29340342014-07-10 15:23:27 -07007141 }
Derek Tan89e89d42014-07-08 17:00:10 -07007142
7143 @Override
Junda Liue64de782015-04-16 17:19:16 -07007144 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007145 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007146 Phone phone = PhoneFactory.getPhone(phoneId);
7147 if (phone == null) {
7148 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007149 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007150 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7151 if (cpt == null) {
7152 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007153 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007154 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007155 }
7156
Amith Yamasani6e118872016-02-19 12:53:51 -08007157 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007158 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007159 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007160 Phone phone = PhoneFactory.getPhone(phoneId);
7161 if (phone == null) {
7162 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007163 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007164 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7165 if (cpt == null) {
7166 return Collections.emptyList();
7167 }
7168 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007169 }
7170
chen xuf7e9fe82019-05-09 19:31:02 -07007171 @Override
7172 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007173 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007174 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007175 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007176 try {
7177 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7178 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7179 }
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007182 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007183 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007184 }
7185
Rambo Wang6812ffb2022-03-15 16:54:17 -07007186 @Override
7187 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7188 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7189
7190 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7191 if (phone == null) {
7192 return null;
7193 }
7194 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7195 if (cpt == null) {
7196 return null;
7197 }
7198 return cpt.getCarrierServicePackageName();
7199 }
7200
Wink Savilleb564aae2014-10-23 10:18:09 -07007201 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007202 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007203 UiccPort port = phone == null ? null : phone.getUiccPort();
7204 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007205 return null;
7206 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007207 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007208 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007209 return null;
7210 }
7211 return iccId;
7212 }
7213
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007214 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007215 public void setCallComposerStatus(int subId, int status) {
7216 enforceModifyPermission();
7217
7218 final long identity = Binder.clearCallingIdentity();
7219 try {
7220 Phone phone = getPhone(subId);
7221 if (phone != null) {
7222 Phone defaultPhone = phone.getImsPhone();
7223 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7224 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7225 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007226 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7227 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007228 }
7229 }
Shuo Qian284ae752020-12-22 19:10:14 -08007230 } catch (ImsException e) {
7231 throw new ServiceSpecificException(e.getCode());
7232 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007233 Binder.restoreCallingIdentity(identity);
7234 }
7235 }
7236
7237 @Override
7238 public int getCallComposerStatus(int subId) {
7239 enforceReadPrivilegedPermission("getCallComposerStatus");
7240
7241 final long identity = Binder.clearCallingIdentity();
7242 try {
7243 Phone phone = getPhone(subId);
7244 if (phone != null) {
7245 Phone defaultPhone = phone.getImsPhone();
7246 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7247 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7248 return imsPhone.getCallComposerStatus();
7249 }
7250 }
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
7254 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7255 }
7256
7257 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007258 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7259 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007260 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007261 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 final String iccId = getIccId(subId);
7266 final Phone phone = getPhone(subId);
7267 if (phone == null) {
7268 return false;
7269 }
7270 final String subscriberId = phone.getSubscriberId();
7271
7272 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007273 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 + subscriberId + " to " + number);
7275 }
7276
7277 if (TextUtils.isEmpty(iccId)) {
7278 return false;
7279 }
7280
7281 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7282
7283 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7284 if (alphaTag == null) {
7285 editor.remove(alphaTagPrefKey);
7286 } else {
7287 editor.putString(alphaTagPrefKey, alphaTag);
7288 }
7289
7290 // Record both the line number and IMSI for this ICCID, since we need to
7291 // track all merged IMSIs based on line number
7292 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7293 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7294 if (number == null) {
7295 editor.remove(numberPrefKey);
7296 editor.remove(subscriberPrefKey);
7297 } else {
7298 editor.putString(numberPrefKey, number);
7299 editor.putString(subscriberPrefKey, subscriberId);
7300 }
7301
7302 editor.commit();
7303 return true;
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007306 }
Derek Tan7226c842014-07-02 17:42:23 -07007307 }
7308
7309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007310 public String getLine1NumberForDisplay(int subId, String callingPackage,
7311 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007312 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007314 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007315 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007316 return null;
7317 }
Derek Tan97ebb422014-09-05 16:55:38 -07007318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 String iccId = getIccId(subId);
7322 if (iccId != null) {
7323 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7324 if (DBG_MERGE) {
7325 log("getLine1NumberForDisplay returning "
7326 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7327 }
7328 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7331 return null;
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007334 }
Derek Tan7226c842014-07-02 17:42:23 -07007335 }
7336
7337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007338 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7339 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007341 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007342 return null;
7343 }
Derek Tan97ebb422014-09-05 16:55:38 -07007344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 String iccId = getIccId(subId);
7348 if (iccId != null) {
7349 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7350 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7351 }
7352 return null;
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007355 }
Derek Tan7226c842014-07-02 17:42:23 -07007356 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007357
7358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007359 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7360 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007361 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7362 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007364 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007365 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007366 return null;
7367 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007368
Jordan Liub49b04b2019-05-06 14:45:15 -07007369 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7370 // the process, where TelephonyManager was instantiated.
7371 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007372 final long identity = Binder.clearCallingIdentity();
7373 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007374 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 final TelephonyManager tele = TelephonyManager.from(context);
7376 final SubscriptionManager sub = SubscriptionManager.from(context);
7377
7378 // Figure out what subscribers are currently active
7379 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380
Jordan Liub49b04b2019-05-06 14:45:15 -07007381 // Only consider subs which match the current subId
7382 // This logic can be simplified. See b/131189269 for progress.
7383 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007384 activeSubscriberIds.add(tele.getSubscriberId(subId));
7385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386
7387 // First pass, find a number override for an active subscriber
7388 String mergeNumber = null;
7389 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7390 for (String key : prefs.keySet()) {
7391 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7392 final String subscriberId = (String) prefs.get(key);
7393 if (activeSubscriberIds.contains(subscriberId)) {
7394 final String iccId = key.substring(
7395 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7396 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7397 mergeNumber = (String) prefs.get(numberKey);
7398 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007399 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 + " for active subscriber " + subscriberId);
7401 }
7402 if (!TextUtils.isEmpty(mergeNumber)) {
7403 break;
7404 }
7405 }
7406 }
7407 }
7408
7409 // Shortcut when no active merged subscribers
7410 if (TextUtils.isEmpty(mergeNumber)) {
7411 return null;
7412 }
7413
7414 // Second pass, find all subscribers under that line override
7415 final ArraySet<String> result = new ArraySet<>();
7416 for (String key : prefs.keySet()) {
7417 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7418 final String number = (String) prefs.get(key);
7419 if (mergeNumber.equals(number)) {
7420 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7421 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7422 final String subscriberId = (String) prefs.get(subscriberKey);
7423 if (!TextUtils.isEmpty(subscriberId)) {
7424 result.add(subscriberId);
7425 }
7426 }
7427 }
7428 }
7429
7430 final String[] resultArray = result.toArray(new String[result.size()]);
7431 Arrays.sort(resultArray);
7432 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007433 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7435 }
7436 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007437 } finally {
7438 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007439 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007440 }
7441
7442 @Override
zoey chen38003472019-12-13 17:16:31 +08007443 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7444 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007445
7446 final long identity = Binder.clearCallingIdentity();
7447 try {
7448 final TelephonyManager telephonyManager = mApp.getSystemService(
7449 TelephonyManager.class);
7450 String subscriberId = telephonyManager.getSubscriberId(subId);
7451 if (subscriberId == null) {
7452 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007453 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007454 + subId);
7455 }
7456 return null;
7457 }
7458
Jack Yu3beaf9d2023-04-14 09:17:27 -07007459 final SubscriptionInfo info = getSubscriptionManagerService()
7460 .getSubscriptionInfo(subId);
7461 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007462 // If it doesn't belong to any group, return just subscriberId of itself.
7463 if (groupUuid == null) {
7464 return new String[]{subscriberId};
7465 }
7466
7467 // Get all subscriberIds from the group.
7468 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007469 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7470 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7471 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007472 for (SubscriptionInfo subInfo : groupInfos) {
7473 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7474 if (subscriberId != null) {
7475 mergedSubscriberIds.add(subscriberId);
7476 }
7477 }
7478
7479 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482
7483 }
7484 }
7485
7486 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007487 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007488 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007489 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
7493 final Phone phone = getPhone(subId);
7494 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007498 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007499
7500 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007501 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007502 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7503 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007504 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7505 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 final Phone phone = getPhone(subId);
7510 if (phone == null) {
7511 return false;
7512 }
7513 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7514 cdmaNonRoamingList);
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007517 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007518 }
7519
7520 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007521 @Deprecated
7522 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7523 enforceModifyPermission();
7524
7525 int returnValue = 0;
7526 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007527 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007528 if(result.exception == null) {
7529 if (result.result != null) {
7530 byte[] responseData = (byte[])(result.result);
7531 if(responseData.length > oemResp.length) {
7532 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7533 responseData.length + "bytes. Buffer Size is " +
7534 oemResp.length + "bytes.");
7535 }
7536 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7537 returnValue = responseData.length;
7538 }
7539 } else {
7540 CommandException ex = (CommandException) result.exception;
7541 returnValue = ex.getCommandError().ordinal();
7542 if(returnValue > 0) returnValue *= -1;
7543 }
7544 } catch (RuntimeException e) {
7545 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7546 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7547 if(returnValue > 0) returnValue *= -1;
7548 }
7549
7550 return returnValue;
7551 }
7552
7553 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007554 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007555 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007556 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007557 if (phone == null) {
7558 return raf;
7559 }
7560
Shuo Qiandee53402020-05-29 14:08:15 -07007561 try {
7562 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007563 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007564 mApp, phone.getSubId(), "getRadioAccessFamily");
7565 } catch (SecurityException e) {
7566 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7567 throw e;
7568 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 final long identity = Binder.clearCallingIdentity();
7571 try {
chen xub97461a2018-10-26 14:17:57 -07007572 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
chen xub97461a2018-10-26 14:17:57 -07007576 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007577 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007578
7579 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007580 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007581 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007582 try {
7583 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7584 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007585 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007586 }
7587 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007588 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007589 }
7590 RoleManager rm = mApp.getSystemService(RoleManager.class);
7591 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7592 if (!dialerRoleHolders.contains(callingPackage)) {
7593 throw new SecurityException("App must be the dialer role holder to"
7594 + " upload a call composer pic");
7595 }
7596
7597 Executors.newSingleThreadExecutor().execute(() -> {
7598 ByteArrayOutputStream output = new ByteArrayOutputStream(
7599 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7600 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7601 boolean readUntilEnd = false;
7602 int totalBytesRead = 0;
7603 byte[] buffer = new byte[16 * 1024];
7604 while (true) {
7605 int numRead;
7606 try {
7607 numRead = input.read(buffer);
7608 } catch (IOException e) {
7609 try {
7610 fd.checkError();
7611 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7612 null);
7613 } catch (IOException e1) {
7614 // This means that the other side closed explicitly with an error. If this
7615 // happens, log and ignore.
7616 loge("Remote end of call composer picture pipe closed: " + e1);
7617 }
7618 break;
7619 }
7620 if (numRead == -1) {
7621 readUntilEnd = true;
7622 break;
7623 }
7624 totalBytesRead += numRead;
7625 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7626 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7627 try {
7628 input.close();
7629 } catch (IOException e) {
7630 // ignore
7631 }
7632 break;
7633 }
7634 output.write(buffer, 0, numRead);
7635 }
7636 // Generally, the remote end will close the file descriptors. The only case where we
7637 // close is above, where the picture size is too big.
7638
7639 try {
7640 fd.checkError();
7641 } catch (IOException e) {
7642 loge("Remote end for call composer closed with an error: " + e);
7643 return;
7644 }
7645
Hall Liuaa4211e2021-01-20 15:43:39 -08007646 if (!readUntilEnd) {
7647 loge("Did not finish reading entire image; aborting");
7648 return;
7649 }
Hall Liu82694d52020-12-11 18:22:04 -08007650
Hall Liuaa4211e2021-01-20 15:43:39 -08007651 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7652 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7653 new CallComposerPictureTransfer.Factory() {},
7654 imageData,
7655 (result) -> {
7656 if (result.first != null) {
7657 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7658 Bundle outputResult = new Bundle();
7659 outputResult.putParcelable(
7660 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7661 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7662 outputResult);
7663 } else {
7664 callback.send(result.second, null);
7665 }
7666 }
7667 );
Hall Liu82694d52020-12-11 18:22:04 -08007668 });
7669 }
7670
7671 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007672 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007673 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675
7676 final long identity = Binder.clearCallingIdentity();
7677 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007678 ImsManager.getInstance(defaultPhone.getContext(),
7679 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 } finally {
7681 Binder.restoreCallingIdentity(identity);
7682 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007683 }
7684
7685 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007686 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007687 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7689 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007690 return false;
7691 }
Svet Ganovb320e182015-04-16 12:30:10 -07007692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 // Check the user preference and the system-level IMS setting. Even if the user has
7696 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7697 // In the long run, we may instead need to check if there exists a connection service
7698 // which can support video calling.
7699 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007700 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 return imsManager.isVtEnabledByPlatform()
7702 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7703 && imsManager.isVtEnabledByUser();
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007707 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007708
Andrew Leea1239f22015-03-02 17:44:07 -08007709 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007710 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7711 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007713 mApp, subId, callingPackage, callingFeatureId,
7714 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 return false;
7716 }
7717
7718 final long identity = Binder.clearCallingIdentity();
7719 try {
7720 CarrierConfigManager configManager =
7721 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007722 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7724 } finally {
7725 Binder.restoreCallingIdentity(identity);
7726 }
Andrew Leea1239f22015-03-02 17:44:07 -08007727 }
7728
7729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007730 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007732 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733 return false;
7734 }
7735
7736 final long identity = Binder.clearCallingIdentity();
7737 try {
7738 CarrierConfigManager configManager =
7739 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007740 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
7744 }
Andrew Leea1239f22015-03-02 17:44:07 -08007745 }
7746
Andrew Lee9431b832015-03-09 18:46:45 -07007747 @Override
7748 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007749 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007750 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007751 }
7752
7753 @Override
7754 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755 final long identity = Binder.clearCallingIdentity();
7756 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007757 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 } finally {
7759 Binder.restoreCallingIdentity(identity);
7760 }
Andrew Lee9431b832015-03-09 18:46:45 -07007761 }
7762
Hall Liuf6668912018-10-31 17:05:23 -07007763 /**
7764 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7765 * support for the feature and device firmware support.
7766 *
7767 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7768 */
7769 @Override
7770 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007772 final Phone phone = getPhone(subscriptionId);
7773 if (phone == null) {
7774 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7775 return false;
7776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007778 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7780 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007781 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 return isCarrierSupported && isDeviceSupported;
7783 } finally {
7784 Binder.restoreCallingIdentity(identity);
7785 }
Hall Liu98187582018-01-22 19:15:32 -08007786 }
7787
Hall Liuf6668912018-10-31 17:05:23 -07007788 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007789 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7790 * RTT setting, will return true if the device and carrier both support RTT.
7791 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007792 */
7793 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 final long identity = Binder.clearCallingIdentity();
7795 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007796 boolean isRttSupported = isRttSupported(subscriptionId);
7797 boolean isUserRttSettingOn = Settings.Secure.getInt(
7798 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7799 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7800 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7801 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007805 }
7806
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007807 @Deprecated
7808 @Override
7809 public String getDeviceId(String callingPackage) {
7810 return getDeviceIdWithFeature(callingPackage, null);
7811 }
7812
Sanket Padawe7310cc72015-01-14 09:53:20 -08007813 /**
7814 * Returns the unique device ID of phone, for example, the IMEI for
7815 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7816 *
7817 * <p>Requires Permission:
7818 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7819 */
7820 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007821 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007822 try {
7823 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7824 } catch (SecurityException se) {
7825 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7826 throw new SecurityException("Package " + callingPackage + " does not belong to "
7827 + Binder.getCallingUid());
7828 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007829 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007830 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007831 return null;
7832 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007833 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007834 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007835 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007836 return null;
7837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838
7839 final long identity = Binder.clearCallingIdentity();
7840 try {
7841 return phone.getDeviceId();
7842 } finally {
7843 Binder.restoreCallingIdentity(identity);
7844 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007845 }
7846
Ping Sunc67b7c22016-03-02 19:16:45 +08007847 /**
7848 * {@hide}
7849 * Returns the IMS Registration Status on a particular subid
7850 *
7851 * @param subId
7852 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007853 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007854 Phone phone = getPhone(subId);
7855 if (phone != null) {
7856 return phone.isImsRegistered();
7857 } else {
7858 return false;
7859 }
7860 }
7861
Santos Cordon7a1885b2015-02-03 11:15:19 -08007862 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007863 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007864 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007866 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007867 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7868 }
7869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7872 } finally {
7873 Binder.restoreCallingIdentity(identity);
7874 }
7875 }
7876
7877 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007878 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007879 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007880 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007881 mApp,
7882 subscriptionId,
7883 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7884 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007885 final long identity = Binder.clearCallingIdentity();
7886 try {
7887 Phone phone = getPhone(subscriptionId);
7888 if (phone == null) {
7889 return null;
7890 }
7891 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
7895 }
7896
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007897 /**
7898 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007899 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007900 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 final long identity = Binder.clearCallingIdentity();
7902 try {
7903 Phone phone = getPhone(subId);
7904 if (phone != null) {
7905 return phone.isWifiCallingEnabled();
7906 } else {
7907 return false;
7908 }
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007911 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007912 }
7913
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007914 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007915 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007916 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007917 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007918 final long identity = Binder.clearCallingIdentity();
7919 try {
7920 Phone phone = getPhone(subId);
7921 if (phone != null) {
7922 return phone.isVideoEnabled();
7923 } else {
7924 return false;
7925 }
7926 } finally {
7927 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007928 }
7929 }
7930
7931 /**
7932 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7933 * defined in {@link ImsRegistrationImplBase}.
7934 */
7935 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 final long identity = Binder.clearCallingIdentity();
7937 try {
7938 Phone phone = getPhone(subId);
7939 if (phone != null) {
7940 return phone.getImsRegistrationTech();
7941 } else {
7942 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7943 }
7944 } finally {
7945 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007946 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007947 }
7948
Stuart Scott8eef64f2015-04-08 15:13:54 -07007949 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007950 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007951 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007952 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7953 return;
7954 }
Kai Shif70f46f2021-03-03 13:59:46 -08007955 Phone defaultPhone = getDefaultPhone();
7956 if (defaultPhone != null) {
7957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7958 mApp, getDefaultPhone().getSubId(), "factoryReset");
7959 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007960 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007961
Svet Ganovcc087f82015-05-12 20:35:54 -07007962 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007963 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7964 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007965 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007966 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007967 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007968 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007969 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007970 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007971 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007972 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007973 // There has been issues when Sms raw table somehow stores orphan
7974 // fragments. They lead to garbled message when new fragments come
7975 // in and combined with those stale ones. In case this happens again,
7976 // user can reset all network settings which will clean up this table.
7977 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007978 // Clean up IMS settings as well here.
7979 int slotId = getSlotIndex(subId);
7980 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7981 ImsManager.getInstance(mApp, slotId).factoryReset();
7982 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007983
Kai Shif70f46f2021-03-03 13:59:46 -08007984 if (defaultPhone == null) {
7985 return;
7986 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007987 // Erase modem config if erase modem on network setting is enabled.
7988 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7989 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7990 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007991 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007992 }
Kai Shif70f46f2021-03-03 13:59:46 -08007993
7994 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007995 } finally {
7996 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007997 }
7998 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007999
SongFerngWangfd89b102021-05-27 22:44:54 +08008000 @VisibleForTesting
8001 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8002 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8003 return;
8004 }
8005 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8006 RILConstants.PREFERRED_NETWORK_MODE);
8007 SubscriptionManager.setSubscriptionProperty(subId,
8008 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8009 "user=" + defaultNetworkType);
8010 phone.loadAllowedNetworksFromSubscriptionDatabase();
8011 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8012 defaultNetworkType, null);
8013 }
8014
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008015 private void cleanUpSmsRawTable(Context context) {
8016 ContentResolver resolver = context.getContentResolver();
8017 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8018 resolver.delete(uri, null, null);
8019 }
8020
Narayan Kamath1c496c22015-04-16 14:40:19 +01008021 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008022 public String getSimLocaleForSubscriber(int subId) {
8023 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8024 final Phone phone = getPhone(subId);
8025 if (phone == null) {
8026 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008027 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029 final long identity = Binder.clearCallingIdentity();
8030 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008031 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8032 phone.getContext().getOpPackageName(),
8033 phone.getContext().getAttributionTag());
8034 if (info == null) {
8035 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8036 return null;
chen xu6291c472019-02-04 12:55:53 -08008037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 // Try and fetch the locale from the carrier properties or from the SIM language
8039 // preferences (EF-PL and EF-LI)...
8040 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008042 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8043 if (localeFromDefaultSim != null) {
8044 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8045 if (DBG) log("Using locale from subId: " + subId + " locale: "
8046 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008047 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008048 } else {
8049 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 }
8051 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 // The SIM language preferences only store a language (e.g. fr = French), not an
8054 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8055 // the SIM and carrier preferences does not include a country we add the country
8056 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008057 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008059 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008060 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 }
8062
8063 if (DBG) log("No locale found - returning null");
8064 return null;
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008068 }
8069
tom hsu0b59d292022-09-29 23:49:21 +08008070 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008071 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008072 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008073 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008074 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008075 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8076 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008077 Locale.forLanguageTag(localeTag).getCountry())) {
8078 return localeTag;
8079 }
8080 }
8081 return inputLocale.toLanguageTag();
8082 }
8083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 /**
8085 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8086 */
8087 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008088 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
8089 mApp.getOpPackageName(), mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008090 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008091
Gary Jian3aa9a762022-01-24 16:41:19 +08008092 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8093 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008094
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008095 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008096 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8097 * representing the state of the modem.
8098 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008099 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8100 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008101 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008102 */
8103 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008104 public void requestModemActivityInfo(ResultReceiver result) {
8105 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008106 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107
8108 final long identity = Binder.clearCallingIdentity();
8109 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008110 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 } finally {
8112 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008113 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008114 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008115
Gary Jian76280a42022-12-07 16:18:33 +08008116 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008117 // less than total activity duration.
8118 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8119 if (info == null) {
8120 return false;
8121 }
8122 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008123 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008124 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8125
Hall Liu49656c02020-10-09 19:00:11 -07008126 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8127
Siddharth Rayb8114062018-06-17 15:02:38 -07008128 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008129 && (info.getSleepTimeMillis() <= activityDurationMs)
8130 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008131 }
8132
Gary Jian3aa9a762022-01-24 16:41:19 +08008133 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8134 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8135 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8136 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8137
8138 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8139 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8140 }
8141
8142 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8143 mLastModemActivityInfo.setReceiveTimeMillis(
8144 rat,
8145 freq,
8146 info.getReceiveTimeMillis(rat, freq)
8147 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8148 }
8149
8150 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8151 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8152 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8153 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8154
8155 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8156 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8157 }
8158 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8159 mLastModemActivityInfo.setReceiveTimeMillis(
8160 rat,
8161 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8162 }
8163
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008164 /**
8165 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8166 * @param info recent ModemActivityInfo
8167 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008168 private void mergeModemActivityInfo(ModemActivityInfo info) {
8169 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008170 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008171 boolean matched;
8172 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8173 matched = false;
8174 int rat = info.getSpecificInfoRat(i);
8175 int freq = info.getSpecificInfoFrequencyRange(i);
8176 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8177 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8178 //if it already exists
8179 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8180 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8181 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8182 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8183 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8184 updateLastModemActivityInfo(info, rat, freq);
8185 matched = true;
8186 }
8187 } else {
8188 updateLastModemActivityInfo(info, rat);
8189 matched = true;
8190 }
8191 }
8192 }
8193
8194 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008195 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008196 new ActivityStatsTechSpecificInfo(
8197 rat,
8198 freq,
8199 info.getTransmitTimeMillis(rat, freq),
8200 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008201 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008202 }
8203 }
8204 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8205 mLastModemActivitySpecificInfo =
8206 new ActivityStatsTechSpecificInfo[merged.size()];
8207 merged.toArray(mLastModemActivitySpecificInfo);
8208
8209 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8210 mLastModemActivityInfo.setSleepTimeMillis(
8211 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008212 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008213 mLastModemActivityInfo.setIdleTimeMillis(
8214 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008215 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008216
8217 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008218 new ModemActivityInfo(
8219 mLastModemActivityInfo.getTimestampMillis(),
8220 mLastModemActivityInfo.getSleepTimeMillis(),
8221 mLastModemActivityInfo.getIdleTimeMillis(),
8222 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008223 }
8224
8225 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8226 ActivityStatsTechSpecificInfo[] info) {
8227 int infoSize = info.length;
8228 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8229 for (int i = 0; i < infoSize; i++) {
8230 ret[i] = new ActivityStatsTechSpecificInfo(
8231 info[i].getRat(), info[i].getFrequencyRange(),
8232 info[i].getTransmitTimeMillis(),
8233 (int) info[i].getReceiveTimeMillis());
8234 }
8235 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008236 }
8237
Jack Yu85bd38a2015-11-09 11:34:32 -08008238 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008239 * Returns the service state information on specified subscription.
8240 */
8241 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008242 public ServiceState getServiceStateForSubscriber(int subId,
8243 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8244 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008246 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008247 return null;
8248 }
8249
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008250 boolean hasFinePermission = false;
8251 boolean hasCoarsePermission = false;
8252 if (!renounceFineLocationAccess) {
8253 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8254 LocationAccessPolicy.checkLocationPermission(mApp,
8255 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8256 .setCallingPackage(callingPackage)
8257 .setCallingFeatureId(callingFeatureId)
8258 .setCallingPid(Binder.getCallingPid())
8259 .setCallingUid(Binder.getCallingUid())
8260 .setMethod("getServiceStateForSubscriber")
8261 .setLogAsInfo(true)
8262 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8263 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8264 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8265 .build());
8266 hasFinePermission =
8267 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8268 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008269
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008270 if (!renounceCoarseLocationAccess) {
8271 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8272 LocationAccessPolicy.checkLocationPermission(mApp,
8273 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8274 .setCallingPackage(callingPackage)
8275 .setCallingFeatureId(callingFeatureId)
8276 .setCallingPid(Binder.getCallingPid())
8277 .setCallingUid(Binder.getCallingUid())
8278 .setMethod("getServiceStateForSubscriber")
8279 .setLogAsInfo(true)
8280 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8281 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8282 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8283 .build());
8284 hasCoarsePermission =
8285 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8286 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008287
Jack Yu479f40e2020-10-27 21:29:25 -07008288 final Phone phone = getPhone(subId);
8289 if (phone == null) {
8290 return null;
8291 }
8292
Jordan Liu0f2bc442020-11-18 16:47:37 -08008293 final long identity = Binder.clearCallingIdentity();
8294
Jack Yu479f40e2020-10-27 21:29:25 -07008295 boolean isCallingPackageDataService = phone.getDataServicePackages()
8296 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008298 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008299 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8300 .getSubscriptionInfoInternal(subId);
8301 if (subInfo == null || !subInfo.isActive()) {
8302 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8303 + "subId=" + subId);
8304 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008305 }
8306
Hall Liuf19c44f2018-11-27 14:38:17 -08008307 ServiceState ss = phone.getServiceState();
8308
8309 // Scrub out the location info in ServiceState depending on what level of access
8310 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008311 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008312 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8313 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 } finally {
8315 Binder.restoreCallingIdentity(identity);
8316 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008317 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008318
8319 /**
8320 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8321 *
8322 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8323 * voicemail ringtone.
8324 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8325 * PhoneAccount.
8326 */
8327 @Override
8328 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8332 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008333 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8337 } finally {
8338 Binder.restoreCallingIdentity(identity);
8339 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008340 }
8341
8342 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008343 * Sets the per-account voicemail ringtone.
8344 *
8345 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8346 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8347 *
8348 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8349 * voicemail ringtone.
8350 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8351 * PhoneAccount.
8352 */
8353 @Override
8354 public void setVoicemailRingtoneUri(String callingPackage,
8355 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008356 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008358 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8359 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8361 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8362 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364
8365 final long identity = Binder.clearCallingIdentity();
8366 try {
8367 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8368 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008369 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370 }
8371 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8372 } finally {
8373 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008374 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008375 }
8376
8377 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008378 * Returns whether vibration is set for voicemail notification in Phone settings.
8379 *
8380 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8381 * voicemail vibration setting.
8382 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8383 */
8384 @Override
8385 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8389 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008390 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
8396 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008397 }
8398
Youhan Wange64578a2016-05-02 15:32:42 -07008399 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008400 * Sets the per-account voicemail vibration.
8401 *
8402 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8403 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8404 *
8405 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8406 * voicemail vibration setting.
8407 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8408 * specific PhoneAccount.
8409 */
8410 @Override
8411 public void setVoicemailVibrationEnabled(String callingPackage,
8412 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008413 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008414 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008415 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8416 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8418 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8419 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008420 }
8421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008422 final long identity = Binder.clearCallingIdentity();
8423 try {
8424 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8425 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008426 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008427 }
8428 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8429 } finally {
8430 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008431 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008432 }
8433
8434 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008435 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8436 *
8437 * @throws SecurityException if the caller does not have the required permission
8438 */
arunvoddud7401012022-12-15 16:08:12 +00008439 @VisibleForTesting
8440 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008442 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008443 }
8444
8445 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008446 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8447 * permission.
8448 *
8449 * @throws SecurityException if the caller does not have the required permission
8450 */
8451 private void enforceSendSmsPermission() {
8452 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8453 }
8454
8455 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008456 * Make sure either called from same process as self (phone) or IPC caller has interact across
8457 * users permission.
8458 *
8459 * @throws SecurityException if the caller does not have the required permission
8460 */
8461 private void enforceInteractAcrossUsersPermission(String message) {
8462 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8463 }
8464
8465 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008466 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008467 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008468 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008469 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008470 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008474 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008475 if (componentName == null) {
8476 throw new SecurityException(
8477 "Caller not current active visual voicemail package[null]");
8478 }
8479 String vvmPackage = componentName.getPackageName();
8480 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008481 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 }
8483 } finally {
8484 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008485 }
8486 }
8487
8488 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008489 * Return the application ID for the app type.
8490 *
8491 * @param subId the subscription ID that this request applies to.
8492 * @param appType the uicc app type.
8493 * @return Application ID for specificied app type, or null if no uicc.
8494 */
8495 @Override
8496 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008497 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008498 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008499
8500 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008501 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008502 if (phone == null) {
8503 return null;
8504 }
8505 String aid = null;
8506 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008507 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 .getApplicationByType(appType).getAid();
8509 } catch (Exception e) {
8510 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8511 }
8512 return aid;
8513 } finally {
8514 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008515 }
Youhan Wange64578a2016-05-02 15:32:42 -07008516 }
8517
Youhan Wang4001d252016-05-11 10:29:41 -07008518 /**
8519 * Return the Electronic Serial Number.
8520 *
8521 * @param subId the subscription ID that this request applies to.
8522 * @return ESN or null if error.
8523 */
8524 @Override
8525 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008526 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008527 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528
8529 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008530 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008531 if (phone == null) {
8532 return null;
8533 }
8534 String esn = null;
8535 try {
8536 esn = phone.getEsn();
8537 } catch (Exception e) {
8538 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8539 }
8540 return esn;
8541 } finally {
8542 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008543 }
Youhan Wang4001d252016-05-11 10:29:41 -07008544 }
8545
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008546 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008547 * Return the Preferred Roaming List Version.
8548 *
8549 * @param subId the subscription ID that this request applies to.
8550 * @return PRLVersion or null if error.
8551 */
8552 @Override
8553 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008554 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008555 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008556
8557 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008558 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008559 if (phone == null) {
8560 return null;
8561 }
8562 String cdmaPrlVersion = null;
8563 try {
8564 cdmaPrlVersion = phone.getCdmaPrlVersion();
8565 } catch (Exception e) {
8566 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8567 }
8568 return cdmaPrlVersion;
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008571 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008572 }
8573
8574 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008575 * Get snapshot of Telephony histograms
8576 * @return List of Telephony histograms
8577 * @hide
8578 */
8579 @Override
8580 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8582 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583
8584 final long identity = Binder.clearCallingIdentity();
8585 try {
8586 return RIL.getTelephonyRILTimingHistograms();
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
8589 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008590 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008591
8592 /**
8593 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008594 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8595 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008596 * Require system privileges. In the future we may add this to carrier APIs.
8597 *
Michele Berionne482f8202018-11-27 18:57:59 -08008598 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008599 */
8600 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008601 @TelephonyManager.SetCarrierRestrictionResult
8602 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008603 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008604 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008605
Michele Berionne482f8202018-11-27 18:57:59 -08008606 if (carrierRestrictionRules == null) {
8607 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008608 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 final long identity = Binder.clearCallingIdentity();
8611 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008612 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008613 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 } finally {
8615 Binder.restoreCallingIdentity(identity);
8616 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008617 }
8618
8619 /**
8620 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008621 * Get the allowed carrier list and the excluded carrier list, including the priority between
8622 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008623 * Require system privileges. In the future we may add this to carrier APIs.
8624 *
Michele Berionne482f8202018-11-27 18:57:59 -08008625 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008626 */
8627 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008628 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008629 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008630 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008634 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8635 if (response instanceof CarrierRestrictionRules) {
8636 return (CarrierRestrictionRules) response;
8637 }
8638 // Response is an Exception of some kind,
8639 // which is signalled to the user as a NULL retval
8640 return null;
8641 } catch (Exception e) {
8642 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8643 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008644 } finally {
8645 Binder.restoreCallingIdentity(identity);
8646 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008647 }
8648
fionaxu59545b42016-05-25 15:53:37 -07008649 /**
arunvoddud7401012022-12-15 16:08:12 +00008650 * Fetches the carrier restriction status of the device and sends the status to the caller
8651 * through the callback.
8652 *
8653 * @param callback The callback that will be used to send the result.
8654 * @throws SecurityException if the caller does not have the required permission/privileges or
8655 * the caller is not allowlisted.
8656 */
8657 @Override
8658 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8659 enforceReadPermission("getCarrierRestrictionStatus");
8660 int carrierId = validateCallerAndGetCarrierId(packageName);
8661 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8662 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8663 throw new SecurityException("Not an authorized caller");
8664 }
8665 final long identity = Binder.clearCallingIdentity();
8666 try {
8667 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8668 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8669 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8670 } finally {
8671 Binder.restoreCallingIdentity(identity);
8672 }
8673 }
8674
8675 @VisibleForTesting
8676 public int validateCallerAndGetCarrierId(String packageName) {
8677 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8678 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8679 }
8680
8681 /**
fionaxu59545b42016-05-25 15:53:37 -07008682 * Action set from carrier signalling broadcast receivers to enable/disable radio
8683 * @param subId the subscription ID that this action applies to.
8684 * @param enabled control enable or disable radio.
8685 * {@hide}
8686 */
8687 @Override
8688 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8689 enforceModifyPermission();
8690 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691
8692 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008693 if (phone == null) {
8694 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8695 return;
8696 }
8697 try {
8698 phone.carrierActionSetRadioEnabled(enabled);
8699 } catch (Exception e) {
8700 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008701 } finally {
8702 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008703 }
8704 }
8705
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008706 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008707 * Enable or disable Voice over NR (VoNR)
8708 * @param subId the subscription ID that this action applies to.
8709 * @param enabled enable or disable VoNR.
8710 * @return operation result.
8711 */
8712 @Override
8713 public int setVoNrEnabled(int subId, boolean enabled) {
8714 enforceModifyPermission();
8715 final Phone phone = getPhone(subId);
8716
8717 final long identity = Binder.clearCallingIdentity();
8718 if (phone == null) {
8719 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8720 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8721 }
8722
8723 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8724 try {
8725 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8726 workSource);
8727 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008728
8729 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8730 if (DBG) {
8731 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8732 }
8733 SubscriptionManager.setSubscriptionProperty(
8734 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8735 (enabled ? "1" : "0"));
8736 }
8737
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008738 return result;
8739 } finally {
8740 Binder.restoreCallingIdentity(identity);
8741 }
8742 }
8743
8744 /**
8745 * Is voice over NR enabled
8746 * @return true if VoNR is enabled else false
8747 */
8748 @Override
8749 public boolean isVoNrEnabled(int subId) {
8750 enforceReadPrivilegedPermission("isVoNrEnabled");
8751 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8752 final long identity = Binder.clearCallingIdentity();
8753 try {
8754 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8755 null, subId, workSource);
8756 if (DBG) log("isVoNrEnabled: " + isEnabled);
8757 return isEnabled;
8758 } finally {
8759 Binder.restoreCallingIdentity(identity);
8760 }
8761 }
8762
8763 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008764 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8765 * network status based on which carrier apps could apply actions accordingly,
8766 * enable/disable default url handler for example.
8767 *
8768 * @param subId the subscription ID that this action applies to.
8769 * @param report control start/stop reporting the default network status.
8770 * {@hide}
8771 */
8772 @Override
8773 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8774 enforceModifyPermission();
8775 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008776
8777 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008778 if (phone == null) {
8779 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8780 return;
8781 }
8782 try {
8783 phone.carrierActionReportDefaultNetworkStatus(report);
8784 } catch (Exception e) {
8785 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008786 } finally {
8787 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008788 }
8789 }
8790
8791 /**
fionaxud9622282017-07-17 17:51:30 -07008792 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8793 * @param subId the subscription ID that this action applies to.
8794 * {@hide}
8795 */
8796 @Override
8797 public void carrierActionResetAll(int subId) {
8798 enforceModifyPermission();
8799 final Phone phone = getPhone(subId);
8800 if (phone == null) {
8801 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8802 return;
8803 }
8804 try {
8805 phone.carrierActionResetAll();
8806 } catch (Exception e) {
8807 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8808 }
8809 }
8810
8811 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008812 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8813 * bug report is being generated.
8814 */
8815 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008816 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008817 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8818 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008819 writer.println("Permission Denial: can't dump Phone from pid="
8820 + Binder.getCallingPid()
8821 + ", uid=" + Binder.getCallingUid()
8822 + "without permission "
8823 + android.Manifest.permission.DUMP);
8824 return;
8825 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008826 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008827 }
Jack Yueb89b242016-06-22 13:27:47 -07008828
Brad Ebingerdac2f002018-04-03 15:17:52 -07008829 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008830 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8831 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8832 @NonNull String[] args) {
8833 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8834 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008835 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008836 }
8837
Jack Yueb89b242016-06-22 13:27:47 -07008838 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008839 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008840 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008841 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008842 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008843 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008844 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008845 */
8846 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008847 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008848 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008849 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8850 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8851 try {
8852 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008853 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008854 } catch (SecurityException se) {
8855 enforceModifyPermission();
8856 }
8857 } else {
8858 enforceModifyPermission();
8859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008860
8861 final long identity = Binder.clearCallingIdentity();
8862 try {
8863 Phone phone = getPhone(subId);
8864 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008865 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8866 phone.carrierActionSetMeteredApnsEnabled(enabled);
8867 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008868 phone.getDataSettingsManager().setDataEnabled(
8869 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008871 }
8872 } finally {
8873 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008874 }
8875 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008876
8877 /**
8878 * Get Client request stats
8879 * @return List of Client Request Stats
8880 * @hide
8881 */
8882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008883 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8884 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008886 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008887 return null;
8888 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008889 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891 final long identity = Binder.clearCallingIdentity();
8892 try {
8893 if (phone != null) {
8894 return phone.getClientRequestStats();
8895 }
8896
8897 return null;
8898 } finally {
8899 Binder.restoreCallingIdentity(identity);
8900 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008901 }
8902
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008903 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008904 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008905 if (uid == Process.ROOT_UID && packageName == null) {
8906 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8907 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8908 // exception. ROOT_UID seems not to have a valid package name returned by
8909 // PackageManager, so just fake it here to avoid issues when running telephony shell
8910 // commands that plumb through the RIL as root, like so:
8911 // $ adb root
8912 // $ adb shell cmd phone ...
8913 packageName = "root";
8914 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008915 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008916 }
Jack Yueb4124c2017-02-16 15:32:43 -08008917
8918 /**
Grace Chen70990072017-03-24 17:21:30 -07008919 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008920 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008921 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008922 * @param state State of SIM (power down, power up, pass through)
8923 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8924 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8925 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008926 *
8927 **/
8928 @Override
Grace Chen70990072017-03-24 17:21:30 -07008929 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008930 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008931 Phone phone = PhoneFactory.getPhone(slotIndex);
8932
vagdeviaf9a5b92018-08-15 16:01:53 -07008933 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 final long identity = Binder.clearCallingIdentity();
8936 try {
8937 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008938 phone.setSimPowerState(state, null, workSource);
8939 }
8940 } finally {
8941 Binder.restoreCallingIdentity(identity);
8942 }
8943 }
8944
8945 /**
8946 * Set SIM card power state.
8947 *
8948 * @param slotIndex SIM slot id.
8949 * @param state State of SIM (power down, power up, pass through)
8950 * @param callback callback to trigger after success or failure
8951 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8952 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8953 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8954 *
8955 **/
8956 @Override
8957 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8958 IIntegerConsumer callback) {
8959 enforceModifyPermission();
8960 Phone phone = PhoneFactory.getPhone(slotIndex);
8961
8962 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8963
8964 final long identity = Binder.clearCallingIdentity();
8965 try {
8966 if (phone != null) {
8967 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8968 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008969 }
8970 } finally {
8971 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008972 }
8973 }
Shuo Qiandd210312017-04-12 22:11:33 +00008974
Tyler Gunn65d45c22017-06-05 11:22:26 -07008975 private boolean isUssdApiAllowed(int subId) {
8976 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008977 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008978 if (configManager == null) {
8979 return false;
8980 }
8981 PersistableBundle pb = configManager.getConfigForSubId(subId);
8982 if (pb == null) {
8983 return false;
8984 }
8985 return pb.getBoolean(
8986 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8987 }
8988
Shuo Qiandd210312017-04-12 22:11:33 +00008989 /**
Ling Mac28f0212023-03-24 16:07:15 -07008990 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008991 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008992 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008993 */
goneil9c5f4872017-12-05 14:07:56 -08008994 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008995 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008996 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008997 final long identity = Binder.clearCallingIdentity();
8998 try {
Ling Mac28f0212023-03-24 16:07:15 -07008999 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009000 } finally {
9001 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009002 }
9003 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009004
9005 /**
9006 * Get the current signal strength information for the given subscription.
9007 * Because this information is not updated when the device is in a low power state
9008 * it should not be relied-upon to be current.
9009 * @param subId Subscription index
9010 * @return the most recent cached signal strength info from the modem
9011 */
9012 @Override
9013 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 Phone p = getPhone(subId);
9017 if (p == null) {
9018 return null;
9019 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009021 return p.getSignalStrength();
9022 } finally {
9023 Binder.restoreCallingIdentity(identity);
9024 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009025 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009026
Pengquan Meng77b7f132018-08-22 14:49:57 -07009027 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009028 * Get the current modem radio state for the given slot.
9029 * @param slotIndex slot index.
9030 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009031 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009032 * @return the current radio power state from the modem
9033 */
9034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009035 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009036 Phone phone = PhoneFactory.getPhone(slotIndex);
9037 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9039 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009040 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9041 }
9042
9043 final long identity = Binder.clearCallingIdentity();
9044 try {
9045 return phone.getRadioPowerState();
9046 } finally {
9047 Binder.restoreCallingIdentity(identity);
9048 }
9049 }
9050 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9051 }
9052
9053 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009054 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9055 *
9056 * <p>Requires one of the following permissions:
9057 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009058 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009059 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9060 * privileges.
9061 *
9062 * @param subId subscription id
9063 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9064 * {@code false}.
9065 */
9066 @Override
9067 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009068 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009069 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009070 try {
9071 mApp.enforceCallingOrSelfPermission(
9072 android.Manifest.permission.ACCESS_NETWORK_STATE,
9073 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009074 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009075 mApp.enforceCallingOrSelfPermission(
9076 permission.READ_BASIC_PHONE_STATE, functionName);
9077 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009078 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009079 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009080 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009081 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009082
Pengquan Menga1bb6272018-09-06 09:59:22 -07009083 boolean isEnabled = false;
9084 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009085 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009086 Phone phone = getPhone(subId);
9087 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009088 } finally {
9089 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009090 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009091 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009092 }
9093
9094
9095 /**
9096 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9097 *
9098 * <p> Requires permission:
9099 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9100 * privileges.
9101 *
9102 * @param subId subscription id
9103 * @param isEnabled {@code true} means enable, {@code false} means disable.
9104 */
9105 @Override
9106 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9108 mApp, subId, "setDataRoamingEnabled");
9109
Pengquan Menga1bb6272018-09-06 09:59:22 -07009110 final long identity = Binder.clearCallingIdentity();
9111 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009112 Phone phone = getPhone(subId);
9113 if (phone != null) {
9114 phone.setDataRoamingEnabled(isEnabled);
9115 }
9116 } finally {
9117 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009118 }
9119 }
9120
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009121 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009122 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009123 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009124 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009125 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009126
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009127 boolean isAllowed = true;
9128 final long identity = Binder.clearCallingIdentity();
9129 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009130 Phone phone = getPhone(subId);
9131 if (phone != null) {
9132 isAllowed = phone.isCspPlmnEnabled();
9133 }
9134 } finally {
9135 Binder.restoreCallingIdentity(identity);
9136 }
9137 return isAllowed;
9138 }
9139
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009140 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9141 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009142 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009143 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009144 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009145 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9146 if (phone == null) {
9147 return false;
9148 }
9149 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9150 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9151 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009152 }
9153
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009154 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009155 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009156 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009157 mApp.getSystemService(AppOpsManager.class)
9158 .checkPackage(Binder.getCallingUid(), callingPackage);
9159
Jordan Liu1e142fc2019-04-22 15:10:43 -07009160 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009161 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009162 try {
9163 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009164 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009165 } catch (SecurityException e) {
9166 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9167 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009168 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009169 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009170 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009171 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009172 }
sandeepjsb6c87872021-09-27 15:34:44 +00009173 // checking compatibility, if calling app's target SDK is T and beyond.
9174 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9175 Binder.getCallingUid())) {
9176 isIccIdAccessRestricted = true;
9177 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009178 final long identity = Binder.clearCallingIdentity();
9179 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009180 UiccController uiccController = UiccController.getInstance();
9181 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009182 if (hasReadPermission) {
9183 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009184 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009185
9186 // Remove private info if the caller doesn't have access
9187 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9188 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009189 //setting the value after compatibility check
9190 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009191 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9192 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009193 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009194 if (card == null) {
9195 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009196 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009197 continue;
9198 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009199 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9200 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009201 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009202 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009203 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009204 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9205 for (UiccPortInfo portInfo : portInfos) {
9206 UiccPort port = uiccController.getUiccPortForSlot(
9207 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9208 if (port == null) {
9209 // assume no access if port is null
9210 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9211 continue;
9212 }
9213 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9214 uiccPortInfos.add(portInfo);
9215 } else {
9216 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9217 }
9218 }
9219 filteredInfos.add(new UiccCardInfo(
9220 cardInfo.isEuicc(),
9221 cardInfo.getCardId(),
9222 null,
9223 cardInfo.getPhysicalSlotIndex(),
9224 cardInfo.isRemovable(),
9225 cardInfo.isMultipleEnabledProfilesSupported(),
9226 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009227 }
9228 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009229 } finally {
9230 Binder.restoreCallingIdentity(identity);
9231 }
9232 }
9233
sandeepjsb6c87872021-09-27 15:34:44 +00009234 /**
9235 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9236 * generally private and require carrier privileges to view.
9237 *
9238 * @hide
9239 */
9240 @NonNull
9241 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9242 List<UiccPortInfo> portinfo = new ArrayList<>();
9243 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9244 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9245 }
9246 return new UiccCardInfo(
9247 cardInfo.isEuicc(),
9248 cardInfo.getCardId(),
9249 null,
9250 cardInfo.getPhysicalSlotIndex(),
9251 cardInfo.isRemovable(),
9252 cardInfo.isMultipleEnabledProfilesSupported(),
9253 portinfo
9254 );
9255 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009256
sandeepjsb6c87872021-09-27 15:34:44 +00009257 /**
9258 * @hide
9259 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9260 * These values are generally private and require carrier privileges to view.
9261 */
9262 @NonNull
9263 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9264 return new UiccPortInfo(
9265 UiccPortInfo.ICCID_REDACTED,
9266 portInfo.getPortIndex(),
9267 portInfo.getLogicalSlotIndex(),
9268 portInfo.isActive()
9269 );
9270 }
9271 @Override
9272 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009273 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009274 mApp.getSystemService(AppOpsManager.class)
9275 .checkPackage(Binder.getCallingUid(), callingPackage);
9276
sandeepjsb6c87872021-09-27 15:34:44 +00009277 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009278
Aman Guptaf3c90b32022-03-17 04:54:16 +00009279 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9280 // we are reading iccId which is PII data.
9281 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009282
9283 // checking compatibility, if calling app's target SDK is T and beyond.
9284 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9285 Binder.getCallingUid())) {
9286 isLogicalSlotAccessRestricted = true;
9287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009291 if (slots == null || slots.length == 0) {
9292 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009293 return null;
9294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009295 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9296 for (int i = 0; i < slots.length; i++) {
9297 UiccSlot slot = slots[i];
9298 if (slot == null) {
9299 continue;
9300 }
9301
Jordan Liu7be7e652019-05-06 18:55:02 +00009302 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009303 UiccCard card = slot.getUiccCard();
9304 if (card != null) {
9305 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009306 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009307 cardId = slot.getEid();
9308 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009309 // If cardId is null, use iccId of default port as cardId.
9310 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009312 }
9313
Jordan Liu857451f2019-05-09 16:35:35 -07009314 if (cardId != null) {
9315 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9316 // if cardId is an EID, it's all digits so this is fine
9317 cardId = IccUtils.stripTrailingFs(cardId);
9318 }
9319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009320 int cardState = 0;
9321 switch (slot.getCardState()) {
9322 case CARDSTATE_ABSENT:
9323 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9324 break;
9325 case CARDSTATE_PRESENT:
9326 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9327 break;
9328 case CARDSTATE_ERROR:
9329 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9330 break;
9331 case CARDSTATE_RESTRICTED:
9332 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9333 break;
9334 default:
9335 break;
9336
9337 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009338 List<UiccPortInfo> portInfos = new ArrayList<>();
9339 int[] portIndexes = slot.getPortList();
9340 for (int portIdx : portIndexes) {
9341 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009342 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009343 portInfos.add(new UiccPortInfo(iccId, portIdx,
9344 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009346 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009347 slot.isEuicc(),
9348 cardId,
9349 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009350 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009351 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009352 //setting the value after compatibility check
9353 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009354 }
9355 return infos;
9356 } finally {
9357 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009358 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009359 }
9360
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009361 /* Returns null if doesn't have read permission or carrier privilege access. */
9362 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9363 boolean hasReadPermission) {
9364 String iccId = slot.getIccId(portIndex);
9365 if (hasReadPermission) { // if has read permission
9366 return iccId;
9367 } else {
9368 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9369 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9370 // if no read permission, checking carrier privilege access
9371 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9372 return iccId;
9373 }
9374 }
9375 }
9376 // No read permission or carrier privilege access.
9377 return UiccPortInfo.ICCID_REDACTED;
9378 }
9379
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009380 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009381 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009382 public boolean switchSlots(int[] physicalSlots) {
9383 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009384
9385 final long identity = Binder.clearCallingIdentity();
9386 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009387 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9388 for (int i = 0; i < physicalSlots.length; i++) {
9389 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9390 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9391 physicalSlots[i], i));
9392 }
9393 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009394 } finally {
9395 Binder.restoreCallingIdentity(identity);
9396 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009397 }
Jack Yu4c988042018-02-27 15:30:01 -08009398
9399 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009400 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9401 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9402 enforceModifyPermission();
9403
9404 final long identity = Binder.clearCallingIdentity();
9405 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009406 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009407 } finally {
9408 Binder.restoreCallingIdentity(identity);
9409 }
9410 }
9411
9412 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009413 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009414 final long identity = Binder.clearCallingIdentity();
9415 try {
9416 return UiccController.getInstance().getCardIdForDefaultEuicc();
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
Pengquan Meng85728fb2018-03-12 16:31:21 -07009422 /**
goneil47ffb6e2018-04-06 15:40:58 -07009423 * A test API to reload the UICC profile.
9424 *
9425 * <p>Requires that the calling app has permission
9426 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9427 * @hide
9428 */
9429 @Override
9430 public void refreshUiccProfile(int subId) {
9431 enforceModifyPermission();
9432
9433 final long identity = Binder.clearCallingIdentity();
9434 try {
9435 Phone phone = getPhone(subId);
9436 if (phone == null) {
9437 return;
9438 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009439 UiccPort uiccPort = phone.getUiccPort();
9440 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009441 return;
9442 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009443 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009444 if (uiccProfile == null) {
9445 return;
9446 }
9447 uiccProfile.refresh();
9448 } finally {
9449 Binder.restoreCallingIdentity(identity);
9450 }
9451 }
9452
9453 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009454 * Returns false if the mobile data is disabled by default, otherwise return true.
9455 */
9456 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009457 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009458 }
9459
9460 /**
9461 * Returns true if the data roaming is enabled by default, i.e the system property
9462 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9463 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9464 */
9465 private boolean getDefaultDataRoamingEnabled(int subId) {
9466 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009467 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009468 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009469 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9470 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9471 return isDataRoamingEnabled;
9472 }
9473
9474 /**
9475 * Returns the default network type for the given {@code subId}, if the default network type is
9476 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9477 */
9478 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009479 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009480 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009481 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9482 return list.get(phoneId);
9483 }
9484 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009485 }
fionaxua13278b2018-03-21 00:08:13 -07009486
9487 @Override
9488 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009489 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009491
9492 final long identity = Binder.clearCallingIdentity();
9493 try {
9494 final Phone phone = getPhone(subId);
9495 if (phone == null) {
9496 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9497 return;
9498 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009499 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9500 if (cpt != null) {
9501 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9502 }
9503 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009504 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9505 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009506 if (carrierPrivilegeRules == null) {
9507 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9508 } else {
9509 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009511 } finally {
9512 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009513 }
fionaxua13278b2018-03-21 00:08:13 -07009514 }
9515
9516 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009517 public void setCarrierServicePackageOverride(
9518 int subId, String carrierServicePackage, String callingPackage) {
9519 TelephonyPermissions.enforceShellOnly(
9520 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9521
9522 // Verify that the callingPackage belongs to the calling UID
9523 mApp.getSystemService(AppOpsManager.class)
9524 .checkPackage(Binder.getCallingUid(), callingPackage);
9525
9526 final long identity = Binder.clearCallingIdentity();
9527 try {
9528 final Phone phone = getPhone(subId);
9529 if (phone == null || phone.getSubId() != subId) {
9530 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9531 throw new IllegalArgumentException("No phone for subid");
9532 }
9533 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9534 if (cpt == null) {
9535 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9536 throw new IllegalStateException("No CPT for phone");
9537 }
9538 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9539 } finally {
9540 Binder.restoreCallingIdentity(identity);
9541 }
9542 }
9543
9544 @Override
fionaxua13278b2018-03-21 00:08:13 -07009545 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009546 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009547
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
9550 final Phone phone = getPhone(subId);
9551 if (phone == null) {
9552 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9553 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9554 }
9555 return phone.getCarrierIdListVersion();
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009558 }
fionaxua13278b2018-03-21 00:08:13 -07009559 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009560
9561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009562 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9563 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009565 mApp, subId, callingPackage, callingFeatureId,
9566 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009567 return -1;
9568 }
9569
9570 final long identity = Binder.clearCallingIdentity();
9571 try {
9572 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9573 } finally {
9574 Binder.restoreCallingIdentity(identity);
9575 }
9576 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009577
9578 @Override
9579 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009580 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009581 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009582 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009583
9584 final long identity = Binder.clearCallingIdentity();
9585 try {
9586 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
9589 }
9590 }
9591
9592 @Override
9593 public boolean setCdmaRoamingMode(int subId, int mode) {
9594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9595 mApp, subId, "setCdmaRoamingMode");
9596
9597 final long identity = Binder.clearCallingIdentity();
9598 try {
9599 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
9604
9605 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009606 public int getCdmaSubscriptionMode(int subId) {
9607 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009608 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009609 mApp, subId, "getCdmaSubscriptionMode");
9610
9611 final long identity = Binder.clearCallingIdentity();
9612 try {
9613 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
9617 }
9618
9619 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009620 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9622 mApp, subId, "setCdmaSubscriptionMode");
9623
9624 final long identity = Binder.clearCallingIdentity();
9625 try {
9626 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9627 } finally {
9628 Binder.restoreCallingIdentity(identity);
9629 }
9630 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009631
sqianc5eccab2018-10-19 18:46:41 -07009632 @Override
sqian8c685422019-02-22 15:55:18 -08009633 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009634 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009636 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9637 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009638 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9639 }
9640 final long identity = Binder.clearCallingIdentity();
9641 try {
sqian854d44b2018-12-12 16:48:18 -08009642 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9643 for (Phone phone: PhoneFactory.getPhones()) {
9644 if (phone.getEmergencyNumberTracker() != null
9645 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9646 emergencyNumberListInternal.put(
9647 phone.getSubId(),
9648 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9649 }
sqian11b7a0e2018-12-05 18:48:28 -08009650 }
sqian854d44b2018-12-12 16:48:18 -08009651 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009652 } finally {
9653 Binder.restoreCallingIdentity(identity);
9654 }
sqianc5eccab2018-10-19 18:46:41 -07009655 }
9656
9657 @Override
sqian8c685422019-02-22 15:55:18 -08009658 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009659 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009660 if (!exactMatch) {
9661 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009662 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009663 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009664 }
9665 final long identity = Binder.clearCallingIdentity();
9666 try {
sqian854d44b2018-12-12 16:48:18 -08009667 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009668 //Note: we ignore passed in param exactMatch. We can remove it once
9669 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009670 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009671 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009672 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009673 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009674 }
sqian11b7a0e2018-12-05 18:48:28 -08009675 }
9676 return false;
9677 } finally {
9678 Binder.restoreCallingIdentity(identity);
9679 }
9680 }
9681
sqianf4ca7ed2019-01-15 18:32:07 -08009682 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009683 * Start emergency callback mode for GsmCdmaPhone for testing.
9684 */
9685 @Override
9686 public void startEmergencyCallbackMode() {
9687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9688 "startEmergencyCallbackMode");
9689 enforceModifyPermission();
9690 final long identity = Binder.clearCallingIdentity();
9691 try {
9692 for (Phone phone : PhoneFactory.getPhones()) {
9693 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9694 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9695 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9696 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9697 gsmCdmaPhone.obtainMessage(
9698 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9699 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9700 }
9701 }
9702 } finally {
9703 Binder.restoreCallingIdentity(identity);
9704 }
9705 }
9706
9707 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009708 * Update emergency number list for test mode.
9709 */
9710 @Override
9711 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9712 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9713 "updateEmergencyNumberListTestMode");
9714
9715 final long identity = Binder.clearCallingIdentity();
9716 try {
9717 for (Phone phone: PhoneFactory.getPhones()) {
9718 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9719 if (tracker != null) {
9720 tracker.executeEmergencyNumberTestModeCommand(action, num);
9721 }
9722 }
9723 } finally {
9724 Binder.restoreCallingIdentity(identity);
9725 }
9726 }
9727
9728 /**
9729 * Get the full emergency number list for test mode.
9730 */
9731 @Override
9732 public List<String> getEmergencyNumberListTestMode() {
9733 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9734 "getEmergencyNumberListTestMode");
9735
9736 final long identity = Binder.clearCallingIdentity();
9737 try {
9738 Set<String> emergencyNumbers = new HashSet<>();
9739 for (Phone phone: PhoneFactory.getPhones()) {
9740 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9741 if (tracker != null) {
9742 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9743 emergencyNumbers.add(num.getNumber());
9744 }
9745 }
9746 }
9747 return new ArrayList<>(emergencyNumbers);
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
chen xud6b45bd2018-10-30 22:27:10 -07009753 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009754 public int getEmergencyNumberDbVersion(int subId) {
9755 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9756
9757 final long identity = Binder.clearCallingIdentity();
9758 try {
9759 final Phone phone = getPhone(subId);
9760 if (phone == null) {
9761 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9762 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9763 }
9764 return phone.getEmergencyNumberDbVersion();
9765 } finally {
9766 Binder.restoreCallingIdentity(identity);
9767 }
9768 }
9769
9770 @Override
9771 public void notifyOtaEmergencyNumberDbInstalled() {
9772 enforceModifyPermission();
9773
9774 final long identity = Binder.clearCallingIdentity();
9775 try {
9776 for (Phone phone: PhoneFactory.getPhones()) {
9777 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9778 if (tracker != null) {
9779 tracker.updateOtaEmergencyNumberDatabase();
9780 }
9781 }
9782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
9786
9787 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009788 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009789 enforceActiveEmergencySessionPermission();
9790
9791 final long identity = Binder.clearCallingIdentity();
9792 try {
9793 for (Phone phone: PhoneFactory.getPhones()) {
9794 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9795 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009796 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9797 }
9798 }
9799 } finally {
9800 Binder.restoreCallingIdentity(identity);
9801 }
9802 }
9803
9804 @Override
9805 public void resetOtaEmergencyNumberDbFilePath() {
9806 enforceActiveEmergencySessionPermission();
9807
9808 final long identity = Binder.clearCallingIdentity();
9809 try {
9810 for (Phone phone: PhoneFactory.getPhones()) {
9811 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9812 if (tracker != null) {
9813 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009814 }
9815 }
9816 } finally {
9817 Binder.restoreCallingIdentity(identity);
9818 }
9819 }
9820
9821 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009822 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9823 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9824 Phone phone = getPhone(subId);
9825 if (phone == null) {
9826 return null;
9827 }
9828 final long identity = Binder.clearCallingIdentity();
9829 try {
9830 UiccProfile profile = UiccController.getInstance()
9831 .getUiccProfileForPhone(phone.getPhoneId());
9832 if (profile != null) {
9833 return profile.getCertsFromCarrierPrivilegeAccessRules();
9834 }
9835 } finally {
9836 Binder.restoreCallingIdentity(identity);
9837 }
9838 return null;
9839 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009840
9841 /**
9842 * Enable or disable a modem stack.
9843 */
9844 @Override
9845 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9846 enforceModifyPermission();
9847
9848 final long identity = Binder.clearCallingIdentity();
9849 try {
9850 Phone phone = PhoneFactory.getPhone(slotIndex);
9851 if (phone == null) {
9852 return false;
9853 } else {
9854 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9855 }
9856 } finally {
9857 Binder.restoreCallingIdentity(identity);
9858 }
9859 }
Michelecea4cf22018-12-21 15:00:11 -08009860
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009861 /**
9862 * Whether a modem stack is enabled or not.
9863 */
9864 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009865 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9866 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009867 Phone phone = PhoneFactory.getPhone(slotIndex);
9868 if (phone == null) return false;
9869
9870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009871 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9872 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009873 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9874 }
9875
9876 final long identity = Binder.clearCallingIdentity();
9877 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009878 try {
9879 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9880 } catch (NoSuchElementException ex) {
9881 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9882 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009883 } finally {
9884 Binder.restoreCallingIdentity(identity);
9885 }
9886 }
9887
Michelecea4cf22018-12-21 15:00:11 -08009888 @Override
Michele0ea7d782019-03-19 14:58:42 -07009889 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009890 enforceModifyPermission();
9891
9892 final long identity = Binder.clearCallingIdentity();
9893 try {
9894 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009895 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009896 .commit();
9897 } finally {
9898 Binder.restoreCallingIdentity(identity);
9899 }
9900 }
9901
9902 @Override
Michele0ea7d782019-03-19 14:58:42 -07009903 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009904 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009906 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9907 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009908 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009909 }
Michelecea4cf22018-12-21 15:00:11 -08009910
9911 final long identity = Binder.clearCallingIdentity();
9912 try {
Michele0ea7d782019-03-19 14:58:42 -07009913 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009914 } finally {
9915 Binder.restoreCallingIdentity(identity);
9916 }
9917 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009918
Michele0ea7d782019-03-19 14:58:42 -07009919 @TelephonyManager.IsMultiSimSupportedResult
9920 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009921 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9922 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9923 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009924 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9925 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009926 }
9927 // Check if the hardware supports multisim functionality. If usage of multisim is not
9928 // supported by the modem, indicate that it is restricted.
9929 PhoneCapability staticCapability =
9930 mPhoneConfigurationManager.getStaticPhoneCapability();
9931 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009932 loge("isMultiSimSupportedInternal: no static configuration available");
9933 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009934 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009935 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009936 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9937 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009938 }
9939 // Check if support of multiple SIMs is restricted by carrier
9940 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009941 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009942 }
9943
Michele0ea7d782019-03-19 14:58:42 -07009944 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009945 }
9946
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009947 /**
9948 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009949 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9950 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9951 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009952 * @param numOfSims number of active sims we want to switch to
9953 */
9954 @Override
9955 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009956 if (numOfSims == 1) {
9957 enforceModifyPermission();
9958 } else {
9959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9960 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9961 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009962 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009963
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009964 try {
Michele30b57b22019-03-01 12:01:14 -08009965 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009966 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009967 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9968 return;
9969 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009970 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9971 } finally {
9972 Binder.restoreCallingIdentity(identity);
9973 }
9974 }
9975
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009976 @Override
9977 public boolean isApplicationOnUicc(int subId, int appType) {
9978 enforceReadPrivilegedPermission("isApplicationOnUicc");
9979 Phone phone = getPhone(subId);
9980 if (phone == null) {
9981 return false;
9982 }
9983 final long identity = Binder.clearCallingIdentity();
9984 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009985 UiccPort uiccPort = phone.getUiccPort();
9986 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009987 return false;
9988 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009989 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009990 if (uiccProfile == null) {
9991 return false;
9992 }
9993 if (TelephonyManager.APPTYPE_SIM <= appType
9994 && appType <= TelephonyManager.APPTYPE_ISIM) {
9995 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9996 }
9997 return false;
9998 } finally {
9999 Binder.restoreCallingIdentity(identity);
10000 }
10001 }
10002
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010003 /**
chen xub4baa772019-04-03 10:23:41 -070010004 * Get whether making changes to modem configurations will trigger reboot.
10005 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010006 */
10007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010008 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10009 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010011 mApp, subId, callingPackage, callingFeatureId,
10012 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010013 return false;
10014 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010015 final long identity = Binder.clearCallingIdentity();
10016 try {
10017 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10018 } finally {
10019 Binder.restoreCallingIdentity(identity);
10020 }
10021 }
10022
Nathan Harold29f5f052019-02-15 13:41:57 -080010023 private void updateModemStateMetrics() {
10024 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10025 // TODO: check the state for each modem if the api is ready.
10026 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10027 }
10028
Pengquan Meng3889a572019-01-23 11:16:29 -080010029 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010030 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010031 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010032 // Verify that the callingPackage belongs to the calling UID
10033 mApp.getSystemService(AppOpsManager.class)
10034 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010035 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010036 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010037 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010038 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10039 if (slotInfos != null) {
10040 for (int i = 0; i < slotInfos.length; i++) {
10041 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10042 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10043 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10044 portInfo.getLogicalSlotIndex()));
10045 }
10046 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010047 }
10048 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010049 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010050 } finally {
10051 Binder.restoreCallingIdentity(identity);
10052 }
10053 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010054
10055 /**
10056 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010057 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010058 */
jimsunf9ec1622022-09-13 21:18:43 +080010059 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010060 @Override
10061 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010062 return getHalVersion(HAL_SERVICE_RADIO);
10063 }
10064
10065 /**
10066 * Get the HAL Version of a specific service
10067 */
10068 @Override
10069 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010070 Phone phone = getDefaultPhone();
10071 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010072 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010073 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10074 return hv.major * 100 + hv.minor;
10075 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010076
10077 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010078 * Get the current calling package name.
10079 * @return the current calling package name
10080 */
10081 @Override
10082 public String getCurrentPackageName() {
10083 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10084 }
10085
10086 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010087 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10088 * corresponding network requests on a subId.
10089 *
10090 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010091 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010092 * 2) APN is un-metered for this subscription, or
10093 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010094 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010095 *
10096 * @return whether data is allowed for a apn type.
10097 *
10098 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010099 */
10100 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010101 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010102 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10103 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010104
10105 // Now that all security checks passes, perform the operation as ourselves.
10106 final long identity = Binder.clearCallingIdentity();
10107 try {
10108 Phone phone = getPhone(subId);
10109 if (phone == null) return false;
10110
Jack Yu27422a52022-03-21 10:38:05 -070010111 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010112 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010113 isMetered = phone.getDataNetworkController().getDataConfigManager()
10114 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10115 phone.getServiceState().getDataRoaming());
10116 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010117 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010118 } finally {
10119 Binder.restoreCallingIdentity(identity);
10120 }
10121 }
10122
10123 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010124 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010125 enforceReadPrivilegedPermission("isApnMetered");
10126
10127 // Now that all security checks passes, perform the operation as ourselves.
10128 final long identity = Binder.clearCallingIdentity();
10129 try {
10130 Phone phone = getPhone(subId);
10131 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010132 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10133 DataUtils.apnTypeToNetworkCapability(apnType),
10134 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010135 } finally {
10136 Binder.restoreCallingIdentity(identity);
10137 }
10138 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010139
10140 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010141 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10142 int subscriptionId, IBooleanConsumer resultCallback) {
10143 enforceModifyPermission();
10144 long token = Binder.clearCallingIdentity();
10145 try {
10146 Phone phone = getPhone(subscriptionId);
10147 if (phone == null) {
10148 try {
10149 if (resultCallback != null) {
10150 resultCallback.accept(false);
10151 }
10152 } catch (RemoteException e) {
10153 // ignore
10154 }
10155 return;
10156 }
10157 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10158 Pair.create(specifiers, (x) -> {
10159 try {
10160 if (resultCallback != null) {
10161 resultCallback.accept(x);
10162 }
10163 } catch (RemoteException e) {
10164 // ignore
10165 }
10166 });
10167 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10168 } finally {
10169 Binder.restoreCallingIdentity(token);
10170 }
10171 }
10172
10173 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010174 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10175 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010176 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010177 mApp, subId, "getSystemSelectionChannels");
10178 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10179 final long identity = Binder.clearCallingIdentity();
10180 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010181 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10182 if (result instanceof IllegalStateException) {
10183 throw (IllegalStateException) result;
10184 }
10185 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010186 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10187 return specifiers;
10188 } finally {
10189 Binder.restoreCallingIdentity(identity);
10190 }
10191 }
10192
10193 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010194 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010195 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010196 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010197 }
10198
10199 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010200 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10201 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010202 if (callingPackage == null) {
10203 callingPackage = getCurrentPackageName();
10204 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010205 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10206 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010207 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10208 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010209 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10210 }
10211 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10212 Intent intent = new Intent();
10213 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10214 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10215 // Bring up choose default SMS subscription dialog right now
10216 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10217 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10218 mApp.startActivity(intent);
10219 }
chen xud5ca2d52019-05-28 15:20:57 -070010220
10221 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010222 public void showSwitchToManagedProfileDialog() {
10223 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010224 try {
10225 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10226 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10227 // for work telephony.
10228 Intent intent = new Intent(Intent.ACTION_SENDTO);
10229 intent.setData(Uri.parse("smsto:"));
10230 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10231 mApp.startActivity(intent);
10232 } catch (ActivityNotFoundException e) {
10233 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10234 Intent intent = new Intent();
10235 intent.setClass(mApp, ErrorDialogActivity.class);
10236 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10237 mApp.startActivity(intent);
10238 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010239 }
10240
10241 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010242 public String getMmsUAProfUrl(int subId) {
10243 //TODO investigate if this API should require proper permission check in R b/133791609
10244 final long identity = Binder.clearCallingIdentity();
10245 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010246 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10247 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10248 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10249 return carrierUAProfUrl;
10250 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010251 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10252 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010253 } finally {
10254 Binder.restoreCallingIdentity(identity);
10255 }
10256 }
10257
10258 @Override
10259 public String getMmsUserAgent(int subId) {
10260 //TODO investigate if this API should require proper permission check in R b/133791609
10261 final long identity = Binder.clearCallingIdentity();
10262 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010263 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10264 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10265 if (!TextUtils.isEmpty(carrierUserAgent)) {
10266 return carrierUserAgent;
10267 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010268 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10269 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010270 } finally {
10271 Binder.restoreCallingIdentity(identity);
10272 }
10273 }
Jack Yub07d4972019-05-28 16:12:25 -070010274
10275 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010276 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10277 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010278
Jack Yub07d4972019-05-28 16:12:25 -070010279 final long identity = Binder.clearCallingIdentity();
10280 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010281 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010282 if (phone == null) return false;
10283
Ling Maf188d502022-09-16 15:22:36 -070010284 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288 }
10289
10290 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010291 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010292 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010293 enforceModifyPermission();
10294
changbettyd5c246e2019-12-24 15:40:37 +080010295 final long identity = Binder.clearCallingIdentity();
10296 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010297 Phone phone = getPhone(subscriptionId);
10298 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010299
Ling Maf188d502022-09-16 15:22:36 -070010300 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010301 } finally {
10302 Binder.restoreCallingIdentity(identity);
10303 }
10304 }
10305
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010306 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010307 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010308 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10309 * otherwise.
10310 */
10311 @Override
10312 public void setCepEnabled(boolean isCepEnabled) {
10313 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10314
10315 final long identity = Binder.clearCallingIdentity();
10316 try {
10317 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10318 for (Phone phone : PhoneFactory.getPhones()) {
10319 Phone defaultPhone = phone.getImsPhone();
10320 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10321 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10322 ImsPhoneCallTracker imsPhoneCallTracker =
10323 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10324 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10325 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10326 + imsPhone.getMsisdn());
10327 }
10328 }
10329 } finally {
10330 Binder.restoreCallingIdentity(identity);
10331 }
10332 }
allenwtsu46dcc572020-01-08 18:24:03 +080010333
10334 /**
10335 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10336 *
10337 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10338 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10339 * before being read.
10340 */
10341 @Override
10342 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10343 isCompressed) {
10344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10345 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10347 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10348 }
10349 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010350 // ProvisioningManager can not handle ServiceSpecificException.
10351 // Throw the IllegalStateException and annotate ProvisioningManager.
10352 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010353 }
10354
10355 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010356 try {
Hui Wang761a6682020-10-31 05:12:53 +000010357 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10358 } finally {
10359 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010360 }
10361 }
zoey chene02881a2019-12-30 16:11:23 +080010362
10363 @Override
10364 public boolean isIccLockEnabled(int subId) {
10365 enforceReadPrivilegedPermission("isIccLockEnabled");
10366
10367 // Now that all security checks passes, perform the operation as ourselves.
10368 final long identity = Binder.clearCallingIdentity();
10369 try {
10370 Phone phone = getPhone(subId);
10371 if (phone != null && phone.getIccCard() != null) {
10372 return phone.getIccCard().getIccLockEnabled();
10373 } else {
10374 return false;
10375 }
10376 } finally {
10377 Binder.restoreCallingIdentity(identity);
10378 }
10379 }
10380
10381 /**
10382 * Set the ICC pin lock enabled or disabled.
10383 *
10384 * @return an integer representing the status of IccLock enabled or disabled in the following
10385 * three cases:
10386 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10387 * successfully.
10388 * - Positive number and zero for remaining password attempts.
10389 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10390 *
10391 */
10392 @Override
10393 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10394 enforceModifyPermission();
10395
10396 Phone phone = getPhone(subId);
10397 if (phone == null) {
10398 return 0;
10399 }
10400 // Now that all security checks passes, perform the operation as ourselves.
10401 final long identity = Binder.clearCallingIdentity();
10402 try {
10403 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10404 new Pair<Boolean, String>(enabled, password), phone, null);
10405 return attemptsRemaining;
10406
10407 } catch (Exception e) {
10408 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
10412 return 0;
10413 }
10414
10415 /**
10416 * Change the ICC password used in ICC pin lock.
10417 *
10418 * @return an integer representing the status of IccLock changed in the following three cases:
10419 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10420 * - Positive number and zero for remaining password attempts.
10421 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10422 *
10423 */
10424 @Override
10425 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10426 enforceModifyPermission();
10427
10428 Phone phone = getPhone(subId);
10429 if (phone == null) {
10430 return 0;
10431 }
10432 // Now that all security checks passes, perform the operation as ourselves.
10433 final long identity = Binder.clearCallingIdentity();
10434 try {
10435 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10436 new Pair<String, String>(oldPassword, newPassword), phone, null);
10437 return attemptsRemaining;
10438
10439 } catch (Exception e) {
10440 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10441 } finally {
10442 Binder.restoreCallingIdentity(identity);
10443 }
10444 return 0;
10445 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010446
10447 /**
10448 * Request for receiving user activity notification
10449 */
10450 @Override
10451 public void requestUserActivityNotification() {
10452 if (!mNotifyUserActivity.get()
10453 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10454 mNotifyUserActivity.set(true);
10455 }
10456 }
10457
10458 /**
10459 * Called when userActivity is signalled in the power manager.
10460 * This is safe to call from any thread, with any window manager locks held or not.
10461 */
10462 @Override
10463 public void userActivity() {
10464 // ***************************************
10465 // * Inherited from PhoneWindowManager *
10466 // ***************************************
10467 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10468 // WITH ITS LOCKS HELD.
10469 //
10470 // This code must be VERY careful about the locks
10471 // it acquires.
10472 // In fact, the current code acquires way too many,
10473 // and probably has lurking deadlocks.
10474
10475 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10476 throw new SecurityException("Only the OS may call notifyUserActivity()");
10477 }
10478
10479 if (mNotifyUserActivity.getAndSet(false)) {
10480 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10481 USER_ACTIVITY_NOTIFICATION_DELAY);
10482 }
10483 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010484
10485 @Override
10486 public boolean canConnectTo5GInDsdsMode() {
10487 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10488 }
Jack Yud10cdd42020-09-28 20:28:01 -070010489
10490 @Override
10491 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10492 String callingFeatureId) {
10493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10494 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10495 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10496 }
10497
10498 Phone phone = getPhone(subId);
10499 if (phone == null) {
10500 throw new RuntimeException("phone is not available");
10501 }
10502 // Now that all security checks passes, perform the operation as ourselves.
10503 final long identity = Binder.clearCallingIdentity();
10504 try {
10505 return phone.getEquivalentHomePlmns();
10506 } finally {
10507 Binder.restoreCallingIdentity(identity);
10508 }
10509 }
Daniel Bright59e67312020-11-13 11:49:37 -080010510
10511 @Override
10512 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010513 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10514 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010515 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010516 if (radioInterfaceCapabilities == null) {
10517 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010518 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010519 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010520 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010521
Hui Wang641e81c2020-10-12 12:14:23 -070010522 @Override
10523 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10524 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010525 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10526 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10527 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10528 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10529 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010530 if (DBG) {
10531 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10532 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10533 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10534 }
10535
10536 if (!SubscriptionManager.isValidSubscriptionId(subId)
10537 || appType < TelephonyManager.APPTYPE_UNKNOWN
10538 || appType > TelephonyManager.APPTYPE_ISIM
10539 || nafUrl == null || securityProtocol == null || callback == null) {
10540 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10541 if (callback != null) {
10542 try {
10543 callback.onAuthenticationFailure(
10544 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10545 } catch (RemoteException exception) {
10546 log("Fail to notify onAuthenticationFailure due to " + exception);
10547 }
10548 return;
10549 }
10550 }
10551
10552 final long token = Binder.clearCallingIdentity();
10553 try {
10554 getGbaManager(subId).bootstrapAuthenticationRequest(
10555 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010556 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010557 } finally {
10558 Binder.restoreCallingIdentity(token);
10559 }
10560 }
10561
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010562 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010563 * Attempts to set the radio power state for all phones for thermal reason.
10564 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010565 * requested radio power state will actually be set. See {@link
10566 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10567 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010568 * @param enable {@code true} if trying to turn radio on.
10569 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10570 * false}.
10571 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010572 private boolean setRadioPowerForThermal(boolean enable) {
10573 boolean isPhoneAvailable = false;
10574 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10575 Phone phone = PhoneFactory.getPhone(i);
10576 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010577 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010578 isPhoneAvailable = true;
10579 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010580 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010581
10582 // return true if successfully informed the phone object about the thermal radio power
10583 // request.
10584 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010585 }
10586
10587 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010588 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010589 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10590 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10591 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10592 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10593 throw new IllegalArgumentException("modem does not support data throttling");
10594 }
10595
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010596 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10597 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010598 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010599 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10600 }
10601
Sarah Chinecc78c42022-03-31 21:16:48 -070010602 setDataEnabledForReason(
10603 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010604
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010605 if (isDataThrottlingSupported) {
10606 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010607 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010608 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10609 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10610 } else if (thermalMitigationResult
10611 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010612 log("Modem likely does not support data throttling on secondary carrier. Data " +
10613 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10614 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010615 }
10616 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010617 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010618
10619 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010620 }
10621
Jack Nudelman644b91a2021-03-12 14:09:48 -080010622 private static List<String> getThermalMitigationAllowlist(Context context) {
10623 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10624 for (String pckg : context.getResources()
10625 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10626 sThermalMitigationAllowlistedPackages.add(pckg);
10627 }
10628 }
10629
10630 return sThermalMitigationAllowlistedPackages;
10631 }
10632
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010633 private boolean isAnyPhoneInEmergencyState() {
10634 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10635 if (tm.isInEmergencyCall()) {
10636 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10637 return true;
10638 }
10639 for (Phone phone : PhoneFactory.getPhones()) {
10640 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10641 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010642 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10643 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010644 return true;
10645 }
10646 }
10647
10648 return false;
10649 }
10650
Jack Nudelman644b91a2021-03-12 14:09:48 -080010651 /**
10652 * Used by shell commands to add an authorized package name for thermal mitigation.
10653 * @param packageName name of package to be allowlisted
10654 * @param context
10655 */
10656 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10657 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10658 sThermalMitigationAllowlistedPackages.add(packageName);
10659 }
10660
10661 /**
10662 * Used by shell commands to remove an authorized package name for thermal mitigation.
10663 * @param packageName name of package to remove from allowlist
10664 * @param context
10665 */
10666 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10667 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10668 sThermalMitigationAllowlistedPackages.remove(packageName);
10669 }
10670
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010671 /**
10672 * Thermal mitigation request to control functionalities at modem.
10673 *
10674 * @param subId the id of the subscription.
10675 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010676 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010677 *
10678 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10679 */
10680 @Override
10681 @ThermalMitigationResult
10682 public int sendThermalMitigationRequest(
10683 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010684 ThermalMitigationRequest thermalMitigationRequest,
10685 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010686 enforceModifyPermission();
10687
Jack Nudelman644b91a2021-03-12 14:09:48 -080010688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10689 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10690 .contains(callingPackage)) {
10691 throw new SecurityException("Calling package must be configured in the device config. "
10692 + "calling package: " + callingPackage);
10693 }
10694
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010695 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10696 final long identity = Binder.clearCallingIdentity();
10697
10698 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10699 try {
10700 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10701 switch (thermalMitigationAction) {
10702 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10703 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010704 handleDataThrottlingRequest(subId,
10705 thermalMitigationRequest.getDataThrottlingRequest(),
10706 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010707 break;
10708 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10709 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10710 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10711 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10712 }
10713
10714 // Ensure that radio is on. If not able to power on due to phone being
10715 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010716 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010717 thermalMitigationResult =
10718 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10719 break;
10720 }
10721
10722 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010723 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010724 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10725 break;
10726 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10727 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10728 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10729 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10730 }
10731
10732 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10733 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010734 Phone phone = getPhone(subId);
10735 if (phone == null) {
10736 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010737 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010738 break;
10739 }
10740
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010741 TelephonyConnectionService service =
10742 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010743 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010744 Log.e(LOG_TAG, "An emergency call is pending");
10745 thermalMitigationResult =
10746 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10747 break;
10748 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010749 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010750 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010751 break;
10752 }
10753 } else {
10754 thermalMitigationResult =
10755 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10756 break;
10757 }
10758
10759 // Turn radio off. If not able to power off due to phone being unavailable,
10760 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010761 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010762 thermalMitigationResult =
10763 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10764 break;
10765 }
10766 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010767 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010768 break;
10769 default:
10770 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10771 + "not exist. Requested action: " + thermalMitigationAction);
10772 }
10773 } catch (IllegalArgumentException e) {
10774 throw e;
10775 } catch (Exception e) {
10776 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10777 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10778 } finally {
10779 Binder.restoreCallingIdentity(identity);
10780 }
10781
10782 if (DBG) {
10783 log("thermalMitigationRequest returning with thermalMitigationResult: "
10784 + thermalMitigationResult);
10785 }
10786
10787 return thermalMitigationResult;
10788 }
Hui Wang641e81c2020-10-12 12:14:23 -070010789
10790 /**
10791 * Set the GbaService Package Name that Telephony will bind to.
10792 *
10793 * @param subId The sim that the GbaService is associated with.
10794 * @param packageName The name of the package to be replaced with.
10795 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10796 */
10797 @Override
10798 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10799 enforceModifyPermission();
10800
10801 final long identity = Binder.clearCallingIdentity();
10802 try {
10803 return getGbaManager(subId).overrideServicePackage(packageName);
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
10808
10809 /**
10810 * Return the package name of the currently bound GbaService.
10811 *
10812 * @param subId The sim that the GbaService is associated with.
10813 * @return the package name of the GbaService configuration, null if GBA is not supported.
10814 */
10815 @Override
10816 public String getBoundGbaService(int subId) {
10817 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10818
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 return getGbaManager(subId).getServicePackage();
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
10827 /**
10828 * Set the release time for telephony to unbind GbaService.
10829 *
10830 * @param subId The sim that the GbaService is associated with.
10831 * @param interval The release time to unbind GbaService by millisecond.
10832 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10833 */
10834 @Override
10835 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10836 enforceModifyPermission();
10837
10838 final long identity = Binder.clearCallingIdentity();
10839 try {
10840 return getGbaManager(subId).overrideReleaseTime(interval);
10841 } finally {
10842 Binder.restoreCallingIdentity(identity);
10843 }
10844 }
10845
10846 /**
10847 * Return the release time for telephony to unbind GbaService.
10848 *
10849 * @param subId The sim that the GbaService is associated with.
10850 * @return The release time to unbind GbaService by millisecond.
10851 */
10852 @Override
10853 public int getGbaReleaseTime(int subId) {
10854 enforceReadPrivilegedPermission("getGbaReleaseTime");
10855
10856 final long identity = Binder.clearCallingIdentity();
10857 try {
10858 return getGbaManager(subId).getReleaseTime();
10859 } finally {
10860 Binder.restoreCallingIdentity(identity);
10861 }
10862 }
10863
10864 private GbaManager getGbaManager(int subId) {
10865 GbaManager instance = GbaManager.getInstance(subId);
10866 if (instance == null) {
10867 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10868 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10869 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10870 }
10871 return instance;
10872 }
Hui Wang761a6682020-10-31 05:12:53 +000010873
10874 /**
10875 * indicate whether the device and the carrier can support
10876 * RCS VoLTE single registration.
10877 */
10878 @Override
10879 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010880 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10881 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10882 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10883 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010884
10885 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10886 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10887 }
10888
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10892 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010893 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10894 if (isCapable != null) {
10895 return isCapable;
10896 }
Hui Wang761a6682020-10-31 05:12:53 +000010897 }
Hui Wang67af90e2021-06-04 16:57:15 -070010898 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10899 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010900 } finally {
10901 Binder.restoreCallingIdentity(identity);
10902 }
10903 }
10904
10905 /**
10906 * Register RCS provisioning callback.
10907 */
10908 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010909 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010910 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010911 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010912 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010913 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10914 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010915
10916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10917 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10918 }
10919 if (!isImsAvailableOnDevice()) {
10920 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10921 "IMS not available on device.");
10922 }
10923
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010926 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010927 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010928 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10929 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010930 }
Hui Wang761a6682020-10-31 05:12:53 +000010931 } finally {
10932 Binder.restoreCallingIdentity(identity);
10933 }
10934 }
10935
10936 /**
10937 * Unregister RCS provisioning callback.
10938 */
10939 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010940 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010941 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010942 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010943 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010944 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10945 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010946
10947 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10948 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10949 }
10950 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010951 // operation failed silently
10952 Rlog.w(LOG_TAG, "IMS not available on device.");
10953 return;
Hui Wang761a6682020-10-31 05:12:53 +000010954 }
10955
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010958 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010959 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010960 } finally {
10961 Binder.restoreCallingIdentity(identity);
10962 }
10963 }
10964
10965 /**
10966 * trigger RCS reconfiguration.
10967 */
10968 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010969 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10970 "triggerRcsReconfiguration",
10971 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010972
10973 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10974 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10975 }
10976 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010977 // ProvisioningManager can not handle ServiceSpecificException.
10978 // Throw the IllegalStateException and annotate ProvisioningManager.
10979 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010980 }
10981
10982 final long identity = Binder.clearCallingIdentity();
10983 try {
10984 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10985 } finally {
10986 Binder.restoreCallingIdentity(identity);
10987 }
10988 }
10989
10990 /**
10991 * Provide the client configuration parameters of the RCS application.
10992 */
10993 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010994 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10995 "setRcsClientConfiguration",
10996 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010997
10998 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10999 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11000 }
11001 if (!isImsAvailableOnDevice()) {
11002 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11003 "IMS not available on device.");
11004 }
11005
11006 final long identity = Binder.clearCallingIdentity();
11007
11008 try {
11009 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11010 if (configBinder == null) {
11011 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011012 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11013 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011014 } else {
11015 configBinder.setRcsClientConfiguration(rcc);
11016 }
joonhunshin3e154242021-09-17 06:33:39 +000011017
11018 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11019 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011020 } catch (RemoteException e) {
11021 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011022 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11023 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011024 } finally {
11025 Binder.restoreCallingIdentity(identity);
11026 }
11027 }
11028
11029 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011030 * Enables or disables the test mode for RCS VoLTE single registration.
11031 */
11032 @Override
11033 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11034 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11035 "setRcsSingleRegistrationTestModeEnabled");
11036
11037 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11038 }
11039
11040 /**
11041 * Gets the test mode for RCS VoLTE single registration.
11042 */
11043 @Override
11044 public boolean getRcsSingleRegistrationTestModeEnabled() {
11045 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11046 "getRcsSingleRegistrationTestModeEnabled");
11047
11048 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11049 }
11050
11051 /**
Hui Wang761a6682020-10-31 05:12:53 +000011052 * Overrides the config of RCS VoLTE single registration enabled for the device.
11053 */
11054 @Override
11055 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11057 "setDeviceSingleRegistrationEnabledOverride");
11058 enforceModifyPermission();
11059
11060 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11061 : Boolean.parseBoolean(enabledStr);
11062 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011063 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011064 }
11065
11066 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011067 * Sends a device to device communication message. Only usable via shell.
11068 * @param message message to send.
11069 * @param value message value.
11070 */
11071 @Override
11072 public void sendDeviceToDeviceMessage(int message, int value) {
11073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011074 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011075 enforceModifyPermission();
11076
11077 final long identity = Binder.clearCallingIdentity();
11078 try {
11079 TelephonyConnectionService service =
11080 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11081 if (service == null) {
11082 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11083 return;
11084 }
11085 service.sendTestDeviceToDeviceMessage(message, value);
11086 } finally {
11087 Binder.restoreCallingIdentity(identity);
11088 }
11089 }
11090
Tyler Gunnbabbda02021-02-10 11:05:02 -080011091 /**
11092 * Sets the specified device to device transport active.
11093 * @param transport The transport to set active.
11094 */
11095 @Override
11096 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11098 "setActiveDeviceToDeviceTransport");
11099 enforceModifyPermission();
11100
11101 final long identity = Binder.clearCallingIdentity();
11102 try {
11103 TelephonyConnectionService service =
11104 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11105 if (service == null) {
11106 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11107 return;
11108 }
11109 service.setActiveDeviceToDeviceTransport(transport);
11110 } finally {
11111 Binder.restoreCallingIdentity(identity);
11112 }
11113 }
Tyler Gunn92479152021-01-20 16:30:10 -080011114
Tyler Gunnd4339262021-05-03 14:46:49 -070011115 @Override
11116 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11118 "setDeviceToDeviceForceEnabled");
11119
11120 final long identity = Binder.clearCallingIdentity();
11121 try {
11122 Arrays.stream(PhoneFactory.getPhones()).forEach(
11123 p -> {
11124 Phone thePhone = p.getImsPhone();
11125 if (thePhone != null && thePhone instanceof ImsPhone) {
11126 ImsPhone imsPhone = (ImsPhone) thePhone;
11127 CallTracker tracker = imsPhone.getCallTracker();
11128 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11129 ImsPhoneCallTracker imsPhoneCallTracker =
11130 (ImsPhoneCallTracker) tracker;
11131 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11132 }
11133 }
11134 }
11135 );
11136 } finally {
11137 Binder.restoreCallingIdentity(identity);
11138 }
11139 }
11140
Tyler Gunn92479152021-01-20 16:30:10 -080011141 /**
Hui Wang761a6682020-10-31 05:12:53 +000011142 * Gets the config of RCS VoLTE single registration enabled for the device.
11143 */
11144 @Override
11145 public boolean getDeviceSingleRegistrationEnabled() {
11146 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11147 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11148 }
11149
11150 /**
11151 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11152 */
11153 @Override
11154 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11156 "setCarrierSingleRegistrationEnabledOverride");
11157 enforceModifyPermission();
11158
11159 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11160 : Boolean.parseBoolean(enabledStr);
11161 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11162 subId, enabled);
11163 }
11164
11165 /**
11166 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11167 */
11168 @Override
11169 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11170 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11171 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11172 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011173
11174 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011175 * Overrides the ims feature validation result
11176 */
11177 @Override
11178 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11180 "setImsFeatureValidationOverride");
11181
11182 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11183 : Boolean.parseBoolean(enabledStr);
11184 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11185 subId, enabled);
11186 }
11187
11188 /**
11189 * Gets the ims feature validation override value
11190 */
11191 @Override
11192 public boolean getImsFeatureValidationOverride(int subId) {
11193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11194 "getImsFeatureValidationOverride");
11195 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11196 }
11197
11198 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011199 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11200 * their mobile plan.
11201 */
11202 @Override
11203 public String getMobileProvisioningUrl() {
11204 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11205 final long identity = Binder.clearCallingIdentity();
11206 try {
11207 return getDefaultPhone().getMobileProvisioningUrl();
11208 } finally {
11209 Binder.restoreCallingIdentity(identity);
11210 }
11211 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011212
James.cf Linbcdf8b32021-01-14 16:44:13 +080011213 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011214 * Get the EAB contact from the EAB database.
11215 */
11216 @Override
11217 public String getContactFromEab(String contact) {
11218 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11219 enforceModifyPermission();
11220 final long identity = Binder.clearCallingIdentity();
11221 try {
11222 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11223 } finally {
11224 Binder.restoreCallingIdentity(identity);
11225 }
11226 }
11227
11228 /**
Calvin Pana1434322021-07-01 19:27:01 +080011229 * Get the EAB capability from the EAB database.
11230 */
11231 @Override
11232 public String getCapabilityFromEab(String contact) {
11233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11234 enforceModifyPermission();
11235 final long identity = Binder.clearCallingIdentity();
11236 try {
11237 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11238 } finally {
11239 Binder.restoreCallingIdentity(identity);
11240 }
11241 }
11242
11243 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011244 * Remove the EAB contacts from the EAB database.
11245 */
11246 @Override
11247 public int removeContactFromEab(int subId, String contacts) {
11248 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11249 enforceModifyPermission();
11250 final long identity = Binder.clearCallingIdentity();
11251 try {
11252 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11253 } finally {
11254 Binder.restoreCallingIdentity(identity);
11255 }
11256 }
11257
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011258 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011259 public boolean getDeviceUceEnabled() {
11260 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11261 final long identity = Binder.clearCallingIdentity();
11262 try {
11263 return mApp.getDeviceUceEnabled();
11264 } finally {
11265 Binder.restoreCallingIdentity(identity);
11266 }
11267 }
11268
11269 @Override
11270 public void setDeviceUceEnabled(boolean isEnabled) {
11271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11272 final long identity = Binder.clearCallingIdentity();
11273 try {
11274 mApp.setDeviceUceEnabled(isEnabled);
11275 } finally {
11276 Binder.restoreCallingIdentity(identity);
11277 }
11278 }
11279
Brad Ebinger14d467f2021-02-12 06:18:28 +000011280 /**
11281 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11282 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11283 */
11284 // Used for SHELL command only right now.
11285 @Override
11286 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11287 List<String> featureTags) {
11288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11289 "addUceRegistrationOverrideShell");
11290 final long identity = Binder.clearCallingIdentity();
11291 try {
11292 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11293 new ArraySet<>(featureTags));
11294 } catch (ImsException e) {
11295 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11296 } finally {
11297 Binder.restoreCallingIdentity(identity);
11298 }
11299 }
11300
11301 /**
11302 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11303 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11304 */
11305 // Used for SHELL command only right now.
11306 @Override
11307 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11308 List<String> featureTags) {
11309 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11310 "removeUceRegistrationOverrideShell");
11311 final long identity = Binder.clearCallingIdentity();
11312 try {
11313 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11314 new ArraySet<>(featureTags));
11315 } catch (ImsException e) {
11316 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11317 } finally {
11318 Binder.restoreCallingIdentity(identity);
11319 }
11320 }
11321
11322 /**
11323 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11324 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11325 */
11326 // Used for SHELL command only right now.
11327 @Override
11328 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11329 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11330 "clearUceRegistrationOverrideShell");
11331 final long identity = Binder.clearCallingIdentity();
11332 try {
11333 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11334 } catch (ImsException e) {
11335 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11336 } finally {
11337 Binder.restoreCallingIdentity(identity);
11338 }
11339 }
11340
11341 /**
11342 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11343 */
11344 // Used for SHELL command only right now.
11345 @Override
11346 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11348 "getLatestRcsContactUceCapabilityShell");
11349 final long identity = Binder.clearCallingIdentity();
11350 try {
11351 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11352 } catch (ImsException e) {
11353 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11354 } finally {
11355 Binder.restoreCallingIdentity(identity);
11356 }
11357 }
11358
11359 /**
11360 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11361 * device does not have an active PUBLISH.
11362 */
11363 // Used for SHELL command only right now.
11364 @Override
11365 public String getLastUcePidfXmlShell(int subId) {
11366 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11367 final long identity = Binder.clearCallingIdentity();
11368 try {
11369 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11370 } catch (ImsException e) {
11371 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11372 } finally {
11373 Binder.restoreCallingIdentity(identity);
11374 }
11375 }
11376
James.cf Line8713a42021-04-29 16:04:26 +080011377 /**
11378 * Remove UCE requests cannot be sent to the network status.
11379 */
11380 // Used for SHELL command only right now.
11381 @Override
11382 public boolean removeUceRequestDisallowedStatus(int subId) {
11383 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11384 final long identity = Binder.clearCallingIdentity();
11385 try {
11386 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11387 } catch (ImsException e) {
11388 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11389 } finally {
11390 Binder.restoreCallingIdentity(identity);
11391 }
11392 }
11393
James.cf Lin18bb9002021-05-25 01:37:38 +080011394 /**
11395 * Remove UCE requests cannot be sent to the network status.
11396 */
11397 // Used for SHELL command only.
11398 @Override
11399 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11400 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11401 final long identity = Binder.clearCallingIdentity();
11402 try {
11403 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11404 } catch (ImsException e) {
11405 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11406 } finally {
11407 Binder.restoreCallingIdentity(identity);
11408 }
11409 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011410
James.cf Lin4b784aa2021-01-31 03:25:15 +080011411 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011412 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11413 String callingPackage) {
11414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11415 mApp, subId, "setSignalStrengthUpdateRequest");
11416
11417 final int callingUid = Binder.getCallingUid();
11418 // Verify that tha callingPackage belongs to the calling UID
11419 mApp.getSystemService(AppOpsManager.class)
11420 .checkPackage(callingUid, callingPackage);
11421
Rambo Wang3607f502021-02-01 21:51:40 -080011422 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011423
11424 final long identity = Binder.clearCallingIdentity();
11425 try {
11426 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11427 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11428
11429 if (result instanceof IllegalStateException) {
11430 throw (IllegalStateException) result;
11431 }
11432 } finally {
11433 Binder.restoreCallingIdentity(identity);
11434 }
11435 }
11436
11437 @Override
11438 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11439 String callingPackage) {
11440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11441 mApp, subId, "clearSignalStrengthUpdateRequest");
11442
11443 final int callingUid = Binder.getCallingUid();
11444 // Verify that tha callingPackage belongs to the calling UID
11445 mApp.getSystemService(AppOpsManager.class)
11446 .checkPackage(callingUid, callingPackage);
11447
11448 final long identity = Binder.clearCallingIdentity();
11449 try {
11450 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11451 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11452
11453 if (result instanceof IllegalStateException) {
11454 throw (IllegalStateException) result;
11455 }
11456 } finally {
11457 Binder.restoreCallingIdentity(identity);
11458 }
11459 }
11460
Rambo Wang3607f502021-02-01 21:51:40 -080011461 private static void validateSignalStrengthUpdateRequest(Context context,
11462 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011463 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11464 // phone/system process do not have further restriction on request
11465 return;
11466 }
11467
11468 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011469 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011470 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011471 context.enforceCallingOrSelfPermission(
11472 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11473 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011474 }
11475
11476 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011477 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011478 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011479 || info.isEnabled()) {
11480 throw new IllegalArgumentException(
11481 "Only system can set hide fields in SignalThresholdInfo");
11482 }
11483
11484 // Thresholds length for each RAN need in range. This has been validated in
11485 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11486 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11487 final int[] thresholds = info.getThresholds();
11488 Objects.requireNonNull(thresholds);
11489 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11490 || thresholds.length
11491 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11492 throw new IllegalArgumentException(
11493 "thresholds length is out of range: " + thresholds.length);
11494 }
11495 }
11496 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011497
11498 /**
11499 * Gets the current phone capability.
11500 *
11501 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11502 * @return the PhoneCapability which describes the data connection capability of modem.
11503 * It's used to evaluate possible phone config change, for example from single
11504 * SIM device to multi-SIM device.
11505 */
11506 @Override
11507 public PhoneCapability getPhoneCapability() {
11508 enforceReadPrivilegedPermission("getPhoneCapability");
11509 final long identity = Binder.clearCallingIdentity();
11510 try {
11511 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11512 } finally {
11513 Binder.restoreCallingIdentity(identity);
11514 }
11515 }
Michele Berionne5e411512020-11-13 02:36:59 +000011516
11517 /**
11518 * Prepare TelephonyManager for an unattended reboot. The reboot is
11519 * required to be done shortly after the API is invoked.
11520 */
11521 @Override
11522 @TelephonyManager.PrepareUnattendedRebootResult
11523 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011524 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011525 enforceRebootPermission();
11526
11527 final long identity = Binder.clearCallingIdentity();
11528 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011529 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011530 } finally {
11531 Binder.restoreCallingIdentity(identity);
11532 }
11533 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011534
11535 /**
11536 * Request to get the current slicing configuration including URSP rules and
11537 * NSSAIs (configured, allowed and rejected).
11538 *
11539 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11540 */
11541 @Override
11542 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011543 TelephonyPermissions
11544 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11545 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011546
11547 final long identity = Binder.clearCallingIdentity();
11548 try {
11549 Phone phone = getDefaultPhone();
11550 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11551 } finally {
11552 Binder.restoreCallingIdentity(identity);
11553 }
11554 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011555
11556 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011557 * Check whether the given premium capability is available for purchase from the carrier.
11558 *
11559 * @param capability The premium capability to check.
11560 * @param subId The subId to check the premium capability for.
11561 *
11562 * @return Whether the given premium capability is available to purchase.
11563 */
11564 @Override
11565 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11566 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11567 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11568 log("Premium capability "
11569 + TelephonyManager.convertPremiumCapabilityToString(capability)
11570 + " is not available for purchase due to missing permissions.");
11571 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11572 + "permission READ_BASIC_PHONE_STATE.");
11573 }
11574
11575 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011576 if (phone == null) {
11577 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11578 return false;
11579 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011580 final long identity = Binder.clearCallingIdentity();
11581 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011582 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011583 .isPremiumCapabilityAvailableForPurchase(capability);
11584 } finally {
11585 Binder.restoreCallingIdentity(identity);
11586 }
11587 }
11588
11589 /**
11590 * Purchase the given premium capability from the carrier.
11591 *
11592 * @param capability The premium capability to purchase.
11593 * @param callback The result of the purchase request.
11594 * @param subId The subId to purchase the premium capability for.
11595 */
11596 @Override
11597 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11598 log("purchasePremiumCapability: capability="
11599 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11600 + getCurrentPackageName());
11601
11602 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11603 mApp, "purchasePremiumCapability")) {
11604 log("purchasePremiumCapability "
11605 + TelephonyManager.convertPremiumCapabilityToString(capability)
11606 + " failed due to missing permissions.");
11607 throw new SecurityException("purchasePremiumCapability requires permission "
11608 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011609 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11610 mApp, "purchasePremiumCapability")) {
11611 log("purchasePremiumCapability "
11612 + TelephonyManager.convertPremiumCapabilityToString(capability)
11613 + " failed due to missing permissions.");
11614 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011615 }
11616
11617 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011618 if (phone == null) {
11619 try {
11620 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11621 callback.accept(result);
11622 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11623 } catch (RemoteException e) {
11624 String logStr = "Purchase premium capability "
11625 + TelephonyManager.convertPremiumCapabilityToString(capability)
11626 + " failed due to RemoteException handling null phone: " + e;
11627 if (DBG) log(logStr);
11628 AnomalyReporter.reportAnomaly(
11629 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11630 }
11631 return;
11632 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011633
11634 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011635 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011636 callingProcess = mApp.getPackageManager().getApplicationInfo(
11637 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011638 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011639 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011640 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011641
11642 boolean isVisible = false;
11643 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11644 if (am != null) {
11645 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11646 if (processes != null) {
11647 for (ActivityManager.RunningAppProcessInfo process : processes) {
11648 log("purchasePremiumCapability: process " + process.processName
11649 + "has importance " + process.importance);
11650 if (process.processName.equals(callingProcess) && process.importance
11651 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11652 isVisible = true;
11653 break;
11654 }
11655 }
11656 }
11657 }
11658
11659 if (!isVisible) {
11660 try {
11661 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11662 callback.accept(result);
11663 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11664 } catch (RemoteException e) {
11665 String logStr = "Purchase premium capability "
11666 + TelephonyManager.convertPremiumCapabilityToString(capability)
11667 + " failed due to RemoteException handling background application: " + e;
11668 if (DBG) log(logStr);
11669 AnomalyReporter.reportAnomaly(
11670 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11671 }
11672 return;
11673 }
11674
Sarah Chin71b3a852022-09-28 15:54:19 -070011675 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011676 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011677 }
11678
11679 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011680 * Register an IMS connection state callback
11681 */
11682 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011683 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11684 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011685 if (feature == ImsFeature.FEATURE_MMTEL) {
11686 // ImsMmTelManager
11687 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11688 TelephonyPermissions
11689 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11690 mApp, subId, "registerImsStateCallback");
11691 } else if (feature == ImsFeature.FEATURE_RCS) {
11692 // ImsRcsManager or SipDelegateManager
11693 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11694 Binder.getCallingUid(), "registerImsStateCallback",
11695 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11696 Manifest.permission.READ_PRECISE_PHONE_STATE,
11697 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11698 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11699 }
11700
11701 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11702 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11703 "IMS not available on device.");
11704 }
11705
11706 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11707 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11708 }
11709
11710 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11711 if (controller == null) {
11712 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11713 "IMS not available on device.");
11714 }
11715
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011716 if (callingPackage == null) {
11717 callingPackage = getCurrentPackageName();
11718 }
11719
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011720 final long token = Binder.clearCallingIdentity();
11721 try {
11722 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011723 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011724 } catch (ImsException e) {
11725 throw new ServiceSpecificException(e.getCode());
11726 } finally {
11727 Binder.restoreCallingIdentity(token);
11728 }
11729 }
11730
11731 /**
11732 * Unregister an IMS connection state callback
11733 */
11734 @Override
11735 public void unregisterImsStateCallback(IImsStateCallback cb) {
11736 final long token = Binder.clearCallingIdentity();
11737 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11738 if (controller == null) {
11739 return;
11740 }
11741 try {
11742 controller.unregisterImsStateCallback(cb);
11743 } finally {
11744 Binder.restoreCallingIdentity(token);
11745 }
11746 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011747
11748 /**
11749 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11750 *
11751 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11752 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11753 * SecurityException.
11754 * If there is current registered network this value will be same as the registered cell
11755 * identity. If the device goes out of service the previous cell identity is cached and
11756 * will be returned. If the cache age of the Cell identity is more than 24 hours
11757 * it will be cleared and null will be returned.
11758 *
11759 */
11760 @Override
11761 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11762 String callingFeatureId) {
11763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11764 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11765 LocationAccessPolicy.checkLocationPermission(mApp,
11766 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11767 .setCallingPackage(callingPackage)
11768 .setCallingFeatureId(callingFeatureId)
11769 .setCallingPid(Binder.getCallingPid())
11770 .setCallingUid(Binder.getCallingUid())
11771 .setMethod("getLastKnownCellIdentity")
11772 .setLogAsInfo(true)
11773 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11774 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11775 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11776 .build());
11777
11778 boolean hasFinePermission =
11779 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11780 if (!hasFinePermission
11781 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11782 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011783 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011784 }
11785
11786 final long identity = Binder.clearCallingIdentity();
11787 try {
Ling Mac28f0212023-03-24 16:07:15 -070011788 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011789 if (sst == null) return null;
11790 return sst.getLastKnownCellIdentity();
11791 } finally {
11792 Binder.restoreCallingIdentity(identity);
11793 }
11794 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011795
jimsun3b9ccac2021-10-26 15:01:23 +080011796 /**
11797 * Sets the modem service class Name that Telephony will bind to.
11798 *
11799 * @param serviceName The class name of the modem service.
11800 * @return true if the operation is succeed, otherwise false.
11801 */
11802 public boolean setModemService(String serviceName) {
11803 Log.d(LOG_TAG, "setModemService - " + serviceName);
11804 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011806 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11807 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011808 return mPhoneConfigurationManager.setModemService(serviceName);
11809 }
11810
11811 /**
11812 * Return the class name of the currently bounded modem service.
11813 *
11814 * @return the class name of the modem service.
11815 */
11816 public String getModemService() {
11817 String result;
11818 Log.d(LOG_TAG, "getModemService");
11819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11820 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011821 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011822 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11823 "getModemService");
11824 result = mPhoneConfigurationManager.getModemService();
11825 Log.d(LOG_TAG, "result = " + result);
11826 return result;
11827 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011828
11829 @Override
11830 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11831 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11832 mApp.enforceCallingOrSelfPermission(
11833 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11834 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11835
11836 final long identity = Binder.clearCallingIdentity();
11837 try {
11838 Phone phone = getPhone(subId);
11839 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011840 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11841 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011842 phone.setVoiceServiceStateOverride(hasService);
11843 } finally {
11844 Binder.restoreCallingIdentity(identity);
11845 }
11846 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011847
11848 /**
11849 * set removable eSIM as default eUICC.
11850 *
11851 * @hide
11852 */
11853 @Override
11854 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11855 enforceModifyPermission();
11856 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11857
11858 final long identity = Binder.clearCallingIdentity();
11859 try {
11860 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11861 } finally {
11862 Binder.restoreCallingIdentity(identity);
11863 }
11864 }
11865
11866 /**
11867 * Returns whether the removable eSIM is default eUICC or not.
11868 *
11869 * @hide
11870 */
11871 @Override
11872 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11873 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11875
11876 final long identity = Binder.clearCallingIdentity();
11877 try {
11878 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11879 } finally {
11880 Binder.restoreCallingIdentity(identity);
11881 }
11882 }
11883
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011884 /**
11885 * Get the component name of the default app to direct respond-via-message intent for the
11886 * user associated with this subscription, update the cache if there is no respond-via-message
11887 * application currently configured for this user.
11888 * @return component name of the app and class to direct Respond Via Message intent to, or
11889 * {@code null} if the functionality is not supported.
11890 * @hide
11891 */
11892 @Override
11893 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11894 boolean updateIfNeeded) {
11895 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011896
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011897 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11898
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011899 UserHandle userHandle = null;
11900 final long identity = Binder.clearCallingIdentity();
11901 try {
11902 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11903 } finally {
11904 Binder.restoreCallingIdentity(identity);
11905 }
11906 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11907 updateIfNeeded, userHandle);
11908 }
Jack Yuf5badd92022-12-08 00:50:53 -080011909
11910 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011911 * Set whether the device is able to connect with null ciphering or integrity
11912 * algorithms. This is a global setting and will apply to all active subscriptions
11913 * and all new subscriptions after this.
11914 *
11915 * @param enabled when true, null cipher and integrity algorithms are allowed.
11916 * @hide
11917 */
11918 @Override
11919 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11920 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11921 enforceModifyPermission();
11922 checkForNullCipherAndIntegritySupport();
11923
11924 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11925 // for listening to these preference changes and applying them immediately.
11926 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11927 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11928 editor.apply();
11929
11930 for (Phone phone: PhoneFactory.getPhones()) {
11931 phone.handleNullCipherEnabledChange();
11932 }
11933 }
11934
11935
11936 /**
11937 * Get whether the device is able to connect with null ciphering or integrity
11938 * algorithms. Note that this retrieves the phone-global preference and not
11939 * the state of the radio.
11940 *
11941 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11942 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11943 * version for this feature.
11944 * @hide
11945 */
11946 @Override
11947 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11948 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11949 enforceReadPermission();
11950 checkForNullCipherAndIntegritySupport();
11951 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11952 }
11953
11954 private void checkForNullCipherAndIntegritySupport() {
11955 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11956 throw new UnsupportedOperationException(
11957 "Null cipher and integrity operations require HAL 2.1 or above");
11958 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011959 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11960 throw new UnsupportedOperationException(
11961 "Null cipher and integrity operations unsupported by modem");
11962 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011963 }
11964
11965 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011966 * Get the SIM state for the slot index.
11967 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11968 *
11969 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11970 */
11971 @Override
11972 @SimState
11973 public int getSimStateForSlotIndex(int slotIndex) {
11974 IccCardConstants.State simState;
11975 if (slotIndex < 0) {
11976 simState = IccCardConstants.State.UNKNOWN;
11977 } else {
11978 Phone phone = null;
11979 try {
11980 phone = PhoneFactory.getPhone(slotIndex);
11981 } catch (IllegalStateException e) {
11982 // ignore
11983 }
11984 if (phone == null) {
11985 simState = IccCardConstants.State.UNKNOWN;
11986 } else {
11987 IccCard icc = phone.getIccCard();
11988 if (icc == null) {
11989 simState = IccCardConstants.State.UNKNOWN;
11990 } else {
11991 simState = icc.getState();
11992 }
11993 }
11994 }
11995 return simState.ordinal();
11996 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011997
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011998 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11999 boolean enableLogcat,
12000 long logcatStartTimestampMillis, boolean enableTelecomDump,
12001 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012002 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12003 TelephonyManager.EmergencyCallDiagnosticParams edp =
12004 new TelephonyManager.EmergencyCallDiagnosticParams();
12005 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12006 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12007 edp.setTelecomDumpSysCollection(enableTelecomDump);
12008 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12009 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12010 Executors.newCachedThreadPool(), db,
12011 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12012 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012013 }
12014
12015 /**
12016 * Request telephony to persist state for debugging emergency call failures.
12017 *
12018 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12019 * @param enableLogcat whether to collect logcat output
12020 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12021 * @param enableTelecomDump whether to collect telecom dumpsys
12022 * @param enableTelephonyDump whether to collect telephony dumpsys
12023 */
12024 @Override
12025 @RequiresPermission(android.Manifest.permission.DUMP)
12026 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12027 long logcatStartTimestampMillis, boolean enableTelecomDump,
12028 boolean enableTelephonyDump) {
12029 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12030 "persistEmergencyCallDiagnosticData");
12031 final long identity = Binder.clearCallingIdentity();
12032 try {
12033 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12034 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12035
12036 } finally {
12037 Binder.restoreCallingIdentity(identity);
12038 }
12039 }
12040
Hui Wang9b5793a2022-12-05 14:38:06 -060012041 /**
12042 * Get current cell broadcast ranges.
12043 */
12044 @Override
12045 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12046 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12047 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12048 "getCellBroadcastIdRanges");
12049 final long identity = Binder.clearCallingIdentity();
12050 try {
12051 return getPhone(subId).getCellBroadcastIdRanges();
12052 } finally {
12053 Binder.restoreCallingIdentity(identity);
12054 }
12055 }
12056
12057 /**
12058 * Set reception of cell broadcast messages with the list of the given ranges
12059 *
12060 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12061 */
12062 @Override
12063 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12064 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12065 @Nullable IIntegerConsumer callback) {
12066 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12067 "setCellBroadcastIdRanges");
12068 final long identity = Binder.clearCallingIdentity();
12069 try {
12070 Phone phone = getPhoneFromSubId(subId);
12071 if (DBG) {
12072 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12073 }
12074 phone.setCellBroadcastIdRanges(ranges, result -> {
12075 if (callback != null) {
12076 try {
12077 callback.accept(result);
12078 } catch (RemoteException e) {
12079 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12080 }
12081 }
12082 });
12083 } finally {
12084 Binder.restoreCallingIdentity(identity);
12085 }
12086 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012087
12088 /**
12089 * Returns whether the device supports the domain selection service.
12090 *
12091 * @return {@code true} if the device supports the domain selection service.
12092 */
12093 @Override
12094 public boolean isDomainSelectionSupported() {
12095 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12096 "isDomainSelectionSupported");
12097
12098 final long identity = Binder.clearCallingIdentity();
12099 try {
12100 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12101 } finally {
12102 Binder.restoreCallingIdentity(identity);
12103 }
12104 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012105
12106 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012107 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12108 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12109 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012110 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012111 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012112 * @param enableSatellite {@code true} to enable the satellite modem and
12113 * {@code false} to disable.
12114 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12115 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012116 *
12117 * @throws SecurityException if the caller doesn't have the required permission.
12118 */
12119 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012120 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12121 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012122 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012123 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12124 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012125 }
12126
12127 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012128 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012129 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012130 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012131 * @param result The result receiver that returns whether the satellite modem is enabled
12132 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012133 *
12134 * @throws SecurityException if the caller doesn't have the required permission.
12135 */
12136 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012137 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12138 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012139 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012140 }
12141
12142 /**
Sarah Chin43457982023-02-15 17:50:38 -080012143 * Request to get whether the satellite service demo mode is enabled.
12144 *
12145 * @param subId The subId of the subscription to check whether the satellite demo mode
12146 * is enabled for.
12147 * @param result The result receiver that returns whether the satellite demo mode is enabled
12148 * if the request is successful or an error code if the request failed.
12149 *
12150 * @throws SecurityException if the caller doesn't have the required permission.
12151 */
12152 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012153 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12154 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12155 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012156 }
12157
12158 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012159 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012160 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012161 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012162 * @param result The result receiver that returns whether the satellite service is supported on
12163 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012164 */
12165 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012166 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012167 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012168 }
12169
12170 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012171 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012172 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012173 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012174 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12175 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012176 *
12177 * @throws SecurityException if the caller doesn't have required permission.
12178 */
12179 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012180 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12181 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012182 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012183 }
12184
12185 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012186 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012187 * This can be called by the pointing UI when the user starts pointing to the satellite.
12188 * Modem should continue to report the pointing input as the device or satellite moves.
12189 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012190 * @param subId The subId of the subscription to start satellite transmission updates for.
12191 * @param resultCallback The callback to get the result of the request.
12192 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012193 *
12194 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012195 */
12196 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012197 public void startSatelliteTransmissionUpdates(int subId,
12198 @NonNull IIntegerConsumer resultCallback,
12199 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12200 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12201 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012202 }
12203
12204 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012205 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012206 * This can be called by the pointing UI when the user stops pointing to the satellite.
12207 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012208 * @param subId The subId of the subscription to stop satellite transmission updates for.
12209 * @param resultCallback The callback to get the result of the request.
12210 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12211 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012212 *
12213 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012214 */
12215 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012216 public void stopSatelliteTransmissionUpdates(int subId,
12217 @NonNull IIntegerConsumer resultCallback,
12218 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12219 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12220 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012221 }
12222
12223 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012224 * Register the subscription with a satellite provider.
12225 * This is needed to register the subscription if the provider allows dynamic registration.
12226 *
12227 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012228 * @param token The token to be used as a unique identifier for provisioning with satellite
12229 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012230 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012231 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012232 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012233 * @return The signal transport used by the caller to cancel the provision request,
12234 * or {@code null} if the request failed.
12235 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012236 * @throws SecurityException if the caller doesn't have the required permission.
12237 */
12238 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012239 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012240 @NonNull String token, @NonNull byte[] provisionData,
12241 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012242 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012243 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12244 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012245 }
12246
12247 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012248 * Unregister the device/subscription with the satellite provider.
12249 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012250 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012251 * should report as deprovisioned.
12252 *
12253 * @param subId The subId of the subscription to be deprovisioned.
12254 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012255 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012256 *
12257 * @throws SecurityException if the caller doesn't have the required permission.
12258 */
12259 @Override
12260 public void deprovisionSatelliteService(int subId,
12261 @NonNull String token, @NonNull IIntegerConsumer callback) {
12262 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012263 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012264 }
12265
12266 /**
Sarah Chin43457982023-02-15 17:50:38 -080012267 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012268 *
Sarah Chin43457982023-02-15 17:50:38 -080012269 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012270 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012271 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012272 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12273 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012274 * @throws SecurityException if the caller doesn't have the required permission.
12275 */
12276 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012277 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012278 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012279 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012280 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012281 }
12282
12283 /**
Sarah Chin43457982023-02-15 17:50:38 -080012284 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012285 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012286 *
Sarah Chin43457982023-02-15 17:50:38 -080012287 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012288 * @param callback The callback that was passed to
12289 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012290 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012291 * @throws SecurityException if the caller doesn't have the required permission.
12292 */
12293 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012294 public void unregisterForSatelliteProvisionStateChanged(
12295 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012296 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012297 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012298 }
12299
12300 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012301 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012302 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012303 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012304 * @param result The result receiver that returns whether the device is provisioned with a
12305 * satellite provider if the request is successful or an error code if the
12306 * request failed.
12307 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012308 * @throws SecurityException if the caller doesn't have the required permission.
12309 */
12310 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012311 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12312 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012313 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012314 }
12315
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012316 /**
Sarah Chin43457982023-02-15 17:50:38 -080012317 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012318 *
Sarah Chin43457982023-02-15 17:50:38 -080012319 * @param subId The subId of the subscription to register for satellite modem state changed.
12320 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012321 *
12322 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12323 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012324 * @throws SecurityException if the caller doesn't have the required permission.
12325 */
12326 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012327 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012328 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012329 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012330 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012331 }
12332
12333 /**
Sarah Chin43457982023-02-15 17:50:38 -080012334 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012335 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012336 *
Sarah Chin43457982023-02-15 17:50:38 -080012337 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012338 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012339 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012340 *
12341 * @throws SecurityException if the caller doesn't have the required permission.
12342 */
12343 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012344 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012345 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012346 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012347 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012348 }
12349
12350 /**
12351 * Register to receive incoming datagrams over satellite.
12352 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012353 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012354 * @param callback The callback to handle incoming datagrams over satellite.
12355 *
12356 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12357 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012358 * @throws SecurityException if the caller doesn't have the required permission.
12359 */
12360 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012361 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012362 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012363 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012364 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012365 }
12366
12367 /**
12368 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012369 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012370 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012371 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12372 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012373 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012374 *
12375 * @throws SecurityException if the caller doesn't have the required permission.
12376 */
12377 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012378 public void unregisterForSatelliteDatagram(int subId,
12379 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012380 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012381 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012382 }
12383
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012384 /**
12385 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012386 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012387 * This method requests modem to check if there are any pending datagrams to be received over
12388 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012389 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012390 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012391 * @param subId The subId of the subscription used for receiving datagrams.
12392 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012393 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012394 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012395 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012396 @Override
12397 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012398 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012399 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012400 }
12401
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012402 /**
12403 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012404 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012405 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12406 * input to this method. Datagram received here will be passed down to modem without any
12407 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012408 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012409 * @param subId The subId of the subscription to send satellite datagrams for.
12410 * @param datagramType datagram type indicating whether the datagram is of type
12411 * SOS_SMS or LOCATION_SHARING.
12412 * @param datagram encoded gateway datagram which is encrypted by the caller.
12413 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012414 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12415 * full screen mode.
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012416 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012417 *
12418 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012419 */
12420 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012421 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12422 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12423 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012424 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012425 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12426 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012427 }
12428
Sarah Chindf715ec2023-02-13 13:46:24 -080012429 /**
12430 * Request to get whether satellite communication is allowed for the current location.
12431 *
12432 * @param subId The subId of the subscription to check whether satellite communication is
12433 * allowed for the current location for.
12434 * @param result The result receiver that returns whether satellite communication is allowed
12435 * for the current location if the request is successful or an error code
12436 * if the request failed.
12437 *
12438 * @throws SecurityException if the caller doesn't have the required permission.
12439 */
12440 @Override
12441 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12442 @NonNull ResultReceiver result) {
12443 enforceSatelliteCommunicationPermission(
12444 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012445 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12446 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012447 }
12448
12449 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080012450 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080012451 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012452 * @param subId The subId to get the time after which the satellite will be visible for.
12453 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012454 * be visible if the request is successful or an error code if the request failed.
12455 *
12456 * @throws SecurityException if the caller doesn't have the required permission.
12457 */
12458 @Override
12459 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12460 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012461 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012462 }
12463
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012464 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012465 * This API can be used by only CTS to update satellite vendor service package name.
12466 *
12467 * @param servicePackageName The package name of the satellite vendor service.
12468 * @return {@code true} if the satellite vendor service is set successfully,
12469 * {@code false} otherwise.
12470 */
12471 public boolean setSatelliteServicePackageName(String servicePackageName) {
12472 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12473 TelephonyPermissions.enforceShellOnly(
12474 Binder.getCallingUid(), "setSatelliteServicePackageName");
12475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12476 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12477 "setSatelliteServicePackageName");
12478 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12479 }
12480
12481 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012482 * This API can be used by only CTS to update satellite gateway service package name.
12483 *
12484 * @param servicePackageName The package name of the satellite gateway service.
12485 * @return {@code true} if the satellite gateway service is set successfully,
12486 * {@code false} otherwise.
12487 */
12488 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12489 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12490 TelephonyPermissions.enforceShellOnly(
12491 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12493 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12494 "setSatelliteGatewayServicePackageName");
12495 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12496 }
12497
12498 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012499 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12500 *
12501 * @param packageName The package name of the satellite pointing UI app.
12502 * @param className The class name of the satellite pointing UI app.
12503 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12504 * {@code false} otherwise.
12505 */
12506 public boolean setSatellitePointingUiClassName(
12507 @Nullable String packageName, @Nullable String className) {
12508 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12509 + ", className=" + className);
12510 TelephonyPermissions.enforceShellOnly(
12511 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12513 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12514 "setSatelliteGatewayServicePackageName");
12515 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12516 }
12517
12518 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012519 * This API can be used by only CTS to update the timeout duration in milliseconds that
12520 * satellite should stay at listening mode to wait for the next incoming page before disabling
12521 * listening mode.
12522 *
12523 * @param timeoutMillis The timeout duration in millisecond.
12524 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12525 */
12526 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12527 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12528 TelephonyPermissions.enforceShellOnly(
12529 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12531 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12532 "setSatelliteListeningTimeoutDuration");
12533 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12534 }
12535
12536 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012537 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12538 *
12539 * <p>This method behaves in one of the following ways:
12540 * <ul>
12541 * <li>return true : if the calling package has the appop permission {@link
12542 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12543 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12544 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12545 * Owner device identifier access check, or the calling package has carrier privileges</>
12546 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12547 * </ul>
12548 */
12549 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12550 String callingPackage, @Nullable String callingFeatureId, String message) {
12551 for (Phone phone : PhoneFactory.getPhones()) {
12552 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12553 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12554 return true;
12555 }
12556 }
12557 return false;
12558 }
arunvoddud7401012022-12-15 16:08:12 +000012559
12560 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012561 * @return The subscription manager service instance.
12562 */
12563 public SubscriptionManagerService getSubscriptionManagerService() {
12564 return SubscriptionManagerService.getInstance();
12565 }
12566
12567 /**
arunvoddud7401012022-12-15 16:08:12 +000012568 * Class binds the consumer[callback] and carrierId.
12569 */
12570 private static class CallerCallbackInfo {
12571 private final Consumer<Integer> mConsumer;
12572 private final int mCarrierId;
12573
12574 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12575 mConsumer = consumer;
12576 mCarrierId = carrierId;
12577 }
12578
12579 public Consumer<Integer> getConsumer() {
12580 return mConsumer;
12581 }
12582
12583 public int getCarrierId() {
12584 return mCarrierId;
12585 }
12586 }
Jack Yufa8ed012023-02-11 15:42:28 -080012587}