blob: 26d1e73457bb4530a5925c0bd658fa864ab6f927 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000042import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070043import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070044import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.content.Context;
46import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070047import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070048import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070049import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.net.Uri;
51import android.os.AsyncResult;
52import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080053import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080055import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070057import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080058import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080059import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.Looper;
61import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070062import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080063import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070064import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070065import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080066import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080067import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070068import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070069import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080070import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070072import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070074import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070075import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080076import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070077import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000078import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090079import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080080import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080081import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070082import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080083import android.telephony.AccessNetworkConstants;
84import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070085import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070086import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070088import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080089import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070090import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080091import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060092import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070093import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080094import android.telephony.CellIdentityCdma;
95import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070097import android.telephony.CellInfoGsm;
98import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070099import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800100import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700101import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700102import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700103import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800104import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700105import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800106import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700107import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800108import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800109import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700110import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800111import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800113import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800114import android.telephony.SignalStrengthUpdateRequest;
115import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800116import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800118import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700119import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700120import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800121import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800122import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800123import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800124import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000125import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000126import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000127import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700128import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700129import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800130import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800131import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700132import android.telephony.gba.GbaAuthRequest;
133import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700134import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000136import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000137import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700138import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000139import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700140import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800141import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700142import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800143import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700144import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000145import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700146import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800147import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800148import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000149import android.telephony.satellite.INtnSignalStrengthCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800150import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800151import android.telephony.satellite.ISatelliteProvisionStateCallback;
152import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800153import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800154import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000155import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800157import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800158import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700161import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800163import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164
Andrew Lee312e8172014-10-23 17:01:36 -0700165import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800166import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800167import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800168import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800169import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700171import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700172import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800173import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800174import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800177import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700178import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800179import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800180import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800181import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700182import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000183import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800185import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800188import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800189import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700190import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700191import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700192import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700194import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800195import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700196import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700197import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700198import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700199import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800200import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800201import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700202import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000203import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700204import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700205import com.android.internal.telephony.SmsPermissions;
Peter Wang59571be2020-01-27 12:35:15 +0800206import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800207import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700208import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000209import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700211import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800212import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700213import com.android.internal.telephony.imsphone.ImsPhone;
214import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000215import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800216import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000217import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800218import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
219import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700220import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221import com.android.internal.telephony.uicc.IccIoResult;
222import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800223import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700224import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800225import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000227import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800228import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000229import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800230import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000231import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700232import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700233import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800234import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800235import com.android.phone.callcomposer.CallComposerPictureManager;
236import com.android.phone.callcomposer.CallComposerPictureTransfer;
237import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700238import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700239import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000240import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700241import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800242import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700243import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700244import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800245import com.android.services.telephony.TelecomAccountRegistry;
246import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800247import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800248
Hall Liu82694d52020-12-11 18:22:04 -0800249import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700250import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800251import java.io.IOException;
252import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700253import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800255import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000256import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800257import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800258import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800259import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800260import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100261import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800262import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700263import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800264import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800265import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700266import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800267import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800268import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800269import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
271/**
272 * Implementation of the ITelephony interface.
273 */
Santos Cordon117fee72014-05-16 17:56:12 -0700274public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 private static final String LOG_TAG = "PhoneInterfaceManager";
276 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
277 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800278 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279
280 // Message codes used with mMainThreadHandler
281 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700282 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
283 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700284 private static final int CMD_OPEN_CHANNEL = 9;
285 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
286 private static final int CMD_CLOSE_CHANNEL = 11;
287 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800288 private static final int CMD_NV_READ_ITEM = 13;
289 private static final int EVENT_NV_READ_ITEM_DONE = 14;
290 private static final int CMD_NV_WRITE_ITEM = 15;
291 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
292 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
293 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700294 private static final int CMD_RESET_MODEM_CONFIG = 19;
295 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800296 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
297 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800298 private static final int CMD_SEND_ENVELOPE = 25;
299 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700300 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
301 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
302 private static final int CMD_EXCHANGE_SIM_IO = 31;
303 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800304 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
305 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700306 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
307 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700308 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
309 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700310 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
311 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
312 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
313 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700314 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
315 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
316 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
317 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700318 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800319 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
320 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000321 private static final int CMD_SWITCH_SLOTS = 50;
322 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700323 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
324 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
325 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
326 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
327 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
328 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
329 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
330 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700331 private static final int CMD_GET_ALL_CELL_INFO = 60;
332 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
333 private static final int CMD_GET_CELL_LOCATION = 62;
334 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700335 private static final int CMD_MODEM_REBOOT = 64;
336 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700337 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
338 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800339 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
340 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700341 private static final int CMD_GET_MODEM_STATUS = 70;
342 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700343 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
344 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700345 private static final int CMD_ERASE_MODEM_CONFIG = 74;
346 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800347 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
348 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
349 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
350 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800351 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
352 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800353 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800354 private static final int CMD_GET_CALL_FORWARDING = 83;
355 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
356 private static final int CMD_SET_CALL_FORWARDING = 85;
357 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
358 private static final int CMD_GET_CALL_WAITING = 87;
359 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
360 private static final int CMD_SET_CALL_WAITING = 89;
361 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700362 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
363 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
364 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
365 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700366 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
367 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800368 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
369 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800370 private static final int CMD_SET_DATA_THROTTLING = 99;
371 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800372 private static final int CMD_SET_SIM_POWER = 101;
373 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800374 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
375 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
376 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
377 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800378 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
379 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000380 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800381 private static final int CMD_GET_SLICING_CONFIG = 110;
382 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800383 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700384 private static final int CMD_ENABLE_VONR = 113;
385 private static final int EVENT_ENABLE_VONR_DONE = 114;
386 private static final int CMD_IS_VONR_ENABLED = 115;
387 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700388 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
389 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000390
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800391 // Parameters of select command.
392 private static final int SELECT_COMMAND = 0xA4;
393 private static final int SELECT_P1 = 0x04;
394 private static final int SELECT_P2 = 0;
395 private static final int SELECT_P3 = 0x10;
396
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000397 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
398 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
399
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 /** The singleton instance. */
401 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800402 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403
Sarah Chin4beb2b72023-02-14 14:47:54 -0800404 private final PhoneGlobals mApp;
405 private final CallManager mCM;
406 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000407
408 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800409 private final UserManager mUserManager;
410 private final AppOpsManager mAppOps;
411 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800412 private final SharedPreferences mTelephonySharedPreferences;
413 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800414 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
Peter Wangdafb9ac2020-01-15 14:13:38 -0800416 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800417 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800418 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
419
Sarah Chin4beb2b72023-02-14 14:47:54 -0800420 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800421
Derek Tan97ebb422014-09-05 16:55:38 -0700422 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
423 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800424 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800425 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700426
Michelecea4cf22018-12-21 15:00:11 -0800427 // String to store multi SIM allowed
428 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
429
Derek Tan740e1672017-06-27 14:56:27 -0700430 // The AID of ISD-R.
431 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
432
yinxub1bed742017-04-17 11:45:04 -0700433 private NetworkScanRequestTracker mNetworkScanRequestTracker;
434
David Kelly5e06a7f2018-03-12 14:10:59 +0000435 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
436 private static final int MANUFACTURER_CODE_LENGTH = 8;
437
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800438 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800439 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800440
Sarah Chin2ec39f62022-08-31 17:03:26 -0700441 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
442 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
443
Derek Tan89e89d42014-07-08 17:00:10 -0700444 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700445 * Experiment flag to enable erase modem config on reset network, default value is false
446 */
447 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
448 "reset_network_erase_modem_config_enabled";
449
Rambo Wang0f050d82021-02-12 11:43:36 -0800450 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800451
Gary Jian76280a42022-12-07 16:18:33 +0800452 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
453
sandeepjsb6c87872021-09-27 15:34:44 +0000454 /**
455 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
456 * one ICCID active at the same time.
457 * Apps should use below API signatures if targeting SDK is T and beyond.
458 *
459 * @hide
460 */
461 @ChangeId
462 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
463 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800464
Naina Nallurid63128d2019-09-17 14:10:30 -0700465 /**
Chen Xu540470b2021-12-14 17:15:47 -0800466 * Apps targeting on Android T and beyond will get exception whenever icc close channel
467 * operation fails.
468 */
469 @ChangeId
470 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
471 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
472
473 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 * A request object to use for transmitting data to an ICC.
475 */
476 private static final class IccAPDUArgument {
477 public int channel, cla, command, p1, p2, p3;
478 public String data;
479
480 public IccAPDUArgument(int channel, int cla, int command,
481 int p1, int p2, int p3, String data) {
482 this.channel = channel;
483 this.cla = cla;
484 this.command = command;
485 this.p1 = p1;
486 this.p2 = p2;
487 this.p3 = p3;
488 this.data = data;
489 }
490 }
491
492 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700493 * A request object to use for transmitting data to an ICC.
494 */
495 private static final class ManualNetworkSelectionArgument {
496 public OperatorInfo operatorInfo;
497 public boolean persistSelection;
498
499 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
500 this.operatorInfo = operatorInfo;
501 this.persistSelection = persistSelection;
502 }
503 }
504
Sarah Chin71b3a852022-09-28 15:54:19 -0700505 private static final class PurchasePremiumCapabilityArgument {
506 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700507 public @NonNull IIntegerConsumer callback;
508
509 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800510 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700511 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700512 this.callback = callback;
513 }
514 }
515
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700516 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
518 * request after sending. The main thread will notify the request when it is complete.
519 */
520 private static final class MainThreadRequest {
521 /** The argument to use for the request */
522 public Object argument;
523 /** The result of the request that is run on the main thread */
524 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800525 // The subscriber id that this request applies to. Defaults to
526 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
527 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
Nathan Harold92bed182018-10-12 18:16:49 -0700529 // In cases where subId is unavailable, the caller needs to specify the phone.
530 public Phone phone;
531
vagdeviaf9a5b92018-08-15 16:01:53 -0700532 public WorkSource workSource;
533
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 public MainThreadRequest(Object argument) {
535 this.argument = argument;
536 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800537
Nathan Harold92bed182018-10-12 18:16:49 -0700538 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
539 this.argument = argument;
540 if (phone != null) {
541 this.phone = phone;
542 }
543 this.workSource = workSource;
544 }
545
vagdeviaf9a5b92018-08-15 16:01:53 -0700546 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800547 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800548 if (subId != null) {
549 this.subId = subId;
550 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700551 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553 }
554
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800555 private static final class IncomingThirdPartyCallArgs {
556 public final ComponentName component;
557 public final String callId;
558 public final String callerDisplayName;
559
560 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
561 String callerDisplayName) {
562 this.component = component;
563 this.callId = callId;
564 this.callerDisplayName = callerDisplayName;
565 }
566 }
567
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 /**
569 * A handler that processes messages on the main thread in the phone process. Since many
570 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
571 * inbound binder threads to the main thread in the phone process. The Binder thread
572 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
573 * on, which will be notified when the operation completes and will contain the result of the
574 * request.
575 *
576 * <p>If a MainThreadRequest object is provided in the msg.obj field,
577 * note that request.result must be set to something non-null for the calling thread to
578 * unblock.
579 */
580 private final class MainThreadHandler extends Handler {
581 @Override
582 public void handleMessage(Message msg) {
583 MainThreadRequest request;
584 Message onCompleted;
585 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000586 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800588 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700589
590 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 case CMD_HANDLE_USSD_REQUEST: {
592 request = (MainThreadRequest) msg.obj;
593 final Phone phone = getPhoneFromRequest(request);
594 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800595 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700597
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 if (!isUssdApiAllowed(request.subId)) {
599 // Carrier does not support use of this API, return failure.
600 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
601 UssdResponse response = new UssdResponse(ussdRequest, null);
602 Bundle returnData = new Bundle();
603 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
604 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700605
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 request.result = true;
607 notifyRequester(request);
608 return;
609 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700610
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 try {
612 request.result = phone != null
613 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
614 } catch (CallStateException cse) {
615 request.result = false;
616 }
617 // Wake up the requesting thread
618 notifyRequester(request);
619 break;
pkanwar32d516d2016-10-14 19:37:38 -0700620 }
621
Yorke Lee716f67e2015-06-17 15:39:16 -0700622 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700623 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700624 final Phone phone = getPhoneFromRequest(request);
625 request.result = phone != null ?
626 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
627 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700628 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000636 uiccPort = getUiccPortFromRequest(request);
637 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800639 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800643 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000644 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800645 iccArgument.channel, iccArgument.cla, iccArgument.command,
646 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
647 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 ar = (AsyncResult) msg.obj;
653 request = (MainThreadRequest) ar.userObj;
654 if (ar.exception == null && ar.result != null) {
655 request.result = ar.result;
656 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800657 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 if (ar.result == null) {
659 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800660 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800662 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
664 loge("iccTransmitApduLogicalChannel: Unknown exception");
665 }
666 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 break;
669
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
671 request = (MainThreadRequest) msg.obj;
672 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000673 uiccPort = getUiccPortFromRequest(request);
674 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800676 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 } else {
679 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800680 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000681 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800682 iccArgument.cla, iccArgument.command, iccArgument.p1,
683 iccArgument.p2,
684 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 }
686 break;
687
688 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result;
693 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800694 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 if (ar.result == null) {
696 loge("iccTransmitApduBasicChannel: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("iccTransmitApduBasicChannel: CommandException: " +
699 ar.exception);
700 } else {
701 loge("iccTransmitApduBasicChannel: Unknown exception");
702 }
703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 break;
706
707 case CMD_EXCHANGE_SIM_IO:
708 request = (MainThreadRequest) msg.obj;
709 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 uiccPort = getUiccPortFromRequest(request);
711 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800713 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 } else {
716 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
717 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000718 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
720 iccArgument.data, onCompleted);
721 }
722 break;
723
724 case EVENT_EXCHANGE_SIM_IO_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result;
729 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800730 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 break;
734
Derek Tan4d5e5c12014-02-04 11:54:58 -0800735 case CMD_SEND_ENVELOPE:
736 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000737 uiccPort = getUiccPortFromRequest(request);
738 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700739 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800740 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 } else {
743 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800744 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800746 break;
747
748 case EVENT_SEND_ENVELOPE_DONE:
749 ar = (AsyncResult) msg.obj;
750 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700751 if (ar.exception == null && ar.result != null) {
752 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800753 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800754 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700755 if (ar.result == null) {
756 loge("sendEnvelopeWithStatus: Empty response");
757 } else if (ar.exception instanceof CommandException) {
758 loge("sendEnvelopeWithStatus: CommandException: " +
759 ar.exception);
760 } else {
761 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
762 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800763 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800765 break;
766
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 case CMD_OPEN_CHANNEL:
768 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000769 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800770 IccLogicalChannelRequest openChannelRequest =
771 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000772 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800774 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800775 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700777 } else {
778 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800779 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
780 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700781 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 break;
783
784 case EVENT_OPEN_CHANNEL_DONE:
785 ar = (AsyncResult) msg.obj;
786 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700787 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700789 int[] result = (int[]) ar.result;
790 int channelId = result[0];
791 byte[] selectResponse = null;
792 if (result.length > 1) {
793 selectResponse = new byte[result.length - 1];
794 for (int i = 1; i < result.length; ++i) {
795 selectResponse[i - 1] = (byte) result[i];
796 }
797 }
798 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800799 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800800
801 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700802 if (uiccPort == null) {
803 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
804 } else {
805 IccLogicalChannelRequest channelRequest =
806 (IccLogicalChannelRequest) request.argument;
807 channelRequest.channel = channelId;
808 uiccPort.onLogicalChannelOpened(channelRequest);
809 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 if (ar.result == null) {
812 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700814 if (ar.exception != null) {
815 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
816 }
817
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700818 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700819 if (ar.exception instanceof CommandException) {
820 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800821 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700822 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700823 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700824 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700825 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700826 }
827 }
828 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800829 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700830 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700831 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700832 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 break;
834
835 case CMD_CLOSE_CHANNEL:
836 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000837 uiccPort = getUiccPortFromRequest(request);
838 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700839 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800840 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800841 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800842 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700843 } else {
844 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000845 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700846 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 break;
848
849 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null) {
853 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800854 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700855 if (uiccPort == null) {
856 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
857 } else {
858 final int channelId = (Integer) request.argument;
859 uiccPort.onLogicalChannelClosed(channelId);
860 }
Chen Xu540470b2021-12-14 17:15:47 -0800861 } else {
862 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800863 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800864 if (ar.exception instanceof CommandException) {
865 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
866 CommandException.Error error =
867 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800868 if (error == CommandException.Error.INVALID_ARGUMENTS) {
869 // should only throw exceptions from the binder threads.
870 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800871 "iccCloseLogicalChannel: invalid argument ");
872 }
873 } else {
874 loge("iccCloseLogicalChannel: Unknown exception");
875 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800876 request.result = (exception != null) ? exception :
877 new IllegalStateException(
878 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800879 }
880 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800881 break;
882
883 case CMD_NV_READ_ITEM:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
887 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800888 break;
889
890 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800893 if (ar.exception == null && ar.result != null) {
894 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700895 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800896 request.result = "";
897 if (ar.result == null) {
898 loge("nvReadItem: Empty response");
899 } else if (ar.exception instanceof CommandException) {
900 loge("nvReadItem: CommandException: " +
901 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700902 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800903 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700904 }
905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700906 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700907 break;
908
Jake Hambye994d462014-02-03 13:10:13 -0800909 case CMD_NV_WRITE_ITEM:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
912 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700914 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800915 break;
916
917 case EVENT_NV_WRITE_ITEM_DONE:
918 handleNullReturnEvent(msg, "nvWriteItem");
919 break;
920
921 case CMD_NV_WRITE_CDMA_PRL:
922 request = (MainThreadRequest) msg.obj;
923 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800924 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800925 break;
926
927 case EVENT_NV_WRITE_CDMA_PRL_DONE:
928 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
929 break;
930
chen xu6dac5ab2018-10-26 17:39:23 -0700931 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800932 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700933 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800934 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800935 break;
936
chen xu6dac5ab2018-10-26 17:39:23 -0700937 case EVENT_RESET_MODEM_CONFIG_DONE:
938 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800939 break;
940
Sooraj Sasindran37444802020-08-11 10:40:43 -0700941 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
944 request);
945 Phone phone = getPhoneFromRequest(request);
946 if (phone != null) {
947 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
948 } else {
949 loge("isNRDualConnectivityEnabled: No phone object");
950 request.result = false;
951 notifyRequester(request);
952 }
953 break;
954 }
955
956 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
957 ar = (AsyncResult) msg.obj;
958 request = (MainThreadRequest) ar.userObj;
959 if (ar.exception == null && ar.result != null) {
960 request.result = ar.result;
961 } else {
962 // request.result must be set to something non-null
963 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700964 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700965 request.result = ar.result;
966 } else {
967 request.result = false;
968 }
969 if (ar.result == null) {
970 loge("isNRDualConnectivityEnabled: Empty response");
971 } else if (ar.exception instanceof CommandException) {
972 loge("isNRDualConnectivityEnabled: CommandException: "
973 + ar.exception);
974 } else {
975 loge("isNRDualConnectivityEnabled: Unknown exception");
976 }
977 }
978 notifyRequester(request);
979 break;
980
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700981 case CMD_IS_VONR_ENABLED: {
982 request = (MainThreadRequest) msg.obj;
983 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
984 request);
985 Phone phone = getPhoneFromRequest(request);
986 if (phone != null) {
987 phone.isVoNrEnabled(onCompleted, request.workSource);
988 } else {
989 loge("isVoNrEnabled: No phone object");
990 request.result = false;
991 notifyRequester(request);
992 }
993 break;
994 }
995
996 case EVENT_IS_VONR_ENABLED_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception == null && ar.result != null) {
1000 request.result = ar.result;
1001 } else {
1002 // request.result must be set to something non-null
1003 // for the calling thread to unblock
1004 if (ar.result != null) {
1005 request.result = ar.result;
1006 } else {
1007 request.result = false;
1008 }
1009 if (ar.result == null) {
1010 loge("isVoNrEnabled: Empty response");
1011 } else if (ar.exception instanceof CommandException) {
1012 loge("isVoNrEnabled: CommandException: "
1013 + ar.exception);
1014 } else {
1015 loge("isVoNrEnabled: Unknown exception");
1016 }
1017 }
1018 notifyRequester(request);
1019 break;
1020
Sooraj Sasindran37444802020-08-11 10:40:43 -07001021 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1024 Phone phone = getPhoneFromRequest(request);
1025 if (phone != null) {
1026 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1027 request.workSource);
1028 } else {
1029 loge("enableNrDualConnectivity: No phone object");
1030 request.result =
1031 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1032 notifyRequester(request);
1033 }
1034 break;
1035 }
1036
1037 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 if (ar.exception == null) {
1041 request.result =
1042 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1043 } else {
1044 request.result =
1045 TelephonyManager
1046 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1047 if (ar.exception instanceof CommandException) {
1048 CommandException.Error error =
1049 ((CommandException) (ar.exception)).getCommandError();
1050 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1051 request.result =
1052 TelephonyManager
1053 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001054 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1055 request.result =
1056 TelephonyManager
1057 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001058 }
1059 loge("enableNrDualConnectivity" + ": CommandException: "
1060 + ar.exception);
1061 } else {
1062 loge("enableNrDualConnectivity" + ": Unknown exception");
1063 }
1064 }
1065 notifyRequester(request);
1066 break;
1067 }
1068
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001069 case CMD_ENABLE_VONR: {
1070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1072 Phone phone = getPhoneFromRequest(request);
1073 if (phone != null) {
1074 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1075 request.workSource);
1076 } else {
1077 loge("setVoNrEnabled: No phone object");
1078 request.result =
1079 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1080 notifyRequester(request);
1081 }
1082 break;
1083 }
1084
1085 case EVENT_ENABLE_VONR_DONE: {
1086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
1088 if (ar.exception == null) {
1089 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1090 } else {
1091 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1092 if (ar.exception instanceof CommandException) {
1093 CommandException.Error error =
1094 ((CommandException) (ar.exception)).getCommandError();
1095 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1096 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1097 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1098 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1099 } else {
1100 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1101 }
1102 loge("setVoNrEnabled" + ": CommandException: "
1103 + ar.exception);
1104 } else {
1105 loge("setVoNrEnabled" + ": Unknown exception");
1106 }
1107 }
1108 notifyRequester(request);
1109 break;
1110 }
1111
SongFerngWang3ef3e072020-12-21 16:41:52 +08001112 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001113 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1115 request);
1116 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001117 break;
1118
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 ar = (AsyncResult) msg.obj;
1121 request = (MainThreadRequest) ar.userObj;
1122 if (ar.exception == null && ar.result != null) {
1123 request.result = ar.result; // Integer
1124 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301125 // request.result must be set to something non-null
1126 // for the calling thread to unblock
1127 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001128 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001129 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 loge("getAllowedNetworkTypesBitmask: CommandException: "
1132 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001133 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001134 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 }
1136 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001137 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 break;
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1143 request);
1144 Pair<Integer, Long> reasonWithNetworkTypes =
1145 (Pair<Integer, Long>) request.argument;
1146 getPhoneFromRequest(request).setAllowedNetworkTypes(
1147 reasonWithNetworkTypes.first,
1148 reasonWithNetworkTypes.second,
1149 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001150 break;
1151
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1153 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 break;
1155
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001156 case CMD_SET_VOICEMAIL_NUMBER:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1159 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001160 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1161 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001162 break;
1163
1164 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1165 handleNullReturnEvent(msg, "setVoicemailNumber");
1166 break;
1167
Stuart Scott54788802015-03-30 13:18:01 -07001168 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1169 request = (MainThreadRequest) msg.obj;
1170 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1171 request);
1172 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1173 break;
1174
1175 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1176 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1177 break;
1178
Shishir Agrawal302c8692015-06-19 13:49:39 -07001179 case CMD_PERFORM_NETWORK_SCAN:
1180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1182 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1183 break;
1184
Hall Liu27d24262020-09-18 19:04:59 -07001185 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001188 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1189 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1190 request.argument;
1191 int callForwardingReason = args.first;
1192 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001193 break;
Hall Liu27d24262020-09-18 19:04:59 -07001194 }
1195 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001198 TelephonyManager.CallForwardingInfoCallback callback =
1199 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1200 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001202 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001203 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1204 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1205 // Service Class is a bit mask per 3gpp 27.007. Search for
1206 // any service for voice call.
1207 if ((callForwardInfo.serviceClass
1208 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001209 callForwardingInfo = new CallForwardingInfo(
1210 callForwardInfo.status
1211 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001212 callForwardInfo.reason,
1213 callForwardInfo.number,
1214 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001215 break;
1216 }
1217 }
1218 // Didn't find a call forward info for voice call.
1219 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001220 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1221 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001222 }
Hall Liu27d24262020-09-18 19:04:59 -07001223 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 } else {
1225 if (ar.result == null) {
1226 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1227 }
1228 if (ar.exception != null) {
1229 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1230 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 int errorCode = TelephonyManager
1232 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001233 if (ar.exception instanceof CommandException) {
1234 CommandException.Error error =
1235 ((CommandException) (ar.exception)).getCommandError();
1236 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 errorCode = TelephonyManager
1238 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001239 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager
1241 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001242 }
1243 }
Hall Liu27d24262020-09-18 19:04:59 -07001244 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 }
Shuo Qian4a594052020-01-23 11:59:30 -08001246 break;
Hall Liu27d24262020-09-18 19:04:59 -07001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248
Hall Liu27d24262020-09-18 19:04:59 -07001249 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001252 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001253 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001254 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1255 request.argument).first;
1256 request.phone.setCallForwardingOption(
1257 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001258 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001259 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001260 callForwardingInfoToSet.getReason(),
1261 callForwardingInfoToSet.getNumber(),
1262 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1263 break;
Hall Liu27d24262020-09-18 19:04:59 -07001264 }
Shuo Qian4a594052020-01-23 11:59:30 -08001265
Hall Liu27d24262020-09-18 19:04:59 -07001266 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001269 Consumer<Integer> callback =
1270 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1271 request.argument).second;
1272 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001273 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001274 int errorCode = TelephonyManager.CallForwardingInfoCallback
1275 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001276 if (ar.exception instanceof CommandException) {
1277 CommandException.Error error =
1278 ((CommandException) (ar.exception)).getCommandError();
1279 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001280 errorCode = TelephonyManager.CallForwardingInfoCallback
1281 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001282 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001283 errorCode = TelephonyManager.CallForwardingInfoCallback
1284 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
1286 }
1287 callback.accept(errorCode);
1288 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001289 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001290 }
Shuo Qian4a594052020-01-23 11:59:30 -08001291 break;
Hall Liu27d24262020-09-18 19:04:59 -07001292 }
Shuo Qian4a594052020-01-23 11:59:30 -08001293
Hall Liu27d24262020-09-18 19:04:59 -07001294 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001295 request = (MainThreadRequest) msg.obj;
1296 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1297 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1298 break;
Hall Liu27d24262020-09-18 19:04:59 -07001299 }
Shuo Qian4a594052020-01-23 11:59:30 -08001300
Hall Liu27d24262020-09-18 19:04:59 -07001301 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001304 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001305 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001306 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001307 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001308 // Service Class is a bit mask per 3gpp 27.007.
1309 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001310 if (callForwardResults.length > 1
1311 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001312 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001313 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001314 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1315 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001316 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001317 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001318 }
1319 } else {
1320 if (ar.result == null) {
1321 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1322 }
1323 if (ar.exception != null) {
1324 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1325 }
1326 if (ar.exception instanceof CommandException) {
1327 CommandException.Error error =
1328 ((CommandException) (ar.exception)).getCommandError();
1329 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001330 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001331 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1333 callWaitingStatus =
1334 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001335 }
1336 }
1337 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001338 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001339 break;
Hall Liu27d24262020-09-18 19:04:59 -07001340 }
Shuo Qian4a594052020-01-23 11:59:30 -08001341
Hall Liu27d24262020-09-18 19:04:59 -07001342 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001343 request = (MainThreadRequest) msg.obj;
1344 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001345 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1346 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001347 break;
Hall Liu27d24262020-09-18 19:04:59 -07001348 }
Shuo Qian4a594052020-01-23 11:59:30 -08001349
Hall Liu27d24262020-09-18 19:04:59 -07001350 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001351 ar = (AsyncResult) msg.obj;
1352 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001353 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1354 Consumer<Integer> callback =
1355 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1356 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001357 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001358 if (ar.exception instanceof CommandException) {
1359 CommandException.Error error =
1360 ((CommandException) (ar.exception)).getCommandError();
1361 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1362 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001363 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1364 callback.accept(
1365 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001366 } else {
1367 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1368 }
1369 } else {
1370 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1371 }
1372 } else {
1373 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1374 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001375 }
Shuo Qian4a594052020-01-23 11:59:30 -08001376 break;
Hall Liu27d24262020-09-18 19:04:59 -07001377 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001378 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
1381 CellNetworkScanResult cellScanResult;
1382 if (ar.exception == null && ar.result != null) {
1383 cellScanResult = new CellNetworkScanResult(
1384 CellNetworkScanResult.STATUS_SUCCESS,
1385 (List<OperatorInfo>) ar.result);
1386 } else {
1387 if (ar.result == null) {
1388 loge("getCellNetworkScanResults: Empty response");
1389 }
1390 if (ar.exception != null) {
1391 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1392 }
1393 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1394 if (ar.exception instanceof CommandException) {
1395 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001396 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001397 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1398 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1399 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1400 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1401 }
1402 }
1403 cellScanResult = new CellNetworkScanResult(errorCode, null);
1404 }
1405 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001406 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 break;
1408
1409 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1410 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001411 ManualNetworkSelectionArgument selArg =
1412 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001413 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1414 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001415 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1416 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001417 break;
1418
1419 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception == null) {
1423 request.result = true;
1424 } else {
1425 request.result = false;
1426 loge("setNetworkSelectionModeManual " + ar.exception);
1427 }
1428 notifyRequester(request);
1429 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 break;
1431
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001432 case CMD_GET_MODEM_ACTIVITY_INFO:
1433 request = (MainThreadRequest) msg.obj;
1434 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001435 if (defaultPhone != null) {
1436 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001437 } else {
1438 ResultReceiver result = (ResultReceiver) request.argument;
1439 Bundle bundle = new Bundle();
1440 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001441 new ModemActivityInfo(0, 0, 0,
1442 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001443 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001444 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001445 break;
1446
Hall Liud0f208c2020-10-14 16:54:44 -07001447 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001450 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001451 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001452 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001453 if (mLastModemActivityInfo == null) {
1454 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1455 mLastModemActivitySpecificInfo[0] =
1456 new ActivityStatsTechSpecificInfo(
1457 0,
1458 0,
1459 new int[ModemActivityInfo.getNumTxPowerLevels()],
1460 0);
1461 mLastModemActivityInfo =
1462 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1463 }
1464
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001465 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 // Update the last modem activity info and the result of the request.
1467 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1468 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001469 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001470 } else {
1471 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001472 }
Kai Shi917fdc62022-11-28 14:01:02 -08001473 // This is needed to decouple ret from mLastModemActivityInfo
1474 // We don't want to return mLastModemActivityInfo which is updated
1475 // inside mergeModemActivityInfo()
1476 ret = new ModemActivityInfo(
1477 mLastModemActivityInfo.getTimestampMillis(),
1478 mLastModemActivityInfo.getSleepTimeMillis(),
1479 mLastModemActivityInfo.getIdleTimeMillis(),
1480 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001481
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001482 } else {
1483 if (ar.result == null) {
1484 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001485 error = TelephonyManager.ModemActivityInfoException
1486 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001487 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001488 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001489 error = TelephonyManager.ModemActivityInfoException
1490 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001491 } else {
1492 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001493 error = TelephonyManager.ModemActivityInfoException
1494 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001495 }
1496 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001497 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001498 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001499 bundle.putParcelable(
1500 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001501 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001502 } else {
1503 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1504 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001505 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001506 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001507 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001508 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001509
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001510 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001511 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001512 CarrierRestrictionRules argument =
1513 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001515 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001516 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001517 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518
1519 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1520 ar = (AsyncResult) msg.obj;
1521 request = (MainThreadRequest) ar.userObj;
1522 if (ar.exception == null && ar.result != null) {
1523 request.result = ar.result;
1524 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001525 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1526 if (ar.exception instanceof CommandException) {
1527 loge("setAllowedCarriers: CommandException: " + ar.exception);
1528 CommandException.Error error =
1529 ((CommandException) (ar.exception)).getCommandError();
1530 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1531 request.result =
1532 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1533 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 } else {
1535 loge("setAllowedCarriers: Unknown exception");
1536 }
1537 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001538 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 break;
1540
1541 case CMD_GET_ALLOWED_CARRIERS:
1542 request = (MainThreadRequest) msg.obj;
1543 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001544 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
1546
1547 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001553 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001554 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001555 if (ar.result == null) {
1556 loge("getAllowedCarriers: Empty response");
1557 } else if (ar.exception instanceof CommandException) {
1558 loge("getAllowedCarriers: CommandException: " +
1559 ar.exception);
1560 } else {
1561 loge("getAllowedCarriers: Unknown exception");
1562 }
1563 }
arunvoddud7401012022-12-15 16:08:12 +00001564 if (request.argument != null) {
1565 // This is for the implementation of carrierRestrictionStatus.
1566 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1567 Consumer<Integer> callback = callbackInfo.getConsumer();
1568 int callerCarrierId = callbackInfo.getCarrierId();
1569 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1570 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1571 CarrierRestrictionRules carrierRestrictionRules =
1572 (CarrierRestrictionRules) ar.result;
1573 int carrierId = -1;
1574 try {
1575 CarrierIdentifier carrierIdentifier =
1576 carrierRestrictionRules.getAllowedCarriers().get(0);
1577 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1578 carrierIdentifier);
1579 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1580 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1581 }
1582 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1583 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1584 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001585 lockStatus = TelephonyManager
1586 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001587 }
1588 } else {
1589 Rlog.e(LOG_TAG,
1590 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1591 }
1592 callback.accept(lockStatus);
1593 } else {
1594 // This is for the implementation of getAllowedCarriers.
1595 notifyRequester(request);
1596 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001597 break;
1598
Nathan Haroldb3014052017-01-25 15:57:32 -08001599 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 if (ar.exception == null && ar.result != null) {
1603 request.result = ar.result;
1604 } else {
1605 request.result = new IllegalArgumentException(
1606 "Failed to retrieve Forbidden Plmns");
1607 if (ar.result == null) {
1608 loge("getForbiddenPlmns: Empty response");
1609 } else {
1610 loge("getForbiddenPlmns: Unknown exception");
1611 }
1612 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001613 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001614 break;
1615
1616 case CMD_GET_FORBIDDEN_PLMNS:
1617 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001618 uiccPort = getUiccPortFromRequest(request);
1619 if (uiccPort == null) {
1620 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001621 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001622 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001623 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001624 break;
1625 }
1626 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001627 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001628 if (uiccApp == null) {
1629 loge("getForbiddenPlmns() no app with specified type -- "
1630 + appType);
1631 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001632 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001633 break;
1634 } else {
1635 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1636 + " specified type -- " + appType);
1637 }
1638 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1639 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001640 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001641 break;
1642
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001643 case CMD_SWITCH_SLOTS:
1644 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001645 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001646 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001647 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001648 break;
1649
1650 case EVENT_SWITCH_SLOTS_DONE:
1651 ar = (AsyncResult) msg.obj;
1652 request = (MainThreadRequest) ar.userObj;
1653 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001654 notifyRequester(request);
1655 break;
1656 case CMD_GET_NETWORK_SELECTION_MODE:
1657 request = (MainThreadRequest) msg.obj;
1658 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1659 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1660 break;
1661
1662 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1663 ar = (AsyncResult) msg.obj;
1664 request = (MainThreadRequest) ar.userObj;
1665 if (ar.exception != null) {
1666 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1667 } else {
1668 int mode = ((int[]) ar.result)[0];
1669 if (mode == 0) {
1670 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1671 } else {
1672 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1673 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001675 notifyRequester(request);
1676 break;
1677 case CMD_GET_CDMA_ROAMING_MODE:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1680 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1681 break;
1682 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 if (ar.exception != null) {
1686 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1687 } else {
1688 request.result = ((int[]) ar.result)[0];
1689 }
1690 notifyRequester(request);
1691 break;
1692 case CMD_SET_CDMA_ROAMING_MODE:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1695 int mode = (int) request.argument;
1696 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1697 break;
1698 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1699 ar = (AsyncResult) msg.obj;
1700 request = (MainThreadRequest) ar.userObj;
1701 request.result = ar.exception == null;
1702 notifyRequester(request);
1703 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001704 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1707 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1708 break;
1709 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1710 ar = (AsyncResult) msg.obj;
1711 request = (MainThreadRequest) ar.userObj;
1712 if (ar.exception != null) {
1713 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1714 } else {
1715 request.result = ((int[]) ar.result)[0];
1716 }
1717 notifyRequester(request);
1718 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001719 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1722 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001723 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1724 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001725 break;
1726 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1727 ar = (AsyncResult) msg.obj;
1728 request = (MainThreadRequest) ar.userObj;
1729 request.result = ar.exception == null;
1730 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001731 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001732 case CMD_GET_ALL_CELL_INFO:
1733 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001734 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001735 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001737 case EVENT_GET_ALL_CELL_INFO_DONE:
1738 ar = (AsyncResult) msg.obj;
1739 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001740 // If a timeout occurs, the response will be null
1741 request.result = (ar.exception == null && ar.result != null)
1742 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001743 synchronized (request) {
1744 request.notifyAll();
1745 }
1746 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001747 case CMD_REQUEST_CELL_INFO_UPDATE:
1748 request = (MainThreadRequest) msg.obj;
1749 request.phone.requestCellInfoUpdate(request.workSource,
1750 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1751 break;
1752 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
1755 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1756 try {
1757 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001758 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001759 cb.onError(
1760 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1761 ar.exception.getClass().getName(),
1762 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001763 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001764 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001765 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001766 } else {
1767 // use the result as returned
1768 cb.onCellInfo((List<CellInfo>) ar.result);
1769 }
1770 } catch (RemoteException re) {
1771 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1772 }
1773 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001774 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001775 request = (MainThreadRequest) msg.obj;
1776 WorkSource ws = (WorkSource) request.argument;
1777 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001778 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001779 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001780 }
1781 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001782 ar = (AsyncResult) msg.obj;
1783 request = (MainThreadRequest) ar.userObj;
1784 if (ar.exception == null) {
1785 request.result = ar.result;
1786 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001787 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001788 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001789 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 }
1791
1792 synchronized (request) {
1793 request.notifyAll();
1794 }
1795 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001796 }
chen xu6dac5ab2018-10-26 17:39:23 -07001797 case CMD_MODEM_REBOOT:
1798 request = (MainThreadRequest) msg.obj;
1799 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001800 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001801 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001802 case EVENT_CMD_MODEM_REBOOT_DONE:
1803 handleNullReturnEvent(msg, "rebootModem");
1804 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001805 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001806 request = (MainThreadRequest) msg.obj;
1807 boolean enable = (boolean) request.argument;
1808 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001809 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001810 PhoneConfigurationManager.getInstance()
1811 .enablePhone(request.phone, enable, onCompleted);
1812 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001813 }
Michele Berionne5e411512020-11-13 02:36:59 +00001814 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001818 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001819 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001820 if ((boolean) request.result) {
1821 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1822 updateModemStateMetrics();
1823 } else {
1824 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1825 + ar.exception);
1826 }
1827 notifyRequester(request);
1828 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001829 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001830 case CMD_GET_MODEM_STATUS:
1831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1833 PhoneConfigurationManager.getInstance()
1834 .getPhoneStatusFromModem(request.phone, onCompleted);
1835 break;
1836 case EVENT_GET_MODEM_STATUS_DONE:
1837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 int id = request.phone.getPhoneId();
1840 if (ar.exception == null && ar.result != null) {
1841 request.result = ar.result;
1842 //update the cache as modem status has changed
1843 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1844 (boolean) request.result);
1845 } else {
1846 // Return true if modem status cannot be retrieved. For most cases,
1847 // modem status is on. And for older version modems, GET_MODEM_STATUS
1848 // and disable modem are not supported. Modem is always on.
1849 // TODO: this should be fixed in R to support a third
1850 // status UNKNOWN b/131631629
1851 request.result = true;
1852 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1853 + ar.exception);
1854 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001855 notifyRequester(request);
1856 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001857 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1858 request = (MainThreadRequest) msg.obj;
1859 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1860 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1861 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1862 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1863 break;
1864 }
1865 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1866 ar = (AsyncResult) msg.obj;
1867 request = (MainThreadRequest) ar.userObj;
1868 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1869 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1870 args.second.accept(ar.exception == null);
1871 notifyRequester(request);
1872 break;
1873 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001874 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1875 request = (MainThreadRequest) msg.obj;
1876 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1877 Phone phone = getPhoneFromRequest(request);
1878 if (phone != null) {
1879 phone.getSystemSelectionChannels(onCompleted);
1880 } else {
1881 loge("getSystemSelectionChannels: No phone object");
1882 request.result = new ArrayList<RadioAccessSpecifier>();
1883 notifyRequester(request);
1884 }
1885 break;
1886 }
1887 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890 if (ar.exception == null && ar.result != null) {
1891 request.result = ar.result;
1892 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001893 request.result = new IllegalStateException(
1894 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001895 if (ar.result == null) {
1896 loge("getSystemSelectionChannels: Empty response");
1897 } else {
1898 loge("getSystemSelectionChannels: Unknown exception");
1899 }
1900 }
1901 notifyRequester(request);
1902 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001903 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1904 ar = (AsyncResult) msg.obj;
1905 request = (MainThreadRequest) ar.userObj;
1906 if (ar.exception == null && ar.result != null) {
1907 request.result = ar.result;
1908 } else {
1909 request.result = -1;
1910 loge("Failed to set Forbidden Plmns");
1911 if (ar.result == null) {
1912 loge("setForbidenPlmns: Empty response");
1913 } else if (ar.exception != null) {
1914 loge("setForbiddenPlmns: Exception: " + ar.exception);
1915 request.result = -1;
1916 } else {
1917 loge("setForbiddenPlmns: Unknown exception");
1918 }
1919 }
1920 notifyRequester(request);
1921 break;
1922 case CMD_SET_FORBIDDEN_PLMNS:
1923 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001924 uiccPort = getUiccPortFromRequest(request);
1925 if (uiccPort == null) {
1926 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001927 request.result = -1;
1928 notifyRequester(request);
1929 break;
1930 }
1931 Pair<Integer, List<String>> setFplmnsArgs =
1932 (Pair<Integer, List<String>>) request.argument;
1933 appType = setFplmnsArgs.first;
1934 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001935 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001936 if (uiccApp == null) {
1937 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1938 request.result = -1;
1939 loge("Failed to get UICC App");
1940 notifyRequester(request);
1941 } else {
1942 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1943 ((SIMRecords) uiccApp.getIccRecords())
1944 .setForbiddenPlmns(onCompleted, fplmns);
1945 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001946 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001947 case CMD_ERASE_MODEM_CONFIG:
1948 request = (MainThreadRequest) msg.obj;
1949 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1950 defaultPhone.eraseModemConfig(onCompleted);
1951 break;
1952 case EVENT_ERASE_MODEM_CONFIG_DONE:
1953 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001954 break;
zoey chene02881a2019-12-30 16:11:23 +08001955
Kai Shif70f46f2021-03-03 13:59:46 -08001956 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1957 request = (MainThreadRequest) msg.obj;
1958 request.result = defaultPhone.eraseDataInSharedPreferences();
1959 notifyRequester(request);
1960 break;
1961
zoey chene02881a2019-12-30 16:11:23 +08001962 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1963 request = (MainThreadRequest) msg.obj;
1964 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1965 Pair<String, String> changed = (Pair<String, String>) request.argument;
1966 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1967 changed.first, changed.second, onCompleted);
1968 break;
1969 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1970 ar = (AsyncResult) msg.obj;
1971 request = (MainThreadRequest) ar.userObj;
1972 if (ar.exception == null) {
1973 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001974 // If the operation is successful, update the PIN storage
1975 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1976 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001977 UiccController.getInstance().getPinStorage()
1978 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001979 } else {
1980 request.result = msg.arg1;
1981 }
1982 notifyRequester(request);
1983 break;
1984
Michele Berionne5e411512020-11-13 02:36:59 +00001985 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1988 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1989 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1990 enabled.first, enabled.second, onCompleted);
1991 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001992 }
zoey chene02881a2019-12-30 16:11:23 +08001993 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1994 ar = (AsyncResult) msg.obj;
1995 request = (MainThreadRequest) ar.userObj;
1996 if (ar.exception == null) {
1997 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001998 // If the operation is successful, update the PIN storage
1999 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2000 int phoneId = getPhoneFromRequest(request).getPhoneId();
2001 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002002 UiccController.getInstance().getPinStorage()
2003 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002004 } else {
2005 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2006 }
zoey chene02881a2019-12-30 16:11:23 +08002007 } else {
2008 request.result = msg.arg1;
2009 }
Michele Berionne5e411512020-11-13 02:36:59 +00002010
2011
zoey chene02881a2019-12-30 16:11:23 +08002012 notifyRequester(request);
2013 break;
2014
Peter Wangdafb9ac2020-01-15 14:13:38 -08002015 case MSG_NOTIFY_USER_ACTIVITY:
2016 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002017 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002018 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2019 getDefaultPhone().getContext().sendBroadcastAsUser(
2020 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2021 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002022
2023 case CMD_SET_DATA_THROTTLING: {
2024 request = (MainThreadRequest) msg.obj;
2025 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2026 DataThrottlingRequest dataThrottlingRequest =
2027 (DataThrottlingRequest) request.argument;
2028 Phone phone = getPhoneFromRequest(request);
2029 if (phone != null) {
2030 phone.setDataThrottling(onCompleted,
2031 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2032 dataThrottlingRequest.getCompletionDurationMillis());
2033 } else {
2034 loge("setDataThrottling: No phone object");
2035 request.result =
2036 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2037 notifyRequester(request);
2038 }
2039
2040 break;
2041 }
2042 case EVENT_SET_DATA_THROTTLING_DONE:
2043 ar = (AsyncResult) msg.obj;
2044 request = (MainThreadRequest) ar.userObj;
2045
2046 if (ar.exception == null) {
2047 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2048 } else if (ar.exception instanceof CommandException) {
2049 loge("setDataThrottling: CommandException: " + ar.exception);
2050 CommandException.Error error =
2051 ((CommandException) (ar.exception)).getCommandError();
2052
2053 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2054 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002055 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002056 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2057 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002058 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2059 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002060 } else {
2061 request.result =
2062 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2063 }
2064 } else {
2065 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2066 }
2067 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2068 notifyRequester(request);
2069 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002070
2071 case CMD_SET_SIM_POWER: {
2072 request = (MainThreadRequest) msg.obj;
2073 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2074 request = (MainThreadRequest) msg.obj;
2075 int stateToSet =
2076 ((Pair<Integer, IIntegerConsumer>)
2077 request.argument).first;
2078 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2079 break;
2080 }
2081 case EVENT_SET_SIM_POWER_DONE: {
2082 ar = (AsyncResult) msg.obj;
2083 request = (MainThreadRequest) ar.userObj;
2084 IIntegerConsumer callback =
2085 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2086 if (ar.exception != null) {
2087 loge("setSimPower exception: " + ar.exception);
2088 int errorCode = TelephonyManager.CallForwardingInfoCallback
2089 .RESULT_ERROR_UNKNOWN;
2090 if (ar.exception instanceof CommandException) {
2091 CommandException.Error error =
2092 ((CommandException) (ar.exception)).getCommandError();
2093 if (error == CommandException.Error.SIM_ERR) {
2094 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2095 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2096 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2097 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2098 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2099 } else {
2100 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2101 }
2102 }
2103 try {
2104 callback.accept(errorCode);
2105 } catch (RemoteException e) {
2106 // Ignore if the remote process is no longer available to call back.
2107 Log.w(LOG_TAG, "setSimPower: callback not available.");
2108 }
2109 } else {
2110 try {
2111 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2112 } catch (RemoteException e) {
2113 // Ignore if the remote process is no longer available to call back.
2114 Log.w(LOG_TAG, "setSimPower: callback not available.");
2115 }
2116 }
2117 break;
2118 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002119 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2120 request = (MainThreadRequest) msg.obj;
2121
2122 final Phone phone = getPhoneFromRequest(request);
2123 if (phone == null || phone.getServiceStateTracker() == null) {
2124 request.result = new IllegalStateException("Phone or SST is null");
2125 notifyRequester(request);
2126 break;
2127 }
2128
2129 Pair<Integer, SignalStrengthUpdateRequest> pair =
2130 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2131 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2132 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002133 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002134 request.subId, pair.first /*callingUid*/,
2135 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002136 break;
2137 }
2138 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2139 ar = (AsyncResult) msg.obj;
2140 request = (MainThreadRequest) ar.userObj;
2141 // request.result will be the exception of ar if present, true otherwise.
2142 // Be cautious not to leave result null which will wait() forever
2143 request.result = ar.exception != null ? ar.exception : true;
2144 notifyRequester(request);
2145 break;
2146 }
2147 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2148 request = (MainThreadRequest) msg.obj;
2149
2150 Phone phone = getPhoneFromRequest(request);
2151 if (phone == null || phone.getServiceStateTracker() == null) {
2152 request.result = new IllegalStateException("Phone or SST is null");
2153 notifyRequester(request);
2154 break;
2155 }
2156
2157 Pair<Integer, SignalStrengthUpdateRequest> pair =
2158 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2159 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2160 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002161 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002162 request.subId, pair.first /*callingUid*/,
2163 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002164 break;
2165 }
2166 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2167 ar = (AsyncResult) msg.obj;
2168 request = (MainThreadRequest) ar.userObj;
2169 request.result = ar.exception != null ? ar.exception : true;
2170 notifyRequester(request);
2171 break;
2172 }
Jordan Liu109698e2020-11-24 14:50:34 -08002173
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002174 case CMD_GET_SLICING_CONFIG: {
2175 request = (MainThreadRequest) msg.obj;
2176 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2177 request.phone.getSlicingConfig(onCompleted);
2178 break;
2179 }
2180 case EVENT_GET_SLICING_CONFIG_DONE: {
2181 ar = (AsyncResult) msg.obj;
2182 request = (MainThreadRequest) ar.userObj;
2183 ResultReceiver result = (ResultReceiver) request.argument;
2184
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002185 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002186 Bundle bundle = new Bundle();
2187 int resultCode = 0;
2188 if (ar.exception != null) {
2189 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2190 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002191 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002192 } else if (ar.result == null) {
2193 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002194 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002195 } else {
2196 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002197 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2198 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002199 }
2200
2201 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002202 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002203 }
2204 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2205 result.send(resultCode, bundle);
2206 notifyRequester(request);
2207 break;
2208 }
2209
Sarah Chin71b3a852022-09-28 15:54:19 -07002210 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002211 request = (MainThreadRequest) msg.obj;
2212 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002213 PurchasePremiumCapabilityArgument arg =
2214 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002215 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002216 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002217 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002218 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002219
Sarah Chin71b3a852022-09-28 15:54:19 -07002220 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002221 ar = (AsyncResult) msg.obj;
2222 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002223 PurchasePremiumCapabilityArgument arg =
2224 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002225 try {
2226 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002227 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002228 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002229 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002230 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002231 + TelephonyManager.convertPurchaseResultToString(result));
2232 } catch (RemoteException e) {
2233 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002234 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002235 + " failed: " + e;
2236 if (DBG) log(logStr);
2237 AnomalyReporter.reportAnomaly(
2238 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2239 }
2240 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242
Michele Berionne5e411512020-11-13 02:36:59 +00002243 case CMD_PREPARE_UNATTENDED_REBOOT:
2244 request = (MainThreadRequest) msg.obj;
2245 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002246 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002247 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002248 notifyRequester(request);
2249 break;
2250
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 default:
2252 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2253 break;
2254 }
2255 }
Jake Hambye994d462014-02-03 13:10:13 -08002256
Pengquan Menga1bb6272018-09-06 09:59:22 -07002257 private void notifyRequester(MainThreadRequest request) {
2258 synchronized (request) {
2259 request.notifyAll();
2260 }
2261 }
2262
Jake Hambye994d462014-02-03 13:10:13 -08002263 private void handleNullReturnEvent(Message msg, String command) {
2264 AsyncResult ar = (AsyncResult) msg.obj;
2265 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2266 if (ar.exception == null) {
2267 request.result = true;
2268 } else {
2269 request.result = false;
2270 if (ar.exception instanceof CommandException) {
2271 loge(command + ": CommandException: " + ar.exception);
2272 } else {
2273 loge(command + ": Unknown exception");
2274 }
2275 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002276 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 }
2279
2280 /**
2281 * Posts the specified command to be executed on the main thread,
2282 * waits for the request to complete, and returns the result.
2283 * @see #sendRequestAsync
2284 */
2285 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002286 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2287 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002288 }
2289
2290 /**
2291 * Posts the specified command to be executed on the main thread,
2292 * waits for the request to complete, and returns the result.
2293 * @see #sendRequestAsync
2294 */
2295 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2296 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002297 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
2300 /**
2301 * Posts the specified command to be executed on the main thread,
2302 * waits for the request to complete, and returns the result.
2303 * @see #sendRequestAsync
2304 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002305 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002306 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2307 }
2308
2309 /**
2310 * Posts the specified command to be executed on the main thread,
2311 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2312 * if not timeout or null otherwise.
2313 * @see #sendRequestAsync
2314 */
2315 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2316 long timeoutInMs) {
2317 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002318 }
2319
2320 /**
2321 * Posts the specified command to be executed on the main thread,
2322 * waits for the request to complete, and returns the result.
2323 * @see #sendRequestAsync
2324 */
Nathan Harold92bed182018-10-12 18:16:49 -07002325 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002326 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002327 }
2328
2329 /**
2330 * Posts the specified command to be executed on the main thread,
2331 * waits for the request to complete, and returns the result.
2332 * @see #sendRequestAsync
2333 */
2334 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002335 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2336 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002337 }
2338
2339 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002340 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2341 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2342 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002343 * @see #sendRequestAsync
2344 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002345 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2346 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2348 throw new RuntimeException("This method will deadlock if called from the main thread.");
2349 }
2350
Nathan Harold92bed182018-10-12 18:16:49 -07002351 MainThreadRequest request = null;
2352 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2353 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2354 } else if (phone != null) {
2355 request = new MainThreadRequest(argument, phone, workSource);
2356 } else {
2357 request = new MainThreadRequest(argument, subId, workSource);
2358 }
2359
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 Message msg = mMainThreadHandler.obtainMessage(command, request);
2361 msg.sendToTarget();
2362
Rambo Wang0f050d82021-02-12 11:43:36 -08002363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002365 if (timeoutInMs >= 0) {
2366 // Wait for at least timeoutInMs before returning null request result
2367 long now = SystemClock.elapsedRealtime();
2368 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002369 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 try {
2371 request.wait(deadline - now);
2372 } catch (InterruptedException e) {
2373 // Do nothing, go back and check if request is completed or timeout
2374 } finally {
2375 now = SystemClock.elapsedRealtime();
2376 }
2377 }
2378 } else {
2379 // Wait for the request to complete
2380 while (request.result == null) {
2381 try {
2382 request.wait();
2383 } catch (InterruptedException e) {
2384 // Do nothing, go back and wait until the request is complete
2385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 }
2387 }
2388 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002389 if (request.result == null) {
2390 Log.wtf(LOG_TAG,
2391 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 return request.result;
2394 }
2395
2396 /**
2397 * Asynchronous ("fire and forget") version of sendRequest():
2398 * Posts the specified command to be executed on the main thread, and
2399 * returns immediately.
2400 * @see #sendRequest
2401 */
2402 private void sendRequestAsync(int command) {
2403 mMainThreadHandler.sendEmptyMessage(command);
2404 }
2405
2406 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002407 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002408 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002409 */
2410 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002411 sendRequestAsync(command, argument, null, null);
2412 }
2413
2414 /**
2415 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2416 * @see {@link #sendRequest(int,Object)}
2417 */
2418 private void sendRequestAsync(
2419 int command, Object argument, Phone phone, WorkSource workSource) {
2420 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002421 Message msg = mMainThreadHandler.obtainMessage(command, request);
2422 msg.sendToTarget();
2423 }
2424
2425 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 * Initialize the singleton PhoneInterfaceManager instance.
2427 * This is only done once, at startup, from PhoneApp.onCreate().
2428 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002429 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 synchronized (PhoneInterfaceManager.class) {
2431 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002432 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 } else {
2434 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2435 }
2436 return sInstance;
2437 }
2438 }
2439
2440 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002441 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002444 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002445 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002446 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2448 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002449 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002450 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002451 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002452 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002453 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002454 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 publish();
arunvoddud7401012022-12-15 16:08:12 +00002456 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002459 @VisibleForTesting
2460 public SharedPreferences getSharedPreferences() {
2461 return mTelephonySharedPreferences;
2462 }
2463
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002464 /**
2465 * Get the default phone for this device.
2466 */
2467 @VisibleForTesting
2468 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002469 Phone thePhone = getPhone(getDefaultSubscription());
2470 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2471 }
2472
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 private void publish() {
2474 if (DBG) log("publish: " + this);
2475
Peter Wangc035ce42020-01-08 21:00:22 -08002476 TelephonyFrameworkInitializer
2477 .getTelephonyServiceManager()
2478 .getTelephonyServiceRegisterer()
2479 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 }
2481
Stuart Scott584921c2015-01-15 17:10:34 -08002482 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002483 if (request.phone != null) {
2484 return request.phone;
2485 } else {
2486 return getPhoneFromSubId(request.subId);
2487 }
2488 }
2489
2490 private Phone getPhoneFromSubId(int subId) {
2491 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2492 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002493 }
2494
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002495 /**
2496 * Get phone object associated with a subscription.
2497 * Return default phone if phone object associated with subscription is null
2498 * @param subId - subscriptionId
2499 * @return phone object associated with a subscription or default phone if null.
2500 */
Ling Mac28f0212023-03-24 16:07:15 -07002501 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002502 Phone phone = getPhoneFromSubId(subId);
2503 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002504 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002505 phone = getDefaultPhone();
2506 }
2507 return phone;
2508 }
2509
Rambo Wange53e07d2022-05-10 13:01:13 -07002510 @Nullable
2511 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002512 Phone phone = getPhoneFromRequest(request);
2513 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002514 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002515 }
2516
Ling Mac28f0212023-03-24 16:07:15 -07002517 /**
2518 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2519 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2520 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2521 * @return The Phone associated the sub Id
2522 */
2523 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002524 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526
Kai Shif70f46f2021-03-03 13:59:46 -08002527 private void sendEraseModemConfig(@NonNull Phone phone) {
2528 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2529 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2530 }
2531
2532 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2533 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2534 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002535 }
2536
Peter Wang44b186e2020-01-13 23:33:09 -08002537 private boolean isImsAvailableOnDevice() {
2538 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2539 if (pm == null) {
2540 // For some reason package manger is not available.. This will fail internally anyway,
2541 // so do not throw error and allow.
2542 return true;
2543 }
2544 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2545 }
2546
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002548 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002549 }
2550
Wink Savilleb564aae2014-10-23 10:18:09 -07002551 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 if (DBG) log("dial: " + number);
2553 // No permission check needed here: This is just a wrapper around the
2554 // ACTION_DIAL intent, which is available to any app since it puts up
2555 // the UI before it does anything.
2556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 String url = createTelUrl(number);
2560 if (url == null) {
2561 return;
2562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 // PENDING: should we just silently fail if phone is offhook or ringing?
2565 PhoneConstants.State state = mCM.getState(subId);
2566 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2567 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2568 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2569 mApp.startActivity(intent);
2570 }
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 }
2574 }
2575
2576 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002577 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
Wink Savilleb564aae2014-10-23 10:18:09 -07002580 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 if (DBG) log("call: " + number);
2582
2583 // This is just a wrapper around the ACTION_CALL intent, but we still
2584 // need to do a permission check since we're calling startActivity()
2585 // from the context of the phone app.
2586 enforceCallPermission();
2587
Jordan Liu1617b712019-07-10 15:06:26 -07002588 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 != AppOpsManager.MODE_ALLOWED) {
2590 return;
2591 }
2592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 String url = createTelUrl(number);
2596 if (url == null) {
2597 return;
2598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 boolean isValid = false;
2601 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2602 if (slist != null) {
2603 for (SubscriptionInfo subInfoRecord : slist) {
2604 if (subInfoRecord.getSubscriptionId() == subId) {
2605 isValid = true;
2606 break;
2607 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002608 }
Wink Saville08874612014-08-31 19:19:58 -07002609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 if (!isValid) {
2611 return;
2612 }
Wink Saville08874612014-08-31 19:19:58 -07002613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2615 intent.putExtra(SUBSCRIPTION_KEY, subId);
2616 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2617 mApp.startActivity(intent);
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
2620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 }
2622
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002624 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002625 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2626 }
2627
Wink Savilleb564aae2014-10-23 10:18:09 -07002628 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002629 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002630 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2631 }
2632
Wink Savilleb564aae2014-10-23 10:18:09 -07002633 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002638 Phone phone = getPhone(subId);
2639 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 checkSimPin.start();
2641 return checkSimPin.unlockSim(null, pin);
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 }
2646
Wink Savilleb564aae2014-10-23 10:18:09 -07002647 public int[] supplyPukReportResultForSubscriber(int subId, String puk, 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 checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 checkSimPuk.start();
2655 return checkSimPuk.unlockSim(puk, pin);
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
2661 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002662 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 * a synchronous one.
2664 */
2665 private static class UnlockSim extends Thread {
2666
2667 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002668 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669
2670 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002671 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2672 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673
2674 // For replies from SimCard interface
2675 private Handler mHandler;
2676
2677 // For async handler to identify request type
2678 private static final int SUPPLY_PIN_COMPLETE = 100;
2679
Michele Berionne5e411512020-11-13 02:36:59 +00002680 UnlockSim(int phoneId, IccCard simCard) {
2681 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 mSimCard = simCard;
2683 }
2684
2685 @Override
2686 public void run() {
2687 Looper.prepare();
2688 synchronized (UnlockSim.this) {
2689 mHandler = new Handler() {
2690 @Override
2691 public void handleMessage(Message msg) {
2692 AsyncResult ar = (AsyncResult) msg.obj;
2693 switch (msg.what) {
2694 case SUPPLY_PIN_COMPLETE:
2695 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2696 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002697 mRetryCount = msg.arg1;
2698 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002699 CommandException.Error error = null;
2700 if (ar.exception instanceof CommandException) {
2701 error = ((CommandException) (ar.exception))
2702 .getCommandError();
2703 }
2704 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002705 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002706 } else if (error == CommandException.Error.ABORTED) {
2707 /* When UiccCardApp dispose, handle message and return
2708 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002709 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002710 } else {
2711 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2712 }
2713 } else {
2714 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 mDone = true;
2717 UnlockSim.this.notifyAll();
2718 }
2719 break;
2720 }
2721 }
2722 };
2723 UnlockSim.this.notifyAll();
2724 }
2725 Looper.loop();
2726 }
2727
2728 /*
2729 * Use PIN or PUK to unlock SIM card
2730 *
2731 * If PUK is null, unlock SIM card with PIN
2732 *
2733 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302734 *
2735 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2736 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 */
Wink Saville9de0f752013-10-22 19:04:03 -07002738 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739
2740 while (mHandler == null) {
2741 try {
2742 wait();
2743 } catch (InterruptedException e) {
2744 Thread.currentThread().interrupt();
2745 }
2746 }
2747 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2748
2749 if (puk == null) {
2750 mSimCard.supplyPin(pin, callback);
2751 } else {
2752 mSimCard.supplyPuk(puk, pin, callback);
2753 }
2754
2755 while (!mDone) {
2756 try {
2757 Log.d(LOG_TAG, "wait for done");
2758 wait();
2759 } catch (InterruptedException e) {
2760 // Restore the interrupted status
2761 Thread.currentThread().interrupt();
2762 }
2763 }
2764 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002765 int[] resultArray = new int[2];
2766 resultArray[0] = mResult;
2767 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002768
2769 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002770 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002771 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302772 // This instance is no longer reused, so quit its thread's looper.
2773 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002774
Wink Saville9de0f752013-10-22 19:04:03 -07002775 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 }
2777 }
2778
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002779 /**
2780 * This method has been removed due to privacy and stability concerns.
2781 */
2782 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002784 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2785 return;
Wink Saville36469e72014-06-11 15:17:00 -07002786 }
2787
Nathan Harold1f889d82020-06-04 17:05:26 -07002788 @Override
2789 public void updateServiceLocationWithPackageName(String callingPackage) {
2790 mApp.getSystemService(AppOpsManager.class)
2791 .checkPackage(Binder.getCallingUid(), callingPackage);
2792
Nathan Haroldf096d982020-11-18 17:18:06 -08002793 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002794 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2795 // Callers targeting S have no business invoking this method.
2796 return;
2797 }
2798
2799 LocationAccessPolicy.LocationPermissionResult locationResult =
2800 LocationAccessPolicy.checkLocationPermission(mApp,
2801 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2802 .setCallingPackage(callingPackage)
2803 .setCallingFeatureId(null)
2804 .setCallingPid(Binder.getCallingPid())
2805 .setCallingUid(Binder.getCallingUid())
2806 .setMethod("updateServiceLocation")
2807 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2808 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2809 .build());
2810 // Apps that lack location permission have no business calling this method;
2811 // however, because no permission was declared in the public API, denials must
2812 // all be "soft".
2813 switch (locationResult) {
2814 case DENIED_HARD: /* fall through */
2815 case DENIED_SOFT:
2816 return;
2817 }
2818
2819 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820 final long identity = Binder.clearCallingIdentity();
2821 try {
Ling Mac28f0212023-03-24 16:07:15 -07002822 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 } finally {
2824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 }
2827
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002828 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002829 @Override
2830 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002831 return isRadioOnWithFeature(callingPackage, null);
2832 }
2833
2834
2835 @Override
2836 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2837 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2838 callingFeatureId);
2839 }
2840
2841 @Deprecated
2842 @Override
2843 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2844 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002845 }
2846
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002848 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2849 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002851 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002852 return false;
2853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 return isRadioOnForSubscriber(subId);
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
2860 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002861 }
2862
2863 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 final Phone phone = getPhone(subId);
2867 if (phone != null) {
2868 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2869 } else {
2870 return false;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876
2877 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002878 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 }
Wink Saville36469e72014-06-11 15:17:00 -07002880
Wink Savilleb564aae2014-10-23 10:18:09 -07002881 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883
2884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 final Phone phone = getPhone(subId);
2887 if (phone != null) {
2888 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002892 }
Wink Saville36469e72014-06-11 15:17:00 -07002893 }
2894
2895 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002896 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002897 }
2898
Wink Savilleb564aae2014-10-23 10:18:09 -07002899 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002900 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901
2902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 final Phone phone = getPhone(subId);
2905 if (phone == null) {
2906 return false;
2907 }
2908 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2909 toggleRadioOnOffForSubscriber(subId);
2910 }
2911 return true;
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002915 }
Wink Saville36469e72014-06-11 15:17:00 -07002916
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002917 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002918 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002919 /*
2920 * If any of the Radios are available, it will need to be
2921 * shutdown. So return true if any Radio is available.
2922 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2926 Phone phone = PhoneFactory.getPhone(i);
2927 if (phone != null && phone.isRadioAvailable()) return true;
2928 }
2929 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2930 return false;
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002933 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002934 }
2935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002937 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 enforceModifyPermission();
2939
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2943 logv("Shutting down Phone " + i);
2944 shutdownRadioUsingPhoneId(i);
2945 }
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002948 }
2949 }
2950
2951 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002952 Phone phone = PhoneFactory.getPhone(phoneId);
2953 if (phone != null && phone.isRadioAvailable()) {
2954 phone.shutdownRadio();
2955 }
2956 }
2957
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002958 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002959 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960
Ling Ma83dc5ea2023-01-12 15:06:04 -08002961 if (!turnOn) {
2962 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2963 }
2964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2968 if (defaultPhone != null) {
2969 defaultPhone.setRadioPower(turnOn);
2970 return true;
2971 } else {
2972 loge("There's no default phone.");
2973 return false;
2974 }
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002977 }
Wink Saville36469e72014-06-11 15:17:00 -07002978 }
2979
Wink Savilleb564aae2014-10-23 10:18:09 -07002980 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002981 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982
Ling Ma83dc5ea2023-01-12 15:06:04 -08002983 if (!turnOn) {
2984 log("setRadioPowerForSubscriber off: subId=" + subId
2985 + ",callingPackage=" + getCurrentPackageName());
2986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 final Phone phone = getPhone(subId);
2990 if (phone != null) {
2991 phone.setRadioPower(turnOn);
2992 return true;
2993 } else {
2994 return false;
2995 }
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002999 }
3000
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003001 /**
3002 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3003 * no reason to power it off. When any of the voters want to power it off, it will be turned
3004 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3005 * powering it off, and these radio off votes will be cleared.
3006 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3007 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3008 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3009 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3010 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3011 * check its vote.
3012 *
3013 * @param subId The subscription ID.
3014 * @param reason The reason for powering off radio.
3015 * @return true on success and false on failure.
3016 */
3017 public boolean requestRadioPowerOffForReason(int subId,
3018 @TelephonyManager.RadioPowerReason int reason) {
3019 enforceModifyPermission();
3020
Ling Ma83dc5ea2023-01-12 15:06:04 -08003021 log("requestRadioPowerOffForReason: subId=" + subId
3022 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003023 final long identity = Binder.clearCallingIdentity();
3024 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003025 boolean result = false;
3026 for (Phone phone : PhoneFactory.getPhones()) {
3027 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003028 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003029 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003030 if (!result) {
3031 loge("requestRadioPowerOffForReason: no phone exists");
3032 }
3033 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 /**
3040 * Remove the vote on powering off the radio for a reason, as requested by
3041 * {@link requestRadioPowerOffForReason}.
3042 *
3043 * @param subId The subscription ID.
3044 * @param reason The reason for powering off radio.
3045 * @return true on success and false on failure.
3046 */
3047 public boolean clearRadioPowerOffForReason(int subId,
3048 @TelephonyManager.RadioPowerReason int reason) {
3049 enforceModifyPermission();
3050
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003053 boolean result = false;
3054 for (Phone phone : PhoneFactory.getPhones()) {
3055 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003056 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003057 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003058 if (!result) {
3059 loge("clearRadioPowerOffForReason: no phone exists");
3060 }
3061 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 /**
3068 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3069 *
3070 * @param subId The subscription ID.
3071 * @param callingPackage The package making the call.
3072 * @param callingFeatureId The feature in the package.
3073 * @return List of reasons for powering off radio.
3074 */
3075 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3076 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3077
3078 final long identity = Binder.clearCallingIdentity();
3079 List result = new ArrayList();
3080 try {
3081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3082 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3083 return result;
3084 }
3085
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003086 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003087 if (phone != null) {
3088 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003089 } else {
3090 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003091 }
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 return result;
3096 }
3097
Wink Saville36469e72014-06-11 15:17:00 -07003098 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003099 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003100 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102
3103 final long identity = Binder.clearCallingIdentity();
3104 try {
Jack Yu285100e2022-12-02 22:48:35 -08003105 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 final Phone phone = getPhone(subId);
3107 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003108 phone.getDataSettingsManager().setDataEnabled(
3109 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110 return true;
3111 } else {
3112 return false;
3113 }
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
Wink Saville36469e72014-06-11 15:17:00 -07003119 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003120 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003121 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
Jack Yu285100e2022-12-02 22:48:35 -08003126 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 final Phone phone = getPhone(subId);
3128 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003129 phone.getDataSettingsManager().setDataEnabled(
3130 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 return true;
3132 } else {
3133 return false;
3134 }
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 }
3139
Sanket Padawe356d7632015-06-22 14:03:32 -07003140 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003141 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 final Phone phone = getPhone(subId);
3145 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003146 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 } else {
3148 return false;
3149 }
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
3155 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003156 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003157 }
3158
pkanwarae03a6b2016-11-06 20:37:09 -08003159 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003160 enforceCallPermission();
3161
3162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3165 return;
3166 }
3167 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3168 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
pkanwar32d516d2016-10-14 19:37:38 -07003172 };
3173
Wink Savilleb564aae2014-10-23 10:18:09 -07003174 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003175 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176
3177 final long identity = Binder.clearCallingIdentity();
3178 try {
3179 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3180 return false;
3181 }
3182 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003188 /**
3189 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3190 * tag on getCallState Binder call.
3191 */
3192 @Deprecated
3193 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003195 if (CompatChanges.isChangeEnabled(
3196 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3197 Binder.getCallingUid())) {
3198 // Do not allow this API to be called on API version 31+, it should only be
3199 // called on old apps using this Binder call directly.
3200 throw new SecurityException("This method can only be used for applications "
3201 + "targeting API version 30 or less.");
3202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 final long identity = Binder.clearCallingIdentity();
3204 try {
Ling Mac28f0212023-03-24 16:07:15 -07003205 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3206 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
3210 }
3211
3212 @Override
3213 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3214 if (CompatChanges.isChangeEnabled(
3215 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3216 Binder.getCallingUid())) {
3217 // Check READ_PHONE_STATE for API version 31+
3218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3219 featureId, "getCallStateForSubscription")) {
3220 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3221 + "targeting API level 31+.");
3222 }
3223 }
3224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3228 PhoneConstantConversions.convertCallState(phone.getState());
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 }
3233
Sanket Padawe356d7632015-06-22 14:03:32 -07003234 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003235 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003236 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003237 }
3238
3239 @Override
3240 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 final long identity = Binder.clearCallingIdentity();
3242 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003243 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003245 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246 } else {
3247 return PhoneConstantConversions.convertDataState(
3248 PhoneConstants.DataState.DISCONNECTED);
3249 }
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
3254
Sanket Padawe356d7632015-06-22 14:03:32 -07003255 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003256 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003257 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003258 }
3259
3260 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003261 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003264 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003266 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 } else {
3268 return TelephonyManager.DATA_ACTIVITY_NONE;
3269 }
3270 } finally {
3271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003273 }
3274
3275 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003276 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003278 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003279
3280 LocationAccessPolicy.LocationPermissionResult locationResult =
3281 LocationAccessPolicy.checkLocationPermission(mApp,
3282 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3283 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003284 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003285 .setCallingPid(Binder.getCallingPid())
3286 .setCallingUid(Binder.getCallingUid())
3287 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003288 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003289 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3290 .build());
3291 switch (locationResult) {
3292 case DENIED_HARD:
3293 throw new SecurityException("Not allowed to access cell location");
3294 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003295 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3296 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297 }
3298
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003299 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003303 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003304 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
Svetoslav64fad262015-04-14 14:35:21 -07003308 }
3309
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003311 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003312 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3313 // registered cell info, so return a NULL country instead.
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003316 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3317 // Get default phone in this case.
3318 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3319 }
Jack Yu285100e2022-12-02 22:48:35 -08003320 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003322 if (phone == null) return "";
3323 ServiceStateTracker sst = phone.getServiceStateTracker();
3324 if (sst == null) return "";
3325 LocaleTracker lt = sst.getLocaleTracker();
3326 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003327 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003331 }
3332
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003333 /**
3334 * This method was removed due to potential issues caused by performing partial
3335 * updates of service state, and lack of a credible use case.
3336 *
3337 * This has the ability to break the telephony implementation by disabling notification of
3338 * changes in device connectivity. DO NOT USE THIS!
3339 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003340 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003341 public void enableLocationUpdates() {
3342 mApp.enforceCallingOrSelfPermission(
3343 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 }
3345
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003346 /**
3347 * This method was removed due to potential issues caused by performing partial
3348 * updates of service state, and lack of a credible use case.
3349 *
3350 * This has the ability to break the telephony implementation by disabling notification of
3351 * changes in device connectivity. DO NOT USE THIS!
3352 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 @Override
3354 public void disableLocationUpdates() {
3355 mApp.enforceCallingOrSelfPermission(
3356 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003357 }
3358
3359 @Override
3360 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003361 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3362 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003363 try {
3364 mApp.getSystemService(AppOpsManager.class)
3365 .checkPackage(Binder.getCallingUid(), callingPackage);
3366 } catch (SecurityException e) {
3367 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3368 throw e;
3369 }
3370
Nathan Haroldf096d982020-11-18 17:18:06 -08003371 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003372 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3373 throw new SecurityException(
3374 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3375 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003376
Jordan Liu1617b712019-07-10 15:06:26 -07003377 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003378 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3379 return null;
3380 }
Svetoslav64fad262015-04-14 14:35:21 -07003381
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003382 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003384 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003385 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386
Nathan Haroldf180aac2018-06-01 18:43:55 -07003387 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3388 for (CellInfo ci : info) {
3389 if (ci instanceof CellInfoGsm) {
3390 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3391 } else if (ci instanceof CellInfoWcdma) {
3392 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003395 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003396 }
3397
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003398 private List<CellInfo> getCachedCellInfo() {
3399 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3400 for (Phone phone : PhoneFactory.getPhones()) {
3401 List<CellInfo> info = phone.getAllCellInfo();
3402 if (info != null) cellInfos.addAll(info);
3403 }
3404 return cellInfos;
3405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003406
3407 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003408 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003410 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003411
3412 LocationAccessPolicy.LocationPermissionResult locationResult =
3413 LocationAccessPolicy.checkLocationPermission(mApp,
3414 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3415 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003416 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003417 .setCallingPid(Binder.getCallingPid())
3418 .setCallingUid(Binder.getCallingUid())
3419 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003420 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003421 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3422 .build());
3423 switch (locationResult) {
3424 case DENIED_HARD:
3425 throw new SecurityException("Not allowed to access cell info");
3426 case DENIED_SOFT:
3427 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 }
3429
Nathan Haroldf096d982020-11-18 17:18:06 -08003430 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003431 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3432 return getCachedCellInfo();
3433 }
3434
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003435 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003436 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3440 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003441 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003442 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 if (info != null) cellInfos.addAll(info);
3444 }
3445 return cellInfos;
3446 } finally {
3447 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 }
3449 }
3450
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003451 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003452 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3453 String callingFeatureId) {
3454 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3455 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003456 }
3457
3458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003459 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3460 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003461 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003462 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003463 }
3464
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003465 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3466 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003467 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003468 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003469
3470 LocationAccessPolicy.LocationPermissionResult locationResult =
3471 LocationAccessPolicy.checkLocationPermission(mApp,
3472 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3473 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003474 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003475 .setCallingPid(Binder.getCallingPid())
3476 .setCallingUid(Binder.getCallingUid())
3477 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003478 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3479 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003480 .build());
3481 switch (locationResult) {
3482 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003483 if (TelephonyPermissions
3484 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003485 // Safetynet logging for b/154934934
3486 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3487 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003488 throw new SecurityException("Not allowed to access cell info");
3489 case DENIED_SOFT:
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 }
Nathan Harold5320c422019-05-09 10:26:08 -07003495 try {
3496 cb.onCellInfo(new ArrayList<CellInfo>());
3497 } catch (RemoteException re) {
3498 // Drop without consequences
3499 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003500 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003501 }
3502
Nathan Harolda939a962019-05-09 10:13:47 -07003503
3504 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003505 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3506
3507 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3508 }
3509
3510 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003511 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003512 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
3515 final long identity = Binder.clearCallingIdentity();
3516 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003517 Phone phone = getPhone(subId);
3518 if (phone == null) {
3519 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3520 } else {
3521 phone.setCellInfoListRate(rateInMillis, workSource);
3522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
Shishir Agrawala9f32182016-04-12 12:00:16 -07003528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003529 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003530 Phone phone = PhoneFactory.getPhone(slotIndex);
3531 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003532 return null;
3533 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003534 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003535 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003536 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003537 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003538 return null;
3539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 return phone.getImei();
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003547 }
3548
3549 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003550 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3551 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3552 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3553 callingFeatureId, "getPrimaryImei")) {
3554 throw new SecurityException("Caller does not have permission");
3555 }
3556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 for (Phone phone : PhoneFactory.getPhones()) {
3559 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3560 return phone.getImei();
3561 }
3562 }
3563 throw new UnsupportedOperationException("Operation not supported");
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
3567 }
3568
3569 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003570 public String getTypeAllocationCodeForSlot(int slotIndex) {
3571 Phone phone = PhoneFactory.getPhone(slotIndex);
3572 String tac = null;
3573 if (phone != null) {
3574 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003575 try {
3576 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3577 } catch (IndexOutOfBoundsException e) {
3578 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3579 return null;
3580 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003581 }
3582 return tac;
3583 }
3584
3585 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003586 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003587 try {
3588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3589 } catch (SecurityException se) {
3590 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3591 throw new SecurityException("Package " + callingPackage + " does not belong to "
3592 + Binder.getCallingUid());
3593 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003594 Phone phone = PhoneFactory.getPhone(slotIndex);
3595 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003596 return null;
3597 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598
Jeff Davidson913390f2018-02-23 17:11:49 -08003599 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003600 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003601 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003602 return null;
3603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604
3605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 return phone.getMeid();
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
3610 }
Jack Yu2af8d712017-03-15 17:14:14 -07003611 }
3612
3613 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003614 public String getManufacturerCodeForSlot(int slotIndex) {
3615 Phone phone = PhoneFactory.getPhone(slotIndex);
3616 String manufacturerCode = null;
3617 if (phone != null) {
3618 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003619 try {
3620 manufacturerCode =
3621 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3622 } catch (IndexOutOfBoundsException e) {
3623 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3624 return null;
3625 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003626 }
3627 return manufacturerCode;
3628 }
3629
3630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003631 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3632 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003633 Phone phone = PhoneFactory.getPhone(slotIndex);
3634 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 return null;
3636 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003637 int subId = phone.getSubId();
3638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003639 mApp, subId, callingPackage, callingFeatureId,
3640 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003641 return null;
3642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643
3644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 return phone.getDeviceSvn();
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
3649 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003650 }
3651
fionaxu43304da2017-11-27 22:51:16 -08003652 @Override
3653 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 final Phone phone = getPhone(subId);
3657 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
fionaxu43304da2017-11-27 22:51:16 -08003661 }
3662
3663 @Override
3664 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 final Phone phone = getPhone(subId);
3668 return phone == null ? null : phone.getCarrierName();
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
fionaxu43304da2017-11-27 22:51:16 -08003672 }
3673
calvinpanffe225e2018-11-01 19:43:06 +08003674 @Override
chen xu0026ca62019-03-06 15:28:50 -08003675 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 final Phone phone = getPhone(subId);
3679 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003680 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
3684 }
3685
3686 @Override
chen xu0026ca62019-03-06 15:28:50 -08003687 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003691 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
chen xu651eec72018-11-11 19:03:44 -08003697 @Override
chen xu864e11c2018-12-06 22:10:03 -08003698 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3699 if (!isSubscriptionMccMnc) {
3700 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3701 }
chen xu651eec72018-11-11 19:03:44 -08003702 final Phone phone = PhoneFactory.getPhone(slotIndex);
3703 if (phone == null) {
3704 return TelephonyManager.UNKNOWN_CARRIER_ID;
3705 }
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
3712 }
3713
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003714 //
3715 // Internal helper methods.
3716 //
3717
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003718 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003719 * Make sure the caller is the calling package itself
3720 *
3721 * @throws SecurityException if the caller is not the calling package
3722 */
3723 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3724 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003725 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3726 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003727 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003728 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003729 } catch (PackageManager.NameNotFoundException e) {
3730 // packageUid is -1
3731 }
3732 if (packageUid != callingUid) {
3733 throw new SecurityException(message + ": Package " + callingPackage
3734 + " does not belong to " + callingUid);
3735 }
3736 }
3737
3738 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003739 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3740 *
3741 * @throws SecurityException if the caller does not have the required permission
3742 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003743 @VisibleForTesting
3744 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003745 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3746 }
3747
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003748 /**
arunvoddud7401012022-12-15 16:08:12 +00003749 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003750 *
3751 * @throws SecurityException if the caller does not have the required permission
3752 */
3753 @VisibleForTesting
3754 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003755 enforceReadPermission(null);
3756 }
3757
3758 /**
3759 * Make sure the caller has the READ_PHONE_STATE permissions.
3760 *
3761 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3762 */
3763 @VisibleForTesting
3764 public void enforceReadPermission(String msg) {
3765 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003766 }
3767
Shuo Qian3b6ee772019-11-13 17:43:31 -08003768 private void enforceActiveEmergencySessionPermission() {
3769 mApp.enforceCallingOrSelfPermission(
3770 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3771 }
3772
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003773 /**
3774 * Make sure the caller has the CALL_PHONE permission.
3775 *
3776 * @throws SecurityException if the caller does not have the required permission
3777 */
3778 private void enforceCallPermission() {
3779 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3780 }
3781
paulhu5a773602019-08-23 19:17:33 +08003782 private void enforceSettingsPermission() {
3783 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003784 }
3785
Michele Berionne5e411512020-11-13 02:36:59 +00003786 private void enforceRebootPermission() {
3787 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3788 }
3789
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003790 /**
3791 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3792 * @param message - log message to print.
3793 * @throws SecurityException if the caller does not have the required permission
3794 */
3795 private void enforceSatelliteCommunicationPermission(String message) {
3796 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3797 }
3798
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003799 private String createTelUrl(String number) {
3800 if (TextUtils.isEmpty(number)) {
3801 return null;
3802 }
3803
Jake Hambye994d462014-02-03 13:10:13 -08003804 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003805 }
3806
Ihab Awadf9e92732013-12-05 18:02:52 -08003807 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003808 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003809 }
3810
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003811 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003812 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003813 }
3814
Ihab Awadf9e92732013-12-05 18:02:52 -08003815 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003816 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003817 }
3818
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003819 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003820 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003821 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003822 }
3823
Sanket Padawe356d7632015-06-22 14:03:32 -07003824 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003825 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = PhoneFactory.getPhone(slotIndex);
3829 if (phone == null) {
3830 return PhoneConstants.PHONE_TYPE_NONE;
3831 } else {
3832 return phone.getPhoneType();
3833 }
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003837 }
3838
3839 /**
3840 * Returns the CDMA ERI icon index to display
3841 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003843 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3844 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3845 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003846 }
3847
Sanket Padawe356d7632015-06-22 14:03:32 -07003848 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003849 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3850 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003852 mApp, subId, callingPackage, callingFeatureId,
3853 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003854 return -1;
3855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856
3857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = getPhone(subId);
3860 if (phone != null) {
3861 return phone.getCdmaEriIconIndex();
3862 } else {
3863 return -1;
3864 }
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003868 }
3869
3870 /**
3871 * Returns the CDMA ERI icon mode,
3872 * 0 - ON
3873 * 1 - FLASHING
3874 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003875 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003876 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3877 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3878 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003879 }
3880
Sanket Padawe356d7632015-06-22 14:03:32 -07003881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003882 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3883 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003885 mApp, subId, callingPackage, callingFeatureId,
3886 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003887 return -1;
3888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889
3890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 final Phone phone = getPhone(subId);
3893 if (phone != null) {
3894 return phone.getCdmaEriIconMode();
3895 } else {
3896 return -1;
3897 }
3898 } finally {
3899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003901 }
3902
3903 /**
3904 * Returns the CDMA ERI text,
3905 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003907 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3908 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3909 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003910 }
3911
Sanket Padawe356d7632015-06-22 14:03:32 -07003912 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003913 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3914 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003916 mApp, subId, callingPackage, callingFeatureId,
3917 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003918 return null;
3919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920
3921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 final Phone phone = getPhone(subId);
3924 if (phone != null) {
3925 return phone.getCdmaEriText();
3926 } else {
3927 return null;
3928 }
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003932 }
3933
3934 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003935 * Returns the CDMA MDN.
3936 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003937 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003938 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3940 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003945 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946 return phone.getLine1Number();
3947 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003948 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 return null;
3950 }
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003953 }
3954 }
3955
3956 /**
3957 * Returns the CDMA MIN.
3958 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003959 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003960 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3962 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963
3964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 final Phone phone = getPhone(subId);
3967 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3968 return phone.getCdmaMin();
3969 } else {
3970 return null;
3971 }
3972 } finally {
3973 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003974 }
3975 }
3976
Hall Liud892bec2018-11-30 14:51:45 -08003977 @Override
3978 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3979 INumberVerificationCallback callback, String callingPackage) {
3980 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3981 != PERMISSION_GRANTED) {
3982 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3983 }
3984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3985
3986 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3987 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003988 throw new SecurityException("Calling package must be configured in the device config: "
3989 + "calling package: " + callingPackage
3990 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003991 }
3992
3993 if (range == null) {
3994 throw new NullPointerException("Range must be non-null");
3995 }
3996
3997 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003998 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003999
4000 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4001 }
4002
Junda Liuca05d5d2014-08-14 22:36:34 -07004003 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004004 * Returns true if CDMA provisioning needs to run.
4005 */
4006 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 final long identity = Binder.clearCallingIdentity();
4008 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004009 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004013 }
4014
4015 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004016 * Sets the voice mail number of a given subId.
4017 */
4018 @Override
4019 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004020 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4021 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022
4023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4026 new Pair<String, String>(alphaTag, number), new Integer(subId));
4027 return success;
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004031 }
4032
Ta-wei Yen87c49842016-05-13 21:19:52 -07004033 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004034 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4035 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004036 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4037 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004038 if (!TextUtils.equals(callingPackage, systemDialer)) {
4039 throw new SecurityException("caller must be system dialer");
4040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041
4042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4045 if (phoneAccountHandle == null) {
4046 return null;
4047 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004048 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 } finally {
4050 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004051 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004052 }
4053
4054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004055 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4056 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004059 mApp, subId, callingPackage, callingFeatureId,
4060 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004061 return null;
4062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004064 final long identity = Binder.clearCallingIdentity();
4065 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004066 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004067 } finally {
4068 Binder.restoreCallingIdentity(identity);
4069 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004070 }
4071
4072 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004073 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4074 VisualVoicemailSmsFilterSettings settings) {
4075 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004080 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004084 }
4085
4086 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004087 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4088 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004093 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 } finally {
4095 Binder.restoreCallingIdentity(identity);
4096 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004097 }
4098
4099 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004100 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4101 String callingPackage, int subId) {
4102 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103
4104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004107 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004111 }
4112
4113 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004114 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116
4117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004124 }
4125
4126 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004127 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4128 String callingAttributionTag, int subId, String number, int port, String text,
4129 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004131 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004132 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004133 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004134 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4135 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004136 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004137
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004138 /**
fionaxu0152e512016-11-14 13:36:14 -08004139 * Sets the voice activation state of a given subId.
4140 */
4141 @Override
4142 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4144 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145
4146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 final Phone phone = getPhone(subId);
4149 if (phone != null) {
4150 phone.setVoiceActivationState(activationState);
4151 } else {
4152 loge("setVoiceActivationState fails with invalid subId: " + subId);
4153 }
4154 } finally {
4155 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004156 }
4157 }
4158
4159 /**
4160 * Sets the data activation state of a given subId.
4161 */
4162 @Override
4163 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4165 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
4169 final Phone phone = getPhone(subId);
4170 if (phone != null) {
4171 phone.setDataActivationState(activationState);
4172 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004173 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174 }
4175 } finally {
4176 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004177 }
4178 }
4179
4180 /**
4181 * Returns the voice activation state of a given subId.
4182 */
4183 @Override
4184 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186
fionaxu0152e512016-11-14 13:36:14 -08004187 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 if (phone != null) {
4191 return phone.getVoiceActivationState();
4192 } else {
4193 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4194 }
4195 } finally {
4196 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004197 }
4198 }
4199
4200 /**
4201 * Returns the data activation state of a given subId.
4202 */
4203 @Override
4204 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004206
fionaxu0152e512016-11-14 13:36:14 -08004207 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 final long identity = Binder.clearCallingIdentity();
4209 try {
4210 if (phone != null) {
4211 return phone.getDataActivationState();
4212 } else {
4213 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4214 }
4215 } finally {
4216 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004217 }
4218 }
4219
4220 /**
Wink Saville36469e72014-06-11 15:17:00 -07004221 * Returns the unread count of voicemails for a subId
4222 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004223 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004224 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4225 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004227 mApp, subId, callingPackage, callingFeatureId,
4228 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004229 return 0;
4230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 final Phone phone = getPhone(subId);
4234 if (phone != null) {
4235 return phone.getVoiceMessageCount();
4236 } else {
4237 return 0;
4238 }
4239 } finally {
4240 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004242 }
4243
4244 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004245 * returns true, if the device is in a state where both voice and data
4246 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004247 */
4248 @Override
4249 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 final long identity = Binder.clearCallingIdentity();
4251 try {
Ling Mac28f0212023-03-24 16:07:15 -07004252 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004256 }
4257
4258 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004259 * Send the dialer code if called from the current default dialer or the caller has
4260 * carrier privilege.
4261 * @param inputCode The dialer code to send
4262 */
4263 @Override
4264 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004265 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004267 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4268 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004269 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004270 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004276 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 } finally {
4278 Binder.restoreCallingIdentity(identity);
4279 }
fionaxu235cc5e2017-03-06 22:25:57 -08004280 }
4281
Pengquan Menga1bb6272018-09-06 09:59:22 -07004282 @Override
4283 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004284 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004285 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4286 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 if (!isActiveSubscription(subId)) {
4290 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4291 }
4292 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4293 } finally {
4294 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004295 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004296 }
4297
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004299 public boolean isInEmergencySmsMode() {
4300 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 for (Phone phone : PhoneFactory.getPhones()) {
4304 if (phone.isInEmergencySmsMode()) {
4305 return true;
4306 }
4307 }
4308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
4311 return false;
4312 }
4313
shilu366312e2019-12-17 09:28:10 -08004314 /**
4315 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4316 * @param subId The subscription to use to check the configuration.
4317 * @param c The callback that will be used to send the result.
4318 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004319 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004320 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4321 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004322 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004323 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004324
4325 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4326 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4327 "IMS not available on device.");
4328 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004329 final long token = Binder.clearCallingIdentity();
4330 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004331 int slotId = getSlotIndexOrException(subId);
4332 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004333
4334 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4335 if (controller != null) {
4336 ImsManager imsManager = controller.getImsManager(subId);
4337 if (imsManager != null) {
4338 imsManager.addRegistrationCallbackForSubscription(c, subId);
4339 } else {
4340 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4341 }
4342 } else {
4343 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4344 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004345 } catch (ImsException e) {
4346 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 } finally {
4348 Binder.restoreCallingIdentity(token);
4349 }
4350 }
4351
shilu366312e2019-12-17 09:28:10 -08004352 /**
4353 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4354 * @param subId The subscription to use to check the configuration.
4355 * @param c The callback that will be used to send the result.
4356 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004358 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004359 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004360 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004361 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4362 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4363 }
Meng Wangafbc5852019-09-19 17:37:13 -07004364 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004365
Meng Wangafbc5852019-09-19 17:37:13 -07004366 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004367 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4368 if (controller != null) {
4369 ImsManager imsManager = controller.getImsManager(subId);
4370 if (imsManager != null) {
4371 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4372 } else {
4373 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4374 + "is inactive, ignoring unregister.");
4375 // If the ImsManager is not valid, just return, since the callback
4376 // will already have been removed internally.
4377 }
4378 }
Meng Wangafbc5852019-09-19 17:37:13 -07004379 } finally {
4380 Binder.restoreCallingIdentity(token);
4381 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 }
4383
Brad Ebingera34a6c22019-10-22 17:36:18 -07004384 /**
4385 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4386 */
4387 @Override
4388 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4389 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4390 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4391 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4392 "IMS not available on device.");
4393 }
4394 final long token = Binder.clearCallingIdentity();
4395 try {
4396 Phone phone = getPhone(subId);
4397 if (phone == null) {
4398 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4399 + subId + "'");
4400 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4401 }
4402 phone.getImsRegistrationState(regState -> {
4403 try {
4404 consumer.accept((regState == null)
4405 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4406 } catch (RemoteException e) {
4407 // Ignore if the remote process is no longer available to call back.
4408 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4409 }
4410 });
4411 } finally {
4412 Binder.restoreCallingIdentity(token);
4413 }
4414 }
4415
4416 /**
4417 * Get the transport type for the IMS service registration state.
4418 */
4419 @Override
4420 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004421 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004422 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004423 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4424 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4425 "IMS not available on device.");
4426 }
4427 final long token = Binder.clearCallingIdentity();
4428 try {
4429 Phone phone = getPhone(subId);
4430 if (phone == null) {
4431 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4432 + subId + "'");
4433 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4434 }
4435 phone.getImsRegistrationTech(regTech -> {
4436 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4437 int regTechConverted = (regTech == null)
4438 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4439 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4440 regTechConverted);
4441 try {
4442 consumer.accept(regTechConverted);
4443 } catch (RemoteException e) {
4444 // Ignore if the remote process is no longer available to call back.
4445 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4446 }
4447 });
4448 } finally {
4449 Binder.restoreCallingIdentity(token);
4450 }
4451 }
4452
shilu366312e2019-12-17 09:28:10 -08004453 /**
4454 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4455 * @param subId The subscription to use to check the configuration.
4456 * @param c The callback that will be used to send the result.
4457 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004458 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004459 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4460 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004461 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004462 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004463 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4464 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4465 "IMS not available on device.");
4466 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 final long token = Binder.clearCallingIdentity();
4468 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004469 int slotId = getSlotIndexOrException(subId);
4470 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004471
4472 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4473 if (controller != null) {
4474 ImsManager imsManager = controller.getImsManager(subId);
4475 if (imsManager != null) {
4476 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4477 } else {
4478 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4479 }
4480 } else {
4481 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4482 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004483 } catch (ImsException e) {
4484 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 } finally {
4486 Binder.restoreCallingIdentity(token);
4487 }
4488 }
4489
shilu366312e2019-12-17 09:28:10 -08004490 /**
4491 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4492 * @param subId The subscription to use to check the configuration.
4493 * @param c The callback that will be used to send the result.
4494 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004496 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004497 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004498 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004499 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4500 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4501 }
Meng Wangafbc5852019-09-19 17:37:13 -07004502
4503 final long token = Binder.clearCallingIdentity();
4504 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004505 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4506 if (controller != null) {
4507 ImsManager imsManager = controller.getImsManager(subId);
4508 if (imsManager != null) {
4509 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4510 } else {
4511 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4512 + " is inactive, ignoring unregister.");
4513 // If the ImsManager is not valid, just return, since the callback
4514 // will already have been removed internally.
4515 }
4516 }
Meng Wangafbc5852019-09-19 17:37:13 -07004517 } finally {
4518 Binder.restoreCallingIdentity(token);
4519 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004520 }
4521
4522 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004523 public boolean isCapable(int subId, int capability, int regTech) {
4524 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004525 final long token = Binder.clearCallingIdentity();
4526 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004527 int slotId = getSlotIndexOrException(subId);
4528 verifyImsMmTelConfiguredOrThrow(slotId);
4529 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4530 } catch (com.android.ims.ImsException e) {
4531 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4532 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004533 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004534 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4535 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004536 } finally {
4537 Binder.restoreCallingIdentity(token);
4538 }
4539 }
4540
4541 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004542 public boolean isAvailable(int subId, int capability, int regTech) {
4543 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 final long token = Binder.clearCallingIdentity();
4545 try {
4546 Phone phone = getPhone(subId);
4547 if (phone == null) return false;
4548 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004549 } catch (com.android.ims.ImsException e) {
4550 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4551 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004552 } finally {
4553 Binder.restoreCallingIdentity(token);
4554 }
4555 }
4556
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004557 /**
4558 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4559 * subscription.
4560 * @param subId The subscription to use to check the configuration.
4561 * @param callback The callback that will be used to send the result.
4562 * @param capability The MmTelFeature capability that will be used to send the result.
4563 * @param transportType The transport type of the MmTelFeature capability.
4564 */
4565 @Override
4566 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4567 int transportType) {
4568 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004569 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4570 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4571 "IMS not available on device.");
4572 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004573 final long token = Binder.clearCallingIdentity();
4574 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004575 int slotId = getSlotIndex(subId);
4576 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4577 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4578 + subId + "'");
4579 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4580 }
4581 verifyImsMmTelConfiguredOrThrow(slotId);
4582 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4583 transportType, aBoolean -> {
4584 try {
4585 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4586 } catch (RemoteException e) {
4587 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4588 + "running. Ignore");
4589 }
4590 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004591 } catch (ImsException e) {
4592 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004593 } finally {
4594 Binder.restoreCallingIdentity(token);
4595 }
4596 }
4597
shilu366312e2019-12-17 09:28:10 -08004598 /**
4599 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4600 * @param subId The subscription to use to check the configuration.
4601 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004602 @Override
4603 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004604 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004605 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004606
Brad Ebinger35c841c2018-10-01 10:40:55 -07004607 final long token = Binder.clearCallingIdentity();
4608 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004609 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004610 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004611 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004612 } catch (ImsException e) {
4613 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004614 } finally {
4615 Binder.restoreCallingIdentity(token);
4616 }
4617 }
4618
4619 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004620 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004622 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 final long identity = Binder.clearCallingIdentity();
4624 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004625 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004626 // This setting doesn't require an active ImsService connection, so do not verify. The
4627 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004628 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004629 } catch (ImsException e) {
4630 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
4634 }
4635
shilu366312e2019-12-17 09:28:10 -08004636 /**
4637 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4638 * @param subId The subscription to use to check the configuration.
4639 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004640 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004641 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004642 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004643 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004644 final long identity = Binder.clearCallingIdentity();
4645 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004646 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004647 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004648 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004649 } catch (ImsException e) {
4650 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
4654 }
4655
4656 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004657 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004659 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004660 final long identity = Binder.clearCallingIdentity();
4661 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004662 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004663 // This setting doesn't require an active ImsService connection, so do not verify. The
4664 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004665 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004666 } catch (ImsException e) {
4667 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
4671 }
4672
shilu366312e2019-12-17 09:28:10 -08004673 /**
4674 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4675 * @param subId The subscription to use to check the configuration.
4676 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004677 @Override
4678 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004679 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004680 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004681 final long identity = Binder.clearCallingIdentity();
4682 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004683 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004684 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004685 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004686 } catch (ImsException e) {
4687 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004688 } finally {
4689 Binder.restoreCallingIdentity(identity);
4690 }
4691 }
4692
4693 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004694 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004696 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004697 final long identity = Binder.clearCallingIdentity();
4698 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004699 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004700 // This setting doesn't require an active ImsService connection, so do not verify. The
4701 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004702 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004703 } catch (ImsException e) {
4704 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
4708 }
4709
shilu366312e2019-12-17 09:28:10 -08004710 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004711 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4712 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4713 * @param subId The subscription to use to check the configuration.
4714 */
4715 @Override
4716 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004717 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004718 mApp, subId, "isCrossSimCallingEnabledByUser");
4719 final long identity = Binder.clearCallingIdentity();
4720 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004721 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004722 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004723 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004724 } catch (ImsException e) {
4725 throw new ServiceSpecificException(e.getCode());
4726 } finally {
4727 Binder.restoreCallingIdentity(identity);
4728 }
4729 }
4730
4731 /**
4732 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4733 * Requires MODIFY_PHONE_STATE permission.
4734 * @param subId The subscription to use to check the configuration.
4735 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4736 * false otherwise
4737 */
4738 @Override
4739 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4741 "setCrossSimCallingEnabled");
4742 final long identity = Binder.clearCallingIdentity();
4743 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004744 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004745 // This setting doesn't require an active ImsService connection, so do not verify. The
4746 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004747 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004748 } catch (ImsException e) {
4749 throw new ServiceSpecificException(e.getCode());
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
4753 }
4754
4755 /**
shilu366312e2019-12-17 09:28:10 -08004756 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4757 * @param subId The subscription to use to check the configuration.
4758 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004759 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004760
Brad Ebinger35c841c2018-10-01 10:40:55 -07004761 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004762 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004763 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004764 final long identity = Binder.clearCallingIdentity();
4765 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004766 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004767 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004768 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004769 } catch (ImsException e) {
4770 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
4774 }
4775
4776 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004777 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004779 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004780 final long identity = Binder.clearCallingIdentity();
4781 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004782 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004783 // This setting doesn't require an active ImsService connection, so do not verify. The
4784 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004785 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004786 } catch (ImsException e) {
4787 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
4791 }
4792
4793 @Override
4794 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4796 "setVoWiFiNonPersistent");
4797 final long identity = Binder.clearCallingIdentity();
4798 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004799 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004800 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004801 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004802 } catch (ImsException e) {
4803 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004804 } finally {
4805 Binder.restoreCallingIdentity(identity);
4806 }
4807 }
4808
shilu366312e2019-12-17 09:28:10 -08004809 /**
4810 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4811 * @param subId The subscription to use to check the configuration.
4812 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 @Override
4814 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004815 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004816 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004817 final long identity = Binder.clearCallingIdentity();
4818 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004819 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004820 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004821 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004822 } catch (ImsException e) {
4823 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004824 } finally {
4825 Binder.restoreCallingIdentity(identity);
4826 }
4827 }
4828
4829 @Override
4830 public void setVoWiFiModeSetting(int subId, int mode) {
4831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4832 "setVoWiFiModeSetting");
4833 final long identity = Binder.clearCallingIdentity();
4834 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004835 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004836 // This setting doesn't require an active ImsService connection, so do not verify. The
4837 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004838 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004839 } catch (ImsException e) {
4840 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004841 } finally {
4842 Binder.restoreCallingIdentity(identity);
4843 }
4844 }
4845
4846 @Override
4847 public int getVoWiFiRoamingModeSetting(int subId) {
4848 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4849 final long identity = Binder.clearCallingIdentity();
4850 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004851 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004852 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004853 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004854 } catch (ImsException e) {
4855 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
4859 }
4860
4861 @Override
4862 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4864 "setVoWiFiRoamingModeSetting");
4865 final long identity = Binder.clearCallingIdentity();
4866 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004867 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004868 // This setting doesn't require an active ImsService connection, so do not verify. The
4869 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004870 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004871 } catch (ImsException e) {
4872 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004873 } finally {
4874 Binder.restoreCallingIdentity(identity);
4875 }
4876 }
4877
4878 @Override
4879 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4881 "setRttCapabilityEnabled");
4882 final long identity = Binder.clearCallingIdentity();
4883 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004884 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004885 // This setting doesn't require an active ImsService connection, so do not verify. The
4886 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004887 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004888 } catch (ImsException e) {
4889 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004890 } finally {
4891 Binder.restoreCallingIdentity(identity);
4892 }
4893 }
4894
shilu366312e2019-12-17 09:28:10 -08004895 /**
4896 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4897 * @param subId The subscription to use to check the configuration.
4898 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004899 @Override
4900 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004901 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004902 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004903 final long identity = Binder.clearCallingIdentity();
4904 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004905 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004906 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004907 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004908 } catch (ImsException e) {
4909 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
4913 }
4914
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004915 @Override
4916 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4917 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004918
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004919 final long identity = Binder.clearCallingIdentity();
4920 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004921 if (!isImsAvailableOnDevice()) {
4922 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4923 "IMS not available on device.");
4924 }
4925 int slotId = getSlotIndexOrException(subId);
4926 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004927
4928 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4929 if (controller != null) {
4930 ImsManager imsManager = controller.getImsManager(subId);
4931 if (imsManager != null) {
4932 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4933 } else {
4934 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4935 }
4936 } else {
4937 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4938 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004939 } catch (ImsException e) {
4940 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004941 } finally {
4942 Binder.restoreCallingIdentity(identity);
4943 }
4944 }
4945
4946 @Override
4947 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4948 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004949
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004950 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004951 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4952 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4953 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004954 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004955 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4956 if (controller != null) {
4957 ImsManager imsManager = controller.getImsManager(subId);
4958 if (imsManager != null) {
4959 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4960 } else {
4961 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4962 + " is inactive, ignoring unregister.");
4963 // If the ImsManager is not valid, just return, since the callback will already
4964 // have been removed internally.
4965 }
4966 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
4970 }
4971
joonhunshincffb7fc2021-11-28 07:32:01 +00004972 @Override
4973 public void registerFeatureProvisioningChangedCallback(int subId,
4974 IFeatureProvisioningCallback callback) {
4975 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4976 mApp, subId, "registerFeatureProvisioningChangedCallback");
4977
4978 final long identity = Binder.clearCallingIdentity();
4979 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4980 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4981 }
4982
joonhunshin91bc1952022-04-29 08:47:15 +00004983 try {
4984 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4985 if (controller == null) {
4986 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4987 "Device does not support IMS");
4988 }
4989 controller.addFeatureProvisioningChangedCallback(subId, callback);
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004993 }
4994
4995 @Override
4996 public void unregisterFeatureProvisioningChangedCallback(int subId,
4997 IFeatureProvisioningCallback callback) {
4998 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4999 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5000
5001 final long identity = Binder.clearCallingIdentity();
5002 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5003 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5004 }
5005
joonhunshin91bc1952022-04-29 08:47:15 +00005006 try {
5007 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5008 if (controller == null) {
5009 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5010 return;
5011 }
5012 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005016 }
allenwtsu99c623b2020-01-03 18:24:23 +08005017
5018 private void checkModifyPhoneStatePermission(int subId, String message) {
5019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5020 message);
5021 }
5022
allenwtsu99c623b2020-01-03 18:24:23 +08005023 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005024 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005025 boolean isProvisioned) {
5026 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5027
5028 final long identity = Binder.clearCallingIdentity();
5029 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005030 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5031 if (controller == null) {
5032 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5033 return;
5034 }
5035 controller.setRcsProvisioningStatusForCapability(
5036 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005037 } finally {
5038 Binder.restoreCallingIdentity(identity);
5039 }
allenwtsu99c623b2020-01-03 18:24:23 +08005040 }
5041
5042
5043 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005044 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5045 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5046 mApp, subId, "getRcsProvisioningStatusForCapability");
5047
allenwtsu99c623b2020-01-03 18:24:23 +08005048 final long identity = Binder.clearCallingIdentity();
5049 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005050 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5051 if (controller == null) {
5052 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5053
5054 // device does not support IMS, this method will return true always.
5055 return true;
5056 }
5057 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
5061 }
5062
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005063 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005064 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5065 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005066 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005067
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005068 final long identity = Binder.clearCallingIdentity();
5069 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005070 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5071 if (controller == null) {
5072 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5073 return;
5074 }
5075 controller.setImsProvisioningStatusForCapability(
5076 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005077 } finally {
5078 Binder.restoreCallingIdentity(identity);
5079 }
5080 }
5081
5082 @Override
5083 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005084 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5085 mApp, subId, "getProvisioningStatusForCapability");
5086
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005089 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5090 if (controller == null) {
5091 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005092
joonhunshin91bc1952022-04-29 08:47:15 +00005093 // device does not support IMS, this method will return true always.
5094 return true;
5095 }
5096 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005097 } finally {
5098 Binder.restoreCallingIdentity(identity);
5099 }
5100 }
5101
5102 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005103 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5104 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5105 mApp, subId, "isProvisioningRequiredForCapability");
5106
5107 final long identity = Binder.clearCallingIdentity();
5108 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005109 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5110 if (controller == null) {
5111 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5112
5113 // device does not support IMS, this method will return false
5114 return false;
5115 }
5116 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005117 } finally {
5118 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005119 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005120 }
5121
5122 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005123 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5124 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5125 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005126
joonhunshincffb7fc2021-11-28 07:32:01 +00005127 final long identity = Binder.clearCallingIdentity();
5128 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005129 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5130 if (controller == null) {
5131 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5132
5133 // device does not support IMS, this method will return false
5134 return false;
5135 }
5136 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005137 } finally {
5138 Binder.restoreCallingIdentity(identity);
5139 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005140 }
5141
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005142 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005143 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005144 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5145 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5146 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005147 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5148 mApp, subId, "getImsProvisioningInt");
5149
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005153 int slotId = getSlotIndex(subId);
5154 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5155 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5156 + subId + "' for key:" + key);
5157 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5158 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005159
joonhunshin91bc1952022-04-29 08:47:15 +00005160 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5161 if (controller == null) {
5162 loge("getImsProvisioningInt: Device does not support IMS");
5163
5164 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5165 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5166 }
5167 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005168 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5169 return retVal;
5170 }
5171
calvinpanb5a34062021-02-08 19:59:36 +08005172 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005173 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005174 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5175 + subId + "' for key:" + key);
5176 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
5180 }
5181
5182 @Override
5183 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005184 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5185 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5186 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005187 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5188 mApp, subId, "getImsProvisioningString");
5189
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005190 final long identity = Binder.clearCallingIdentity();
5191 try {
5192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005193 int slotId = getSlotIndex(subId);
5194 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5195 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5196 + subId + "' for key:" + key);
5197 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5198 }
calvinpanb5a34062021-02-08 19:59:36 +08005199 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005200 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005201 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5202 + subId + "' for key:" + key);
5203 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206 }
5207 }
5208
5209 @Override
5210 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005211 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5212 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5213 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5215 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005216
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005217 final long identity = Binder.clearCallingIdentity();
5218 try {
5219 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005220 int slotId = getSlotIndex(subId);
5221 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5222 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5223 + subId + "' for key:" + key);
5224 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5225 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005226
joonhunshin91bc1952022-04-29 08:47:15 +00005227 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5228 if (controller == null) {
5229 loge("setImsProvisioningInt: Device does not support IMS");
5230
5231 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5232 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5233 }
5234 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005235 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5236 return retVal;
5237 }
5238
calvinpanb5a34062021-02-08 19:59:36 +08005239 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5240 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005241 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005242 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005243 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
5247 }
5248
5249 @Override
5250 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005251 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5252 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5253 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5255 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005256 final long identity = Binder.clearCallingIdentity();
5257 try {
5258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005259 int slotId = getSlotIndex(subId);
5260 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5261 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5262 + subId + "' for key:" + key);
5263 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5264 }
calvinpanb5a34062021-02-08 19:59:36 +08005265 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5266 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005267 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005268 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005269 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
5273 }
5274
Brad Ebinger919631e2021-06-02 17:46:35 -07005275 /**
5276 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5277 * for the given slot ID or no ImsResolver instance has been created.
5278 * @param slotId The slot ID that the IMS service is created for.
5279 * @throws ImsException If there is no ImsService configured for this slot.
5280 */
5281 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5282 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5283 ImsFeature.FEATURE_MMTEL)) {
5284 throw new ImsException("This subscription does not support MMTEL over IMS",
5285 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5286 }
5287 }
5288
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005289 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005290 int slotId = SubscriptionManager.getSlotIndex(subId);
5291 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005292 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5293 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005294 }
5295 return slotId;
5296 }
5297
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005298 private int getSlotIndex(int subId) {
5299 int slotId = SubscriptionManager.getSlotIndex(subId);
5300 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5301 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5302 }
5303 return slotId;
5304 }
5305
Wink Saville36469e72014-06-11 15:17:00 -07005306 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005307 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005308 */
5309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005310 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5311 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005312 try {
5313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5314 } catch (SecurityException se) {
5315 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5316 throw new SecurityException("Package " + callingPackage + " does not belong to "
5317 + Binder.getCallingUid());
5318 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005319 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005320 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005321 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005322 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005323 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005324 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005325 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005326 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5327 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 final long identity = Binder.clearCallingIdentity();
5330 try {
5331 final Phone phone = getPhone(subId);
5332 if (phone != null) {
5333 return phone.getServiceState().getDataNetworkType();
5334 } else {
5335 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5336 }
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005340 }
5341
5342 /**
5343 * Returns the data network type
5344 */
5345 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005346 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005347 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005348 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005349 }
5350
5351 /**
5352 * Returns the data network type for a subId
5353 */
5354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005355 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5356 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005357 String functionName = "getDataNetworkTypeForSubscriber";
5358 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5359 mApp, functionName)) {
5360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5361 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5362 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5363 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005364 }
5365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 final long identity = Binder.clearCallingIdentity();
5367 try {
5368 final Phone phone = getPhone(subId);
5369 if (phone != null) {
5370 return phone.getServiceState().getDataNetworkType();
5371 } else {
5372 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5373 }
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005377 }
5378
5379 /**
Wink Saville36469e72014-06-11 15:17:00 -07005380 * Returns the Voice network type for a subId
5381 */
5382 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005383 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5384 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005385 String functionName = "getVoiceNetworkTypeForSubscriber";
5386 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5387 mApp, functionName)) {
5388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5389 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5390 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5391 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005392 }
5393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 final Phone phone = getPhone(subId);
5397 if (phone != null) {
5398 return phone.getServiceState().getVoiceNetworkType();
5399 } else {
5400 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5401 }
5402 } finally {
5403 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005405 }
5406
5407 /**
5408 * @return true if a ICC card is present
5409 */
5410 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005411 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005412 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005413 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005414 }
5415
5416 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005417 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005418 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005419 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005420 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 final long identity = Binder.clearCallingIdentity();
5422 try {
5423 final Phone phone = PhoneFactory.getPhone(slotIndex);
5424 if (phone != null) {
5425 return phone.getIccCard().hasIccCard();
5426 } else {
5427 return false;
5428 }
5429 } finally {
5430 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005432 }
5433
5434 /**
5435 * Return if the current radio is LTE on CDMA. This
5436 * is a tri-state return value as for a period of time
5437 * the mode may be unknown.
5438 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005439 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005440 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005441 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005442 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005443 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005444 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5445 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5446 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005447 }
5448
Sanket Padawe356d7632015-06-22 14:03:32 -07005449 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005450 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5451 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005452 try {
5453 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5454 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005455 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5456 }
5457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 final long identity = Binder.clearCallingIdentity();
5459 try {
5460 final Phone phone = getPhone(subId);
5461 if (phone == null) {
5462 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5463 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005464 return TelephonyProperties.lte_on_cdma_device()
5465 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 }
5467 } finally {
5468 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005469 }
Wink Saville36469e72014-06-11 15:17:00 -07005470 }
5471
Wink Saville36469e72014-06-11 15:17:00 -07005472 /**
5473 * {@hide}
5474 * Returns Default subId, 0 in the case of single standby.
5475 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005476 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005477 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005478 }
5479
Shishir Agrawala9f32182016-04-12 12:00:16 -07005480 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005481 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005482 }
5483
Wink Savilleb564aae2014-10-23 10:18:09 -07005484 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005485 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005486 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005487
Pengquan Menge92a50d2018-09-21 15:54:48 -07005488 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005489 return getSubscriptionManagerService().isActiveSubId(subId,
5490 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005491 }
5492
Ihab Awadf2177b72013-11-25 13:33:23 -08005493 /**
5494 * @see android.telephony.TelephonyManager.WifiCallingChoices
5495 */
5496 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 final long identity = Binder.clearCallingIdentity();
5498 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005499 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5501 getWhenToMakeWifiCallsDefaultPreference());
5502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005505 }
5506
5507 /**
5508 * @see android.telephony.TelephonyManager.WifiCallingChoices
5509 */
5510 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005514 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005519 }
5520
Sailesh Nepald1e68152013-12-12 19:08:02 -08005521 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005522 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005523 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005524 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005525
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005526 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5527 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5528 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005529 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005530 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005531 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005532 }
5533 return PhoneFactory.getPhone(phoneId);
5534 }
5535
Shishir Agrawal566b7612013-10-28 14:41:00 -07005536 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005537 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005538 @NonNull IccLogicalChannelRequest request) {
5539 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5540 /*message=*/ "iccOpenLogicalChannel");
5541
5542 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5543 // Verify that the callingPackage in the request belongs to the calling UID
5544 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5545
5546 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005547 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005548
Rambo Wanga1782702021-11-10 20:15:19 -08005549 private Phone getPhoneFromValidIccLogicalChannelRequest(
5550 @NonNull IccLogicalChannelRequest request, String message) {
5551 Phone phone;
5552 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5554 mApp, request.subId, message);
5555 phone = getPhoneFromSubId(request.subId);
5556 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5557 enforceModifyPermission();
5558 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5559 } else {
5560 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005561 }
Rambo Wanga1782702021-11-10 20:15:19 -08005562 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005563 }
5564
5565 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005566 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 final long identity = Binder.clearCallingIdentity();
5568 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005569 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005571 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5572 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005573 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5574 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 loge("The calling package is not allowed to access ISD-R.");
5576 throw new SecurityException(
5577 "The calling package is not allowed to access ISD-R.");
5578 }
Derek Tan740e1672017-06-27 14:56:27 -07005579 }
Derek Tan740e1672017-06-27 14:56:27 -07005580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005582 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5583 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 return response;
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005588 }
5589
5590 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005591 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5592 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5593 /*message=*/"iccCloseLogicalChannel");
5594
5595 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5596
5597 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005598 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005599
Rambo Wanga1782702021-11-10 20:15:19 -08005600 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5601 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005602 // before this feature is enabled, this API should only return false if
5603 // the operation fails instead of throwing runtime exception for
5604 // backward-compatibility.
5605 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5606 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 final long identity = Binder.clearCallingIdentity();
5608 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005609 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005610 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 }
Chen Xue9d737e2022-01-01 23:41:31 -08005612 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005613 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005614 Boolean success = false;
5615 if (result instanceof RuntimeException) {
5616 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005617 if (shouldThrowExceptionOnFailure) {
5618 throw (RuntimeException) result;
5619 } else {
5620 return false;
5621 }
Chen Xue9d737e2022-01-01 23:41:31 -08005622 } else if (result instanceof Boolean) {
5623 success = (Boolean) result;
5624 } else {
5625 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5626 }
Rambo Wanga1782702021-11-10 20:15:19 -08005627 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 return success;
5629 } finally {
5630 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005631 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005632 }
5633
5634 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005635 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005636 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5638 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005639 if (DBG) {
5640 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5641 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5642 + p3 + " data=" + data);
5643 }
5644 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5645 command, p1, p2, p3, data);
5646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005647
Jordan Liu4c733742019-02-28 12:03:40 -08005648 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005649 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005650 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005651 enforceModifyPermission();
5652 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005653 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005654 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5655 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005656 }
5657 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005658 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5659 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005660 }
5661
5662 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5663 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 final long identity = Binder.clearCallingIdentity();
5665 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005666 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 return "";
5668 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005671 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5672 null /* workSource */);
5673 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 // Append the returned status code to the end of the response payload.
5676 String s = Integer.toHexString(
5677 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5678 if (response.payload != null) {
5679 s = IccUtils.bytesToHexString(response.payload) + s;
5680 }
5681 return s;
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005684 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005685 }
Jake Hambye994d462014-02-03 13:10:13 -08005686
Evan Charltonc66da362014-05-16 14:06:40 -07005687 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005688 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5689 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005693 if (DBG) {
5694 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5695 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5696 }
5697 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5698 cla, command, p1, p2, p3, data);
5699 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005700
Jordan Liu4c733742019-02-28 12:03:40 -08005701 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005702 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005703 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005704 enforceModifyPermission();
5705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5706 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005707 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005708 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5709 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005710 }
5711
5712 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005713 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5714 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005715 }
5716
5717 // open APDU basic channel assuming the caller has sufficient permissions
5718 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5719 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5723 && TextUtils.equals(ISDR_AID, data)) {
5724 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5726 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 if (bestComponent == null
5728 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5729 loge("The calling package is not allowed to select ISD-R.");
5730 throw new SecurityException(
5731 "The calling package is not allowed to select ISD-R.");
5732 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005733 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005736 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5737 null /* workSource */);
5738 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 // Append the returned status code to the end of the response payload.
5741 String s = Integer.toHexString(
5742 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5743 if (response.payload != null) {
5744 s = IccUtils.bytesToHexString(response.payload) + s;
5745 }
5746 return s;
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005749 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005750 }
5751
5752 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005753 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005754 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5756 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758 final long identity = Binder.clearCallingIdentity();
5759 try {
5760 if (DBG) {
5761 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5762 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5763 }
5764
5765 IccIoResult response =
5766 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5767 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5768 subId);
5769
5770 if (DBG) {
5771 log("Exchange SIM_IO [R]" + response);
5772 }
5773
5774 byte[] result = null;
5775 int length = 2;
5776 if (response.payload != null) {
5777 length = 2 + response.payload.length;
5778 result = new byte[length];
5779 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5780 } else {
5781 result = new byte[length];
5782 }
5783
5784 result[length - 1] = (byte) response.sw2;
5785 result[length - 2] = (byte) response.sw1;
5786 return result;
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005789 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005790 }
5791
Nathan Haroldb3014052017-01-25 15:57:32 -08005792 /**
5793 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5794 * on a particular subscription
5795 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005796 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5797 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005798 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005799 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005800 return null;
5801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 if (appType != TelephonyManager.APPTYPE_USIM
5806 && appType != TelephonyManager.APPTYPE_SIM) {
5807 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5808 return null;
5809 }
5810 Object response = sendRequest(
5811 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5812 if (response instanceof String[]) {
5813 return (String[]) response;
5814 }
yincheng zhao2737e882019-09-06 17:06:54 -07005815 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005817 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 } finally {
5819 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005820 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005821 }
5822
yincheng zhao2737e882019-09-06 17:06:54 -07005823 /**
5824 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5825 * subscription.
5826 *
5827 * @param subId the id of the subscription.
5828 * @param appType the uicc app type, must be USIM or SIM.
5829 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5830 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005831 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005832 * @return number of fplmns that is successfully written to the SIM.
5833 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005834 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5835 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5837 mApp, subId, "setForbiddenPlmns");
5838
yincheng zhao2737e882019-09-06 17:06:54 -07005839 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5840 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5841 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5842 }
5843 if (fplmns == null) {
5844 throw new IllegalArgumentException("Fplmn List provided is null");
5845 }
5846 for (String fplmn : fplmns) {
5847 if (!CellIdentity.isValidPlmn(fplmn)) {
5848 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5849 }
5850 }
5851 final long identity = Binder.clearCallingIdentity();
5852 try {
5853 Object response = sendRequest(
5854 CMD_SET_FORBIDDEN_PLMNS,
5855 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5856 subId);
5857 return (int) response;
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
5861 }
5862
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005863 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005864 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5866 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
5870 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5871 if (response.payload == null) {
5872 return "";
5873 }
Evan Charltonc66da362014-05-16 14:06:40 -07005874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 // Append the returned status code to the end of the response payload.
5876 String s = Integer.toHexString(
5877 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5878 s = IccUtils.bytesToHexString(response.payload) + s;
5879 return s;
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Evan Charltonc66da362014-05-16 14:06:40 -07005883 }
5884
Jake Hambye994d462014-02-03 13:10:13 -08005885 /**
5886 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5887 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5888 *
5889 * @param itemID the ID of the item to read
5890 * @return the NV item as a String, or null on error.
5891 */
5892 @Override
5893 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5896 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897
5898 final long identity = Binder.clearCallingIdentity();
5899 try {
5900 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005901 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5903 return value;
5904 } finally {
5905 Binder.restoreCallingIdentity(identity);
5906 }
Jake Hambye994d462014-02-03 13:10:13 -08005907 }
5908
5909 /**
5910 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5911 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5912 *
5913 * @param itemID the ID of the item to read
5914 * @param itemValue the value to write, as a String
5915 * @return true on success; false on any failure
5916 */
5917 @Override
5918 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005919 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5921 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922
5923 final long identity = Binder.clearCallingIdentity();
5924 try {
5925 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5926 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005927 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5929 return success;
5930 } finally {
5931 Binder.restoreCallingIdentity(identity);
5932 }
Jake Hambye994d462014-02-03 13:10:13 -08005933 }
5934
5935 /**
5936 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5937 * Used for device configuration by some CDMA operators.
5938 *
5939 * @param preferredRoamingList byte array containing the new PRL
5940 * @return true on success; false on any failure
5941 */
5942 @Override
5943 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5945 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5950 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5951 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5952 return success;
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Jake Hambye994d462014-02-03 13:10:13 -08005956 }
5957
5958 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005959 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005960 * Used for device configuration by some CDMA operators.
5961 *
chen xu6dac5ab2018-10-26 17:39:23 -07005962 * @param slotIndex - device slot.
5963 *
Jake Hambye994d462014-02-03 13:10:13 -08005964 * @return true on success; false on any failure
5965 */
5966 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005967 public boolean resetModemConfig(int slotIndex) {
5968 Phone phone = PhoneFactory.getPhone(slotIndex);
5969 if (phone != null) {
5970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5971 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972
chen xu6dac5ab2018-10-26 17:39:23 -07005973 final long identity = Binder.clearCallingIdentity();
5974 try {
5975 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5976 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5977 return success;
5978 } finally {
5979 Binder.restoreCallingIdentity(identity);
5980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 }
chen xu6dac5ab2018-10-26 17:39:23 -07005982 return false;
5983 }
5984
5985 /**
5986 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5987 *
5988 * @param slotIndex - device slot.
5989 *
5990 * @return true on success; false on any failure
5991 */
5992 @Override
5993 public boolean rebootModem(int slotIndex) {
5994 Phone phone = PhoneFactory.getPhone(slotIndex);
5995 if (phone != null) {
5996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5997 mApp, phone.getSubId(), "rebootModem");
5998
5999 final long identity = Binder.clearCallingIdentity();
6000 try {
6001 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6002 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6003 return success;
6004 } finally {
6005 Binder.restoreCallingIdentity(identity);
6006 }
6007 }
6008 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006009 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006010
Brad Ebinger51f743a2017-01-23 13:50:20 -08006011 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006012 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6013 * {@link #disableIms(int)}.
6014 * @param slotIndex device slot.
6015 */
6016 public void resetIms(int slotIndex) {
6017 enforceModifyPermission();
6018
6019 final long identity = Binder.clearCallingIdentity();
6020 try {
6021 if (mImsResolver == null) {
6022 // may happen if the does not support IMS.
6023 return;
6024 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006025 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006026 } finally {
6027 Binder.restoreCallingIdentity(identity);
6028 }
6029 }
6030
6031 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006032 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6033 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006034 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006035 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006036 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037
6038 final long identity = Binder.clearCallingIdentity();
6039 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006040 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006041 // may happen if the device does not support IMS.
6042 return;
6043 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006044 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006048 }
6049
6050 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006051 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6052 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006053 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006054 public void disableIms(int slotId) {
6055 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056
6057 final long identity = Binder.clearCallingIdentity();
6058 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006059 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006060 // may happen if the device does not support IMS.
6061 return;
6062 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006063 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 } finally {
6065 Binder.restoreCallingIdentity(identity);
6066 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006067 }
6068
6069 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006070 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6071 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006072 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006073 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006074 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006075 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076
6077 final long identity = Binder.clearCallingIdentity();
6078 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006079 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6081 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006082 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006083 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006087 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006088 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006089 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6090 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006091 @Override
6092 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006093 enforceModifyPermission();
6094
6095 final long identity = Binder.clearCallingIdentity();
6096 try {
6097 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006098 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
6102 }
6103
6104 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006105 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006106 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006107 */
6108 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6109 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006113 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006114 // may happen if the device does not support IMS.
6115 return null;
6116 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006117 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006121 }
6122
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006123 /**
6124 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006125 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006126 */
6127 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6128 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129
6130 final long identity = Binder.clearCallingIdentity();
6131 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006132 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006133 // may happen if the device does not support IMS.
6134 return null;
6135 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006136 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006140 }
6141
Brad Ebinger884c07b2018-02-15 16:17:40 -08006142 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006143 * Sets the ImsService Package Name that Telephony will bind to.
6144 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006145 * @param slotIndex the slot ID that the ImsService should bind for.
6146 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006147 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006148 * @param featureTypes An integer array of feature types associated with a packageName.
6149 * @param packageName The name of the package that the current configuration will be replaced
6150 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006151 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006152 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006153 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6154 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006157 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 final long identity = Binder.clearCallingIdentity();
6160 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006161 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006162 // may happen if the device does not support IMS.
6163 return false;
6164 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006165 Map<Integer, String> featureConfig = new HashMap<>();
6166 for (int featureType : featureTypes) {
6167 featureConfig.put(featureType, packageName);
6168 }
6169 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6170 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006174 }
6175
6176 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006177 * Clears any carrier ImsService overrides for the slot index specified that were previously
6178 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6179 *
6180 * This should only be used for testing.
6181 *
6182 * @param slotIndex the slot ID that the ImsService should bind for.
6183 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6184 */
6185 @Override
6186 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006187 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6188 "clearCarrierImsServiceOverride");
6189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006190 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006191
6192 final long identity = Binder.clearCallingIdentity();
6193 try {
6194 if (mImsResolver == null) {
6195 // may happen if the device does not support IMS.
6196 return false;
6197 }
6198 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6199 } finally {
6200 Binder.restoreCallingIdentity(identity);
6201 }
6202 }
6203
6204 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006205 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006206 *
6207 * @param slotId The slot that the ImsService is associated with.
6208 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6209 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006210 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006211 * @return the package name of the ImsService configuration.
6212 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006213 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6214 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006215 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006216 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6217 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 final long identity = Binder.clearCallingIdentity();
6220 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006221 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006222 // may happen if the device does not support IMS.
6223 return "";
6224 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006225 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006226 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6227 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006231 }
6232
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006233 /**
6234 * Get the MmTelFeature state associated with the requested subscription id.
6235 * @param subId The subscription that the MmTelFeature is associated with.
6236 * @param callback A callback with an integer containing the
6237 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6238 */
6239 @Override
6240 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6241 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006242 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6243 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6244 "IMS not available on device.");
6245 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006246 final long token = Binder.clearCallingIdentity();
6247 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006248 int slotId = getSlotIndex(subId);
6249 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6250 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6251 + subId + "'");
6252 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6253 }
6254 verifyImsMmTelConfiguredOrThrow(slotId);
6255 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6256 try {
6257 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6258 } catch (RemoteException e) {
6259 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6260 + "Ignore");
6261 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006262 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006263 } catch (ImsException e) {
6264 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006265 } finally {
6266 Binder.restoreCallingIdentity(token);
6267 }
6268 }
6269
Daniel Brightbb5840b2021-01-12 15:48:18 -08006270 /**
6271 * Sets the ims registration state on all valid {@link Phone}s.
6272 */
6273 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275
6276 final long identity = Binder.clearCallingIdentity();
6277 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006278 // NOTE: Before S, this method only set the default phone.
6279 for (final Phone phone : PhoneFactory.getPhones()) {
6280 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6281 phone.setImsRegistrationState(registered);
6282 }
6283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286 }
Wink Saville36469e72014-06-11 15:17:00 -07006287 }
6288
6289 /**
Stuart Scott54788802015-03-30 13:18:01 -07006290 * Set the network selection mode to automatic.
6291 *
6292 */
6293 @Override
6294 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6296 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297
6298 final long identity = Binder.clearCallingIdentity();
6299 try {
shilufc958392020-01-20 11:36:01 -08006300 if (!isActiveSubscription(subId)) {
6301 return;
6302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006304 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6305 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
Stuart Scott54788802015-03-30 13:18:01 -07006309 }
6310
Jack Yud10cdd42020-09-28 20:28:01 -07006311 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006312 * Ask the radio to connect to the input network and change selection mode to manual.
6313 *
6314 * @param subId the id of the subscription.
6315 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6316 * the operator to attach to.
6317 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6318 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6319 * normal network selection next time.
6320 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006321 */
6322 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006323 public boolean setNetworkSelectionModeManual(
6324 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6326 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006327
Jack Yu285100e2022-12-02 22:48:35 -08006328 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006329 if (!isActiveSubscription(subId)) {
6330 return false;
6331 }
6332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006334 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006336 if (DBG) {
6337 log("setNetworkSelectionModeManual: subId: " + subId
6338 + " operator: " + operatorInfo);
6339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6341 } finally {
6342 Binder.restoreCallingIdentity(identity);
6343 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006344 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006345 /**
shilu84f6e8b2019-12-19 13:58:01 -08006346 * Get the manual network selection
6347 *
6348 * @param subId the id of the subscription.
6349 *
6350 * @return the previously saved user selected PLMN
6351 */
6352 @Override
6353 public String getManualNetworkSelectionPlmn(int subId) {
6354 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006355 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6356 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006357
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006361 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006362 }
6363
6364 final Phone phone = getPhone(subId);
6365 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006366 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006367 }
6368 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6369 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006370 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006375
6376 /**
6377 * Scans for available networks.
6378 */
6379 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006380 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6381 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6383 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006384 LocationAccessPolicy.LocationPermissionResult locationResult =
6385 LocationAccessPolicy.checkLocationPermission(mApp,
6386 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6387 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006388 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006389 .setCallingPid(Binder.getCallingPid())
6390 .setCallingUid(Binder.getCallingUid())
6391 .setMethod("getCellNetworkScanResults")
6392 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006393 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6394 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006395 .build());
6396 switch (locationResult) {
6397 case DENIED_HARD:
6398 throw new SecurityException("Not allowed to access scan results -- location");
6399 case DENIED_SOFT:
6400 return null;
6401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402
Pengquan Menga1bb6272018-09-06 09:59:22 -07006403 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 try {
6405 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006406 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 } finally {
6409 Binder.restoreCallingIdentity(identity);
6410 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006411 }
6412
6413 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006414 * Get the call forwarding info, given the call forwarding reason.
6415 */
6416 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006417 public void getCallForwarding(int subId, int callForwardingReason,
6418 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006419 enforceReadPrivilegedPermission("getCallForwarding");
6420 long identity = Binder.clearCallingIdentity();
6421 try {
6422 if (DBG) {
6423 log("getCallForwarding: subId " + subId
6424 + " callForwardingReason" + callForwardingReason);
6425 }
Hall Liu27d24262020-09-18 19:04:59 -07006426
6427 Phone phone = getPhone(subId);
6428 if (phone == null) {
6429 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006430 callback.onError(
6431 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006432 } catch (RemoteException e) {
6433 // ignore
6434 }
6435 return;
6436 }
6437
6438 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6439 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6440 @Override
6441 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6442 try {
6443 callback.onCallForwardingInfoAvailable(info);
6444 } catch (RemoteException e) {
6445 // ignore
6446 }
6447 }
6448
6449 @Override
6450 public void onError(int error) {
6451 try {
6452 callback.onError(error);
6453 } catch (RemoteException e) {
6454 // ignore
6455 }
6456 }
6457 });
6458 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006459 } finally {
6460 Binder.restoreCallingIdentity(identity);
6461 }
6462 }
6463
6464 /**
6465 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6466 * reason, the number to forward, and the timeout before the forwarding is attempted.
6467 */
6468 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006469 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6470 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006471 enforceModifyPermission();
6472 long identity = Binder.clearCallingIdentity();
6473 try {
6474 if (DBG) {
6475 log("setCallForwarding: subId " + subId
6476 + " callForwardingInfo" + callForwardingInfo);
6477 }
Hall Liu27d24262020-09-18 19:04:59 -07006478
6479 Phone phone = getPhone(subId);
6480 if (phone == null) {
6481 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006482 callback.accept(
6483 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006484 } catch (RemoteException e) {
6485 // ignore
6486 }
6487 return;
6488 }
6489
6490 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6491 FunctionalUtils.ignoreRemoteException(callback::accept));
6492
6493 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006494 } finally {
6495 Binder.restoreCallingIdentity(identity);
6496 }
6497 }
6498
6499 /**
Hall Liu27d24262020-09-18 19:04:59 -07006500 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006501 */
6502 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006503 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006504 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006505 long identity = Binder.clearCallingIdentity();
6506 try {
Hall Liu27d24262020-09-18 19:04:59 -07006507 Phone phone = getPhone(subId);
6508 if (phone == null) {
6509 try {
6510 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6511 } catch (RemoteException e) {
6512 // ignore
6513 }
6514 return;
6515 }
SongFerngWang0e767992021-03-31 22:08:45 +08006516 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6517 PersistableBundle c = configManager.getConfigForSubId(subId);
6518 boolean requireUssd = c.getBoolean(
6519 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006520
Shuo Qian4a594052020-01-23 11:59:30 -08006521 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006522 if (requireUssd) {
6523 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6524 getSubscriptionCarrierId(subId));
6525 String newUssdCommand = "";
6526 try {
6527 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006528 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006529 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6530 } catch (NullPointerException e) {
6531 loge("Failed to generate USSD number" + e);
6532 }
6533 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6534 mMainThreadHandler, callback, carrierXmlParser,
6535 CarrierXmlParser.SsEntry.SSAction.QUERY);
6536 final String ussdCommand = newUssdCommand;
6537 Executors.newSingleThreadExecutor().execute(() -> {
6538 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6539 });
6540 } else {
6541 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6542 callback::accept);
6543 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6544 }
Shuo Qian4a594052020-01-23 11:59:30 -08006545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
6548 }
6549
6550 /**
Hall Liu27d24262020-09-18 19:04:59 -07006551 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006552 */
6553 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006554 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006555 enforceModifyPermission();
6556 long identity = Binder.clearCallingIdentity();
6557 try {
Hall Liu27d24262020-09-18 19:04:59 -07006558 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6559
6560 Phone phone = getPhone(subId);
6561 if (phone == null) {
6562 try {
6563 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6564 } catch (RemoteException e) {
6565 // ignore
6566 }
6567 return;
6568 }
6569
SongFerngWang0e767992021-03-31 22:08:45 +08006570 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6571 PersistableBundle c = configManager.getConfigForSubId(subId);
6572 boolean requireUssd = c.getBoolean(
6573 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006574
SongFerngWang0e767992021-03-31 22:08:45 +08006575 if (DBG) log("getCallWaitingStatus: subId " + subId);
6576 if (requireUssd) {
6577 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6578 getSubscriptionCarrierId(subId));
6579 CarrierXmlParser.SsEntry.SSAction ssAction =
6580 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6581 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6582 String newUssdCommand = "";
6583 try {
6584 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006585 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006586 .makeCommand(ssAction, null);
6587 } catch (NullPointerException e) {
6588 loge("Failed to generate USSD number" + e);
6589 }
6590 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6591 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6592 final String ussdCommand = newUssdCommand;
6593 Executors.newSingleThreadExecutor().execute(() -> {
6594 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6595 });
6596 } else {
6597 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6598 FunctionalUtils.ignoreRemoteException(callback::accept));
6599
6600 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6601 }
Shuo Qian4a594052020-01-23 11:59:30 -08006602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604 }
6605 }
6606
6607 /**
yinxub1bed742017-04-17 11:45:04 -07006608 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006609 *
yinxub1bed742017-04-17 11:45:04 -07006610 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006611 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6612 * location related information which will be sent if the caller already possess
6613 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006614 * @param request contains the radio access networks with bands/channels to scan
6615 * @param messenger callback messenger for scan results or errors
6616 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006617 * @return the id of the requested scan which can be used to stop the scan.
6618 */
6619 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006620 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6621 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006622 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6624 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006625 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006626 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6627 if (!renounceFineLocationAccess) {
6628 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006629 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6630 .setCallingPackage(callingPackage)
6631 .setCallingFeatureId(callingFeatureId)
6632 .setCallingPid(Binder.getCallingPid())
6633 .setCallingUid(Binder.getCallingUid())
6634 .setMethod("requestNetworkScan")
6635 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6636 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6637 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6638 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006639 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006640 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006641 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6642 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006643 if (e != null) {
6644 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6645 throw e;
6646 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006647 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006648 return TelephonyScanManager.INVALID_SCAN_ID;
6649 }
6650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651 }
Hall Liu912dfd32019-04-25 14:02:26 -07006652 int callingUid = Binder.getCallingUid();
6653 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006657 renounceFineLocationAccess, request, messenger, binder,
6658 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006659 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006660 } finally {
6661 Binder.restoreCallingIdentity(identity);
6662 }
yinxu504e1392017-04-12 16:03:22 -07006663 }
6664
Hall Liub2ac8ef2019-02-28 15:56:23 -08006665 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006666 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006667 boolean hasCarrierPriv;
6668 final long identity = Binder.clearCallingIdentity();
6669 try {
6670 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6671 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6672 } finally {
6673 Binder.restoreCallingIdentity(identity);
6674 }
Hall Liu558027f2019-05-15 19:14:05 -07006675 boolean hasNetworkScanPermission =
6676 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006677 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006678
6679 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6680 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6681 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006682 }
6683
6684 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6685 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006686 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6687 return new SecurityException("Specific channels must not be"
6688 + " scanned without location access.");
6689 }
6690 }
6691 }
6692
Hall Liub2ac8ef2019-02-28 15:56:23 -08006693 return null;
6694 }
6695
yinxu504e1392017-04-12 16:03:22 -07006696 /**
6697 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006698 *
6699 * @param subId id of the subscription
6700 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006701 */
6702 @Override
6703 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6705 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706
Hall Liu912dfd32019-04-25 14:02:26 -07006707 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 final long identity = Binder.clearCallingIdentity();
6709 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006710 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
yinxu504e1392017-04-12 16:03:22 -07006714 }
6715
6716 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006717 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006718 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006719 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006720 */
6721 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006722 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006723 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006724 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006725 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726
6727 final long identity = Binder.clearCallingIdentity();
6728 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006729 if (DBG) log("getAllowedNetworkTypesBitmask");
6730 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6731 int networkTypesBitmask = (result != null ? result[0] : -1);
6732 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6733 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006737 }
6738
6739 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006740 * Get the allowed network types for certain reason.
6741 *
6742 * @param subId the id of the subscription.
6743 * @param reason the reason the allowed network type change is taking place
6744 * @return the allowed network types.
6745 */
6746 @Override
6747 public long getAllowedNetworkTypesForReason(int subId,
6748 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006749 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006750 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006751 final long identity = Binder.clearCallingIdentity();
6752 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006753 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006754 } finally {
6755 Binder.restoreCallingIdentity(identity);
6756 }
6757 }
6758
6759 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006760 * Enable/Disable E-UTRA-NR Dual Connectivity
6761 * @param subId subscription id of the sim card
6762 * @param nrDualConnectivityState expected NR dual connectivity state
6763 * This can be passed following states
6764 * <ol>
6765 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6766 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6767 * <li>Disable NR dual connectivity and force secondary cell to be released
6768 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6769 * </ol>
6770 * @return operation result.
6771 */
6772 @Override
6773 public int setNrDualConnectivityState(int subId,
6774 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6776 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006777 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006778 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6779 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6780 }
6781
Sooraj Sasindran37444802020-08-11 10:40:43 -07006782 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6786 nrDualConnectivityState, subId,
6787 workSource);
6788 if (DBG) log("enableNRDualConnectivity result: " + result);
6789 return result;
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 }
6794
6795 /**
6796 * Is E-UTRA-NR Dual Connectivity enabled
6797 * @return true if dual connectivity is enabled else false
6798 */
6799 @Override
6800 public boolean isNrDualConnectivityEnabled(int subId) {
6801 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006802 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006803 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006804 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006805 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6806 return false;
6807 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006808 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6809 final long identity = Binder.clearCallingIdentity();
6810 try {
6811 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6812 null, subId, workSource);
6813 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6814 return isEnabled;
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
6818 }
6819
6820 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006821 * Set the allowed network types of the device and
6822 * provide the reason triggering the allowed network change.
6823 *
6824 * @param subId the id of the subscription.
6825 * @param reason the reason the allowed network type change is taking place
6826 * @param allowedNetworkTypes the allowed network types.
6827 * @return true on success; false on any failure.
6828 */
6829 @Override
6830 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006831 @TelephonyManager.AllowedNetworkTypesReason int reason,
6832 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6834 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006835 // If the caller only has carrier privileges, then they should not be able to override
6836 // any network types which were set for security reasons.
6837 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6838 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006839 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006840 throw new SecurityException(
6841 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006842 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006843 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006844 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006845 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006846 return false;
6847 }
6848 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6849 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006850 return false;
6851 }
6852
Jack Yu5b494332023-01-23 18:18:04 +00006853 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6854 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006855
Jack Yue37dd262022-12-16 11:53:37 -08006856 Phone phone = getPhone(subId);
6857 if (phone == null) {
6858 return false;
6859 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006860
Jack Yue37dd262022-12-16 11:53:37 -08006861 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006862 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006863 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006864 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006865
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006866 final long identity = Binder.clearCallingIdentity();
6867 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006868 Boolean success = (Boolean) sendRequest(
6869 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6870 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6871
6872 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6873 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
6878
6879 /**
Miaoa84611c2019-03-15 09:21:10 +08006880 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006881 *
Miaoa84611c2019-03-15 09:21:10 +08006882 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006883 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006884 * @hide
6885 */
6886 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006887 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006888 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006890 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 try {
Miaoa84611c2019-03-15 09:21:10 +08006892 if (phone != null) {
6893 return phone.hasMatchedTetherApnSetting();
6894 } else {
6895 return false;
6896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 } finally {
6898 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006899 }
Junda Liu475951f2014-11-07 16:45:03 -08006900 }
6901
6902 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006903 * Get the user enabled state of Mobile Data.
6904 *
6905 * TODO: remove and use isUserDataEnabled.
6906 * This can't be removed now because some vendor codes
6907 * calls through ITelephony directly while they should
6908 * use TelephonyManager.
6909 *
6910 * @return true on enabled
6911 */
6912 @Override
6913 public boolean getDataEnabled(int subId) {
6914 return isUserDataEnabled(subId);
6915 }
6916
6917 /**
6918 * Get whether mobile data is enabled per user setting.
6919 *
6920 * There are other factors deciding whether mobile data is actually enabled, but they are
6921 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006922 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006923 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6924 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006925 *
6926 * @return {@code true} if data is enabled else {@code false}
6927 */
6928 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006929 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006930 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006931 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006932 try {
6933 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6934 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006935 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006936 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6937 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006938 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006940 mApp, subId, functionName);
6941
Robert Greenwalt646120a2014-05-23 11:54:03 -07006942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943
6944 final long identity = Binder.clearCallingIdentity();
6945 try {
Jack Yu285100e2022-12-02 22:48:35 -08006946 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6948 Phone phone = PhoneFactory.getPhone(phoneId);
6949 if (phone != null) {
6950 boolean retVal = phone.isUserDataEnabled();
6951 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6952 return retVal;
6953 } else {
6954 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6955 return false;
6956 }
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006959 }
6960 }
6961
6962 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006963 * Checks if the device is capable of mobile data by considering whether whether the
6964 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6965 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006966 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006967 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006968 */
6969 @Override
6970 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006971 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006972 try {
6973 try {
6974 mApp.enforceCallingOrSelfPermission(
6975 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006976 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006977 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006978 try {
6979 mApp.enforceCallingOrSelfPermission(
6980 android.Manifest.permission.READ_PHONE_STATE,
6981 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006982 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006983 mApp.enforceCallingOrSelfPermission(
6984 permission.READ_BASIC_PHONE_STATE, functionName);
6985 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006986 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006987 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006988 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990
6991 final long identity = Binder.clearCallingIdentity();
6992 try {
Jack Yu285100e2022-12-02 22:48:35 -08006993 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 Phone phone = PhoneFactory.getPhone(phoneId);
6995 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006996 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006997 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 return retVal;
6999 } else {
7000 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7001 return false;
7002 }
7003 } finally {
7004 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007005 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007006 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007007
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007008 /**
7009 * Check if data is enabled for a specific reason
7010 * @param subId Subscription index
7011 * @param reason the reason the data enable change is taking place
7012 * @return {@code true} if the overall data is enabled; {@code false} if not.
7013 */
7014 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007015 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007016 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007017 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007018 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007019 try {
7020 mApp.enforceCallingOrSelfPermission(
7021 android.Manifest.permission.ACCESS_NETWORK_STATE,
7022 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007023 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007024 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7025 functionName);
7026 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007027 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007028 try {
7029 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007030 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007031 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007033 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007034 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007035 }
7036
7037
7038 final long identity = Binder.clearCallingIdentity();
7039 try {
Jack Yu285100e2022-12-02 22:48:35 -08007040 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007041 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007042 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007043 + " reason=" + reason);
7044 }
7045 Phone phone = PhoneFactory.getPhone(phoneId);
7046 if (phone != null) {
7047 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007048 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007049 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007050 return retVal;
7051 } else {
7052 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007053 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007054 + subId + " retVal=false");
7055 }
7056 return false;
7057 }
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
7061 }
7062
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007063 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007064 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007065 // No permission needed; this only lets the caller inspect their own status.
7066 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007067 }
Junda Liu29340342014-07-10 15:23:27 -07007068
7069 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007070 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007071 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007072 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7073 }
7074
7075 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7076 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007077 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007078 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007079 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7080 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007081 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7082 if (cpt == null) {
7083 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7085 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007086 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007087 }
7088
7089 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007090 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007091 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007092 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007093 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007094 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007095 Phone phone = getPhone(subId);
7096 if (phone == null) {
7097 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7098 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7099 }
7100 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7101 if (cpt == null) {
7102 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007103 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7104 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007105 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007106 }
7107
7108 @Override
7109 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007110 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007111 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7112 }
7113
7114 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007115 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007116 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007117 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007118 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007119 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7120 Phone phone = PhoneFactory.getPhone(phoneId);
7121 if (phone == null) {
7122 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007123 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007124 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7125 if (cpt == null) {
7126 continue;
7127 }
7128 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007129 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7130 break;
7131 }
7132 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007133 return result;
Junda Liu29340342014-07-10 15:23:27 -07007134 }
Derek Tan89e89d42014-07-08 17:00:10 -07007135
7136 @Override
Junda Liue64de782015-04-16 17:19:16 -07007137 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007138 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007139 Phone phone = PhoneFactory.getPhone(phoneId);
7140 if (phone == null) {
7141 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007142 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007143 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7144 if (cpt == null) {
7145 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007146 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007147 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007148 }
7149
Amith Yamasani6e118872016-02-19 12:53:51 -08007150 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007151 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007152 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007153 Phone phone = PhoneFactory.getPhone(phoneId);
7154 if (phone == null) {
7155 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007156 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007157 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7158 if (cpt == null) {
7159 return Collections.emptyList();
7160 }
7161 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007162 }
7163
chen xuf7e9fe82019-05-09 19:31:02 -07007164 @Override
7165 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007166 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007167 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007168 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007169 try {
7170 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7171 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7172 }
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007175 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007176 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007177 }
7178
Rambo Wang6812ffb2022-03-15 16:54:17 -07007179 @Override
7180 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7181 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7182
7183 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7184 if (phone == null) {
7185 return null;
7186 }
7187 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7188 if (cpt == null) {
7189 return null;
7190 }
7191 return cpt.getCarrierServicePackageName();
7192 }
7193
Wink Savilleb564aae2014-10-23 10:18:09 -07007194 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007195 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007196 UiccPort port = phone == null ? null : phone.getUiccPort();
7197 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007198 return null;
7199 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007200 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007201 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007202 return null;
7203 }
7204 return iccId;
7205 }
7206
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007207 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007208 public void setCallComposerStatus(int subId, int status) {
7209 enforceModifyPermission();
7210
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 Phone phone = getPhone(subId);
7214 if (phone != null) {
7215 Phone defaultPhone = phone.getImsPhone();
7216 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7217 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7218 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007219 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7220 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007221 }
7222 }
Shuo Qian284ae752020-12-22 19:10:14 -08007223 } catch (ImsException e) {
7224 throw new ServiceSpecificException(e.getCode());
7225 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007226 Binder.restoreCallingIdentity(identity);
7227 }
7228 }
7229
7230 @Override
7231 public int getCallComposerStatus(int subId) {
7232 enforceReadPrivilegedPermission("getCallComposerStatus");
7233
7234 final long identity = Binder.clearCallingIdentity();
7235 try {
7236 Phone phone = getPhone(subId);
7237 if (phone != null) {
7238 Phone defaultPhone = phone.getImsPhone();
7239 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7240 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7241 return imsPhone.getCallComposerStatus();
7242 }
7243 }
7244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
7247 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7248 }
7249
7250 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007251 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7252 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007253 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007254 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 final String iccId = getIccId(subId);
7259 final Phone phone = getPhone(subId);
7260 if (phone == null) {
7261 return false;
7262 }
7263 final String subscriberId = phone.getSubscriberId();
7264
7265 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007266 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007267 + subscriberId + " to " + number);
7268 }
7269
7270 if (TextUtils.isEmpty(iccId)) {
7271 return false;
7272 }
7273
7274 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7275
7276 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7277 if (alphaTag == null) {
7278 editor.remove(alphaTagPrefKey);
7279 } else {
7280 editor.putString(alphaTagPrefKey, alphaTag);
7281 }
7282
7283 // Record both the line number and IMSI for this ICCID, since we need to
7284 // track all merged IMSIs based on line number
7285 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7286 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7287 if (number == null) {
7288 editor.remove(numberPrefKey);
7289 editor.remove(subscriberPrefKey);
7290 } else {
7291 editor.putString(numberPrefKey, number);
7292 editor.putString(subscriberPrefKey, subscriberId);
7293 }
7294
7295 editor.commit();
7296 return true;
7297 } finally {
7298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007299 }
Derek Tan7226c842014-07-02 17:42:23 -07007300 }
7301
7302 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007303 public String getLine1NumberForDisplay(int subId, String callingPackage,
7304 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007305 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007307 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007308 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007309 return null;
7310 }
Derek Tan97ebb422014-09-05 16:55:38 -07007311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 String iccId = getIccId(subId);
7315 if (iccId != null) {
7316 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7317 if (DBG_MERGE) {
7318 log("getLine1NumberForDisplay returning "
7319 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7320 }
7321 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7324 return null;
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007327 }
Derek Tan7226c842014-07-02 17:42:23 -07007328 }
7329
7330 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007331 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7332 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007334 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007335 return null;
7336 }
Derek Tan97ebb422014-09-05 16:55:38 -07007337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338 final long identity = Binder.clearCallingIdentity();
7339 try {
7340 String iccId = getIccId(subId);
7341 if (iccId != null) {
7342 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7343 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7344 }
7345 return null;
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007348 }
Derek Tan7226c842014-07-02 17:42:23 -07007349 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007350
7351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007352 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7353 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007354 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7355 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007357 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007358 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007359 return null;
7360 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007361
Jordan Liub49b04b2019-05-06 14:45:15 -07007362 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7363 // the process, where TelephonyManager was instantiated.
7364 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007365 final long identity = Binder.clearCallingIdentity();
7366 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007367 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 final TelephonyManager tele = TelephonyManager.from(context);
7369 final SubscriptionManager sub = SubscriptionManager.from(context);
7370
7371 // Figure out what subscribers are currently active
7372 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373
Jordan Liub49b04b2019-05-06 14:45:15 -07007374 // Only consider subs which match the current subId
7375 // This logic can be simplified. See b/131189269 for progress.
7376 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007377 activeSubscriberIds.add(tele.getSubscriberId(subId));
7378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379
7380 // First pass, find a number override for an active subscriber
7381 String mergeNumber = null;
7382 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7383 for (String key : prefs.keySet()) {
7384 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7385 final String subscriberId = (String) prefs.get(key);
7386 if (activeSubscriberIds.contains(subscriberId)) {
7387 final String iccId = key.substring(
7388 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7389 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7390 mergeNumber = (String) prefs.get(numberKey);
7391 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007392 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 + " for active subscriber " + subscriberId);
7394 }
7395 if (!TextUtils.isEmpty(mergeNumber)) {
7396 break;
7397 }
7398 }
7399 }
7400 }
7401
7402 // Shortcut when no active merged subscribers
7403 if (TextUtils.isEmpty(mergeNumber)) {
7404 return null;
7405 }
7406
7407 // Second pass, find all subscribers under that line override
7408 final ArraySet<String> result = new ArraySet<>();
7409 for (String key : prefs.keySet()) {
7410 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7411 final String number = (String) prefs.get(key);
7412 if (mergeNumber.equals(number)) {
7413 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7414 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7415 final String subscriberId = (String) prefs.get(subscriberKey);
7416 if (!TextUtils.isEmpty(subscriberId)) {
7417 result.add(subscriberId);
7418 }
7419 }
7420 }
7421 }
7422
7423 final String[] resultArray = result.toArray(new String[result.size()]);
7424 Arrays.sort(resultArray);
7425 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007426 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7428 }
7429 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007430 } finally {
7431 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007432 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007433 }
7434
7435 @Override
zoey chen38003472019-12-13 17:16:31 +08007436 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7437 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007438
7439 final long identity = Binder.clearCallingIdentity();
7440 try {
7441 final TelephonyManager telephonyManager = mApp.getSystemService(
7442 TelephonyManager.class);
7443 String subscriberId = telephonyManager.getSubscriberId(subId);
7444 if (subscriberId == null) {
7445 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007446 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007447 + subId);
7448 }
7449 return null;
7450 }
7451
Jack Yu3beaf9d2023-04-14 09:17:27 -07007452 final SubscriptionInfo info = getSubscriptionManagerService()
7453 .getSubscriptionInfo(subId);
7454 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007455 // If it doesn't belong to any group, return just subscriberId of itself.
7456 if (groupUuid == null) {
7457 return new String[]{subscriberId};
7458 }
7459
7460 // Get all subscriberIds from the group.
7461 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007462 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7463 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7464 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007465 for (SubscriptionInfo subInfo : groupInfos) {
7466 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7467 if (subscriberId != null) {
7468 mergedSubscriberIds.add(subscriberId);
7469 }
7470 }
7471
7472 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7473 } finally {
7474 Binder.restoreCallingIdentity(identity);
7475
7476 }
7477 }
7478
7479 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007480 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007481 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007482 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483
7484 final long identity = Binder.clearCallingIdentity();
7485 try {
7486 final Phone phone = getPhone(subId);
7487 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007491 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007492
7493 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007494 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007495 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7496 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007497 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7498 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499
7500 final long identity = Binder.clearCallingIdentity();
7501 try {
7502 final Phone phone = getPhone(subId);
7503 if (phone == null) {
7504 return false;
7505 }
7506 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7507 cdmaNonRoamingList);
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007510 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007511 }
7512
7513 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007514 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007515 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007516 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007517 if (phone == null) {
7518 return raf;
7519 }
7520
Shuo Qiandee53402020-05-29 14:08:15 -07007521 try {
7522 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007523 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007524 mApp, phone.getSubId(), "getRadioAccessFamily");
7525 } catch (SecurityException e) {
7526 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7527 throw e;
7528 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 final long identity = Binder.clearCallingIdentity();
7531 try {
chen xub97461a2018-10-26 14:17:57 -07007532 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
chen xub97461a2018-10-26 14:17:57 -07007536 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007537 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007538
7539 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007540 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007541 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007542 try {
7543 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7544 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007545 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007546 }
7547 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007548 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007549 }
7550 RoleManager rm = mApp.getSystemService(RoleManager.class);
7551 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7552 if (!dialerRoleHolders.contains(callingPackage)) {
7553 throw new SecurityException("App must be the dialer role holder to"
7554 + " upload a call composer pic");
7555 }
7556
7557 Executors.newSingleThreadExecutor().execute(() -> {
7558 ByteArrayOutputStream output = new ByteArrayOutputStream(
7559 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7560 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7561 boolean readUntilEnd = false;
7562 int totalBytesRead = 0;
7563 byte[] buffer = new byte[16 * 1024];
7564 while (true) {
7565 int numRead;
7566 try {
7567 numRead = input.read(buffer);
7568 } catch (IOException e) {
7569 try {
7570 fd.checkError();
7571 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7572 null);
7573 } catch (IOException e1) {
7574 // This means that the other side closed explicitly with an error. If this
7575 // happens, log and ignore.
7576 loge("Remote end of call composer picture pipe closed: " + e1);
7577 }
7578 break;
7579 }
7580 if (numRead == -1) {
7581 readUntilEnd = true;
7582 break;
7583 }
7584 totalBytesRead += numRead;
7585 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7586 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7587 try {
7588 input.close();
7589 } catch (IOException e) {
7590 // ignore
7591 }
7592 break;
7593 }
7594 output.write(buffer, 0, numRead);
7595 }
7596 // Generally, the remote end will close the file descriptors. The only case where we
7597 // close is above, where the picture size is too big.
7598
7599 try {
7600 fd.checkError();
7601 } catch (IOException e) {
7602 loge("Remote end for call composer closed with an error: " + e);
7603 return;
7604 }
7605
Hall Liuaa4211e2021-01-20 15:43:39 -08007606 if (!readUntilEnd) {
7607 loge("Did not finish reading entire image; aborting");
7608 return;
7609 }
Hall Liu82694d52020-12-11 18:22:04 -08007610
Hall Liuaa4211e2021-01-20 15:43:39 -08007611 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7612 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7613 new CallComposerPictureTransfer.Factory() {},
7614 imageData,
7615 (result) -> {
7616 if (result.first != null) {
7617 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7618 Bundle outputResult = new Bundle();
7619 outputResult.putParcelable(
7620 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7621 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7622 outputResult);
7623 } else {
7624 callback.send(result.second, null);
7625 }
7626 }
7627 );
Hall Liu82694d52020-12-11 18:22:04 -08007628 });
7629 }
7630
7631 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007632 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007633 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635
7636 final long identity = Binder.clearCallingIdentity();
7637 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007638 ImsManager.getInstance(defaultPhone.getContext(),
7639 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640 } finally {
7641 Binder.restoreCallingIdentity(identity);
7642 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007643 }
7644
7645 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007646 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007647 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7649 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007650 return false;
7651 }
Svet Ganovb320e182015-04-16 12:30:10 -07007652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653 final long identity = Binder.clearCallingIdentity();
7654 try {
7655 // Check the user preference and the system-level IMS setting. Even if the user has
7656 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7657 // In the long run, we may instead need to check if there exists a connection service
7658 // which can support video calling.
7659 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007660 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007661 return imsManager.isVtEnabledByPlatform()
7662 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7663 && imsManager.isVtEnabledByUser();
7664 } finally {
7665 Binder.restoreCallingIdentity(identity);
7666 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007667 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007668
Andrew Leea1239f22015-03-02 17:44:07 -08007669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007670 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7671 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007673 mApp, subId, callingPackage, callingFeatureId,
7674 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 return false;
7676 }
7677
7678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 CarrierConfigManager configManager =
7681 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007682 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
7686 }
Andrew Leea1239f22015-03-02 17:44:07 -08007687 }
7688
7689 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007690 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007692 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 return false;
7694 }
7695
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
7698 CarrierConfigManager configManager =
7699 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007700 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
Andrew Leea1239f22015-03-02 17:44:07 -08007705 }
7706
Andrew Lee9431b832015-03-09 18:46:45 -07007707 @Override
7708 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007709 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007710 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007711 }
7712
7713 @Override
7714 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 final long identity = Binder.clearCallingIdentity();
7716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007717 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 } finally {
7719 Binder.restoreCallingIdentity(identity);
7720 }
Andrew Lee9431b832015-03-09 18:46:45 -07007721 }
7722
Hall Liuf6668912018-10-31 17:05:23 -07007723 /**
7724 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7725 * support for the feature and device firmware support.
7726 *
7727 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7728 */
7729 @Override
7730 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007732 final Phone phone = getPhone(subscriptionId);
7733 if (phone == null) {
7734 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7735 return false;
7736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007738 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7740 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 return isCarrierSupported && isDeviceSupported;
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
Hall Liu98187582018-01-22 19:15:32 -08007746 }
7747
Hall Liuf6668912018-10-31 17:05:23 -07007748 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007749 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7750 * RTT setting, will return true if the device and carrier both support RTT.
7751 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007752 */
7753 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 final long identity = Binder.clearCallingIdentity();
7755 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007756 boolean isRttSupported = isRttSupported(subscriptionId);
7757 boolean isUserRttSettingOn = Settings.Secure.getInt(
7758 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7759 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7760 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7761 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762 } finally {
7763 Binder.restoreCallingIdentity(identity);
7764 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007765 }
7766
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007767 @Deprecated
7768 @Override
7769 public String getDeviceId(String callingPackage) {
7770 return getDeviceIdWithFeature(callingPackage, null);
7771 }
7772
Sanket Padawe7310cc72015-01-14 09:53:20 -08007773 /**
7774 * Returns the unique device ID of phone, for example, the IMEI for
7775 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7776 *
7777 * <p>Requires Permission:
7778 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7779 */
7780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007781 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007782 try {
7783 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7784 } catch (SecurityException se) {
7785 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7786 throw new SecurityException("Package " + callingPackage + " does not belong to "
7787 + Binder.getCallingUid());
7788 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007789 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007790 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007791 return null;
7792 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007793 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007794 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007795 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007796 return null;
7797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798
7799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 return phone.getDeviceId();
7802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007805 }
7806
Ping Sunc67b7c22016-03-02 19:16:45 +08007807 /**
7808 * {@hide}
7809 * Returns the IMS Registration Status on a particular subid
7810 *
7811 * @param subId
7812 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007813 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007814 Phone phone = getPhone(subId);
7815 if (phone != null) {
7816 return phone.isImsRegistered();
7817 } else {
7818 return false;
7819 }
7820 }
7821
Santos Cordon7a1885b2015-02-03 11:15:19 -08007822 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007823 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007824 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007826 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007827 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7828 }
7829 final long identity = Binder.clearCallingIdentity();
7830 try {
7831 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7832 } finally {
7833 Binder.restoreCallingIdentity(identity);
7834 }
7835 }
7836
7837 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007838 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007839 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007840 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007841 mApp,
7842 subscriptionId,
7843 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7844 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007845 final long identity = Binder.clearCallingIdentity();
7846 try {
7847 Phone phone = getPhone(subscriptionId);
7848 if (phone == null) {
7849 return null;
7850 }
7851 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
7854 }
7855 }
7856
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007857 /**
7858 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007859 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007860 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 Phone phone = getPhone(subId);
7864 if (phone != null) {
7865 return phone.isWifiCallingEnabled();
7866 } else {
7867 return false;
7868 }
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007871 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007872 }
7873
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007874 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007875 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007876 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007877 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878 final long identity = Binder.clearCallingIdentity();
7879 try {
7880 Phone phone = getPhone(subId);
7881 if (phone != null) {
7882 return phone.isVideoEnabled();
7883 } else {
7884 return false;
7885 }
7886 } finally {
7887 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007888 }
7889 }
7890
7891 /**
7892 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7893 * defined in {@link ImsRegistrationImplBase}.
7894 */
7895 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 final long identity = Binder.clearCallingIdentity();
7897 try {
7898 Phone phone = getPhone(subId);
7899 if (phone != null) {
7900 return phone.getImsRegistrationTech();
7901 } else {
7902 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7903 }
7904 } finally {
7905 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007906 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007907 }
7908
Stuart Scott8eef64f2015-04-08 15:13:54 -07007909 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007910 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007911 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007912 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7913 return;
7914 }
Kai Shif70f46f2021-03-03 13:59:46 -08007915 Phone defaultPhone = getDefaultPhone();
7916 if (defaultPhone != null) {
7917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7918 mApp, getDefaultPhone().getSubId(), "factoryReset");
7919 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007920 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007921
Svet Ganovcc087f82015-05-12 20:35:54 -07007922 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007923 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7924 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007925 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007926 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007927 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007928 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007929 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007931 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007932 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007933 // There has been issues when Sms raw table somehow stores orphan
7934 // fragments. They lead to garbled message when new fragments come
7935 // in and combined with those stale ones. In case this happens again,
7936 // user can reset all network settings which will clean up this table.
7937 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007938 // Clean up IMS settings as well here.
7939 int slotId = getSlotIndex(subId);
7940 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7941 ImsManager.getInstance(mApp, slotId).factoryReset();
7942 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007943
Kai Shif70f46f2021-03-03 13:59:46 -08007944 if (defaultPhone == null) {
7945 return;
7946 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007947 // Erase modem config if erase modem on network setting is enabled.
7948 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7949 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7950 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007951 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007952 }
Kai Shif70f46f2021-03-03 13:59:46 -08007953
7954 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007955 } finally {
7956 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007957 }
7958 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007959
SongFerngWangfd89b102021-05-27 22:44:54 +08007960 @VisibleForTesting
7961 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7962 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7963 return;
7964 }
7965 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7966 RILConstants.PREFERRED_NETWORK_MODE);
7967 SubscriptionManager.setSubscriptionProperty(subId,
7968 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7969 "user=" + defaultNetworkType);
7970 phone.loadAllowedNetworksFromSubscriptionDatabase();
7971 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7972 defaultNetworkType, null);
7973 }
7974
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007975 private void cleanUpSmsRawTable(Context context) {
7976 ContentResolver resolver = context.getContentResolver();
7977 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7978 resolver.delete(uri, null, null);
7979 }
7980
Narayan Kamath1c496c22015-04-16 14:40:19 +01007981 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007982 public String getSimLocaleForSubscriber(int subId) {
7983 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7984 final Phone phone = getPhone(subId);
7985 if (phone == null) {
7986 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007987 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 final long identity = Binder.clearCallingIdentity();
7990 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07007991 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
7992 phone.getContext().getOpPackageName(),
7993 phone.getContext().getAttributionTag());
7994 if (info == null) {
7995 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7996 return null;
chen xu6291c472019-02-04 12:55:53 -08007997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998 // Try and fetch the locale from the carrier properties or from the SIM language
7999 // preferences (EF-PL and EF-LI)...
8000 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008002 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8003 if (localeFromDefaultSim != null) {
8004 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8005 if (DBG) log("Using locale from subId: " + subId + " locale: "
8006 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008007 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008008 } else {
8009 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 }
8011 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 // The SIM language preferences only store a language (e.g. fr = French), not an
8014 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8015 // the SIM and carrier preferences does not include a country we add the country
8016 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008017 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008019 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008020 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 }
8022
8023 if (DBG) log("No locale found - returning null");
8024 return null;
8025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008028 }
8029
tom hsu0b59d292022-09-29 23:49:21 +08008030 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008031 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008032 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008033 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008034 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008035 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8036 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008037 Locale.forLanguageTag(localeTag).getCountry())) {
8038 return localeTag;
8039 }
8040 }
8041 return inputLocale.toLanguageTag();
8042 }
8043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008044 /**
8045 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8046 */
8047 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008048 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
8049 mApp.getOpPackageName(), mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008050 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008051
Gary Jian3aa9a762022-01-24 16:41:19 +08008052 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8053 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008054
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008055 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008056 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8057 * representing the state of the modem.
8058 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008059 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8060 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008061 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008062 */
8063 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008064 public void requestModemActivityInfo(ResultReceiver result) {
8065 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008066 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067
8068 final long identity = Binder.clearCallingIdentity();
8069 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008070 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 } finally {
8072 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008073 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008074 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008075
Gary Jian76280a42022-12-07 16:18:33 +08008076 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008077 // less than total activity duration.
8078 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8079 if (info == null) {
8080 return false;
8081 }
8082 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008083 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008084 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8085
Hall Liu49656c02020-10-09 19:00:11 -07008086 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8087
Siddharth Rayb8114062018-06-17 15:02:38 -07008088 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008089 && (info.getSleepTimeMillis() <= activityDurationMs)
8090 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008091 }
8092
Gary Jian3aa9a762022-01-24 16:41:19 +08008093 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8094 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8095 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8096 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8097
8098 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8099 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8100 }
8101
8102 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8103 mLastModemActivityInfo.setReceiveTimeMillis(
8104 rat,
8105 freq,
8106 info.getReceiveTimeMillis(rat, freq)
8107 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8108 }
8109
8110 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8111 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8112 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8113 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8114
8115 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8116 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8117 }
8118 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8119 mLastModemActivityInfo.setReceiveTimeMillis(
8120 rat,
8121 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8122 }
8123
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008124 /**
8125 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8126 * @param info recent ModemActivityInfo
8127 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008128 private void mergeModemActivityInfo(ModemActivityInfo info) {
8129 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008130 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008131 boolean matched;
8132 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8133 matched = false;
8134 int rat = info.getSpecificInfoRat(i);
8135 int freq = info.getSpecificInfoFrequencyRange(i);
8136 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8137 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8138 //if it already exists
8139 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8140 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8141 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8142 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8143 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8144 updateLastModemActivityInfo(info, rat, freq);
8145 matched = true;
8146 }
8147 } else {
8148 updateLastModemActivityInfo(info, rat);
8149 matched = true;
8150 }
8151 }
8152 }
8153
8154 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008155 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008156 new ActivityStatsTechSpecificInfo(
8157 rat,
8158 freq,
8159 info.getTransmitTimeMillis(rat, freq),
8160 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008161 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008162 }
8163 }
8164 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8165 mLastModemActivitySpecificInfo =
8166 new ActivityStatsTechSpecificInfo[merged.size()];
8167 merged.toArray(mLastModemActivitySpecificInfo);
8168
8169 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8170 mLastModemActivityInfo.setSleepTimeMillis(
8171 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008172 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008173 mLastModemActivityInfo.setIdleTimeMillis(
8174 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008175 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008176
8177 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008178 new ModemActivityInfo(
8179 mLastModemActivityInfo.getTimestampMillis(),
8180 mLastModemActivityInfo.getSleepTimeMillis(),
8181 mLastModemActivityInfo.getIdleTimeMillis(),
8182 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008183 }
8184
8185 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8186 ActivityStatsTechSpecificInfo[] info) {
8187 int infoSize = info.length;
8188 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8189 for (int i = 0; i < infoSize; i++) {
8190 ret[i] = new ActivityStatsTechSpecificInfo(
8191 info[i].getRat(), info[i].getFrequencyRange(),
8192 info[i].getTransmitTimeMillis(),
8193 (int) info[i].getReceiveTimeMillis());
8194 }
8195 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008196 }
8197
Jack Yu85bd38a2015-11-09 11:34:32 -08008198 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008199 * Returns the service state information on specified subscription.
8200 */
8201 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008202 public ServiceState getServiceStateForSubscriber(int subId,
8203 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8204 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008205 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008206 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008207 return null;
8208 }
8209
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008210 boolean hasFinePermission = false;
8211 boolean hasCoarsePermission = false;
8212 if (!renounceFineLocationAccess) {
8213 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8214 LocationAccessPolicy.checkLocationPermission(mApp,
8215 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8216 .setCallingPackage(callingPackage)
8217 .setCallingFeatureId(callingFeatureId)
8218 .setCallingPid(Binder.getCallingPid())
8219 .setCallingUid(Binder.getCallingUid())
8220 .setMethod("getServiceStateForSubscriber")
8221 .setLogAsInfo(true)
8222 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8223 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8224 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8225 .build());
8226 hasFinePermission =
8227 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8228 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008229
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008230 if (!renounceCoarseLocationAccess) {
8231 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8232 LocationAccessPolicy.checkLocationPermission(mApp,
8233 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8234 .setCallingPackage(callingPackage)
8235 .setCallingFeatureId(callingFeatureId)
8236 .setCallingPid(Binder.getCallingPid())
8237 .setCallingUid(Binder.getCallingUid())
8238 .setMethod("getServiceStateForSubscriber")
8239 .setLogAsInfo(true)
8240 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8241 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8242 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8243 .build());
8244 hasCoarsePermission =
8245 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8246 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008247
Jack Yu479f40e2020-10-27 21:29:25 -07008248 final Phone phone = getPhone(subId);
8249 if (phone == null) {
8250 return null;
8251 }
8252
Jordan Liu0f2bc442020-11-18 16:47:37 -08008253 final long identity = Binder.clearCallingIdentity();
8254
Jack Yu479f40e2020-10-27 21:29:25 -07008255 boolean isCallingPackageDataService = phone.getDataServicePackages()
8256 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008258 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008259 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8260 .getSubscriptionInfoInternal(subId);
8261 if (subInfo == null || !subInfo.isActive()) {
8262 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8263 + "subId=" + subId);
8264 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008265 }
8266
Hall Liuf19c44f2018-11-27 14:38:17 -08008267 ServiceState ss = phone.getServiceState();
8268
8269 // Scrub out the location info in ServiceState depending on what level of access
8270 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008271 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008272 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8273 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 } finally {
8275 Binder.restoreCallingIdentity(identity);
8276 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008277 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008278
8279 /**
8280 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8281 *
8282 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8283 * voicemail ringtone.
8284 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8285 * PhoneAccount.
8286 */
8287 @Override
8288 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008289 final long identity = Binder.clearCallingIdentity();
8290 try {
8291 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8292 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008293 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008300 }
8301
8302 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008303 * Sets the per-account voicemail ringtone.
8304 *
8305 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8306 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8307 *
8308 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8309 * voicemail ringtone.
8310 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8311 * PhoneAccount.
8312 */
8313 @Override
8314 public void setVoicemailRingtoneUri(String callingPackage,
8315 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008316 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008317 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008318 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8319 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8321 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8322 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324
8325 final long identity = Binder.clearCallingIdentity();
8326 try {
8327 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8328 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008329 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 }
8331 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008334 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008335 }
8336
8337 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008338 * Returns whether vibration is set for voicemail notification in Phone settings.
8339 *
8340 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8341 * voicemail vibration setting.
8342 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8343 */
8344 @Override
8345 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008346 final long identity = Binder.clearCallingIdentity();
8347 try {
8348 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8349 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008350 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008351 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8354 } finally {
8355 Binder.restoreCallingIdentity(identity);
8356 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008357 }
8358
Youhan Wange64578a2016-05-02 15:32:42 -07008359 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008360 * Sets the per-account voicemail vibration.
8361 *
8362 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8363 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8364 *
8365 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8366 * voicemail vibration setting.
8367 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8368 * specific PhoneAccount.
8369 */
8370 @Override
8371 public void setVoicemailVibrationEnabled(String callingPackage,
8372 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008373 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008375 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8376 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8378 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8379 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008380 }
8381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8385 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008386 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 }
8388 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8389 } finally {
8390 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008391 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008392 }
8393
8394 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008395 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8396 *
8397 * @throws SecurityException if the caller does not have the required permission
8398 */
arunvoddud7401012022-12-15 16:08:12 +00008399 @VisibleForTesting
8400 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008401 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008402 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008403 }
8404
8405 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008406 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8407 * permission.
8408 *
8409 * @throws SecurityException if the caller does not have the required permission
8410 */
8411 private void enforceSendSmsPermission() {
8412 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8413 }
8414
8415 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008416 * Make sure either called from same process as self (phone) or IPC caller has interact across
8417 * users permission.
8418 *
8419 * @throws SecurityException if the caller does not have the required permission
8420 */
8421 private void enforceInteractAcrossUsersPermission(String message) {
8422 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8423 }
8424
8425 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008426 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008427 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008428 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008429 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008430 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008434 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 if (componentName == null) {
8436 throw new SecurityException(
8437 "Caller not current active visual voicemail package[null]");
8438 }
8439 String vvmPackage = componentName.getPackageName();
8440 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008441 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442 }
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008445 }
8446 }
8447
8448 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008449 * Return the application ID for the app type.
8450 *
8451 * @param subId the subscription ID that this request applies to.
8452 * @param appType the uicc app type.
8453 * @return Application ID for specificied app type, or null if no uicc.
8454 */
8455 @Override
8456 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008457 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008458 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459
8460 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008461 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462 if (phone == null) {
8463 return null;
8464 }
8465 String aid = null;
8466 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008467 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468 .getApplicationByType(appType).getAid();
8469 } catch (Exception e) {
8470 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8471 }
8472 return aid;
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008475 }
Youhan Wange64578a2016-05-02 15:32:42 -07008476 }
8477
Youhan Wang4001d252016-05-11 10:29:41 -07008478 /**
8479 * Return the Electronic Serial Number.
8480 *
8481 * @param subId the subscription ID that this request applies to.
8482 * @return ESN or null if error.
8483 */
8484 @Override
8485 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008486 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008487 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008488
8489 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008490 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008491 if (phone == null) {
8492 return null;
8493 }
8494 String esn = null;
8495 try {
8496 esn = phone.getEsn();
8497 } catch (Exception e) {
8498 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8499 }
8500 return esn;
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008503 }
Youhan Wang4001d252016-05-11 10:29:41 -07008504 }
8505
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008506 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008507 * Return the Preferred Roaming List Version.
8508 *
8509 * @param subId the subscription ID that this request applies to.
8510 * @return PRLVersion or null if error.
8511 */
8512 @Override
8513 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008514 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008515 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516
8517 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008518 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008519 if (phone == null) {
8520 return null;
8521 }
8522 String cdmaPrlVersion = null;
8523 try {
8524 cdmaPrlVersion = phone.getCdmaPrlVersion();
8525 } catch (Exception e) {
8526 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8527 }
8528 return cdmaPrlVersion;
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008531 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008532 }
8533
8534 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008535 * Get snapshot of Telephony histograms
8536 * @return List of Telephony histograms
8537 * @hide
8538 */
8539 @Override
8540 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8542 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543
8544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 return RIL.getTelephonyRILTimingHistograms();
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
8549 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008550 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008551
8552 /**
8553 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008554 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8555 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008556 * Require system privileges. In the future we may add this to carrier APIs.
8557 *
Michele Berionne482f8202018-11-27 18:57:59 -08008558 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008559 */
8560 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008561 @TelephonyManager.SetCarrierRestrictionResult
8562 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008563 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008565
Michele Berionne482f8202018-11-27 18:57:59 -08008566 if (carrierRestrictionRules == null) {
8567 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008568 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570 final long identity = Binder.clearCallingIdentity();
8571 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008572 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008573 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 } finally {
8575 Binder.restoreCallingIdentity(identity);
8576 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008577 }
8578
8579 /**
8580 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008581 * Get the allowed carrier list and the excluded carrier list, including the priority between
8582 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008583 * Require system privileges. In the future we may add this to carrier APIs.
8584 *
Michele Berionne482f8202018-11-27 18:57:59 -08008585 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008586 */
8587 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008588 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008589 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008590 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008591
8592 final long identity = Binder.clearCallingIdentity();
8593 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008594 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8595 if (response instanceof CarrierRestrictionRules) {
8596 return (CarrierRestrictionRules) response;
8597 }
8598 // Response is an Exception of some kind,
8599 // which is signalled to the user as a NULL retval
8600 return null;
8601 } catch (Exception e) {
8602 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8603 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008604 } finally {
8605 Binder.restoreCallingIdentity(identity);
8606 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008607 }
8608
fionaxu59545b42016-05-25 15:53:37 -07008609 /**
arunvoddud7401012022-12-15 16:08:12 +00008610 * Fetches the carrier restriction status of the device and sends the status to the caller
8611 * through the callback.
8612 *
8613 * @param callback The callback that will be used to send the result.
8614 * @throws SecurityException if the caller does not have the required permission/privileges or
8615 * the caller is not allowlisted.
8616 */
8617 @Override
8618 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8619 enforceReadPermission("getCarrierRestrictionStatus");
8620 int carrierId = validateCallerAndGetCarrierId(packageName);
8621 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8622 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8623 throw new SecurityException("Not an authorized caller");
8624 }
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8628 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8629 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634
arunvoddu567f2b42023-04-25 17:22:00 +00008635 @Override
8636 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8637 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8638 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8639 return allowListInfo.getShaIdList(pkgName, carrierId);
8640 }
8641
arunvoddud7401012022-12-15 16:08:12 +00008642 @VisibleForTesting
8643 public int validateCallerAndGetCarrierId(String packageName) {
8644 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8645 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8646 }
8647
8648 /**
fionaxu59545b42016-05-25 15:53:37 -07008649 * Action set from carrier signalling broadcast receivers to enable/disable radio
8650 * @param subId the subscription ID that this action applies to.
8651 * @param enabled control enable or disable radio.
8652 * {@hide}
8653 */
8654 @Override
8655 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8656 enforceModifyPermission();
8657 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658
8659 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008660 if (phone == null) {
8661 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8662 return;
8663 }
8664 try {
8665 phone.carrierActionSetRadioEnabled(enabled);
8666 } catch (Exception e) {
8667 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668 } finally {
8669 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008670 }
8671 }
8672
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008673 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008674 * Enable or disable Voice over NR (VoNR)
8675 * @param subId the subscription ID that this action applies to.
8676 * @param enabled enable or disable VoNR.
8677 * @return operation result.
8678 */
8679 @Override
8680 public int setVoNrEnabled(int subId, boolean enabled) {
8681 enforceModifyPermission();
8682 final Phone phone = getPhone(subId);
8683
8684 final long identity = Binder.clearCallingIdentity();
8685 if (phone == null) {
8686 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8687 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8688 }
8689
8690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8691 try {
8692 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8693 workSource);
8694 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008695
8696 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8697 if (DBG) {
8698 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8699 }
8700 SubscriptionManager.setSubscriptionProperty(
8701 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8702 (enabled ? "1" : "0"));
8703 }
8704
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008705 return result;
8706 } finally {
8707 Binder.restoreCallingIdentity(identity);
8708 }
8709 }
8710
8711 /**
8712 * Is voice over NR enabled
8713 * @return true if VoNR is enabled else false
8714 */
8715 @Override
8716 public boolean isVoNrEnabled(int subId) {
8717 enforceReadPrivilegedPermission("isVoNrEnabled");
8718 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8722 null, subId, workSource);
8723 if (DBG) log("isVoNrEnabled: " + isEnabled);
8724 return isEnabled;
8725 } finally {
8726 Binder.restoreCallingIdentity(identity);
8727 }
8728 }
8729
8730 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008731 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8732 * network status based on which carrier apps could apply actions accordingly,
8733 * enable/disable default url handler for example.
8734 *
8735 * @param subId the subscription ID that this action applies to.
8736 * @param report control start/stop reporting the default network status.
8737 * {@hide}
8738 */
8739 @Override
8740 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8741 enforceModifyPermission();
8742 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743
8744 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008745 if (phone == null) {
8746 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8747 return;
8748 }
8749 try {
8750 phone.carrierActionReportDefaultNetworkStatus(report);
8751 } catch (Exception e) {
8752 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008753 } finally {
8754 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008755 }
8756 }
8757
8758 /**
fionaxud9622282017-07-17 17:51:30 -07008759 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8760 * @param subId the subscription ID that this action applies to.
8761 * {@hide}
8762 */
8763 @Override
8764 public void carrierActionResetAll(int subId) {
8765 enforceModifyPermission();
8766 final Phone phone = getPhone(subId);
8767 if (phone == null) {
8768 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8769 return;
8770 }
8771 try {
8772 phone.carrierActionResetAll();
8773 } catch (Exception e) {
8774 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8775 }
8776 }
8777
8778 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008779 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8780 * bug report is being generated.
8781 */
8782 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008783 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008784 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8785 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008786 writer.println("Permission Denial: can't dump Phone from pid="
8787 + Binder.getCallingPid()
8788 + ", uid=" + Binder.getCallingUid()
8789 + "without permission "
8790 + android.Manifest.permission.DUMP);
8791 return;
8792 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008793 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008794 }
Jack Yueb89b242016-06-22 13:27:47 -07008795
Brad Ebingerdac2f002018-04-03 15:17:52 -07008796 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008797 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8798 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8799 @NonNull String[] args) {
8800 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8801 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008802 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008803 }
8804
Jack Yueb89b242016-06-22 13:27:47 -07008805 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008806 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008807 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008808 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008809 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008810 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008811 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008812 */
8813 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008814 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008815 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008816 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8817 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8818 try {
8819 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008820 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008821 } catch (SecurityException se) {
8822 enforceModifyPermission();
8823 }
8824 } else {
8825 enforceModifyPermission();
8826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008827
8828 final long identity = Binder.clearCallingIdentity();
8829 try {
8830 Phone phone = getPhone(subId);
8831 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008832 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8833 phone.carrierActionSetMeteredApnsEnabled(enabled);
8834 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008835 phone.getDataSettingsManager().setDataEnabled(
8836 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008838 }
8839 } finally {
8840 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008841 }
8842 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008843
8844 /**
8845 * Get Client request stats
8846 * @return List of Client Request Stats
8847 * @hide
8848 */
8849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008850 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8851 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008853 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008854 return null;
8855 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008856 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008858 final long identity = Binder.clearCallingIdentity();
8859 try {
8860 if (phone != null) {
8861 return phone.getClientRequestStats();
8862 }
8863
8864 return null;
8865 } finally {
8866 Binder.restoreCallingIdentity(identity);
8867 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008868 }
8869
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008870 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008871 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008872 if (uid == Process.ROOT_UID && packageName == null) {
8873 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8874 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8875 // exception. ROOT_UID seems not to have a valid package name returned by
8876 // PackageManager, so just fake it here to avoid issues when running telephony shell
8877 // commands that plumb through the RIL as root, like so:
8878 // $ adb root
8879 // $ adb shell cmd phone ...
8880 packageName = "root";
8881 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008882 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008883 }
Jack Yueb4124c2017-02-16 15:32:43 -08008884
8885 /**
Grace Chen70990072017-03-24 17:21:30 -07008886 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008887 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008888 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008889 * @param state State of SIM (power down, power up, pass through)
8890 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8891 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8892 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008893 *
8894 **/
8895 @Override
Grace Chen70990072017-03-24 17:21:30 -07008896 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008897 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008898 Phone phone = PhoneFactory.getPhone(slotIndex);
8899
vagdeviaf9a5b92018-08-15 16:01:53 -07008900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008902 final long identity = Binder.clearCallingIdentity();
8903 try {
8904 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008905 phone.setSimPowerState(state, null, workSource);
8906 }
8907 } finally {
8908 Binder.restoreCallingIdentity(identity);
8909 }
8910 }
8911
8912 /**
8913 * Set SIM card power state.
8914 *
8915 * @param slotIndex SIM slot id.
8916 * @param state State of SIM (power down, power up, pass through)
8917 * @param callback callback to trigger after success or failure
8918 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8919 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8920 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8921 *
8922 **/
8923 @Override
8924 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8925 IIntegerConsumer callback) {
8926 enforceModifyPermission();
8927 Phone phone = PhoneFactory.getPhone(slotIndex);
8928
8929 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8930
8931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 if (phone != null) {
8934 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8935 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936 }
8937 } finally {
8938 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008939 }
8940 }
Shuo Qiandd210312017-04-12 22:11:33 +00008941
Tyler Gunn65d45c22017-06-05 11:22:26 -07008942 private boolean isUssdApiAllowed(int subId) {
8943 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008944 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008945 if (configManager == null) {
8946 return false;
8947 }
8948 PersistableBundle pb = configManager.getConfigForSubId(subId);
8949 if (pb == null) {
8950 return false;
8951 }
8952 return pb.getBoolean(
8953 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8954 }
8955
Shuo Qiandd210312017-04-12 22:11:33 +00008956 /**
Ling Mac28f0212023-03-24 16:07:15 -07008957 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008958 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008959 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008960 */
goneil9c5f4872017-12-05 14:07:56 -08008961 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008962 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008963 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008964 final long identity = Binder.clearCallingIdentity();
8965 try {
Ling Mac28f0212023-03-24 16:07:15 -07008966 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008967 } finally {
8968 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008969 }
8970 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008971
8972 /**
8973 * Get the current signal strength information for the given subscription.
8974 * Because this information is not updated when the device is in a low power state
8975 * it should not be relied-upon to be current.
8976 * @param subId Subscription index
8977 * @return the most recent cached signal strength info from the modem
8978 */
8979 @Override
8980 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 final long identity = Binder.clearCallingIdentity();
8982 try {
8983 Phone p = getPhone(subId);
8984 if (p == null) {
8985 return null;
8986 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008988 return p.getSignalStrength();
8989 } finally {
8990 Binder.restoreCallingIdentity(identity);
8991 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008992 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008993
Pengquan Meng77b7f132018-08-22 14:49:57 -07008994 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008995 * Get the current modem radio state for the given slot.
8996 * @param slotIndex slot index.
8997 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008998 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008999 * @return the current radio power state from the modem
9000 */
9001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009002 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009003 Phone phone = PhoneFactory.getPhone(slotIndex);
9004 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9006 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009007 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9008 }
9009
9010 final long identity = Binder.clearCallingIdentity();
9011 try {
9012 return phone.getRadioPowerState();
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
9015 }
9016 }
9017 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9018 }
9019
9020 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009021 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9022 *
9023 * <p>Requires one of the following permissions:
9024 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009025 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009026 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9027 * privileges.
9028 *
9029 * @param subId subscription id
9030 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9031 * {@code false}.
9032 */
9033 @Override
9034 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009035 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009036 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009037 try {
9038 mApp.enforceCallingOrSelfPermission(
9039 android.Manifest.permission.ACCESS_NETWORK_STATE,
9040 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009041 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009042 mApp.enforceCallingOrSelfPermission(
9043 permission.READ_BASIC_PHONE_STATE, functionName);
9044 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009045 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009046 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009047 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009048 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009049
Pengquan Menga1bb6272018-09-06 09:59:22 -07009050 boolean isEnabled = false;
9051 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009052 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009053 Phone phone = getPhone(subId);
9054 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009055 } finally {
9056 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009057 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009058 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009059 }
9060
9061
9062 /**
9063 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9064 *
9065 * <p> Requires permission:
9066 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9067 * privileges.
9068 *
9069 * @param subId subscription id
9070 * @param isEnabled {@code true} means enable, {@code false} means disable.
9071 */
9072 @Override
9073 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9075 mApp, subId, "setDataRoamingEnabled");
9076
Pengquan Menga1bb6272018-09-06 09:59:22 -07009077 final long identity = Binder.clearCallingIdentity();
9078 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009079 Phone phone = getPhone(subId);
9080 if (phone != null) {
9081 phone.setDataRoamingEnabled(isEnabled);
9082 }
9083 } finally {
9084 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009085 }
9086 }
9087
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009088 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009089 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009090 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009091 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009092 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009093
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009094 boolean isAllowed = true;
9095 final long identity = Binder.clearCallingIdentity();
9096 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009097 Phone phone = getPhone(subId);
9098 if (phone != null) {
9099 isAllowed = phone.isCspPlmnEnabled();
9100 }
9101 } finally {
9102 Binder.restoreCallingIdentity(identity);
9103 }
9104 return isAllowed;
9105 }
9106
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009107 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9108 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009109 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009110 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009111 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009112 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9113 if (phone == null) {
9114 return false;
9115 }
9116 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9117 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9118 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009119 }
9120
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009121 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009122 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009123 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009124 mApp.getSystemService(AppOpsManager.class)
9125 .checkPackage(Binder.getCallingUid(), callingPackage);
9126
Jordan Liu1e142fc2019-04-22 15:10:43 -07009127 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009128 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009129 try {
9130 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009131 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009132 } catch (SecurityException e) {
9133 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9134 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009135 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009136 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009137 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009138 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009139 }
sandeepjsb6c87872021-09-27 15:34:44 +00009140 // checking compatibility, if calling app's target SDK is T and beyond.
9141 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9142 Binder.getCallingUid())) {
9143 isIccIdAccessRestricted = true;
9144 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009145 final long identity = Binder.clearCallingIdentity();
9146 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009147 UiccController uiccController = UiccController.getInstance();
9148 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009149 if (hasReadPermission) {
9150 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009151 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009152
9153 // Remove private info if the caller doesn't have access
9154 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9155 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009156 //setting the value after compatibility check
9157 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009158 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9159 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009160 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009161 if (card == null) {
9162 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009163 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009164 continue;
9165 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009166 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9167 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009168 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009169 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009170 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009171 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9172 for (UiccPortInfo portInfo : portInfos) {
9173 UiccPort port = uiccController.getUiccPortForSlot(
9174 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9175 if (port == null) {
9176 // assume no access if port is null
9177 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9178 continue;
9179 }
9180 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9181 uiccPortInfos.add(portInfo);
9182 } else {
9183 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9184 }
9185 }
9186 filteredInfos.add(new UiccCardInfo(
9187 cardInfo.isEuicc(),
9188 cardInfo.getCardId(),
9189 null,
9190 cardInfo.getPhysicalSlotIndex(),
9191 cardInfo.isRemovable(),
9192 cardInfo.isMultipleEnabledProfilesSupported(),
9193 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009194 }
9195 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
9199 }
9200
sandeepjsb6c87872021-09-27 15:34:44 +00009201 /**
9202 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9203 * generally private and require carrier privileges to view.
9204 *
9205 * @hide
9206 */
9207 @NonNull
9208 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9209 List<UiccPortInfo> portinfo = new ArrayList<>();
9210 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9211 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9212 }
9213 return new UiccCardInfo(
9214 cardInfo.isEuicc(),
9215 cardInfo.getCardId(),
9216 null,
9217 cardInfo.getPhysicalSlotIndex(),
9218 cardInfo.isRemovable(),
9219 cardInfo.isMultipleEnabledProfilesSupported(),
9220 portinfo
9221 );
9222 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009223
sandeepjsb6c87872021-09-27 15:34:44 +00009224 /**
9225 * @hide
9226 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9227 * These values are generally private and require carrier privileges to view.
9228 */
9229 @NonNull
9230 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9231 return new UiccPortInfo(
9232 UiccPortInfo.ICCID_REDACTED,
9233 portInfo.getPortIndex(),
9234 portInfo.getLogicalSlotIndex(),
9235 portInfo.isActive()
9236 );
9237 }
9238 @Override
9239 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009240 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009241 mApp.getSystemService(AppOpsManager.class)
9242 .checkPackage(Binder.getCallingUid(), callingPackage);
9243
sandeepjsb6c87872021-09-27 15:34:44 +00009244 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009245
Aman Guptaf3c90b32022-03-17 04:54:16 +00009246 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9247 // we are reading iccId which is PII data.
9248 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009249
9250 // checking compatibility, if calling app's target SDK is T and beyond.
9251 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9252 Binder.getCallingUid())) {
9253 isLogicalSlotAccessRestricted = true;
9254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009258 if (slots == null || slots.length == 0) {
9259 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009260 return null;
9261 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009262 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9263 for (int i = 0; i < slots.length; i++) {
9264 UiccSlot slot = slots[i];
9265 if (slot == null) {
9266 continue;
9267 }
9268
Jordan Liu7be7e652019-05-06 18:55:02 +00009269 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009270 UiccCard card = slot.getUiccCard();
9271 if (card != null) {
9272 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009273 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009274 cardId = slot.getEid();
9275 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009276 // If cardId is null, use iccId of default port as cardId.
9277 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009279 }
9280
Jordan Liu857451f2019-05-09 16:35:35 -07009281 if (cardId != null) {
9282 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9283 // if cardId is an EID, it's all digits so this is fine
9284 cardId = IccUtils.stripTrailingFs(cardId);
9285 }
9286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009287 int cardState = 0;
9288 switch (slot.getCardState()) {
9289 case CARDSTATE_ABSENT:
9290 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9291 break;
9292 case CARDSTATE_PRESENT:
9293 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9294 break;
9295 case CARDSTATE_ERROR:
9296 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9297 break;
9298 case CARDSTATE_RESTRICTED:
9299 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9300 break;
9301 default:
9302 break;
9303
9304 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009305 List<UiccPortInfo> portInfos = new ArrayList<>();
9306 int[] portIndexes = slot.getPortList();
9307 for (int portIdx : portIndexes) {
9308 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009309 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009310 portInfos.add(new UiccPortInfo(iccId, portIdx,
9311 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009313 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009314 slot.isEuicc(),
9315 cardId,
9316 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009317 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009318 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009319 //setting the value after compatibility check
9320 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009321 }
9322 return infos;
9323 } finally {
9324 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009325 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009326 }
9327
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009328 /* Returns null if doesn't have read permission or carrier privilege access. */
9329 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9330 boolean hasReadPermission) {
9331 String iccId = slot.getIccId(portIndex);
9332 if (hasReadPermission) { // if has read permission
9333 return iccId;
9334 } else {
9335 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9336 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9337 // if no read permission, checking carrier privilege access
9338 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9339 return iccId;
9340 }
9341 }
9342 }
9343 // No read permission or carrier privilege access.
9344 return UiccPortInfo.ICCID_REDACTED;
9345 }
9346
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009347 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009348 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009349 public boolean switchSlots(int[] physicalSlots) {
9350 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009351
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009354 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9355 for (int i = 0; i < physicalSlots.length; i++) {
9356 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9357 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9358 physicalSlots[i], i));
9359 }
9360 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009361 } finally {
9362 Binder.restoreCallingIdentity(identity);
9363 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009364 }
Jack Yu4c988042018-02-27 15:30:01 -08009365
9366 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009367 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9368 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9369 enforceModifyPermission();
9370
9371 final long identity = Binder.clearCallingIdentity();
9372 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009373 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009374 } finally {
9375 Binder.restoreCallingIdentity(identity);
9376 }
9377 }
9378
9379 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009380 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009381 final long identity = Binder.clearCallingIdentity();
9382 try {
9383 return UiccController.getInstance().getCardIdForDefaultEuicc();
9384 } finally {
9385 Binder.restoreCallingIdentity(identity);
9386 }
9387 }
9388
Pengquan Meng85728fb2018-03-12 16:31:21 -07009389 /**
goneil47ffb6e2018-04-06 15:40:58 -07009390 * A test API to reload the UICC profile.
9391 *
9392 * <p>Requires that the calling app has permission
9393 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9394 * @hide
9395 */
9396 @Override
9397 public void refreshUiccProfile(int subId) {
9398 enforceModifyPermission();
9399
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
9402 Phone phone = getPhone(subId);
9403 if (phone == null) {
9404 return;
9405 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009406 UiccPort uiccPort = phone.getUiccPort();
9407 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009408 return;
9409 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009410 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009411 if (uiccProfile == null) {
9412 return;
9413 }
9414 uiccProfile.refresh();
9415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 }
9419
9420 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009421 * Returns false if the mobile data is disabled by default, otherwise return true.
9422 */
9423 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009424 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009425 }
9426
9427 /**
9428 * Returns true if the data roaming is enabled by default, i.e the system property
9429 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9430 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9431 */
9432 private boolean getDefaultDataRoamingEnabled(int subId) {
9433 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009434 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009435 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009436 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9437 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9438 return isDataRoamingEnabled;
9439 }
9440
9441 /**
9442 * Returns the default network type for the given {@code subId}, if the default network type is
9443 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9444 */
9445 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009446 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009447 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009448 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9449 return list.get(phoneId);
9450 }
9451 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009452 }
fionaxua13278b2018-03-21 00:08:13 -07009453
9454 @Override
9455 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009456 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009457 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009458
9459 final long identity = Binder.clearCallingIdentity();
9460 try {
9461 final Phone phone = getPhone(subId);
9462 if (phone == null) {
9463 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9464 return;
9465 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009466 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9467 if (cpt != null) {
9468 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9469 }
9470 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009471 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9472 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009473 if (carrierPrivilegeRules == null) {
9474 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9475 } else {
9476 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009478 } finally {
9479 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009480 }
fionaxua13278b2018-03-21 00:08:13 -07009481 }
9482
9483 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009484 public void setCarrierServicePackageOverride(
9485 int subId, String carrierServicePackage, String callingPackage) {
9486 TelephonyPermissions.enforceShellOnly(
9487 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9488
Benedict Wong66477622023-02-03 23:30:57 +00009489 final long identity = Binder.clearCallingIdentity();
9490 try {
9491 final Phone phone = getPhone(subId);
9492 if (phone == null || phone.getSubId() != subId) {
9493 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9494 throw new IllegalArgumentException("No phone for subid");
9495 }
9496 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9497 if (cpt == null) {
9498 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9499 throw new IllegalStateException("No CPT for phone");
9500 }
9501 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
9505 }
9506
9507 @Override
fionaxua13278b2018-03-21 00:08:13 -07009508 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009509 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009510
9511 final long identity = Binder.clearCallingIdentity();
9512 try {
9513 final Phone phone = getPhone(subId);
9514 if (phone == null) {
9515 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9516 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9517 }
9518 return phone.getCarrierIdListVersion();
9519 } finally {
9520 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009521 }
fionaxua13278b2018-03-21 00:08:13 -07009522 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009523
9524 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009525 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9526 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009528 mApp, subId, callingPackage, callingFeatureId,
9529 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009530 return -1;
9531 }
9532
9533 final long identity = Binder.clearCallingIdentity();
9534 try {
9535 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9536 } finally {
9537 Binder.restoreCallingIdentity(identity);
9538 }
9539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009540
9541 @Override
9542 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009543 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009544 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009545 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009546
9547 final long identity = Binder.clearCallingIdentity();
9548 try {
9549 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9550 } finally {
9551 Binder.restoreCallingIdentity(identity);
9552 }
9553 }
9554
9555 @Override
9556 public boolean setCdmaRoamingMode(int subId, int mode) {
9557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9558 mApp, subId, "setCdmaRoamingMode");
9559
9560 final long identity = Binder.clearCallingIdentity();
9561 try {
9562 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
9567
9568 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009569 public int getCdmaSubscriptionMode(int subId) {
9570 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009571 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009572 mApp, subId, "getCdmaSubscriptionMode");
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9577 } finally {
9578 Binder.restoreCallingIdentity(identity);
9579 }
9580 }
9581
9582 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009583 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9585 mApp, subId, "setCdmaSubscriptionMode");
9586
9587 final long identity = Binder.clearCallingIdentity();
9588 try {
9589 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9590 } finally {
9591 Binder.restoreCallingIdentity(identity);
9592 }
9593 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009594
sqianc5eccab2018-10-19 18:46:41 -07009595 @Override
sqian8c685422019-02-22 15:55:18 -08009596 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009597 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009599 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9600 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009601 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9602 }
9603 final long identity = Binder.clearCallingIdentity();
9604 try {
sqian854d44b2018-12-12 16:48:18 -08009605 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9606 for (Phone phone: PhoneFactory.getPhones()) {
9607 if (phone.getEmergencyNumberTracker() != null
9608 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9609 emergencyNumberListInternal.put(
9610 phone.getSubId(),
9611 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9612 }
sqian11b7a0e2018-12-05 18:48:28 -08009613 }
sqian854d44b2018-12-12 16:48:18 -08009614 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
sqianc5eccab2018-10-19 18:46:41 -07009618 }
9619
9620 @Override
sqian8c685422019-02-22 15:55:18 -08009621 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009622 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009623 if (!exactMatch) {
9624 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009625 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009626 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009627 }
9628 final long identity = Binder.clearCallingIdentity();
9629 try {
sqian854d44b2018-12-12 16:48:18 -08009630 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009631 //Note: we ignore passed in param exactMatch. We can remove it once
9632 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009633 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009634 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009635 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009636 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009637 }
sqian11b7a0e2018-12-05 18:48:28 -08009638 }
9639 return false;
9640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 }
9644
sqianf4ca7ed2019-01-15 18:32:07 -08009645 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009646 * Start emergency callback mode for GsmCdmaPhone for testing.
9647 */
9648 @Override
9649 public void startEmergencyCallbackMode() {
9650 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9651 "startEmergencyCallbackMode");
9652 enforceModifyPermission();
9653 final long identity = Binder.clearCallingIdentity();
9654 try {
9655 for (Phone phone : PhoneFactory.getPhones()) {
9656 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9657 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9658 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9659 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9660 gsmCdmaPhone.obtainMessage(
9661 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9662 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9663 }
9664 }
9665 } finally {
9666 Binder.restoreCallingIdentity(identity);
9667 }
9668 }
9669
9670 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009671 * Update emergency number list for test mode.
9672 */
9673 @Override
9674 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9675 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9676 "updateEmergencyNumberListTestMode");
9677
9678 final long identity = Binder.clearCallingIdentity();
9679 try {
9680 for (Phone phone: PhoneFactory.getPhones()) {
9681 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9682 if (tracker != null) {
9683 tracker.executeEmergencyNumberTestModeCommand(action, num);
9684 }
9685 }
9686 } finally {
9687 Binder.restoreCallingIdentity(identity);
9688 }
9689 }
9690
9691 /**
9692 * Get the full emergency number list for test mode.
9693 */
9694 @Override
9695 public List<String> getEmergencyNumberListTestMode() {
9696 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9697 "getEmergencyNumberListTestMode");
9698
9699 final long identity = Binder.clearCallingIdentity();
9700 try {
9701 Set<String> emergencyNumbers = new HashSet<>();
9702 for (Phone phone: PhoneFactory.getPhones()) {
9703 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9704 if (tracker != null) {
9705 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9706 emergencyNumbers.add(num.getNumber());
9707 }
9708 }
9709 }
9710 return new ArrayList<>(emergencyNumbers);
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715
chen xud6b45bd2018-10-30 22:27:10 -07009716 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009717 public int getEmergencyNumberDbVersion(int subId) {
9718 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9719
9720 final long identity = Binder.clearCallingIdentity();
9721 try {
9722 final Phone phone = getPhone(subId);
9723 if (phone == null) {
9724 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9725 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9726 }
9727 return phone.getEmergencyNumberDbVersion();
9728 } finally {
9729 Binder.restoreCallingIdentity(identity);
9730 }
9731 }
9732
9733 @Override
9734 public void notifyOtaEmergencyNumberDbInstalled() {
9735 enforceModifyPermission();
9736
9737 final long identity = Binder.clearCallingIdentity();
9738 try {
9739 for (Phone phone: PhoneFactory.getPhones()) {
9740 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9741 if (tracker != null) {
9742 tracker.updateOtaEmergencyNumberDatabase();
9743 }
9744 }
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
9747 }
9748 }
9749
9750 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009751 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009752 enforceActiveEmergencySessionPermission();
9753
9754 final long identity = Binder.clearCallingIdentity();
9755 try {
9756 for (Phone phone: PhoneFactory.getPhones()) {
9757 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9758 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009759 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9760 }
9761 }
9762 } finally {
9763 Binder.restoreCallingIdentity(identity);
9764 }
9765 }
9766
9767 @Override
9768 public void resetOtaEmergencyNumberDbFilePath() {
9769 enforceActiveEmergencySessionPermission();
9770
9771 final long identity = Binder.clearCallingIdentity();
9772 try {
9773 for (Phone phone: PhoneFactory.getPhones()) {
9774 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9775 if (tracker != null) {
9776 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009777 }
9778 }
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
9783
9784 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009785 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9786 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9787 Phone phone = getPhone(subId);
9788 if (phone == null) {
9789 return null;
9790 }
9791 final long identity = Binder.clearCallingIdentity();
9792 try {
9793 UiccProfile profile = UiccController.getInstance()
9794 .getUiccProfileForPhone(phone.getPhoneId());
9795 if (profile != null) {
9796 return profile.getCertsFromCarrierPrivilegeAccessRules();
9797 }
9798 } finally {
9799 Binder.restoreCallingIdentity(identity);
9800 }
9801 return null;
9802 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009803
9804 /**
9805 * Enable or disable a modem stack.
9806 */
9807 @Override
9808 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9809 enforceModifyPermission();
9810
9811 final long identity = Binder.clearCallingIdentity();
9812 try {
9813 Phone phone = PhoneFactory.getPhone(slotIndex);
9814 if (phone == null) {
9815 return false;
9816 } else {
9817 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9818 }
9819 } finally {
9820 Binder.restoreCallingIdentity(identity);
9821 }
9822 }
Michelecea4cf22018-12-21 15:00:11 -08009823
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009824 /**
9825 * Whether a modem stack is enabled or not.
9826 */
9827 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009828 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9829 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009830 Phone phone = PhoneFactory.getPhone(slotIndex);
9831 if (phone == null) return false;
9832
9833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009834 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9835 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009836 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9837 }
9838
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009841 try {
9842 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9843 } catch (NoSuchElementException ex) {
9844 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9845 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009846 } finally {
9847 Binder.restoreCallingIdentity(identity);
9848 }
9849 }
9850
Michelecea4cf22018-12-21 15:00:11 -08009851 @Override
Michele0ea7d782019-03-19 14:58:42 -07009852 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009853 enforceModifyPermission();
9854
9855 final long identity = Binder.clearCallingIdentity();
9856 try {
9857 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009858 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009859 .commit();
9860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 }
9864
9865 @Override
Michele0ea7d782019-03-19 14:58:42 -07009866 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009867 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009868 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009869 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9870 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009871 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009872 }
Michelecea4cf22018-12-21 15:00:11 -08009873
9874 final long identity = Binder.clearCallingIdentity();
9875 try {
Michele0ea7d782019-03-19 14:58:42 -07009876 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009877 } finally {
9878 Binder.restoreCallingIdentity(identity);
9879 }
9880 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009881
Michele0ea7d782019-03-19 14:58:42 -07009882 @TelephonyManager.IsMultiSimSupportedResult
9883 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009884 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9885 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9886 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009887 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9888 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009889 }
9890 // Check if the hardware supports multisim functionality. If usage of multisim is not
9891 // supported by the modem, indicate that it is restricted.
9892 PhoneCapability staticCapability =
9893 mPhoneConfigurationManager.getStaticPhoneCapability();
9894 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009895 loge("isMultiSimSupportedInternal: no static configuration available");
9896 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009897 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009898 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009899 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9900 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009901 }
9902 // Check if support of multiple SIMs is restricted by carrier
9903 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009904 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009905 }
9906
Michele0ea7d782019-03-19 14:58:42 -07009907 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009908 }
9909
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009910 /**
9911 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009912 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9913 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9914 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009915 * @param numOfSims number of active sims we want to switch to
9916 */
9917 @Override
9918 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009919 if (numOfSims == 1) {
9920 enforceModifyPermission();
9921 } else {
9922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9923 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9924 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009925 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009926
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009927 try {
Michele30b57b22019-03-01 12:01:14 -08009928 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009929 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009930 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9931 return;
9932 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009933 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9934 } finally {
9935 Binder.restoreCallingIdentity(identity);
9936 }
9937 }
9938
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009939 @Override
9940 public boolean isApplicationOnUicc(int subId, int appType) {
9941 enforceReadPrivilegedPermission("isApplicationOnUicc");
9942 Phone phone = getPhone(subId);
9943 if (phone == null) {
9944 return false;
9945 }
9946 final long identity = Binder.clearCallingIdentity();
9947 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009948 UiccPort uiccPort = phone.getUiccPort();
9949 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009950 return false;
9951 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009952 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009953 if (uiccProfile == null) {
9954 return false;
9955 }
9956 if (TelephonyManager.APPTYPE_SIM <= appType
9957 && appType <= TelephonyManager.APPTYPE_ISIM) {
9958 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9959 }
9960 return false;
9961 } finally {
9962 Binder.restoreCallingIdentity(identity);
9963 }
9964 }
9965
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009966 /**
chen xub4baa772019-04-03 10:23:41 -07009967 * Get whether making changes to modem configurations will trigger reboot.
9968 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009969 */
9970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009971 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9972 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009974 mApp, subId, callingPackage, callingFeatureId,
9975 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009976 return false;
9977 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009978 final long identity = Binder.clearCallingIdentity();
9979 try {
9980 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 }
9985
Nathan Harold29f5f052019-02-15 13:41:57 -08009986 private void updateModemStateMetrics() {
9987 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9988 // TODO: check the state for each modem if the api is ready.
9989 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9990 }
9991
Pengquan Meng3889a572019-01-23 11:16:29 -08009992 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009993 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009994 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009995 // Verify that the callingPackage belongs to the calling UID
9996 mApp.getSystemService(AppOpsManager.class)
9997 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009998 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009999 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010000 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010001 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10002 if (slotInfos != null) {
10003 for (int i = 0; i < slotInfos.length; i++) {
10004 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10005 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10006 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10007 portInfo.getLogicalSlotIndex()));
10008 }
10009 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010010 }
10011 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010012 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010013 } finally {
10014 Binder.restoreCallingIdentity(identity);
10015 }
10016 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010017
10018 /**
10019 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010020 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010021 */
jimsunf9ec1622022-09-13 21:18:43 +080010022 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010023 @Override
10024 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010025 return getHalVersion(HAL_SERVICE_RADIO);
10026 }
10027
10028 /**
10029 * Get the HAL Version of a specific service
10030 */
10031 @Override
10032 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010033 Phone phone = getDefaultPhone();
10034 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010035 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010036 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10037 return hv.major * 100 + hv.minor;
10038 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010039
10040 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010041 * Get the current calling package name.
10042 * @return the current calling package name
10043 */
10044 @Override
10045 public String getCurrentPackageName() {
10046 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10047 }
10048
10049 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010050 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10051 * corresponding network requests on a subId.
10052 *
10053 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010054 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010055 * 2) APN is un-metered for this subscription, or
10056 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010057 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010058 *
10059 * @return whether data is allowed for a apn type.
10060 *
10061 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010062 */
10063 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010064 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010065 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10066 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010067
10068 // Now that all security checks passes, perform the operation as ourselves.
10069 final long identity = Binder.clearCallingIdentity();
10070 try {
10071 Phone phone = getPhone(subId);
10072 if (phone == null) return false;
10073
Jack Yu27422a52022-03-21 10:38:05 -070010074 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010075 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010076 isMetered = phone.getDataNetworkController().getDataConfigManager()
10077 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10078 phone.getServiceState().getDataRoaming());
10079 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010080 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010081 } finally {
10082 Binder.restoreCallingIdentity(identity);
10083 }
10084 }
10085
10086 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010087 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010088 enforceReadPrivilegedPermission("isApnMetered");
10089
10090 // Now that all security checks passes, perform the operation as ourselves.
10091 final long identity = Binder.clearCallingIdentity();
10092 try {
10093 Phone phone = getPhone(subId);
10094 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010095 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10096 DataUtils.apnTypeToNetworkCapability(apnType),
10097 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010102
10103 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010104 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10105 int subscriptionId, IBooleanConsumer resultCallback) {
10106 enforceModifyPermission();
10107 long token = Binder.clearCallingIdentity();
10108 try {
10109 Phone phone = getPhone(subscriptionId);
10110 if (phone == null) {
10111 try {
10112 if (resultCallback != null) {
10113 resultCallback.accept(false);
10114 }
10115 } catch (RemoteException e) {
10116 // ignore
10117 }
10118 return;
10119 }
10120 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10121 Pair.create(specifiers, (x) -> {
10122 try {
10123 if (resultCallback != null) {
10124 resultCallback.accept(x);
10125 }
10126 } catch (RemoteException e) {
10127 // ignore
10128 }
10129 });
10130 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10131 } finally {
10132 Binder.restoreCallingIdentity(token);
10133 }
10134 }
10135
10136 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010137 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10138 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010139 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010140 mApp, subId, "getSystemSelectionChannels");
10141 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10142 final long identity = Binder.clearCallingIdentity();
10143 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010144 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10145 if (result instanceof IllegalStateException) {
10146 throw (IllegalStateException) result;
10147 }
10148 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010149 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10150 return specifiers;
10151 } finally {
10152 Binder.restoreCallingIdentity(identity);
10153 }
10154 }
10155
10156 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010157 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010158 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010159 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010160 }
10161
10162 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010163 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10164 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010165 if (callingPackage == null) {
10166 callingPackage = getCurrentPackageName();
10167 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010168 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10169 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010170 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10171 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010172 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10173 }
10174 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10175 Intent intent = new Intent();
10176 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10177 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10178 // Bring up choose default SMS subscription dialog right now
10179 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10180 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10181 mApp.startActivity(intent);
10182 }
chen xud5ca2d52019-05-28 15:20:57 -070010183
10184 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010185 public void showSwitchToManagedProfileDialog() {
10186 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010187 try {
10188 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10189 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10190 // for work telephony.
10191 Intent intent = new Intent(Intent.ACTION_SENDTO);
10192 intent.setData(Uri.parse("smsto:"));
10193 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10194 mApp.startActivity(intent);
10195 } catch (ActivityNotFoundException e) {
10196 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10197 Intent intent = new Intent();
10198 intent.setClass(mApp, ErrorDialogActivity.class);
10199 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10200 mApp.startActivity(intent);
10201 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010202 }
10203
10204 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010205 public String getMmsUAProfUrl(int subId) {
10206 //TODO investigate if this API should require proper permission check in R b/133791609
10207 final long identity = Binder.clearCallingIdentity();
10208 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010209 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10210 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10211 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10212 return carrierUAProfUrl;
10213 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010214 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10215 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010216 } finally {
10217 Binder.restoreCallingIdentity(identity);
10218 }
10219 }
10220
10221 @Override
10222 public String getMmsUserAgent(int subId) {
10223 //TODO investigate if this API should require proper permission check in R b/133791609
10224 final long identity = Binder.clearCallingIdentity();
10225 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010226 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10227 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10228 if (!TextUtils.isEmpty(carrierUserAgent)) {
10229 return carrierUserAgent;
10230 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010231 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10232 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010233 } finally {
10234 Binder.restoreCallingIdentity(identity);
10235 }
10236 }
Jack Yub07d4972019-05-28 16:12:25 -070010237
10238 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010239 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10240 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010241
Jack Yub07d4972019-05-28 16:12:25 -070010242 final long identity = Binder.clearCallingIdentity();
10243 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010244 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010245 if (phone == null) return false;
10246
Ling Maf188d502022-09-16 15:22:36 -070010247 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010248 } finally {
10249 Binder.restoreCallingIdentity(identity);
10250 }
10251 }
10252
10253 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010254 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010255 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010256 enforceModifyPermission();
10257
changbettyd5c246e2019-12-24 15:40:37 +080010258 final long identity = Binder.clearCallingIdentity();
10259 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010260 Phone phone = getPhone(subscriptionId);
10261 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010262
Ling Maf188d502022-09-16 15:22:36 -070010263 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010264 } finally {
10265 Binder.restoreCallingIdentity(identity);
10266 }
10267 }
10268
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010269 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010270 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010271 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10272 * otherwise.
10273 */
10274 @Override
10275 public void setCepEnabled(boolean isCepEnabled) {
10276 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10277
10278 final long identity = Binder.clearCallingIdentity();
10279 try {
10280 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10281 for (Phone phone : PhoneFactory.getPhones()) {
10282 Phone defaultPhone = phone.getImsPhone();
10283 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10284 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10285 ImsPhoneCallTracker imsPhoneCallTracker =
10286 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10287 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10288 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10289 + imsPhone.getMsisdn());
10290 }
10291 }
10292 } finally {
10293 Binder.restoreCallingIdentity(identity);
10294 }
10295 }
allenwtsu46dcc572020-01-08 18:24:03 +080010296
10297 /**
10298 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10299 *
10300 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10301 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10302 * before being read.
10303 */
10304 @Override
10305 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10306 isCompressed) {
10307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10308 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10310 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10311 }
10312 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010313 // ProvisioningManager can not handle ServiceSpecificException.
10314 // Throw the IllegalStateException and annotate ProvisioningManager.
10315 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010316 }
10317
10318 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010319 try {
Hui Wang761a6682020-10-31 05:12:53 +000010320 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10321 } finally {
10322 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010323 }
10324 }
zoey chene02881a2019-12-30 16:11:23 +080010325
10326 @Override
10327 public boolean isIccLockEnabled(int subId) {
10328 enforceReadPrivilegedPermission("isIccLockEnabled");
10329
10330 // Now that all security checks passes, perform the operation as ourselves.
10331 final long identity = Binder.clearCallingIdentity();
10332 try {
10333 Phone phone = getPhone(subId);
10334 if (phone != null && phone.getIccCard() != null) {
10335 return phone.getIccCard().getIccLockEnabled();
10336 } else {
10337 return false;
10338 }
10339 } finally {
10340 Binder.restoreCallingIdentity(identity);
10341 }
10342 }
10343
10344 /**
10345 * Set the ICC pin lock enabled or disabled.
10346 *
10347 * @return an integer representing the status of IccLock enabled or disabled in the following
10348 * three cases:
10349 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10350 * successfully.
10351 * - Positive number and zero for remaining password attempts.
10352 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10353 *
10354 */
10355 @Override
10356 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10357 enforceModifyPermission();
10358
10359 Phone phone = getPhone(subId);
10360 if (phone == null) {
10361 return 0;
10362 }
10363 // Now that all security checks passes, perform the operation as ourselves.
10364 final long identity = Binder.clearCallingIdentity();
10365 try {
10366 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10367 new Pair<Boolean, String>(enabled, password), phone, null);
10368 return attemptsRemaining;
10369
10370 } catch (Exception e) {
10371 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 return 0;
10376 }
10377
10378 /**
10379 * Change the ICC password used in ICC pin lock.
10380 *
10381 * @return an integer representing the status of IccLock changed in the following three cases:
10382 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10383 * - Positive number and zero for remaining password attempts.
10384 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10385 *
10386 */
10387 @Override
10388 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10389 enforceModifyPermission();
10390
10391 Phone phone = getPhone(subId);
10392 if (phone == null) {
10393 return 0;
10394 }
10395 // Now that all security checks passes, perform the operation as ourselves.
10396 final long identity = Binder.clearCallingIdentity();
10397 try {
10398 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10399 new Pair<String, String>(oldPassword, newPassword), phone, null);
10400 return attemptsRemaining;
10401
10402 } catch (Exception e) {
10403 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10404 } finally {
10405 Binder.restoreCallingIdentity(identity);
10406 }
10407 return 0;
10408 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010409
10410 /**
10411 * Request for receiving user activity notification
10412 */
10413 @Override
10414 public void requestUserActivityNotification() {
10415 if (!mNotifyUserActivity.get()
10416 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10417 mNotifyUserActivity.set(true);
10418 }
10419 }
10420
10421 /**
10422 * Called when userActivity is signalled in the power manager.
10423 * This is safe to call from any thread, with any window manager locks held or not.
10424 */
10425 @Override
10426 public void userActivity() {
10427 // ***************************************
10428 // * Inherited from PhoneWindowManager *
10429 // ***************************************
10430 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10431 // WITH ITS LOCKS HELD.
10432 //
10433 // This code must be VERY careful about the locks
10434 // it acquires.
10435 // In fact, the current code acquires way too many,
10436 // and probably has lurking deadlocks.
10437
10438 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10439 throw new SecurityException("Only the OS may call notifyUserActivity()");
10440 }
10441
10442 if (mNotifyUserActivity.getAndSet(false)) {
10443 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10444 USER_ACTIVITY_NOTIFICATION_DELAY);
10445 }
10446 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010447
10448 @Override
10449 public boolean canConnectTo5GInDsdsMode() {
10450 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10451 }
Jack Yud10cdd42020-09-28 20:28:01 -070010452
10453 @Override
10454 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10455 String callingFeatureId) {
10456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10457 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10458 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10459 }
10460
10461 Phone phone = getPhone(subId);
10462 if (phone == null) {
10463 throw new RuntimeException("phone is not available");
10464 }
10465 // Now that all security checks passes, perform the operation as ourselves.
10466 final long identity = Binder.clearCallingIdentity();
10467 try {
10468 return phone.getEquivalentHomePlmns();
10469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
Daniel Bright59e67312020-11-13 11:49:37 -080010473
10474 @Override
10475 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010476 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10477 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010478 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010479 if (radioInterfaceCapabilities == null) {
10480 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010481 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010482 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010483 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010484
Hui Wang641e81c2020-10-12 12:14:23 -070010485 @Override
10486 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10487 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010488 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10489 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10490 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10491 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10492 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010493 if (DBG) {
10494 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10495 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10496 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10497 }
10498
10499 if (!SubscriptionManager.isValidSubscriptionId(subId)
10500 || appType < TelephonyManager.APPTYPE_UNKNOWN
10501 || appType > TelephonyManager.APPTYPE_ISIM
10502 || nafUrl == null || securityProtocol == null || callback == null) {
10503 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10504 if (callback != null) {
10505 try {
10506 callback.onAuthenticationFailure(
10507 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10508 } catch (RemoteException exception) {
10509 log("Fail to notify onAuthenticationFailure due to " + exception);
10510 }
10511 return;
10512 }
10513 }
10514
10515 final long token = Binder.clearCallingIdentity();
10516 try {
10517 getGbaManager(subId).bootstrapAuthenticationRequest(
10518 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010519 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010520 } finally {
10521 Binder.restoreCallingIdentity(token);
10522 }
10523 }
10524
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010525 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010526 * Attempts to set the radio power state for all phones for thermal reason.
10527 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010528 * requested radio power state will actually be set. See {@link
10529 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10530 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010531 * @param enable {@code true} if trying to turn radio on.
10532 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10533 * false}.
10534 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010535 private boolean setRadioPowerForThermal(boolean enable) {
10536 boolean isPhoneAvailable = false;
10537 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10538 Phone phone = PhoneFactory.getPhone(i);
10539 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010540 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010541 isPhoneAvailable = true;
10542 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010543 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010544
10545 // return true if successfully informed the phone object about the thermal radio power
10546 // request.
10547 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010548 }
10549
10550 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010551 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010552 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10553 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10554 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10555 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10556 throw new IllegalArgumentException("modem does not support data throttling");
10557 }
10558
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010559 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10560 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010561 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010562 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10563 }
10564
Sarah Chinecc78c42022-03-31 21:16:48 -070010565 setDataEnabledForReason(
10566 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010567
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010568 if (isDataThrottlingSupported) {
10569 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010570 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010571 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10572 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10573 } else if (thermalMitigationResult
10574 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010575 log("Modem likely does not support data throttling on secondary carrier. Data " +
10576 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10577 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010578 }
10579 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010580 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010581
10582 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010583 }
10584
Jack Nudelman644b91a2021-03-12 14:09:48 -080010585 private static List<String> getThermalMitigationAllowlist(Context context) {
10586 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10587 for (String pckg : context.getResources()
10588 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10589 sThermalMitigationAllowlistedPackages.add(pckg);
10590 }
10591 }
10592
10593 return sThermalMitigationAllowlistedPackages;
10594 }
10595
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010596 private boolean isAnyPhoneInEmergencyState() {
10597 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10598 if (tm.isInEmergencyCall()) {
10599 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10600 return true;
10601 }
10602 for (Phone phone : PhoneFactory.getPhones()) {
10603 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10604 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010605 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10606 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010607 return true;
10608 }
10609 }
10610
10611 return false;
10612 }
10613
Jack Nudelman644b91a2021-03-12 14:09:48 -080010614 /**
10615 * Used by shell commands to add an authorized package name for thermal mitigation.
10616 * @param packageName name of package to be allowlisted
10617 * @param context
10618 */
10619 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10620 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10621 sThermalMitigationAllowlistedPackages.add(packageName);
10622 }
10623
10624 /**
10625 * Used by shell commands to remove an authorized package name for thermal mitigation.
10626 * @param packageName name of package to remove from allowlist
10627 * @param context
10628 */
10629 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10630 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10631 sThermalMitigationAllowlistedPackages.remove(packageName);
10632 }
10633
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010634 /**
10635 * Thermal mitigation request to control functionalities at modem.
10636 *
10637 * @param subId the id of the subscription.
10638 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010639 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010640 *
10641 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10642 */
10643 @Override
10644 @ThermalMitigationResult
10645 public int sendThermalMitigationRequest(
10646 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010647 ThermalMitigationRequest thermalMitigationRequest,
10648 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010649 enforceModifyPermission();
10650
Jack Nudelman644b91a2021-03-12 14:09:48 -080010651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10652 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10653 .contains(callingPackage)) {
10654 throw new SecurityException("Calling package must be configured in the device config. "
10655 + "calling package: " + callingPackage);
10656 }
10657
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10659 final long identity = Binder.clearCallingIdentity();
10660
10661 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10662 try {
10663 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10664 switch (thermalMitigationAction) {
10665 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10666 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010667 handleDataThrottlingRequest(subId,
10668 thermalMitigationRequest.getDataThrottlingRequest(),
10669 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010670 break;
10671 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10672 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10673 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10674 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10675 }
10676
10677 // Ensure that radio is on. If not able to power on due to phone being
10678 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010679 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010680 thermalMitigationResult =
10681 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10682 break;
10683 }
10684
10685 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010686 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010687 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10688 break;
10689 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10690 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10691 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10692 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10693 }
10694
10695 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10696 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010697 Phone phone = getPhone(subId);
10698 if (phone == null) {
10699 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010700 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010701 break;
10702 }
10703
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010704 TelephonyConnectionService service =
10705 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010706 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010707 Log.e(LOG_TAG, "An emergency call is pending");
10708 thermalMitigationResult =
10709 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10710 break;
10711 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010712 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010713 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010714 break;
10715 }
10716 } else {
10717 thermalMitigationResult =
10718 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10719 break;
10720 }
10721
10722 // Turn radio off. If not able to power off due to phone being unavailable,
10723 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010724 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010725 thermalMitigationResult =
10726 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10727 break;
10728 }
10729 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010730 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010731 break;
10732 default:
10733 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10734 + "not exist. Requested action: " + thermalMitigationAction);
10735 }
10736 } catch (IllegalArgumentException e) {
10737 throw e;
10738 } catch (Exception e) {
10739 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10740 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744
10745 if (DBG) {
10746 log("thermalMitigationRequest returning with thermalMitigationResult: "
10747 + thermalMitigationResult);
10748 }
10749
10750 return thermalMitigationResult;
10751 }
Hui Wang641e81c2020-10-12 12:14:23 -070010752
10753 /**
10754 * Set the GbaService Package Name that Telephony will bind to.
10755 *
10756 * @param subId The sim that the GbaService is associated with.
10757 * @param packageName The name of the package to be replaced with.
10758 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10759 */
10760 @Override
10761 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10762 enforceModifyPermission();
10763
10764 final long identity = Binder.clearCallingIdentity();
10765 try {
10766 return getGbaManager(subId).overrideServicePackage(packageName);
10767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
10771
10772 /**
10773 * Return the package name of the currently bound GbaService.
10774 *
10775 * @param subId The sim that the GbaService is associated with.
10776 * @return the package name of the GbaService configuration, null if GBA is not supported.
10777 */
10778 @Override
10779 public String getBoundGbaService(int subId) {
10780 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10781
10782 final long identity = Binder.clearCallingIdentity();
10783 try {
10784 return getGbaManager(subId).getServicePackage();
10785 } finally {
10786 Binder.restoreCallingIdentity(identity);
10787 }
10788 }
10789
10790 /**
10791 * Set the release time for telephony to unbind GbaService.
10792 *
10793 * @param subId The sim that the GbaService is associated with.
10794 * @param interval The release time to unbind GbaService by millisecond.
10795 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10796 */
10797 @Override
10798 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10799 enforceModifyPermission();
10800
10801 final long identity = Binder.clearCallingIdentity();
10802 try {
10803 return getGbaManager(subId).overrideReleaseTime(interval);
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
10808
10809 /**
10810 * Return the release time for telephony to unbind GbaService.
10811 *
10812 * @param subId The sim that the GbaService is associated with.
10813 * @return The release time to unbind GbaService by millisecond.
10814 */
10815 @Override
10816 public int getGbaReleaseTime(int subId) {
10817 enforceReadPrivilegedPermission("getGbaReleaseTime");
10818
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 return getGbaManager(subId).getReleaseTime();
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
10827 private GbaManager getGbaManager(int subId) {
10828 GbaManager instance = GbaManager.getInstance(subId);
10829 if (instance == null) {
10830 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10831 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10832 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10833 }
10834 return instance;
10835 }
Hui Wang761a6682020-10-31 05:12:53 +000010836
10837 /**
10838 * indicate whether the device and the carrier can support
10839 * RCS VoLTE single registration.
10840 */
10841 @Override
10842 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010843 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10844 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10845 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10846 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010847
10848 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10849 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10850 }
10851
10852 final long identity = Binder.clearCallingIdentity();
10853 try {
10854 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10855 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010856 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10857 if (isCapable != null) {
10858 return isCapable;
10859 }
Hui Wang761a6682020-10-31 05:12:53 +000010860 }
Hui Wang67af90e2021-06-04 16:57:15 -070010861 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10862 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010863 } finally {
10864 Binder.restoreCallingIdentity(identity);
10865 }
10866 }
10867
10868 /**
10869 * Register RCS provisioning callback.
10870 */
10871 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010872 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010873 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010874 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010875 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010876 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10877 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010878
10879 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10880 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10881 }
10882 if (!isImsAvailableOnDevice()) {
10883 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10884 "IMS not available on device.");
10885 }
10886
10887 final long identity = Binder.clearCallingIdentity();
10888 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010889 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010890 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010891 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10892 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010893 }
Hui Wang761a6682020-10-31 05:12:53 +000010894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
10898
10899 /**
10900 * Unregister RCS provisioning callback.
10901 */
10902 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010903 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010904 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010905 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010906 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010907 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10908 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010909
10910 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10911 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10912 }
10913 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010914 // operation failed silently
10915 Rlog.w(LOG_TAG, "IMS not available on device.");
10916 return;
Hui Wang761a6682020-10-31 05:12:53 +000010917 }
10918
10919 final long identity = Binder.clearCallingIdentity();
10920 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010921 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010922 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
10928 /**
10929 * trigger RCS reconfiguration.
10930 */
10931 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010932 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10933 "triggerRcsReconfiguration",
10934 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010935
10936 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10937 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10938 }
10939 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010940 // ProvisioningManager can not handle ServiceSpecificException.
10941 // Throw the IllegalStateException and annotate ProvisioningManager.
10942 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010943 }
10944
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10948 } finally {
10949 Binder.restoreCallingIdentity(identity);
10950 }
10951 }
10952
10953 /**
10954 * Provide the client configuration parameters of the RCS application.
10955 */
10956 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010957 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10958 "setRcsClientConfiguration",
10959 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010960
10961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10962 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10963 }
10964 if (!isImsAvailableOnDevice()) {
10965 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10966 "IMS not available on device.");
10967 }
10968
10969 final long identity = Binder.clearCallingIdentity();
10970
10971 try {
10972 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10973 if (configBinder == null) {
10974 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010975 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10976 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010977 } else {
10978 configBinder.setRcsClientConfiguration(rcc);
10979 }
joonhunshin3e154242021-09-17 06:33:39 +000010980
10981 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10982 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010983 } catch (RemoteException e) {
10984 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010985 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10986 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010987 } finally {
10988 Binder.restoreCallingIdentity(identity);
10989 }
10990 }
10991
10992 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010993 * Enables or disables the test mode for RCS VoLTE single registration.
10994 */
10995 @Override
10996 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10997 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10998 "setRcsSingleRegistrationTestModeEnabled");
10999
11000 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11001 }
11002
11003 /**
11004 * Gets the test mode for RCS VoLTE single registration.
11005 */
11006 @Override
11007 public boolean getRcsSingleRegistrationTestModeEnabled() {
11008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11009 "getRcsSingleRegistrationTestModeEnabled");
11010
11011 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11012 }
11013
11014 /**
Hui Wang761a6682020-10-31 05:12:53 +000011015 * Overrides the config of RCS VoLTE single registration enabled for the device.
11016 */
11017 @Override
11018 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11020 "setDeviceSingleRegistrationEnabledOverride");
11021 enforceModifyPermission();
11022
11023 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11024 : Boolean.parseBoolean(enabledStr);
11025 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011026 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011027 }
11028
11029 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011030 * Sends a device to device communication message. Only usable via shell.
11031 * @param message message to send.
11032 * @param value message value.
11033 */
11034 @Override
11035 public void sendDeviceToDeviceMessage(int message, int value) {
11036 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011037 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011038 enforceModifyPermission();
11039
11040 final long identity = Binder.clearCallingIdentity();
11041 try {
11042 TelephonyConnectionService service =
11043 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11044 if (service == null) {
11045 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11046 return;
11047 }
11048 service.sendTestDeviceToDeviceMessage(message, value);
11049 } finally {
11050 Binder.restoreCallingIdentity(identity);
11051 }
11052 }
11053
Tyler Gunnbabbda02021-02-10 11:05:02 -080011054 /**
11055 * Sets the specified device to device transport active.
11056 * @param transport The transport to set active.
11057 */
11058 @Override
11059 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11061 "setActiveDeviceToDeviceTransport");
11062 enforceModifyPermission();
11063
11064 final long identity = Binder.clearCallingIdentity();
11065 try {
11066 TelephonyConnectionService service =
11067 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11068 if (service == null) {
11069 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11070 return;
11071 }
11072 service.setActiveDeviceToDeviceTransport(transport);
11073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
Tyler Gunn92479152021-01-20 16:30:10 -080011077
Tyler Gunnd4339262021-05-03 14:46:49 -070011078 @Override
11079 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11080 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11081 "setDeviceToDeviceForceEnabled");
11082
11083 final long identity = Binder.clearCallingIdentity();
11084 try {
11085 Arrays.stream(PhoneFactory.getPhones()).forEach(
11086 p -> {
11087 Phone thePhone = p.getImsPhone();
11088 if (thePhone != null && thePhone instanceof ImsPhone) {
11089 ImsPhone imsPhone = (ImsPhone) thePhone;
11090 CallTracker tracker = imsPhone.getCallTracker();
11091 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11092 ImsPhoneCallTracker imsPhoneCallTracker =
11093 (ImsPhoneCallTracker) tracker;
11094 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11095 }
11096 }
11097 }
11098 );
11099 } finally {
11100 Binder.restoreCallingIdentity(identity);
11101 }
11102 }
11103
Tyler Gunn92479152021-01-20 16:30:10 -080011104 /**
Hui Wang761a6682020-10-31 05:12:53 +000011105 * Gets the config of RCS VoLTE single registration enabled for the device.
11106 */
11107 @Override
11108 public boolean getDeviceSingleRegistrationEnabled() {
11109 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11110 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11111 }
11112
11113 /**
11114 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11115 */
11116 @Override
11117 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11119 "setCarrierSingleRegistrationEnabledOverride");
11120 enforceModifyPermission();
11121
11122 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11123 : Boolean.parseBoolean(enabledStr);
11124 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11125 subId, enabled);
11126 }
11127
11128 /**
11129 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11130 */
11131 @Override
11132 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11133 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11134 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11135 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011136
11137 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011138 * Overrides the ims feature validation result
11139 */
11140 @Override
11141 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11143 "setImsFeatureValidationOverride");
11144
11145 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11146 : Boolean.parseBoolean(enabledStr);
11147 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11148 subId, enabled);
11149 }
11150
11151 /**
11152 * Gets the ims feature validation override value
11153 */
11154 @Override
11155 public boolean getImsFeatureValidationOverride(int subId) {
11156 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11157 "getImsFeatureValidationOverride");
11158 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11159 }
11160
11161 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011162 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11163 * their mobile plan.
11164 */
11165 @Override
11166 public String getMobileProvisioningUrl() {
11167 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11168 final long identity = Binder.clearCallingIdentity();
11169 try {
11170 return getDefaultPhone().getMobileProvisioningUrl();
11171 } finally {
11172 Binder.restoreCallingIdentity(identity);
11173 }
11174 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011175
James.cf Linbcdf8b32021-01-14 16:44:13 +080011176 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011177 * Get the EAB contact from the EAB database.
11178 */
11179 @Override
11180 public String getContactFromEab(String contact) {
11181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11182 enforceModifyPermission();
11183 final long identity = Binder.clearCallingIdentity();
11184 try {
11185 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11186 } finally {
11187 Binder.restoreCallingIdentity(identity);
11188 }
11189 }
11190
11191 /**
Calvin Pana1434322021-07-01 19:27:01 +080011192 * Get the EAB capability from the EAB database.
11193 */
11194 @Override
11195 public String getCapabilityFromEab(String contact) {
11196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11197 enforceModifyPermission();
11198 final long identity = Binder.clearCallingIdentity();
11199 try {
11200 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11201 } finally {
11202 Binder.restoreCallingIdentity(identity);
11203 }
11204 }
11205
11206 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011207 * Remove the EAB contacts from the EAB database.
11208 */
11209 @Override
11210 public int removeContactFromEab(int subId, String contacts) {
11211 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11212 enforceModifyPermission();
11213 final long identity = Binder.clearCallingIdentity();
11214 try {
11215 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11216 } finally {
11217 Binder.restoreCallingIdentity(identity);
11218 }
11219 }
11220
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011221 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011222 public boolean getDeviceUceEnabled() {
11223 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11224 final long identity = Binder.clearCallingIdentity();
11225 try {
11226 return mApp.getDeviceUceEnabled();
11227 } finally {
11228 Binder.restoreCallingIdentity(identity);
11229 }
11230 }
11231
11232 @Override
11233 public void setDeviceUceEnabled(boolean isEnabled) {
11234 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11235 final long identity = Binder.clearCallingIdentity();
11236 try {
11237 mApp.setDeviceUceEnabled(isEnabled);
11238 } finally {
11239 Binder.restoreCallingIdentity(identity);
11240 }
11241 }
11242
Brad Ebinger14d467f2021-02-12 06:18:28 +000011243 /**
11244 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11245 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11246 */
11247 // Used for SHELL command only right now.
11248 @Override
11249 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11250 List<String> featureTags) {
11251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11252 "addUceRegistrationOverrideShell");
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11256 new ArraySet<>(featureTags));
11257 } catch (ImsException e) {
11258 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11259 } finally {
11260 Binder.restoreCallingIdentity(identity);
11261 }
11262 }
11263
11264 /**
11265 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11266 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11267 */
11268 // Used for SHELL command only right now.
11269 @Override
11270 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11271 List<String> featureTags) {
11272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11273 "removeUceRegistrationOverrideShell");
11274 final long identity = Binder.clearCallingIdentity();
11275 try {
11276 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11277 new ArraySet<>(featureTags));
11278 } catch (ImsException e) {
11279 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11280 } finally {
11281 Binder.restoreCallingIdentity(identity);
11282 }
11283 }
11284
11285 /**
11286 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11287 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11288 */
11289 // Used for SHELL command only right now.
11290 @Override
11291 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11292 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11293 "clearUceRegistrationOverrideShell");
11294 final long identity = Binder.clearCallingIdentity();
11295 try {
11296 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11297 } catch (ImsException e) {
11298 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11299 } finally {
11300 Binder.restoreCallingIdentity(identity);
11301 }
11302 }
11303
11304 /**
11305 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11306 */
11307 // Used for SHELL command only right now.
11308 @Override
11309 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11310 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11311 "getLatestRcsContactUceCapabilityShell");
11312 final long identity = Binder.clearCallingIdentity();
11313 try {
11314 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11315 } catch (ImsException e) {
11316 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11317 } finally {
11318 Binder.restoreCallingIdentity(identity);
11319 }
11320 }
11321
11322 /**
11323 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11324 * device does not have an active PUBLISH.
11325 */
11326 // Used for SHELL command only right now.
11327 @Override
11328 public String getLastUcePidfXmlShell(int subId) {
11329 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11330 final long identity = Binder.clearCallingIdentity();
11331 try {
11332 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11333 } catch (ImsException e) {
11334 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11335 } finally {
11336 Binder.restoreCallingIdentity(identity);
11337 }
11338 }
11339
James.cf Line8713a42021-04-29 16:04:26 +080011340 /**
11341 * Remove UCE requests cannot be sent to the network status.
11342 */
11343 // Used for SHELL command only right now.
11344 @Override
11345 public boolean removeUceRequestDisallowedStatus(int subId) {
11346 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11347 final long identity = Binder.clearCallingIdentity();
11348 try {
11349 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11350 } catch (ImsException e) {
11351 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11352 } finally {
11353 Binder.restoreCallingIdentity(identity);
11354 }
11355 }
11356
James.cf Lin18bb9002021-05-25 01:37:38 +080011357 /**
11358 * Remove UCE requests cannot be sent to the network status.
11359 */
11360 // Used for SHELL command only.
11361 @Override
11362 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11363 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11364 final long identity = Binder.clearCallingIdentity();
11365 try {
11366 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11367 } catch (ImsException e) {
11368 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11369 } finally {
11370 Binder.restoreCallingIdentity(identity);
11371 }
11372 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011373
James.cf Lin4b784aa2021-01-31 03:25:15 +080011374 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011375 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11376 String callingPackage) {
11377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11378 mApp, subId, "setSignalStrengthUpdateRequest");
11379
11380 final int callingUid = Binder.getCallingUid();
11381 // Verify that tha callingPackage belongs to the calling UID
11382 mApp.getSystemService(AppOpsManager.class)
11383 .checkPackage(callingUid, callingPackage);
11384
Rambo Wang3607f502021-02-01 21:51:40 -080011385 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011386
11387 final long identity = Binder.clearCallingIdentity();
11388 try {
11389 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11390 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11391
11392 if (result instanceof IllegalStateException) {
11393 throw (IllegalStateException) result;
11394 }
11395 } finally {
11396 Binder.restoreCallingIdentity(identity);
11397 }
11398 }
11399
11400 @Override
11401 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11402 String callingPackage) {
11403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11404 mApp, subId, "clearSignalStrengthUpdateRequest");
11405
11406 final int callingUid = Binder.getCallingUid();
11407 // Verify that tha callingPackage belongs to the calling UID
11408 mApp.getSystemService(AppOpsManager.class)
11409 .checkPackage(callingUid, callingPackage);
11410
11411 final long identity = Binder.clearCallingIdentity();
11412 try {
11413 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11414 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11415
11416 if (result instanceof IllegalStateException) {
11417 throw (IllegalStateException) result;
11418 }
11419 } finally {
11420 Binder.restoreCallingIdentity(identity);
11421 }
11422 }
11423
Rambo Wang3607f502021-02-01 21:51:40 -080011424 private static void validateSignalStrengthUpdateRequest(Context context,
11425 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011426 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11427 // phone/system process do not have further restriction on request
11428 return;
11429 }
11430
11431 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011432 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011433 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011434 context.enforceCallingOrSelfPermission(
11435 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11436 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011437 }
11438
11439 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011440 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011441 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011442 || info.isEnabled()) {
11443 throw new IllegalArgumentException(
11444 "Only system can set hide fields in SignalThresholdInfo");
11445 }
11446
11447 // Thresholds length for each RAN need in range. This has been validated in
11448 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11449 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11450 final int[] thresholds = info.getThresholds();
11451 Objects.requireNonNull(thresholds);
11452 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11453 || thresholds.length
11454 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11455 throw new IllegalArgumentException(
11456 "thresholds length is out of range: " + thresholds.length);
11457 }
11458 }
11459 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011460
11461 /**
11462 * Gets the current phone capability.
11463 *
11464 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11465 * @return the PhoneCapability which describes the data connection capability of modem.
11466 * It's used to evaluate possible phone config change, for example from single
11467 * SIM device to multi-SIM device.
11468 */
11469 @Override
11470 public PhoneCapability getPhoneCapability() {
11471 enforceReadPrivilegedPermission("getPhoneCapability");
11472 final long identity = Binder.clearCallingIdentity();
11473 try {
11474 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11475 } finally {
11476 Binder.restoreCallingIdentity(identity);
11477 }
11478 }
Michele Berionne5e411512020-11-13 02:36:59 +000011479
11480 /**
11481 * Prepare TelephonyManager for an unattended reboot. The reboot is
11482 * required to be done shortly after the API is invoked.
11483 */
11484 @Override
11485 @TelephonyManager.PrepareUnattendedRebootResult
11486 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011487 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011488 enforceRebootPermission();
11489
11490 final long identity = Binder.clearCallingIdentity();
11491 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011492 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011493 } finally {
11494 Binder.restoreCallingIdentity(identity);
11495 }
11496 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011497
11498 /**
11499 * Request to get the current slicing configuration including URSP rules and
11500 * NSSAIs (configured, allowed and rejected).
11501 *
11502 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11503 */
11504 @Override
11505 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011506 TelephonyPermissions
11507 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11508 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011509
11510 final long identity = Binder.clearCallingIdentity();
11511 try {
11512 Phone phone = getDefaultPhone();
11513 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11514 } finally {
11515 Binder.restoreCallingIdentity(identity);
11516 }
11517 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011518
11519 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011520 * Check whether the given premium capability is available for purchase from the carrier.
11521 *
11522 * @param capability The premium capability to check.
11523 * @param subId The subId to check the premium capability for.
11524 *
11525 * @return Whether the given premium capability is available to purchase.
11526 */
11527 @Override
11528 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11529 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11530 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11531 log("Premium capability "
11532 + TelephonyManager.convertPremiumCapabilityToString(capability)
11533 + " is not available for purchase due to missing permissions.");
11534 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11535 + "permission READ_BASIC_PHONE_STATE.");
11536 }
11537
11538 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011539 if (phone == null) {
11540 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11541 return false;
11542 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011543 final long identity = Binder.clearCallingIdentity();
11544 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011545 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011546 .isPremiumCapabilityAvailableForPurchase(capability);
11547 } finally {
11548 Binder.restoreCallingIdentity(identity);
11549 }
11550 }
11551
11552 /**
11553 * Purchase the given premium capability from the carrier.
11554 *
11555 * @param capability The premium capability to purchase.
11556 * @param callback The result of the purchase request.
11557 * @param subId The subId to purchase the premium capability for.
11558 */
11559 @Override
11560 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11561 log("purchasePremiumCapability: capability="
11562 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11563 + getCurrentPackageName());
11564
11565 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11566 mApp, "purchasePremiumCapability")) {
11567 log("purchasePremiumCapability "
11568 + TelephonyManager.convertPremiumCapabilityToString(capability)
11569 + " failed due to missing permissions.");
11570 throw new SecurityException("purchasePremiumCapability requires permission "
11571 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011572 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11573 mApp, "purchasePremiumCapability")) {
11574 log("purchasePremiumCapability "
11575 + TelephonyManager.convertPremiumCapabilityToString(capability)
11576 + " failed due to missing permissions.");
11577 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011578 }
11579
11580 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011581 if (phone == null) {
11582 try {
11583 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11584 callback.accept(result);
11585 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11586 } catch (RemoteException e) {
11587 String logStr = "Purchase premium capability "
11588 + TelephonyManager.convertPremiumCapabilityToString(capability)
11589 + " failed due to RemoteException handling null phone: " + e;
11590 if (DBG) log(logStr);
11591 AnomalyReporter.reportAnomaly(
11592 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11593 }
11594 return;
11595 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011596
11597 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011598 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011599 callingProcess = mApp.getPackageManager().getApplicationInfo(
11600 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011601 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011602 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011603 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011604
11605 boolean isVisible = false;
11606 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11607 if (am != null) {
11608 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11609 if (processes != null) {
11610 for (ActivityManager.RunningAppProcessInfo process : processes) {
11611 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011612 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011613 if (process.processName.equals(callingProcess) && process.importance
11614 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11615 isVisible = true;
11616 break;
11617 }
11618 }
11619 }
11620 }
11621
11622 if (!isVisible) {
11623 try {
11624 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11625 callback.accept(result);
11626 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11627 } catch (RemoteException e) {
11628 String logStr = "Purchase premium capability "
11629 + TelephonyManager.convertPremiumCapabilityToString(capability)
11630 + " failed due to RemoteException handling background application: " + e;
11631 if (DBG) log(logStr);
11632 AnomalyReporter.reportAnomaly(
11633 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11634 }
11635 return;
11636 }
11637
Sarah Chin71b3a852022-09-28 15:54:19 -070011638 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011639 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011640 }
11641
11642 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011643 * Register an IMS connection state callback
11644 */
11645 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011646 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11647 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011648 if (feature == ImsFeature.FEATURE_MMTEL) {
11649 // ImsMmTelManager
11650 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11651 TelephonyPermissions
11652 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11653 mApp, subId, "registerImsStateCallback");
11654 } else if (feature == ImsFeature.FEATURE_RCS) {
11655 // ImsRcsManager or SipDelegateManager
11656 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11657 Binder.getCallingUid(), "registerImsStateCallback",
11658 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11659 Manifest.permission.READ_PRECISE_PHONE_STATE,
11660 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11661 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11662 }
11663
11664 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11665 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11666 "IMS not available on device.");
11667 }
11668
11669 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11670 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11671 }
11672
11673 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11674 if (controller == null) {
11675 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11676 "IMS not available on device.");
11677 }
11678
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011679 if (callingPackage == null) {
11680 callingPackage = getCurrentPackageName();
11681 }
11682
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011683 final long token = Binder.clearCallingIdentity();
11684 try {
11685 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011686 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011687 } catch (ImsException e) {
11688 throw new ServiceSpecificException(e.getCode());
11689 } finally {
11690 Binder.restoreCallingIdentity(token);
11691 }
11692 }
11693
11694 /**
11695 * Unregister an IMS connection state callback
11696 */
11697 @Override
11698 public void unregisterImsStateCallback(IImsStateCallback cb) {
11699 final long token = Binder.clearCallingIdentity();
11700 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11701 if (controller == null) {
11702 return;
11703 }
11704 try {
11705 controller.unregisterImsStateCallback(cb);
11706 } finally {
11707 Binder.restoreCallingIdentity(token);
11708 }
11709 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011710
11711 /**
11712 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11713 *
11714 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11715 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11716 * SecurityException.
11717 * If there is current registered network this value will be same as the registered cell
11718 * identity. If the device goes out of service the previous cell identity is cached and
11719 * will be returned. If the cache age of the Cell identity is more than 24 hours
11720 * it will be cleared and null will be returned.
11721 *
11722 */
11723 @Override
11724 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11725 String callingFeatureId) {
11726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11727 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11728 LocationAccessPolicy.checkLocationPermission(mApp,
11729 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11730 .setCallingPackage(callingPackage)
11731 .setCallingFeatureId(callingFeatureId)
11732 .setCallingPid(Binder.getCallingPid())
11733 .setCallingUid(Binder.getCallingUid())
11734 .setMethod("getLastKnownCellIdentity")
11735 .setLogAsInfo(true)
11736 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11737 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11738 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11739 .build());
11740
11741 boolean hasFinePermission =
11742 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11743 if (!hasFinePermission
11744 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11745 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011746 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011747 }
11748
11749 final long identity = Binder.clearCallingIdentity();
11750 try {
Ling Mac28f0212023-03-24 16:07:15 -070011751 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011752 if (sst == null) return null;
11753 return sst.getLastKnownCellIdentity();
11754 } finally {
11755 Binder.restoreCallingIdentity(identity);
11756 }
11757 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011758
jimsun3b9ccac2021-10-26 15:01:23 +080011759 /**
11760 * Sets the modem service class Name that Telephony will bind to.
11761 *
11762 * @param serviceName The class name of the modem service.
11763 * @return true if the operation is succeed, otherwise false.
11764 */
11765 public boolean setModemService(String serviceName) {
11766 Log.d(LOG_TAG, "setModemService - " + serviceName);
11767 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011769 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11770 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011771 return mPhoneConfigurationManager.setModemService(serviceName);
11772 }
11773
11774 /**
11775 * Return the class name of the currently bounded modem service.
11776 *
11777 * @return the class name of the modem service.
11778 */
11779 public String getModemService() {
11780 String result;
11781 Log.d(LOG_TAG, "getModemService");
11782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11783 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011784 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011785 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11786 "getModemService");
11787 result = mPhoneConfigurationManager.getModemService();
11788 Log.d(LOG_TAG, "result = " + result);
11789 return result;
11790 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011791
11792 @Override
11793 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11794 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11795 mApp.enforceCallingOrSelfPermission(
11796 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11798
11799 final long identity = Binder.clearCallingIdentity();
11800 try {
11801 Phone phone = getPhone(subId);
11802 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011803 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11804 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011805 phone.setVoiceServiceStateOverride(hasService);
11806 } finally {
11807 Binder.restoreCallingIdentity(identity);
11808 }
11809 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011810
11811 /**
11812 * set removable eSIM as default eUICC.
11813 *
11814 * @hide
11815 */
11816 @Override
11817 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11818 enforceModifyPermission();
11819 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11820
11821 final long identity = Binder.clearCallingIdentity();
11822 try {
11823 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11824 } finally {
11825 Binder.restoreCallingIdentity(identity);
11826 }
11827 }
11828
11829 /**
11830 * Returns whether the removable eSIM is default eUICC or not.
11831 *
11832 * @hide
11833 */
11834 @Override
11835 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11836 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11838
11839 final long identity = Binder.clearCallingIdentity();
11840 try {
11841 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11842 } finally {
11843 Binder.restoreCallingIdentity(identity);
11844 }
11845 }
11846
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011847 /**
11848 * Get the component name of the default app to direct respond-via-message intent for the
11849 * user associated with this subscription, update the cache if there is no respond-via-message
11850 * application currently configured for this user.
11851 * @return component name of the app and class to direct Respond Via Message intent to, or
11852 * {@code null} if the functionality is not supported.
11853 * @hide
11854 */
11855 @Override
11856 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11857 boolean updateIfNeeded) {
11858 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011859
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011860 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11861
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011862 UserHandle userHandle = null;
11863 final long identity = Binder.clearCallingIdentity();
11864 try {
11865 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11866 } finally {
11867 Binder.restoreCallingIdentity(identity);
11868 }
11869 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11870 updateIfNeeded, userHandle);
11871 }
Jack Yuf5badd92022-12-08 00:50:53 -080011872
11873 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011874 * Set whether the device is able to connect with null ciphering or integrity
11875 * algorithms. This is a global setting and will apply to all active subscriptions
11876 * and all new subscriptions after this.
11877 *
11878 * @param enabled when true, null cipher and integrity algorithms are allowed.
11879 * @hide
11880 */
11881 @Override
11882 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11883 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11884 enforceModifyPermission();
11885 checkForNullCipherAndIntegritySupport();
11886
11887 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11888 // for listening to these preference changes and applying them immediately.
11889 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11890 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11891 editor.apply();
11892
11893 for (Phone phone: PhoneFactory.getPhones()) {
11894 phone.handleNullCipherEnabledChange();
11895 }
11896 }
11897
11898
11899 /**
11900 * Get whether the device is able to connect with null ciphering or integrity
11901 * algorithms. Note that this retrieves the phone-global preference and not
11902 * the state of the radio.
11903 *
11904 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11905 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11906 * version for this feature.
11907 * @hide
11908 */
11909 @Override
11910 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11911 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11912 enforceReadPermission();
11913 checkForNullCipherAndIntegritySupport();
11914 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11915 }
11916
11917 private void checkForNullCipherAndIntegritySupport() {
11918 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11919 throw new UnsupportedOperationException(
11920 "Null cipher and integrity operations require HAL 2.1 or above");
11921 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011922 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11923 throw new UnsupportedOperationException(
11924 "Null cipher and integrity operations unsupported by modem");
11925 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011926 }
11927
11928 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011929 * Get the SIM state for the slot index.
11930 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11931 *
11932 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11933 */
11934 @Override
11935 @SimState
11936 public int getSimStateForSlotIndex(int slotIndex) {
11937 IccCardConstants.State simState;
11938 if (slotIndex < 0) {
11939 simState = IccCardConstants.State.UNKNOWN;
11940 } else {
11941 Phone phone = null;
11942 try {
11943 phone = PhoneFactory.getPhone(slotIndex);
11944 } catch (IllegalStateException e) {
11945 // ignore
11946 }
11947 if (phone == null) {
11948 simState = IccCardConstants.State.UNKNOWN;
11949 } else {
11950 IccCard icc = phone.getIccCard();
11951 if (icc == null) {
11952 simState = IccCardConstants.State.UNKNOWN;
11953 } else {
11954 simState = icc.getState();
11955 }
11956 }
11957 }
11958 return simState.ordinal();
11959 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011960
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011961 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11962 boolean enableLogcat,
11963 long logcatStartTimestampMillis, boolean enableTelecomDump,
11964 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011965 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11966 TelephonyManager.EmergencyCallDiagnosticParams edp =
11967 new TelephonyManager.EmergencyCallDiagnosticParams();
11968 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11969 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11970 edp.setTelecomDumpSysCollection(enableTelecomDump);
11971 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11972 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
11973 Executors.newCachedThreadPool(), db,
11974 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
11975 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011976 }
11977
11978 /**
11979 * Request telephony to persist state for debugging emergency call failures.
11980 *
11981 * @param dropBoxTag Tag to use when persisting data to dropbox service.
11982 * @param enableLogcat whether to collect logcat output
11983 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
11984 * @param enableTelecomDump whether to collect telecom dumpsys
11985 * @param enableTelephonyDump whether to collect telephony dumpsys
11986 */
11987 @Override
11988 @RequiresPermission(android.Manifest.permission.DUMP)
11989 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
11990 long logcatStartTimestampMillis, boolean enableTelecomDump,
11991 boolean enableTelephonyDump) {
11992 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
11993 "persistEmergencyCallDiagnosticData");
11994 final long identity = Binder.clearCallingIdentity();
11995 try {
11996 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
11997 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
11998
11999 } finally {
12000 Binder.restoreCallingIdentity(identity);
12001 }
12002 }
12003
Hui Wang9b5793a2022-12-05 14:38:06 -060012004 /**
12005 * Get current cell broadcast ranges.
12006 */
12007 @Override
12008 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12009 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12010 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12011 "getCellBroadcastIdRanges");
12012 final long identity = Binder.clearCallingIdentity();
12013 try {
12014 return getPhone(subId).getCellBroadcastIdRanges();
12015 } finally {
12016 Binder.restoreCallingIdentity(identity);
12017 }
12018 }
12019
12020 /**
12021 * Set reception of cell broadcast messages with the list of the given ranges
12022 *
12023 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12024 */
12025 @Override
12026 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12027 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12028 @Nullable IIntegerConsumer callback) {
12029 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12030 "setCellBroadcastIdRanges");
12031 final long identity = Binder.clearCallingIdentity();
12032 try {
12033 Phone phone = getPhoneFromSubId(subId);
12034 if (DBG) {
12035 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12036 }
12037 phone.setCellBroadcastIdRanges(ranges, result -> {
12038 if (callback != null) {
12039 try {
12040 callback.accept(result);
12041 } catch (RemoteException e) {
12042 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12043 }
12044 }
12045 });
12046 } finally {
12047 Binder.restoreCallingIdentity(identity);
12048 }
12049 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012050
12051 /**
12052 * Returns whether the device supports the domain selection service.
12053 *
12054 * @return {@code true} if the device supports the domain selection service.
12055 */
12056 @Override
12057 public boolean isDomainSelectionSupported() {
12058 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12059 "isDomainSelectionSupported");
12060
12061 final long identity = Binder.clearCallingIdentity();
12062 try {
12063 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12064 } finally {
12065 Binder.restoreCallingIdentity(identity);
12066 }
12067 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012068
12069 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012070 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12071 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12072 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012073 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012074 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012075 * @param enableSatellite {@code true} to enable the satellite modem and
12076 * {@code false} to disable.
12077 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12078 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012079 *
12080 * @throws SecurityException if the caller doesn't have the required permission.
12081 */
12082 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012083 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12084 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012085 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012086 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12087 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012088 }
12089
12090 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012091 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012092 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012093 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012094 * @param result The result receiver that returns whether the satellite modem is enabled
12095 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012096 *
12097 * @throws SecurityException if the caller doesn't have the required permission.
12098 */
12099 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012100 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12101 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012102 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012103 }
12104
12105 /**
Sarah Chin43457982023-02-15 17:50:38 -080012106 * Request to get whether the satellite service demo mode is enabled.
12107 *
12108 * @param subId The subId of the subscription to check whether the satellite demo mode
12109 * is enabled for.
12110 * @param result The result receiver that returns whether the satellite demo mode is enabled
12111 * if the request is successful or an error code if the request failed.
12112 *
12113 * @throws SecurityException if the caller doesn't have the required permission.
12114 */
12115 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012116 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12117 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12118 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012119 }
12120
12121 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012122 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012123 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012124 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012125 * @param result The result receiver that returns whether the satellite service is supported on
12126 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012127 */
12128 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012129 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012130 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012131 }
12132
12133 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012134 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012135 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012136 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012137 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12138 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012139 *
12140 * @throws SecurityException if the caller doesn't have required permission.
12141 */
12142 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012143 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12144 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012145 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012146 }
12147
12148 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012149 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012150 * This can be called by the pointing UI when the user starts pointing to the satellite.
12151 * Modem should continue to report the pointing input as the device or satellite moves.
12152 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012153 * @param subId The subId of the subscription to start satellite transmission updates for.
12154 * @param resultCallback The callback to get the result of the request.
12155 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012156 *
12157 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012158 */
12159 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012160 public void startSatelliteTransmissionUpdates(int subId,
12161 @NonNull IIntegerConsumer resultCallback,
12162 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12163 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12164 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012165 }
12166
12167 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012168 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012169 * This can be called by the pointing UI when the user stops pointing to the satellite.
12170 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012171 * @param subId The subId of the subscription to stop satellite transmission updates for.
12172 * @param resultCallback The callback to get the result of the request.
12173 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12174 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012175 *
12176 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012177 */
12178 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012179 public void stopSatelliteTransmissionUpdates(int subId,
12180 @NonNull IIntegerConsumer resultCallback,
12181 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12182 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12183 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012184 }
12185
12186 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012187 * Register the subscription with a satellite provider.
12188 * This is needed to register the subscription if the provider allows dynamic registration.
12189 *
12190 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012191 * @param token The token to be used as a unique identifier for provisioning with satellite
12192 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012193 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012194 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012195 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012196 * @return The signal transport used by the caller to cancel the provision request,
12197 * or {@code null} if the request failed.
12198 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012199 * @throws SecurityException if the caller doesn't have the required permission.
12200 */
12201 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012202 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012203 @NonNull String token, @NonNull byte[] provisionData,
12204 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012205 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012206 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12207 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012208 }
12209
12210 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012211 * Unregister the device/subscription with the satellite provider.
12212 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012213 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012214 * should report as deprovisioned.
12215 *
12216 * @param subId The subId of the subscription to be deprovisioned.
12217 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012218 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012219 *
12220 * @throws SecurityException if the caller doesn't have the required permission.
12221 */
12222 @Override
12223 public void deprovisionSatelliteService(int subId,
12224 @NonNull String token, @NonNull IIntegerConsumer callback) {
12225 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012226 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012227 }
12228
12229 /**
Sarah Chin43457982023-02-15 17:50:38 -080012230 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012231 *
Sarah Chin43457982023-02-15 17:50:38 -080012232 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012233 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012234 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012235 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012236 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012237 * @throws SecurityException if the caller doesn't have the required permission.
12238 */
12239 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012240 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12241 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012242 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012243 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012244 }
12245
12246 /**
Sarah Chin43457982023-02-15 17:50:38 -080012247 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012248 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012249 *
Sarah Chin43457982023-02-15 17:50:38 -080012250 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012251 * @param callback The callback that was passed to
12252 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012253 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012254 * @throws SecurityException if the caller doesn't have the required permission.
12255 */
12256 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012257 public void unregisterForSatelliteProvisionStateChanged(
12258 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012259 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012260 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012261 }
12262
12263 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012264 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012265 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012266 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012267 * @param result The result receiver that returns whether the device is provisioned with a
12268 * satellite provider if the request is successful or an error code if the
12269 * request failed.
12270 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012271 * @throws SecurityException if the caller doesn't have the required permission.
12272 */
12273 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012274 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12275 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012276 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012277 }
12278
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012279 /**
Sarah Chin43457982023-02-15 17:50:38 -080012280 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012281 *
Sarah Chin43457982023-02-15 17:50:38 -080012282 * @param subId The subId of the subscription to register for satellite modem state changed.
12283 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012284 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012285 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012286 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012287 * @throws SecurityException if the caller doesn't have the required permission.
12288 */
12289 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012290 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012291 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012292 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012293 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012294 }
12295
12296 /**
Sarah Chin43457982023-02-15 17:50:38 -080012297 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012298 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012299 *
Sarah Chin43457982023-02-15 17:50:38 -080012300 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012301 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012302 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012303 *
12304 * @throws SecurityException if the caller doesn't have the required permission.
12305 */
12306 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012307 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012308 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012309 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012310 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012311 }
12312
12313 /**
12314 * Register to receive incoming datagrams over satellite.
12315 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012316 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012317 * @param callback The callback to handle incoming datagrams over satellite.
12318 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012319 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012320 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012321 * @throws SecurityException if the caller doesn't have the required permission.
12322 */
12323 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012324 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012325 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012326 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012327 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012328 }
12329
12330 /**
12331 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012332 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012333 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012334 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12335 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012336 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012337 *
12338 * @throws SecurityException if the caller doesn't have the required permission.
12339 */
12340 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012341 public void unregisterForSatelliteDatagram(int subId,
12342 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012343 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012344 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012345 }
12346
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012347 /**
12348 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012349 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012350 * This method requests modem to check if there are any pending datagrams to be received over
12351 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012352 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012353 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012354 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012355 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012356 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012357 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012358 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012359 @Override
12360 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012361 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012362 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012363 }
12364
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012365 /**
12366 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012367 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012368 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12369 * input to this method. Datagram received here will be passed down to modem without any
12370 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012371 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012372 * @param subId The subId of the subscription to send satellite datagrams for.
12373 * @param datagramType datagram type indicating whether the datagram is of type
12374 * SOS_SMS or LOCATION_SHARING.
12375 * @param datagram encoded gateway datagram which is encrypted by the caller.
12376 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012377 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12378 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012379 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012380 *
12381 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012382 */
12383 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012384 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12385 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12386 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012387 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012388 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12389 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012390 }
12391
Sarah Chindf715ec2023-02-13 13:46:24 -080012392 /**
12393 * Request to get whether satellite communication is allowed for the current location.
12394 *
12395 * @param subId The subId of the subscription to check whether satellite communication is
12396 * allowed for the current location for.
12397 * @param result The result receiver that returns whether satellite communication is allowed
12398 * for the current location if the request is successful or an error code
12399 * if the request failed.
12400 *
12401 * @throws SecurityException if the caller doesn't have the required permission.
12402 */
12403 @Override
12404 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12405 @NonNull ResultReceiver result) {
12406 enforceSatelliteCommunicationPermission(
12407 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012408 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12409 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012410 }
12411
12412 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012413 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012414 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012415 * @param subId The subId to get the time after which the satellite will be visible for.
12416 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012417 * be visible if the request is successful or an error code if the request failed.
12418 *
12419 * @throws SecurityException if the caller doesn't have the required permission.
12420 */
12421 @Override
12422 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12423 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012424 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012425 }
12426
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012427 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012428 * Inform that Device is aligned to satellite for demo mode.
12429 *
12430 * @param subId The subId to get the time after which the satellite will be visible for.
12431 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12432 * {@code false} Device fails to align with the satellite for demo mode.
12433 *
12434 * @throws SecurityException if the caller doesn't have required permission.
12435 */
12436 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12437
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012438 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012439 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012440 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012441 }
12442
12443 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012444 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12445 * by modem.
12446 *
12447 * @param subId The subId of the subscription to request for.
12448 * @param reason Reason for disallowing satellite communication for carrier.
12449 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12450 * operation.
12451 *
12452 * @throws SecurityException if the caller doesn't have required permission.
12453 */
12454 public void addSatelliteAttachRestrictionForCarrier(int subId,
12455 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12456 @NonNull IIntegerConsumer callback) {
12457 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12458 final long identity = Binder.clearCallingIdentity();
12459 try {
12460 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12461 } finally {
12462 Binder.restoreCallingIdentity(identity);
12463 }
12464 }
12465
12466 /**
12467 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12468 * by modem.
12469 *
12470 * @param subId The subId of the subscription to request for.
12471 * @param reason Reason for disallowing satellite communication.
12472 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12473 * operation.
12474 *
12475 * @throws SecurityException if the caller doesn't have required permission.
12476 */
12477 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12478 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12479 @NonNull IIntegerConsumer callback) {
12480 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12481 final long identity = Binder.clearCallingIdentity();
12482 try {
12483 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12484 callback);
12485 } finally {
12486 Binder.restoreCallingIdentity(identity);
12487 }
12488 }
12489
12490 /**
12491 * Get reasons for disallowing satellite communication, as requested by
12492 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12493 *
12494 * @param subId The subId of the subscription to request for.
12495 *
12496 * @return Integer array of reasons for disallowing satellite communication.
12497 *
12498 * @throws SecurityException if the caller doesn't have the required permission.
12499 */
12500 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12501 int subId) {
12502 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12503 final long identity = Binder.clearCallingIdentity();
12504 try {
12505 Set<Integer> reasonSet =
12506 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12507 return reasonSet.stream().mapToInt(i->i).toArray();
12508 } finally {
12509 Binder.restoreCallingIdentity(identity);
12510 }
12511 }
12512
12513 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012514 * Request to get the signal strength of the satellite connection.
12515 *
12516 * @param subId The subId of the subscription to request for.
12517 * @param result Result receiver to get the error code of the request and the current signal
12518 * strength of the satellite connection.
12519 *
12520 * @throws SecurityException if the caller doesn't have required permission.
12521 */
12522 @Override
12523 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12524 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12525 final long identity = Binder.clearCallingIdentity();
12526 try {
12527 mSatelliteController.requestNtnSignalStrength(subId, result);
12528 } finally {
12529 Binder.restoreCallingIdentity(identity);
12530 }
12531 }
12532
12533 /**
12534 * Registers for NTN signal strength changed from satellite modem.
12535 *
12536 * @param subId The subId of the subscription to request for.
12537 * @param callback The callback to handle the NTN signal strength changed event.
12538 *
12539 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12540 *
12541 * @throws SecurityException if the caller doesn't have the required permission.
12542 */
12543 @Override
12544 @SatelliteManager.SatelliteResult public int registerForNtnSignalStrengthChanged(
12545 int subId, @NonNull INtnSignalStrengthCallback callback) {
12546 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12547 final long identity = Binder.clearCallingIdentity();
12548 try {
12549 return mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
12550 } finally {
12551 Binder.restoreCallingIdentity(identity);
12552 }
12553 }
12554
12555 /**
12556 * Unregisters for NTN signal strength changed from satellite modem.
12557 * If callback was not registered before, the request will be ignored.
12558 *
12559 * @param subId The subId of the subscription to unregister for provision state changed.
12560 * @param callback The callback that was passed to
12561 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12562 *
12563 * @throws SecurityException if the caller doesn't have the required permission.
12564 */
12565 @Override
12566 public void unregisterForNtnSignalStrengthChanged(
12567 int subId, @NonNull INtnSignalStrengthCallback callback) {
12568 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12569 final long identity = Binder.clearCallingIdentity();
12570 try {
12571 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12572 } finally {
12573 Binder.restoreCallingIdentity(identity);
12574 }
12575 }
12576
12577 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012578 * This API can be used by only CTS to update satellite vendor service package name.
12579 *
12580 * @param servicePackageName The package name of the satellite vendor service.
12581 * @return {@code true} if the satellite vendor service is set successfully,
12582 * {@code false} otherwise.
12583 */
12584 public boolean setSatelliteServicePackageName(String servicePackageName) {
12585 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12586 TelephonyPermissions.enforceShellOnly(
12587 Binder.getCallingUid(), "setSatelliteServicePackageName");
12588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12589 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12590 "setSatelliteServicePackageName");
12591 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12592 }
12593
12594 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012595 * This API can be used by only CTS to update satellite gateway service package name.
12596 *
12597 * @param servicePackageName The package name of the satellite gateway service.
12598 * @return {@code true} if the satellite gateway service is set successfully,
12599 * {@code false} otherwise.
12600 */
12601 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12602 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12603 TelephonyPermissions.enforceShellOnly(
12604 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12606 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12607 "setSatelliteGatewayServicePackageName");
12608 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12609 }
12610
12611 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012612 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12613 *
12614 * @param packageName The package name of the satellite pointing UI app.
12615 * @param className The class name of the satellite pointing UI app.
12616 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12617 * {@code false} otherwise.
12618 */
12619 public boolean setSatellitePointingUiClassName(
12620 @Nullable String packageName, @Nullable String className) {
12621 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12622 + ", className=" + className);
12623 TelephonyPermissions.enforceShellOnly(
12624 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12626 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12627 "setSatelliteGatewayServicePackageName");
12628 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12629 }
12630
12631 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012632 * This API can be used by only CTS to update the timeout duration in milliseconds that
12633 * satellite should stay at listening mode to wait for the next incoming page before disabling
12634 * listening mode.
12635 *
12636 * @param timeoutMillis The timeout duration in millisecond.
12637 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12638 */
12639 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12640 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12641 TelephonyPermissions.enforceShellOnly(
12642 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12644 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12645 "setSatelliteListeningTimeoutDuration");
12646 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12647 }
12648
12649 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012650 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12651 * the device is aligned with the satellite for demo mode
12652 *
12653 * @param timeoutMillis The timeout duration in millisecond.
12654 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12655 */
12656 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12657 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12658 TelephonyPermissions.enforceShellOnly(
12659 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12661 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12662 "setDeviceAlignedTimeoutDuration");
12663 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12664 }
12665
12666 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012667 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12668 *
12669 * <p>This method behaves in one of the following ways:
12670 * <ul>
12671 * <li>return true : if the calling package has the appop permission {@link
12672 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12673 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12674 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12675 * Owner device identifier access check, or the calling package has carrier privileges</>
12676 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12677 * </ul>
12678 */
12679 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12680 String callingPackage, @Nullable String callingFeatureId, String message) {
12681 for (Phone phone : PhoneFactory.getPhones()) {
12682 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12683 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12684 return true;
12685 }
12686 }
12687 return false;
12688 }
arunvoddud7401012022-12-15 16:08:12 +000012689
12690 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012691 * @return The subscription manager service instance.
12692 */
12693 public SubscriptionManagerService getSubscriptionManagerService() {
12694 return SubscriptionManagerService.getInstance();
12695 }
12696
12697 /**
arunvoddud7401012022-12-15 16:08:12 +000012698 * Class binds the consumer[callback] and carrierId.
12699 */
12700 private static class CallerCallbackInfo {
12701 private final Consumer<Integer> mConsumer;
12702 private final int mCarrierId;
12703
12704 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12705 mConsumer = consumer;
12706 mCarrierId = carrierId;
12707 }
12708
12709 public Consumer<Integer> getConsumer() {
12710 return mConsumer;
12711 }
12712
12713 public int getCarrierId() {
12714 return mCarrierId;
12715 }
12716 }
Jack Yufa8ed012023-02-11 15:42:28 -080012717}