blob: 0b92395cbf540e738b6cfa92e6f905c0cfa5d6ce [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;
Nate Myrenae97d192023-06-09 15:22:31 -070020import static android.permission.flags.Flags.opEnableMobileDataByUser;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000021import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080022import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080023
Shuo Qianccbaf742021-02-22 18:32:21 -080024import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
25import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070026import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070027import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000028import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070029
Brad Ebinger34c09a52021-02-17 23:23:21 +000030import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080032import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070033import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000034import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080035import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080037import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070038import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000039import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080040import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.compat.annotation.ChangeId;
42import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000043import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070044import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070045import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.content.Context;
47import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070049import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070050import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.net.Uri;
52import android.os.AsyncResult;
53import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080054import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080056import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070058import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080059import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080060import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.os.Looper;
62import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070063import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080064import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070065import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070066import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080067import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080068import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070069import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070070import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080071import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070073import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070075import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070076import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080077import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070078import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000079import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090080import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080081import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080082import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070083import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080084import android.telephony.AccessNetworkConstants;
85import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070086import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070087import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080088import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070089import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080090import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070091import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080092import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060093import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070094import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080095import android.telephony.CellIdentityCdma;
96import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070098import android.telephony.CellInfoGsm;
99import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700100import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800101import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700102import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700103import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700104import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800105import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700106import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800107import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700108import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800109import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800110import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700111import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800112import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800114import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800115import android.telephony.SignalStrengthUpdateRequest;
116import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800117import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800119import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700120import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700121import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800122import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800123import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800124import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800125import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000127import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000128import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700129import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700130import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800131import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800132import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700133import android.telephony.gba.GbaAuthRequest;
134import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700135import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000137import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000138import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700139import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000140import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700141import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700143import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800144import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700145import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000146import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700147import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800148import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800149import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000150import android.telephony.satellite.INtnSignalStrengthCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800151import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800152import android.telephony.satellite.ISatelliteProvisionStateCallback;
153import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800154import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800155import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000156import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800157import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800158import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800159import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800161import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700162import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800164import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800165
Andrew Lee312e8172014-10-23 17:01:36 -0700166import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800167import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800168import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800169import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800170import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700171import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700172import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700173import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800174import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800175import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700176import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800178import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700179import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800180import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800181import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800182import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700183import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000184import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700185import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800186import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800188import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800189import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800190import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700191import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700192import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700193import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700195import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800196import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700197import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700198import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700199import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700200import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800201import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800202import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700203import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000204import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700205import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700206import com.android.internal.telephony.SmsPermissions;
Peter Wang59571be2020-01-27 12:35:15 +0800207import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800208import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700209import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000210import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800211import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700212import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700213import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800214import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700215import com.android.internal.telephony.imsphone.ImsPhone;
216import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000217import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800218import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000219import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800220import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
221import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700222import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700223import com.android.internal.telephony.uicc.IccIoResult;
224import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800225import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700226import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800227import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700228import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000229import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800230import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000231import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800232import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000233import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700234import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700235import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800236import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800237import com.android.phone.callcomposer.CallComposerPictureManager;
238import com.android.phone.callcomposer.CallComposerPictureTransfer;
239import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700240import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700241import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000242import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700243import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800244import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700245import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700246import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800247import com.android.services.telephony.TelecomAccountRegistry;
248import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800249import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800250
Hall Liu82694d52020-12-11 18:22:04 -0800251import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700252import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800253import java.io.IOException;
254import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700255import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000258import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800259import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800260import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800261import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800262import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100263import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800264import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700265import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800267import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700268import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800270import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800271import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272
273/**
274 * Implementation of the ITelephony interface.
275 */
Santos Cordon117fee72014-05-16 17:56:12 -0700276public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 private static final String LOG_TAG = "PhoneInterfaceManager";
278 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
279 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800280 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281
282 // Message codes used with mMainThreadHandler
283 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700284 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
285 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700286 private static final int CMD_OPEN_CHANNEL = 9;
287 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
288 private static final int CMD_CLOSE_CHANNEL = 11;
289 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800290 private static final int CMD_NV_READ_ITEM = 13;
291 private static final int EVENT_NV_READ_ITEM_DONE = 14;
292 private static final int CMD_NV_WRITE_ITEM = 15;
293 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
294 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
295 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700296 private static final int CMD_RESET_MODEM_CONFIG = 19;
297 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800298 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
299 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800300 private static final int CMD_SEND_ENVELOPE = 25;
301 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700302 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
303 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
304 private static final int CMD_EXCHANGE_SIM_IO = 31;
305 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800306 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
307 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700308 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
309 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700310 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
311 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700312 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
313 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
314 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
315 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700316 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
317 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
318 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
319 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700320 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800321 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
322 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000323 private static final int CMD_SWITCH_SLOTS = 50;
324 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700325 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
326 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
327 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
328 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
329 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
330 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
331 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
332 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700333 private static final int CMD_GET_ALL_CELL_INFO = 60;
334 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
335 private static final int CMD_GET_CELL_LOCATION = 62;
336 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700337 private static final int CMD_MODEM_REBOOT = 64;
338 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700339 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
340 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800341 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
342 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700343 private static final int CMD_GET_MODEM_STATUS = 70;
344 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700345 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
346 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700347 private static final int CMD_ERASE_MODEM_CONFIG = 74;
348 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800349 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
350 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
351 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
352 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800353 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
354 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800355 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800356 private static final int CMD_GET_CALL_FORWARDING = 83;
357 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
358 private static final int CMD_SET_CALL_FORWARDING = 85;
359 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
360 private static final int CMD_GET_CALL_WAITING = 87;
361 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
362 private static final int CMD_SET_CALL_WAITING = 89;
363 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700364 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
365 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
366 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
367 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700368 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
369 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800370 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
371 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800372 private static final int CMD_SET_DATA_THROTTLING = 99;
373 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800374 private static final int CMD_SET_SIM_POWER = 101;
375 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800376 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
377 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
378 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
379 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800380 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
381 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000382 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800383 private static final int CMD_GET_SLICING_CONFIG = 110;
384 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800385 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700386 private static final int CMD_ENABLE_VONR = 113;
387 private static final int EVENT_ENABLE_VONR_DONE = 114;
388 private static final int CMD_IS_VONR_ENABLED = 115;
389 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700390 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
391 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000392
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800393 // Parameters of select command.
394 private static final int SELECT_COMMAND = 0xA4;
395 private static final int SELECT_P1 = 0x04;
396 private static final int SELECT_P2 = 0;
397 private static final int SELECT_P3 = 0x10;
398
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000399 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
400 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
401
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 /** The singleton instance. */
403 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800404 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405
Sarah Chin4beb2b72023-02-14 14:47:54 -0800406 private final PhoneGlobals mApp;
Sarah Chincc5446f2023-10-23 17:57:19 -0700407 private final FeatureFlags mFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800408 private final CallManager mCM;
409 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000410
411 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800412 private final UserManager mUserManager;
413 private final AppOpsManager mAppOps;
414 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800415 private final SharedPreferences mTelephonySharedPreferences;
416 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800417 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
Peter Wangdafb9ac2020-01-15 14:13:38 -0800419 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800420 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800421 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
422
Sarah Chin4beb2b72023-02-14 14:47:54 -0800423 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800424
Derek Tan97ebb422014-09-05 16:55:38 -0700425 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
426 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800427 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800428 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700429
Michelecea4cf22018-12-21 15:00:11 -0800430 // String to store multi SIM allowed
431 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
432
Derek Tan740e1672017-06-27 14:56:27 -0700433 // The AID of ISD-R.
434 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
435
yinxub1bed742017-04-17 11:45:04 -0700436 private NetworkScanRequestTracker mNetworkScanRequestTracker;
437
David Kelly5e06a7f2018-03-12 14:10:59 +0000438 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
439 private static final int MANUFACTURER_CODE_LENGTH = 8;
440
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800441 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800442 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800443
Sarah Chin2ec39f62022-08-31 17:03:26 -0700444 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
445 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
446
Derek Tan89e89d42014-07-08 17:00:10 -0700447 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700448 * Experiment flag to enable erase modem config on reset network, default value is false
449 */
450 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
451 "reset_network_erase_modem_config_enabled";
452
Rambo Wang0f050d82021-02-12 11:43:36 -0800453 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800454
Gary Jian76280a42022-12-07 16:18:33 +0800455 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
456
sandeepjsb6c87872021-09-27 15:34:44 +0000457 /**
458 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
459 * one ICCID active at the same time.
460 * Apps should use below API signatures if targeting SDK is T and beyond.
461 *
462 * @hide
463 */
464 @ChangeId
465 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
466 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800467
Naina Nallurid63128d2019-09-17 14:10:30 -0700468 /**
Chen Xu540470b2021-12-14 17:15:47 -0800469 * Apps targeting on Android T and beyond will get exception whenever icc close channel
470 * operation fails.
471 */
472 @ChangeId
473 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
474 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
475
476 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 * A request object to use for transmitting data to an ICC.
478 */
479 private static final class IccAPDUArgument {
480 public int channel, cla, command, p1, p2, p3;
481 public String data;
482
483 public IccAPDUArgument(int channel, int cla, int command,
484 int p1, int p2, int p3, String data) {
485 this.channel = channel;
486 this.cla = cla;
487 this.command = command;
488 this.p1 = p1;
489 this.p2 = p2;
490 this.p3 = p3;
491 this.data = data;
492 }
493 }
494
495 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700496 * A request object to use for transmitting data to an ICC.
497 */
498 private static final class ManualNetworkSelectionArgument {
499 public OperatorInfo operatorInfo;
500 public boolean persistSelection;
501
502 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
503 this.operatorInfo = operatorInfo;
504 this.persistSelection = persistSelection;
505 }
506 }
507
Sarah Chin71b3a852022-09-28 15:54:19 -0700508 private static final class PurchasePremiumCapabilityArgument {
509 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700510 public @NonNull IIntegerConsumer callback;
511
512 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800513 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700514 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700515 this.callback = callback;
516 }
517 }
518
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700519 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
521 * request after sending. The main thread will notify the request when it is complete.
522 */
523 private static final class MainThreadRequest {
524 /** The argument to use for the request */
525 public Object argument;
526 /** The result of the request that is run on the main thread */
527 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800528 // The subscriber id that this request applies to. Defaults to
529 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
530 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531
Nathan Harold92bed182018-10-12 18:16:49 -0700532 // In cases where subId is unavailable, the caller needs to specify the phone.
533 public Phone phone;
534
vagdeviaf9a5b92018-08-15 16:01:53 -0700535 public WorkSource workSource;
536
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 public MainThreadRequest(Object argument) {
538 this.argument = argument;
539 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800540
Nathan Harold92bed182018-10-12 18:16:49 -0700541 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
542 this.argument = argument;
543 if (phone != null) {
544 this.phone = phone;
545 }
546 this.workSource = workSource;
547 }
548
vagdeviaf9a5b92018-08-15 16:01:53 -0700549 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800550 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800551 if (subId != null) {
552 this.subId = subId;
553 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700554 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 }
557
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800558 private static final class IncomingThirdPartyCallArgs {
559 public final ComponentName component;
560 public final String callId;
561 public final String callerDisplayName;
562
563 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
564 String callerDisplayName) {
565 this.component = component;
566 this.callId = callId;
567 this.callerDisplayName = callerDisplayName;
568 }
569 }
570
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 /**
572 * A handler that processes messages on the main thread in the phone process. Since many
573 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
574 * inbound binder threads to the main thread in the phone process. The Binder thread
575 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
576 * on, which will be notified when the operation completes and will contain the result of the
577 * request.
578 *
579 * <p>If a MainThreadRequest object is provided in the msg.obj field,
580 * note that request.result must be set to something non-null for the calling thread to
581 * unblock.
582 */
583 private final class MainThreadHandler extends Handler {
584 @Override
585 public void handleMessage(Message msg) {
586 MainThreadRequest request;
587 Message onCompleted;
588 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000589 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800591 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592
593 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 case CMD_HANDLE_USSD_REQUEST: {
595 request = (MainThreadRequest) msg.obj;
596 final Phone phone = getPhoneFromRequest(request);
597 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800598 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700600
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 if (!isUssdApiAllowed(request.subId)) {
602 // Carrier does not support use of this API, return failure.
603 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
604 UssdResponse response = new UssdResponse(ussdRequest, null);
605 Bundle returnData = new Bundle();
606 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
607 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700608
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 request.result = true;
610 notifyRequester(request);
611 return;
612 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700613
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 try {
615 request.result = phone != null
616 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
617 } catch (CallStateException cse) {
618 request.result = false;
619 }
620 // Wake up the requesting thread
621 notifyRequester(request);
622 break;
pkanwar32d516d2016-10-14 19:37:38 -0700623 }
624
Yorke Lee716f67e2015-06-17 15:39:16 -0700625 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700626 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700627 final Phone phone = getPhoneFromRequest(request);
628 request.result = phone != null ?
629 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
630 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700633 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700635
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000639 uiccPort = getUiccPortFromRequest(request);
640 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800642 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000647 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800648 iccArgument.channel, iccArgument.cla, iccArgument.command,
649 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
650 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 break;
653
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 ar = (AsyncResult) msg.obj;
656 request = (MainThreadRequest) ar.userObj;
657 if (ar.exception == null && ar.result != null) {
658 request.result = ar.result;
659 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800660 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 if (ar.result == null) {
662 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800663 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800665 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 } else {
667 loge("iccTransmitApduLogicalChannel: Unknown exception");
668 }
669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 break;
672
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
674 request = (MainThreadRequest) msg.obj;
675 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000676 uiccPort = getUiccPortFromRequest(request);
677 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800679 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 } else {
682 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800685 iccArgument.cla, iccArgument.command, iccArgument.p1,
686 iccArgument.p2,
687 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 }
689 break;
690
691 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
692 ar = (AsyncResult) msg.obj;
693 request = (MainThreadRequest) ar.userObj;
694 if (ar.exception == null && ar.result != null) {
695 request.result = ar.result;
696 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800697 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 if (ar.result == null) {
699 loge("iccTransmitApduBasicChannel: Empty response");
700 } else if (ar.exception instanceof CommandException) {
701 loge("iccTransmitApduBasicChannel: CommandException: " +
702 ar.exception);
703 } else {
704 loge("iccTransmitApduBasicChannel: Unknown exception");
705 }
706 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700707 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 break;
709
710 case CMD_EXCHANGE_SIM_IO:
711 request = (MainThreadRequest) msg.obj;
712 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000713 uiccPort = getUiccPortFromRequest(request);
714 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800716 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 } else {
719 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
720 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
723 iccArgument.data, onCompleted);
724 }
725 break;
726
727 case EVENT_EXCHANGE_SIM_IO_DONE:
728 ar = (AsyncResult) msg.obj;
729 request = (MainThreadRequest) ar.userObj;
730 if (ar.exception == null && ar.result != null) {
731 request.result = ar.result;
732 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800733 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 break;
737
Derek Tan4d5e5c12014-02-04 11:54:58 -0800738 case CMD_SEND_ENVELOPE:
739 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000740 uiccPort = getUiccPortFromRequest(request);
741 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800743 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 } else {
746 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800747 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800749 break;
750
751 case EVENT_SEND_ENVELOPE_DONE:
752 ar = (AsyncResult) msg.obj;
753 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700754 if (ar.exception == null && ar.result != null) {
755 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800756 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800757 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700758 if (ar.result == null) {
759 loge("sendEnvelopeWithStatus: Empty response");
760 } else if (ar.exception instanceof CommandException) {
761 loge("sendEnvelopeWithStatus: CommandException: " +
762 ar.exception);
763 } else {
764 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
765 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800766 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700767 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800768 break;
769
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 case CMD_OPEN_CHANNEL:
771 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000772 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800773 IccLogicalChannelRequest openChannelRequest =
774 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000775 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700776 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800777 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800778 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700780 } else {
781 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800782 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
783 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700784 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
787 case EVENT_OPEN_CHANNEL_DONE:
788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700790 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700792 int[] result = (int[]) ar.result;
793 int channelId = result[0];
794 byte[] selectResponse = null;
795 if (result.length > 1) {
796 selectResponse = new byte[result.length - 1];
797 for (int i = 1; i < result.length; ++i) {
798 selectResponse[i - 1] = (byte) result[i];
799 }
800 }
801 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800802 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800803
804 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700805 if (uiccPort == null) {
806 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
807 } else {
808 IccLogicalChannelRequest channelRequest =
809 (IccLogicalChannelRequest) request.argument;
810 channelRequest.channel = channelId;
811 uiccPort.onLogicalChannelOpened(channelRequest);
812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700814 if (ar.result == null) {
815 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700817 if (ar.exception != null) {
818 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
819 }
820
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700821 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700822 if (ar.exception instanceof CommandException) {
823 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800824 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700825 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700826 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700827 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700828 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700829 }
830 }
831 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800832 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700834 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700835 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 break;
837
838 case CMD_CLOSE_CHANNEL:
839 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000840 uiccPort = getUiccPortFromRequest(request);
841 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700842 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800843 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800844 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800845 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700846 } else {
847 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000848 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700849 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 break;
851
852 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null) {
856 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800857 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700858 if (uiccPort == null) {
859 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
860 } else {
861 final int channelId = (Integer) request.argument;
862 uiccPort.onLogicalChannelClosed(channelId);
863 }
Chen Xu540470b2021-12-14 17:15:47 -0800864 } else {
865 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800866 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800867 if (ar.exception instanceof CommandException) {
868 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
869 CommandException.Error error =
870 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800871 if (error == CommandException.Error.INVALID_ARGUMENTS) {
872 // should only throw exceptions from the binder threads.
873 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800874 "iccCloseLogicalChannel: invalid argument ");
875 }
876 } else {
877 loge("iccCloseLogicalChannel: Unknown exception");
878 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800879 request.result = (exception != null) ? exception :
880 new IllegalStateException(
881 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800882 }
883 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800884 break;
885
886 case CMD_NV_READ_ITEM:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800889 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
890 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
893 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700898 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800899 request.result = "";
900 if (ar.result == null) {
901 loge("nvReadItem: Empty response");
902 } else if (ar.exception instanceof CommandException) {
903 loge("nvReadItem: CommandException: " +
904 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700905 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800906 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700907 }
908 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700909 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700910 break;
911
Jake Hambye994d462014-02-03 13:10:13 -0800912 case CMD_NV_WRITE_ITEM:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
915 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800916 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700917 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800918 break;
919
920 case EVENT_NV_WRITE_ITEM_DONE:
921 handleNullReturnEvent(msg, "nvWriteItem");
922 break;
923
924 case CMD_NV_WRITE_CDMA_PRL:
925 request = (MainThreadRequest) msg.obj;
926 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800927 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800928 break;
929
930 case EVENT_NV_WRITE_CDMA_PRL_DONE:
931 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
932 break;
933
chen xu6dac5ab2018-10-26 17:39:23 -0700934 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800935 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700936 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800937 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800938 break;
939
chen xu6dac5ab2018-10-26 17:39:23 -0700940 case EVENT_RESET_MODEM_CONFIG_DONE:
941 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800942 break;
943
Sooraj Sasindran37444802020-08-11 10:40:43 -0700944 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
947 request);
948 Phone phone = getPhoneFromRequest(request);
949 if (phone != null) {
950 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
951 } else {
952 loge("isNRDualConnectivityEnabled: No phone object");
953 request.result = false;
954 notifyRequester(request);
955 }
956 break;
957 }
958
959 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
960 ar = (AsyncResult) msg.obj;
961 request = (MainThreadRequest) ar.userObj;
962 if (ar.exception == null && ar.result != null) {
963 request.result = ar.result;
964 } else {
965 // request.result must be set to something non-null
966 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700967 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700968 request.result = ar.result;
969 } else {
970 request.result = false;
971 }
972 if (ar.result == null) {
973 loge("isNRDualConnectivityEnabled: Empty response");
974 } else if (ar.exception instanceof CommandException) {
975 loge("isNRDualConnectivityEnabled: CommandException: "
976 + ar.exception);
977 } else {
978 loge("isNRDualConnectivityEnabled: Unknown exception");
979 }
980 }
981 notifyRequester(request);
982 break;
983
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700984 case CMD_IS_VONR_ENABLED: {
985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
987 request);
988 Phone phone = getPhoneFromRequest(request);
989 if (phone != null) {
990 phone.isVoNrEnabled(onCompleted, request.workSource);
991 } else {
992 loge("isVoNrEnabled: No phone object");
993 request.result = false;
994 notifyRequester(request);
995 }
996 break;
997 }
998
999 case EVENT_IS_VONR_ENABLED_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception == null && ar.result != null) {
1003 request.result = ar.result;
1004 } else {
1005 // request.result must be set to something non-null
1006 // for the calling thread to unblock
1007 if (ar.result != null) {
1008 request.result = ar.result;
1009 } else {
1010 request.result = false;
1011 }
1012 if (ar.result == null) {
1013 loge("isVoNrEnabled: Empty response");
1014 } else if (ar.exception instanceof CommandException) {
1015 loge("isVoNrEnabled: CommandException: "
1016 + ar.exception);
1017 } else {
1018 loge("isVoNrEnabled: Unknown exception");
1019 }
1020 }
1021 notifyRequester(request);
1022 break;
1023
Sooraj Sasindran37444802020-08-11 10:40:43 -07001024 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1027 Phone phone = getPhoneFromRequest(request);
1028 if (phone != null) {
1029 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1030 request.workSource);
1031 } else {
1032 loge("enableNrDualConnectivity: No phone object");
1033 request.result =
1034 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1035 notifyRequester(request);
1036 }
1037 break;
1038 }
1039
1040 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 if (ar.exception == null) {
1044 request.result =
1045 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1046 } else {
1047 request.result =
1048 TelephonyManager
1049 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1050 if (ar.exception instanceof CommandException) {
1051 CommandException.Error error =
1052 ((CommandException) (ar.exception)).getCommandError();
1053 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1054 request.result =
1055 TelephonyManager
1056 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001057 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1058 request.result =
1059 TelephonyManager
1060 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001061 }
1062 loge("enableNrDualConnectivity" + ": CommandException: "
1063 + ar.exception);
1064 } else {
1065 loge("enableNrDualConnectivity" + ": Unknown exception");
1066 }
1067 }
1068 notifyRequester(request);
1069 break;
1070 }
1071
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001072 case CMD_ENABLE_VONR: {
1073 request = (MainThreadRequest) msg.obj;
1074 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1075 Phone phone = getPhoneFromRequest(request);
1076 if (phone != null) {
1077 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1078 request.workSource);
1079 } else {
1080 loge("setVoNrEnabled: No phone object");
1081 request.result =
1082 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1083 notifyRequester(request);
1084 }
1085 break;
1086 }
1087
1088 case EVENT_ENABLE_VONR_DONE: {
1089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
1091 if (ar.exception == null) {
1092 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1093 } else {
1094 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1095 if (ar.exception instanceof CommandException) {
1096 CommandException.Error error =
1097 ((CommandException) (ar.exception)).getCommandError();
1098 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1099 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1100 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1101 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1102 } else {
1103 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1104 }
1105 loge("setVoNrEnabled" + ": CommandException: "
1106 + ar.exception);
1107 } else {
1108 loge("setVoNrEnabled" + ": Unknown exception");
1109 }
1110 }
1111 notifyRequester(request);
1112 break;
1113 }
1114
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001116 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001117 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1118 request);
1119 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 break;
1121
SongFerngWang3ef3e072020-12-21 16:41:52 +08001122 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 ar = (AsyncResult) msg.obj;
1124 request = (MainThreadRequest) ar.userObj;
1125 if (ar.exception == null && ar.result != null) {
1126 request.result = ar.result; // Integer
1127 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301128 // request.result must be set to something non-null
1129 // for the calling thread to unblock
1130 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001132 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001133 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001134 loge("getAllowedNetworkTypesBitmask: CommandException: "
1135 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 }
1139 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001140 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 break;
1142
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001145 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1146 request);
1147 Pair<Integer, Long> reasonWithNetworkTypes =
1148 (Pair<Integer, Long>) request.argument;
1149 getPhoneFromRequest(request).setAllowedNetworkTypes(
1150 reasonWithNetworkTypes.first,
1151 reasonWithNetworkTypes.second,
1152 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 break;
1154
SongFerngWang3ef3e072020-12-21 16:41:52 +08001155 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1156 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 break;
1158
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001159 case CMD_SET_VOICEMAIL_NUMBER:
1160 request = (MainThreadRequest) msg.obj;
1161 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1162 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001163 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1164 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001165 break;
1166
1167 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1168 handleNullReturnEvent(msg, "setVoicemailNumber");
1169 break;
1170
Stuart Scott54788802015-03-30 13:18:01 -07001171 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1174 request);
1175 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1176 break;
1177
1178 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1179 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1180 break;
1181
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 case CMD_PERFORM_NETWORK_SCAN:
1183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1185 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1186 break;
1187
Hall Liu27d24262020-09-18 19:04:59 -07001188 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001189 request = (MainThreadRequest) msg.obj;
1190 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001191 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1192 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1193 request.argument;
1194 int callForwardingReason = args.first;
1195 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001196 break;
Hall Liu27d24262020-09-18 19:04:59 -07001197 }
1198 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001199 ar = (AsyncResult) msg.obj;
1200 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001201 TelephonyManager.CallForwardingInfoCallback callback =
1202 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1203 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001205 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1207 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1208 // Service Class is a bit mask per 3gpp 27.007. Search for
1209 // any service for voice call.
1210 if ((callForwardInfo.serviceClass
1211 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001212 callForwardingInfo = new CallForwardingInfo(
1213 callForwardInfo.status
1214 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001215 callForwardInfo.reason,
1216 callForwardInfo.number,
1217 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001218 break;
1219 }
1220 }
1221 // Didn't find a call forward info for voice call.
1222 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001223 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1224 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001225 }
Hall Liu27d24262020-09-18 19:04:59 -07001226 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001227 } else {
1228 if (ar.result == null) {
1229 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1230 }
1231 if (ar.exception != null) {
1232 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1233 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001234 int errorCode = TelephonyManager
1235 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001236 if (ar.exception instanceof CommandException) {
1237 CommandException.Error error =
1238 ((CommandException) (ar.exception)).getCommandError();
1239 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager
1241 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001242 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001243 errorCode = TelephonyManager
1244 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001245 }
1246 }
Hall Liu27d24262020-09-18 19:04:59 -07001247 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 }
Shuo Qian4a594052020-01-23 11:59:30 -08001249 break;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
Shuo Qian4a594052020-01-23 11:59:30 -08001251
Hall Liu27d24262020-09-18 19:04:59 -07001252 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001253 request = (MainThreadRequest) msg.obj;
1254 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001255 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001257 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1258 request.argument).first;
1259 request.phone.setCallForwardingOption(
1260 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001261 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001262 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001263 callForwardingInfoToSet.getReason(),
1264 callForwardingInfoToSet.getNumber(),
1265 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1266 break;
Hall Liu27d24262020-09-18 19:04:59 -07001267 }
Shuo Qian4a594052020-01-23 11:59:30 -08001268
Hall Liu27d24262020-09-18 19:04:59 -07001269 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001270 ar = (AsyncResult) msg.obj;
1271 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001272 Consumer<Integer> callback =
1273 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1274 request.argument).second;
1275 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001276 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001277 int errorCode = TelephonyManager.CallForwardingInfoCallback
1278 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001279 if (ar.exception instanceof CommandException) {
1280 CommandException.Error error =
1281 ((CommandException) (ar.exception)).getCommandError();
1282 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001283 errorCode = TelephonyManager.CallForwardingInfoCallback
1284 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001285 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001286 errorCode = TelephonyManager.CallForwardingInfoCallback
1287 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001288 }
1289 }
1290 callback.accept(errorCode);
1291 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001292 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294 break;
Hall Liu27d24262020-09-18 19:04:59 -07001295 }
Shuo Qian4a594052020-01-23 11:59:30 -08001296
Hall Liu27d24262020-09-18 19:04:59 -07001297 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001298 request = (MainThreadRequest) msg.obj;
1299 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1300 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1301 break;
Hall Liu27d24262020-09-18 19:04:59 -07001302 }
Shuo Qian4a594052020-01-23 11:59:30 -08001303
Hall Liu27d24262020-09-18 19:04:59 -07001304 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001305 ar = (AsyncResult) msg.obj;
1306 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001307 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001308 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001309 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001310 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001311 // Service Class is a bit mask per 3gpp 27.007.
1312 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001313 if (callForwardResults.length > 1
1314 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001315 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001316 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001317 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1318 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001319 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 }
1322 } else {
1323 if (ar.result == null) {
1324 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1325 }
1326 if (ar.exception != null) {
1327 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1328 }
1329 if (ar.exception instanceof CommandException) {
1330 CommandException.Error error =
1331 ((CommandException) (ar.exception)).getCommandError();
1332 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001334 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001335 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1336 callWaitingStatus =
1337 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001338 }
1339 }
1340 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001342 break;
Hall Liu27d24262020-09-18 19:04:59 -07001343 }
Shuo Qian4a594052020-01-23 11:59:30 -08001344
Hall Liu27d24262020-09-18 19:04:59 -07001345 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001346 request = (MainThreadRequest) msg.obj;
1347 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001348 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1349 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001350 break;
Hall Liu27d24262020-09-18 19:04:59 -07001351 }
Shuo Qian4a594052020-01-23 11:59:30 -08001352
Hall Liu27d24262020-09-18 19:04:59 -07001353 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001356 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1357 Consumer<Integer> callback =
1358 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1359 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001360 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001361 if (ar.exception instanceof CommandException) {
1362 CommandException.Error error =
1363 ((CommandException) (ar.exception)).getCommandError();
1364 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1365 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001366 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1367 callback.accept(
1368 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001369 } else {
1370 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1371 }
1372 } else {
1373 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1374 }
1375 } else {
1376 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1377 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001378 }
Shuo Qian4a594052020-01-23 11:59:30 -08001379 break;
Hall Liu27d24262020-09-18 19:04:59 -07001380 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001381 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1382 ar = (AsyncResult) msg.obj;
1383 request = (MainThreadRequest) ar.userObj;
1384 CellNetworkScanResult cellScanResult;
1385 if (ar.exception == null && ar.result != null) {
1386 cellScanResult = new CellNetworkScanResult(
1387 CellNetworkScanResult.STATUS_SUCCESS,
1388 (List<OperatorInfo>) ar.result);
1389 } else {
1390 if (ar.result == null) {
1391 loge("getCellNetworkScanResults: Empty response");
1392 }
1393 if (ar.exception != null) {
1394 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1395 }
1396 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1397 if (ar.exception instanceof CommandException) {
1398 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001399 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001400 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1401 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1402 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1403 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1404 }
1405 }
1406 cellScanResult = new CellNetworkScanResult(errorCode, null);
1407 }
1408 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001409 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001410 break;
1411
1412 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1413 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001414 ManualNetworkSelectionArgument selArg =
1415 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1417 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001418 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1419 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001420 break;
1421
1422 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001423 ar = (AsyncResult) msg.obj;
1424 request = (MainThreadRequest) ar.userObj;
1425 if (ar.exception == null) {
1426 request.result = true;
1427 } else {
1428 request.result = false;
1429 loge("setNetworkSelectionModeManual " + ar.exception);
1430 }
1431 notifyRequester(request);
1432 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001433 break;
1434
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001435 case CMD_GET_MODEM_ACTIVITY_INFO:
1436 request = (MainThreadRequest) msg.obj;
1437 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001438 if (defaultPhone != null) {
1439 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001440 } else {
1441 ResultReceiver result = (ResultReceiver) request.argument;
1442 Bundle bundle = new Bundle();
1443 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001444 new ModemActivityInfo(0, 0, 0,
1445 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001446 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001447 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 break;
1449
Hall Liud0f208c2020-10-14 16:54:44 -07001450 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 ar = (AsyncResult) msg.obj;
1452 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001454 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001455 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001456 if (mLastModemActivityInfo == null) {
1457 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1458 mLastModemActivitySpecificInfo[0] =
1459 new ActivityStatsTechSpecificInfo(
1460 0,
1461 0,
1462 new int[ModemActivityInfo.getNumTxPowerLevels()],
1463 0);
1464 mLastModemActivityInfo =
1465 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1466 }
1467
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001469 // Update the last modem activity info and the result of the request.
1470 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1471 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001472 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001473 } else {
1474 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001475 }
Kai Shi917fdc62022-11-28 14:01:02 -08001476 // This is needed to decouple ret from mLastModemActivityInfo
1477 // We don't want to return mLastModemActivityInfo which is updated
1478 // inside mergeModemActivityInfo()
1479 ret = new ModemActivityInfo(
1480 mLastModemActivityInfo.getTimestampMillis(),
1481 mLastModemActivityInfo.getSleepTimeMillis(),
1482 mLastModemActivityInfo.getIdleTimeMillis(),
1483 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001484
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001485 } else {
1486 if (ar.result == null) {
1487 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001488 error = TelephonyManager.ModemActivityInfoException
1489 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001491 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001492 error = TelephonyManager.ModemActivityInfoException
1493 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001494 } else {
1495 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001496 error = TelephonyManager.ModemActivityInfoException
1497 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001498 }
1499 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001500 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001501 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001502 bundle.putParcelable(
1503 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001504 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001505 } else {
1506 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1507 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001508 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001509 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001511 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001512
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001513 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001515 CarrierRestrictionRules argument =
1516 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001517 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001518 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001520 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001521
1522 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1523 ar = (AsyncResult) msg.obj;
1524 request = (MainThreadRequest) ar.userObj;
1525 if (ar.exception == null && ar.result != null) {
1526 request.result = ar.result;
1527 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001528 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1529 if (ar.exception instanceof CommandException) {
1530 loge("setAllowedCarriers: CommandException: " + ar.exception);
1531 CommandException.Error error =
1532 ((CommandException) (ar.exception)).getCommandError();
1533 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1534 request.result =
1535 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1536 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 } else {
1538 loge("setAllowedCarriers: Unknown exception");
1539 }
1540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001541 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 break;
1543
1544 case CMD_GET_ALLOWED_CARRIERS:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001547 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001548 break;
1549
1550 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 if (ar.exception == null && ar.result != null) {
1554 request.result = ar.result;
1555 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001556 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001557 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001558 if (ar.result == null) {
1559 loge("getAllowedCarriers: Empty response");
1560 } else if (ar.exception instanceof CommandException) {
1561 loge("getAllowedCarriers: CommandException: " +
1562 ar.exception);
1563 } else {
1564 loge("getAllowedCarriers: Unknown exception");
1565 }
1566 }
arunvoddud7401012022-12-15 16:08:12 +00001567 if (request.argument != null) {
1568 // This is for the implementation of carrierRestrictionStatus.
1569 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1570 Consumer<Integer> callback = callbackInfo.getConsumer();
1571 int callerCarrierId = callbackInfo.getCarrierId();
1572 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1573 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1574 CarrierRestrictionRules carrierRestrictionRules =
1575 (CarrierRestrictionRules) ar.result;
1576 int carrierId = -1;
1577 try {
1578 CarrierIdentifier carrierIdentifier =
1579 carrierRestrictionRules.getAllowedCarriers().get(0);
1580 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1581 carrierIdentifier);
1582 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1583 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1584 }
1585 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1586 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1587 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001588 lockStatus = TelephonyManager
1589 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001590 }
1591 } else {
1592 Rlog.e(LOG_TAG,
1593 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1594 }
1595 callback.accept(lockStatus);
1596 } else {
1597 // This is for the implementation of getAllowedCarriers.
1598 notifyRequester(request);
1599 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001600 break;
1601
Nathan Haroldb3014052017-01-25 15:57:32 -08001602 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1603 ar = (AsyncResult) msg.obj;
1604 request = (MainThreadRequest) ar.userObj;
1605 if (ar.exception == null && ar.result != null) {
1606 request.result = ar.result;
1607 } else {
1608 request.result = new IllegalArgumentException(
1609 "Failed to retrieve Forbidden Plmns");
1610 if (ar.result == null) {
1611 loge("getForbiddenPlmns: Empty response");
1612 } else {
1613 loge("getForbiddenPlmns: Unknown exception");
1614 }
1615 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001616 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001617 break;
1618
1619 case CMD_GET_FORBIDDEN_PLMNS:
1620 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001621 uiccPort = getUiccPortFromRequest(request);
1622 if (uiccPort == null) {
1623 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001624 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001625 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001626 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001627 break;
1628 }
1629 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001630 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001631 if (uiccApp == null) {
1632 loge("getForbiddenPlmns() no app with specified type -- "
1633 + appType);
1634 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001635 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001636 break;
1637 } else {
1638 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1639 + " specified type -- " + appType);
1640 }
1641 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1642 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001643 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 break;
1645
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001646 case CMD_SWITCH_SLOTS:
1647 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001648 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001649 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001650 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001651 break;
1652
1653 case EVENT_SWITCH_SLOTS_DONE:
1654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001657 notifyRequester(request);
1658 break;
1659 case CMD_GET_NETWORK_SELECTION_MODE:
1660 request = (MainThreadRequest) msg.obj;
1661 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1662 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1663 break;
1664
1665 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
1668 if (ar.exception != null) {
1669 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1670 } else {
1671 int mode = ((int[]) ar.result)[0];
1672 if (mode == 0) {
1673 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1674 } else {
1675 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1676 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001678 notifyRequester(request);
1679 break;
1680 case CMD_GET_CDMA_ROAMING_MODE:
1681 request = (MainThreadRequest) msg.obj;
1682 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1683 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1684 break;
1685 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 if (ar.exception != null) {
1689 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1690 } else {
1691 request.result = ((int[]) ar.result)[0];
1692 }
1693 notifyRequester(request);
1694 break;
1695 case CMD_SET_CDMA_ROAMING_MODE:
1696 request = (MainThreadRequest) msg.obj;
1697 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1698 int mode = (int) request.argument;
1699 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1700 break;
1701 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1702 ar = (AsyncResult) msg.obj;
1703 request = (MainThreadRequest) ar.userObj;
1704 request.result = ar.exception == null;
1705 notifyRequester(request);
1706 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001707 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1710 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1711 break;
1712 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception != null) {
1716 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1717 } else {
1718 request.result = ((int[]) ar.result)[0];
1719 }
1720 notifyRequester(request);
1721 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001722 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1725 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001726 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1727 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001728 break;
1729 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 request.result = ar.exception == null;
1733 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001734 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001735 case CMD_GET_ALL_CELL_INFO:
1736 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001737 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001738 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001740 case EVENT_GET_ALL_CELL_INFO_DONE:
1741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001743 // If a timeout occurs, the response will be null
1744 request.result = (ar.exception == null && ar.result != null)
1745 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001746 synchronized (request) {
1747 request.notifyAll();
1748 }
1749 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001750 case CMD_REQUEST_CELL_INFO_UPDATE:
1751 request = (MainThreadRequest) msg.obj;
1752 request.phone.requestCellInfoUpdate(request.workSource,
1753 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1754 break;
1755 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1756 ar = (AsyncResult) msg.obj;
1757 request = (MainThreadRequest) ar.userObj;
1758 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1759 try {
1760 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001761 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001762 cb.onError(
1763 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1764 ar.exception.getClass().getName(),
1765 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001766 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001767 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001768 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001769 } else {
1770 // use the result as returned
1771 cb.onCellInfo((List<CellInfo>) ar.result);
1772 }
1773 } catch (RemoteException re) {
1774 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1775 }
1776 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001777 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001778 request = (MainThreadRequest) msg.obj;
1779 WorkSource ws = (WorkSource) request.argument;
1780 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001781 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001782 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001783 }
1784 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001785 ar = (AsyncResult) msg.obj;
1786 request = (MainThreadRequest) ar.userObj;
1787 if (ar.exception == null) {
1788 request.result = ar.result;
1789 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001790 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001791 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001792 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001793 }
1794
1795 synchronized (request) {
1796 request.notifyAll();
1797 }
1798 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001799 }
chen xu6dac5ab2018-10-26 17:39:23 -07001800 case CMD_MODEM_REBOOT:
1801 request = (MainThreadRequest) msg.obj;
1802 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001803 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001804 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001805 case EVENT_CMD_MODEM_REBOOT_DONE:
1806 handleNullReturnEvent(msg, "rebootModem");
1807 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001808 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001809 request = (MainThreadRequest) msg.obj;
1810 boolean enable = (boolean) request.argument;
1811 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001812 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001813 PhoneConfigurationManager.getInstance()
1814 .enablePhone(request.phone, enable, onCompleted);
1815 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001816 }
Michele Berionne5e411512020-11-13 02:36:59 +00001817 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001818 ar = (AsyncResult) msg.obj;
1819 request = (MainThreadRequest) ar.userObj;
1820 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001821 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001822 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001823 if ((boolean) request.result) {
1824 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1825 updateModemStateMetrics();
1826 } else {
1827 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1828 + ar.exception);
1829 }
1830 notifyRequester(request);
1831 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001832 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001833 case CMD_GET_MODEM_STATUS:
1834 request = (MainThreadRequest) msg.obj;
1835 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1836 PhoneConfigurationManager.getInstance()
1837 .getPhoneStatusFromModem(request.phone, onCompleted);
1838 break;
1839 case EVENT_GET_MODEM_STATUS_DONE:
1840 ar = (AsyncResult) msg.obj;
1841 request = (MainThreadRequest) ar.userObj;
1842 int id = request.phone.getPhoneId();
1843 if (ar.exception == null && ar.result != null) {
1844 request.result = ar.result;
1845 //update the cache as modem status has changed
1846 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1847 (boolean) request.result);
1848 } else {
1849 // Return true if modem status cannot be retrieved. For most cases,
1850 // modem status is on. And for older version modems, GET_MODEM_STATUS
1851 // and disable modem are not supported. Modem is always on.
1852 // TODO: this should be fixed in R to support a third
1853 // status UNKNOWN b/131631629
1854 request.result = true;
1855 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1856 + ar.exception);
1857 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001858 notifyRequester(request);
1859 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001860 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1861 request = (MainThreadRequest) msg.obj;
1862 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1863 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1864 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1865 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1866 break;
1867 }
1868 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1869 ar = (AsyncResult) msg.obj;
1870 request = (MainThreadRequest) ar.userObj;
1871 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1872 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1873 args.second.accept(ar.exception == null);
1874 notifyRequester(request);
1875 break;
1876 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001877 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1878 request = (MainThreadRequest) msg.obj;
1879 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1880 Phone phone = getPhoneFromRequest(request);
1881 if (phone != null) {
1882 phone.getSystemSelectionChannels(onCompleted);
1883 } else {
1884 loge("getSystemSelectionChannels: No phone object");
1885 request.result = new ArrayList<RadioAccessSpecifier>();
1886 notifyRequester(request);
1887 }
1888 break;
1889 }
1890 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1891 ar = (AsyncResult) msg.obj;
1892 request = (MainThreadRequest) ar.userObj;
1893 if (ar.exception == null && ar.result != null) {
1894 request.result = ar.result;
1895 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001896 request.result = new IllegalStateException(
1897 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001898 if (ar.result == null) {
1899 loge("getSystemSelectionChannels: Empty response");
1900 } else {
1901 loge("getSystemSelectionChannels: Unknown exception");
1902 }
1903 }
1904 notifyRequester(request);
1905 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001906 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1907 ar = (AsyncResult) msg.obj;
1908 request = (MainThreadRequest) ar.userObj;
1909 if (ar.exception == null && ar.result != null) {
1910 request.result = ar.result;
1911 } else {
1912 request.result = -1;
1913 loge("Failed to set Forbidden Plmns");
1914 if (ar.result == null) {
1915 loge("setForbidenPlmns: Empty response");
1916 } else if (ar.exception != null) {
1917 loge("setForbiddenPlmns: Exception: " + ar.exception);
1918 request.result = -1;
1919 } else {
1920 loge("setForbiddenPlmns: Unknown exception");
1921 }
1922 }
1923 notifyRequester(request);
1924 break;
1925 case CMD_SET_FORBIDDEN_PLMNS:
1926 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001927 uiccPort = getUiccPortFromRequest(request);
1928 if (uiccPort == null) {
1929 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001930 request.result = -1;
1931 notifyRequester(request);
1932 break;
1933 }
1934 Pair<Integer, List<String>> setFplmnsArgs =
1935 (Pair<Integer, List<String>>) request.argument;
1936 appType = setFplmnsArgs.first;
1937 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001938 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001939 if (uiccApp == null) {
1940 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1941 request.result = -1;
1942 loge("Failed to get UICC App");
1943 notifyRequester(request);
1944 } else {
1945 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1946 ((SIMRecords) uiccApp.getIccRecords())
1947 .setForbiddenPlmns(onCompleted, fplmns);
1948 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001949 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001950 case CMD_ERASE_MODEM_CONFIG:
1951 request = (MainThreadRequest) msg.obj;
1952 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1953 defaultPhone.eraseModemConfig(onCompleted);
1954 break;
1955 case EVENT_ERASE_MODEM_CONFIG_DONE:
1956 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001957 break;
zoey chene02881a2019-12-30 16:11:23 +08001958
Kai Shif70f46f2021-03-03 13:59:46 -08001959 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1960 request = (MainThreadRequest) msg.obj;
1961 request.result = defaultPhone.eraseDataInSharedPreferences();
1962 notifyRequester(request);
1963 break;
1964
zoey chene02881a2019-12-30 16:11:23 +08001965 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1966 request = (MainThreadRequest) msg.obj;
1967 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1968 Pair<String, String> changed = (Pair<String, String>) request.argument;
1969 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1970 changed.first, changed.second, onCompleted);
1971 break;
1972 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1973 ar = (AsyncResult) msg.obj;
1974 request = (MainThreadRequest) ar.userObj;
1975 if (ar.exception == null) {
1976 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001977 // If the operation is successful, update the PIN storage
1978 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1979 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001980 UiccController.getInstance().getPinStorage()
1981 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001982 } else {
1983 request.result = msg.arg1;
1984 }
1985 notifyRequester(request);
1986 break;
1987
Michele Berionne5e411512020-11-13 02:36:59 +00001988 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001989 request = (MainThreadRequest) msg.obj;
1990 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1991 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1992 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1993 enabled.first, enabled.second, onCompleted);
1994 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001995 }
zoey chene02881a2019-12-30 16:11:23 +08001996 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1997 ar = (AsyncResult) msg.obj;
1998 request = (MainThreadRequest) ar.userObj;
1999 if (ar.exception == null) {
2000 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002001 // If the operation is successful, update the PIN storage
2002 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2003 int phoneId = getPhoneFromRequest(request).getPhoneId();
2004 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002005 UiccController.getInstance().getPinStorage()
2006 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002007 } else {
2008 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2009 }
zoey chene02881a2019-12-30 16:11:23 +08002010 } else {
2011 request.result = msg.arg1;
2012 }
Michele Berionne5e411512020-11-13 02:36:59 +00002013
2014
zoey chene02881a2019-12-30 16:11:23 +08002015 notifyRequester(request);
2016 break;
2017
Peter Wangdafb9ac2020-01-15 14:13:38 -08002018 case MSG_NOTIFY_USER_ACTIVITY:
2019 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002020 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002021 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2022 getDefaultPhone().getContext().sendBroadcastAsUser(
2023 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2024 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002025
2026 case CMD_SET_DATA_THROTTLING: {
2027 request = (MainThreadRequest) msg.obj;
2028 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2029 DataThrottlingRequest dataThrottlingRequest =
2030 (DataThrottlingRequest) request.argument;
2031 Phone phone = getPhoneFromRequest(request);
2032 if (phone != null) {
2033 phone.setDataThrottling(onCompleted,
2034 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2035 dataThrottlingRequest.getCompletionDurationMillis());
2036 } else {
2037 loge("setDataThrottling: No phone object");
2038 request.result =
2039 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2040 notifyRequester(request);
2041 }
2042
2043 break;
2044 }
2045 case EVENT_SET_DATA_THROTTLING_DONE:
2046 ar = (AsyncResult) msg.obj;
2047 request = (MainThreadRequest) ar.userObj;
2048
2049 if (ar.exception == null) {
2050 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2051 } else if (ar.exception instanceof CommandException) {
2052 loge("setDataThrottling: CommandException: " + ar.exception);
2053 CommandException.Error error =
2054 ((CommandException) (ar.exception)).getCommandError();
2055
2056 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2057 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002058 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002059 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2060 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002061 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2062 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002063 } else {
2064 request.result =
2065 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2066 }
2067 } else {
2068 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2069 }
2070 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2071 notifyRequester(request);
2072 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002073
2074 case CMD_SET_SIM_POWER: {
2075 request = (MainThreadRequest) msg.obj;
2076 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2077 request = (MainThreadRequest) msg.obj;
2078 int stateToSet =
2079 ((Pair<Integer, IIntegerConsumer>)
2080 request.argument).first;
2081 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2082 break;
2083 }
2084 case EVENT_SET_SIM_POWER_DONE: {
2085 ar = (AsyncResult) msg.obj;
2086 request = (MainThreadRequest) ar.userObj;
2087 IIntegerConsumer callback =
2088 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2089 if (ar.exception != null) {
2090 loge("setSimPower exception: " + ar.exception);
2091 int errorCode = TelephonyManager.CallForwardingInfoCallback
2092 .RESULT_ERROR_UNKNOWN;
2093 if (ar.exception instanceof CommandException) {
2094 CommandException.Error error =
2095 ((CommandException) (ar.exception)).getCommandError();
2096 if (error == CommandException.Error.SIM_ERR) {
2097 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2098 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2099 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2100 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2101 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2102 } else {
2103 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2104 }
2105 }
2106 try {
2107 callback.accept(errorCode);
2108 } catch (RemoteException e) {
2109 // Ignore if the remote process is no longer available to call back.
2110 Log.w(LOG_TAG, "setSimPower: callback not available.");
2111 }
2112 } else {
2113 try {
2114 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2115 } catch (RemoteException e) {
2116 // Ignore if the remote process is no longer available to call back.
2117 Log.w(LOG_TAG, "setSimPower: callback not available.");
2118 }
2119 }
2120 break;
2121 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002122 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2123 request = (MainThreadRequest) msg.obj;
2124
2125 final Phone phone = getPhoneFromRequest(request);
2126 if (phone == null || phone.getServiceStateTracker() == null) {
2127 request.result = new IllegalStateException("Phone or SST is null");
2128 notifyRequester(request);
2129 break;
2130 }
2131
2132 Pair<Integer, SignalStrengthUpdateRequest> pair =
2133 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2134 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2135 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002136 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002137 request.subId, pair.first /*callingUid*/,
2138 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002139 break;
2140 }
2141 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2142 ar = (AsyncResult) msg.obj;
2143 request = (MainThreadRequest) ar.userObj;
2144 // request.result will be the exception of ar if present, true otherwise.
2145 // Be cautious not to leave result null which will wait() forever
2146 request.result = ar.exception != null ? ar.exception : true;
2147 notifyRequester(request);
2148 break;
2149 }
2150 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2151 request = (MainThreadRequest) msg.obj;
2152
2153 Phone phone = getPhoneFromRequest(request);
2154 if (phone == null || phone.getServiceStateTracker() == null) {
2155 request.result = new IllegalStateException("Phone or SST is null");
2156 notifyRequester(request);
2157 break;
2158 }
2159
2160 Pair<Integer, SignalStrengthUpdateRequest> pair =
2161 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2162 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2163 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002164 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002165 request.subId, pair.first /*callingUid*/,
2166 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002167 break;
2168 }
2169 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2170 ar = (AsyncResult) msg.obj;
2171 request = (MainThreadRequest) ar.userObj;
2172 request.result = ar.exception != null ? ar.exception : true;
2173 notifyRequester(request);
2174 break;
2175 }
Jordan Liu109698e2020-11-24 14:50:34 -08002176
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002177 case CMD_GET_SLICING_CONFIG: {
2178 request = (MainThreadRequest) msg.obj;
2179 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2180 request.phone.getSlicingConfig(onCompleted);
2181 break;
2182 }
2183 case EVENT_GET_SLICING_CONFIG_DONE: {
2184 ar = (AsyncResult) msg.obj;
2185 request = (MainThreadRequest) ar.userObj;
2186 ResultReceiver result = (ResultReceiver) request.argument;
2187
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002188 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002189 Bundle bundle = new Bundle();
2190 int resultCode = 0;
2191 if (ar.exception != null) {
2192 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2193 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002194 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002195 } else if (ar.result == null) {
2196 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002197 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002198 } else {
2199 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002200 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2201 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002202 }
2203
2204 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002205 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002206 }
2207 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2208 result.send(resultCode, bundle);
2209 notifyRequester(request);
2210 break;
2211 }
2212
Sarah Chin71b3a852022-09-28 15:54:19 -07002213 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002214 request = (MainThreadRequest) msg.obj;
2215 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002216 PurchasePremiumCapabilityArgument arg =
2217 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002218 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2219 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002220 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002221 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002222
Sarah Chin71b3a852022-09-28 15:54:19 -07002223 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002224 ar = (AsyncResult) msg.obj;
2225 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002226 PurchasePremiumCapabilityArgument arg =
2227 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002228 try {
2229 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002230 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002231 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002232 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002233 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 + TelephonyManager.convertPurchaseResultToString(result));
2235 } catch (RemoteException e) {
2236 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002237 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002238 + " failed: " + e;
2239 if (DBG) log(logStr);
2240 AnomalyReporter.reportAnomaly(
2241 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2242 }
2243 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245
Michele Berionne5e411512020-11-13 02:36:59 +00002246 case CMD_PREPARE_UNATTENDED_REBOOT:
2247 request = (MainThreadRequest) msg.obj;
2248 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002249 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002250 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002251 notifyRequester(request);
2252 break;
2253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 default:
2255 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2256 break;
2257 }
2258 }
Jake Hambye994d462014-02-03 13:10:13 -08002259
Pengquan Menga1bb6272018-09-06 09:59:22 -07002260 private void notifyRequester(MainThreadRequest request) {
2261 synchronized (request) {
2262 request.notifyAll();
2263 }
2264 }
2265
Jake Hambye994d462014-02-03 13:10:13 -08002266 private void handleNullReturnEvent(Message msg, String command) {
2267 AsyncResult ar = (AsyncResult) msg.obj;
2268 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2269 if (ar.exception == null) {
2270 request.result = true;
2271 } else {
2272 request.result = false;
2273 if (ar.exception instanceof CommandException) {
2274 loge(command + ": CommandException: " + ar.exception);
2275 } else {
2276 loge(command + ": Unknown exception");
2277 }
2278 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002279 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
2283 /**
2284 * Posts the specified command to be executed on the main thread,
2285 * waits for the request to complete, and returns the result.
2286 * @see #sendRequestAsync
2287 */
2288 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002289 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2290 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002291 }
2292
2293 /**
2294 * Posts the specified command to be executed on the main thread,
2295 * waits for the request to complete, and returns the result.
2296 * @see #sendRequestAsync
2297 */
2298 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2299 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002300 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002301 }
2302
2303 /**
2304 * Posts the specified command to be executed on the main thread,
2305 * waits for the request to complete, and returns the result.
2306 * @see #sendRequestAsync
2307 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002308 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002309 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2310 }
2311
2312 /**
2313 * Posts the specified command to be executed on the main thread,
2314 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2315 * if not timeout or null otherwise.
2316 * @see #sendRequestAsync
2317 */
2318 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2319 long timeoutInMs) {
2320 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002321 }
2322
2323 /**
2324 * Posts the specified command to be executed on the main thread,
2325 * waits for the request to complete, and returns the result.
2326 * @see #sendRequestAsync
2327 */
Nathan Harold92bed182018-10-12 18:16:49 -07002328 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002329 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002330 }
2331
2332 /**
2333 * Posts the specified command to be executed on the main thread,
2334 * waits for the request to complete, and returns the result.
2335 * @see #sendRequestAsync
2336 */
2337 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002338 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2339 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002340 }
2341
2342 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002343 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2344 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2345 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002346 * @see #sendRequestAsync
2347 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002348 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2349 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2351 throw new RuntimeException("This method will deadlock if called from the main thread.");
2352 }
2353
Nathan Harold92bed182018-10-12 18:16:49 -07002354 MainThreadRequest request = null;
2355 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2356 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2357 } else if (phone != null) {
2358 request = new MainThreadRequest(argument, phone, workSource);
2359 } else {
2360 request = new MainThreadRequest(argument, subId, workSource);
2361 }
2362
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 Message msg = mMainThreadHandler.obtainMessage(command, request);
2364 msg.sendToTarget();
2365
Rambo Wang0f050d82021-02-12 11:43:36 -08002366
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002368 if (timeoutInMs >= 0) {
2369 // Wait for at least timeoutInMs before returning null request result
2370 long now = SystemClock.elapsedRealtime();
2371 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002372 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002373 try {
2374 request.wait(deadline - now);
2375 } catch (InterruptedException e) {
2376 // Do nothing, go back and check if request is completed or timeout
2377 } finally {
2378 now = SystemClock.elapsedRealtime();
2379 }
2380 }
2381 } else {
2382 // Wait for the request to complete
2383 while (request.result == null) {
2384 try {
2385 request.wait();
2386 } catch (InterruptedException e) {
2387 // Do nothing, go back and wait until the request is complete
2388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 }
2390 }
2391 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002392 if (request.result == null) {
2393 Log.wtf(LOG_TAG,
2394 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 return request.result;
2397 }
2398
2399 /**
2400 * Asynchronous ("fire and forget") version of sendRequest():
2401 * Posts the specified command to be executed on the main thread, and
2402 * returns immediately.
2403 * @see #sendRequest
2404 */
2405 private void sendRequestAsync(int command) {
2406 mMainThreadHandler.sendEmptyMessage(command);
2407 }
2408
2409 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002410 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002411 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002412 */
2413 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002414 sendRequestAsync(command, argument, null, null);
2415 }
2416
2417 /**
2418 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2419 * @see {@link #sendRequest(int,Object)}
2420 */
2421 private void sendRequestAsync(
2422 int command, Object argument, Phone phone, WorkSource workSource) {
2423 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002424 Message msg = mMainThreadHandler.obtainMessage(command, request);
2425 msg.sendToTarget();
2426 }
2427
2428 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 * Initialize the singleton PhoneInterfaceManager instance.
2430 * This is only done once, at startup, from PhoneApp.onCreate().
2431 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002432 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 synchronized (PhoneInterfaceManager.class) {
2434 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002435 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 } else {
2437 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2438 }
2439 return sInstance;
2440 }
2441 }
2442
2443 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002444 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002446 mFeatureFlags = featureFlags;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002448 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002449 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002450 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2452 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002453 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002454 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002455 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002456 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002457 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002458 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 publish();
arunvoddud7401012022-12-15 16:08:12 +00002460 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 }
2462
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002463 @VisibleForTesting
2464 public SharedPreferences getSharedPreferences() {
2465 return mTelephonySharedPreferences;
2466 }
2467
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002468 /**
2469 * Get the default phone for this device.
2470 */
2471 @VisibleForTesting
2472 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002473 Phone thePhone = getPhone(getDefaultSubscription());
2474 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2475 }
2476
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 private void publish() {
2478 if (DBG) log("publish: " + this);
2479
Peter Wangc035ce42020-01-08 21:00:22 -08002480 TelephonyFrameworkInitializer
2481 .getTelephonyServiceManager()
2482 .getTelephonyServiceRegisterer()
2483 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
Stuart Scott584921c2015-01-15 17:10:34 -08002486 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002487 if (request.phone != null) {
2488 return request.phone;
2489 } else {
2490 return getPhoneFromSubId(request.subId);
2491 }
2492 }
2493
2494 private Phone getPhoneFromSubId(int subId) {
2495 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2496 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002497 }
2498
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002499 /**
2500 * Get phone object associated with a subscription.
2501 * Return default phone if phone object associated with subscription is null
2502 * @param subId - subscriptionId
2503 * @return phone object associated with a subscription or default phone if null.
2504 */
Ling Mac28f0212023-03-24 16:07:15 -07002505 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002506 Phone phone = getPhoneFromSubId(subId);
2507 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002508 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002509 phone = getDefaultPhone();
2510 }
2511 return phone;
2512 }
2513
Rambo Wange53e07d2022-05-10 13:01:13 -07002514 @Nullable
2515 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002516 Phone phone = getPhoneFromRequest(request);
2517 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002518 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 }
2520
Ling Mac28f0212023-03-24 16:07:15 -07002521 /**
2522 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2523 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2524 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2525 * @return The Phone associated the sub Id
2526 */
2527 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002528 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530
Kai Shif70f46f2021-03-03 13:59:46 -08002531 private void sendEraseModemConfig(@NonNull Phone phone) {
2532 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2533 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2534 }
2535
2536 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2537 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2538 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002539 }
2540
Peter Wang44b186e2020-01-13 23:33:09 -08002541 private boolean isImsAvailableOnDevice() {
2542 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2543 if (pm == null) {
2544 // For some reason package manger is not available.. This will fail internally anyway,
2545 // so do not throw error and allow.
2546 return true;
2547 }
2548 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2549 }
2550
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002552 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002553 }
2554
Wink Savilleb564aae2014-10-23 10:18:09 -07002555 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 if (DBG) log("dial: " + number);
2557 // No permission check needed here: This is just a wrapper around the
2558 // ACTION_DIAL intent, which is available to any app since it puts up
2559 // the UI before it does anything.
2560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561 final long identity = Binder.clearCallingIdentity();
2562 try {
2563 String url = createTelUrl(number);
2564 if (url == null) {
2565 return;
2566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568 // PENDING: should we just silently fail if phone is offhook or ringing?
2569 PhoneConstants.State state = mCM.getState(subId);
2570 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2571 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2572 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2573 mApp.startActivity(intent);
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 }
2578 }
2579
2580 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002581 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
Wink Savilleb564aae2014-10-23 10:18:09 -07002584 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 if (DBG) log("call: " + number);
2586
2587 // This is just a wrapper around the ACTION_CALL intent, but we still
2588 // need to do a permission check since we're calling startActivity()
2589 // from the context of the phone app.
2590 enforceCallPermission();
2591
Jordan Liu1617b712019-07-10 15:06:26 -07002592 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 != AppOpsManager.MODE_ALLOWED) {
2594 return;
2595 }
2596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 String url = createTelUrl(number);
2600 if (url == null) {
2601 return;
2602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 boolean isValid = false;
2605 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2606 if (slist != null) {
2607 for (SubscriptionInfo subInfoRecord : slist) {
2608 if (subInfoRecord.getSubscriptionId() == subId) {
2609 isValid = true;
2610 break;
2611 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002612 }
Wink Saville08874612014-08-31 19:19:58 -07002613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 if (!isValid) {
2615 return;
2616 }
Wink Saville08874612014-08-31 19:19:58 -07002617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2619 intent.putExtra(SUBSCRIPTION_KEY, subId);
2620 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2621 mApp.startActivity(intent);
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
2624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
Wink Savilleb564aae2014-10-23 10:18:09 -07002627 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002628 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002629 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2630 }
2631
Wink Savilleb564aae2014-10-23 10:18:09 -07002632 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002633 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002634 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2635 }
2636
Wink Savilleb564aae2014-10-23 10:18:09 -07002637 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639
2640 final long identity = Binder.clearCallingIdentity();
2641 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002642 Phone phone = getPhone(subId);
2643 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 checkSimPin.start();
2645 return checkSimPin.unlockSim(null, pin);
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 }
2650
Wink Savilleb564aae2014-10-23 10:18:09 -07002651 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002656 Phone phone = getPhone(subId);
2657 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 checkSimPuk.start();
2659 return checkSimPuk.unlockSim(puk, pin);
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 }
2664
2665 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002666 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 * a synchronous one.
2668 */
2669 private static class UnlockSim extends Thread {
2670
2671 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002672 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673
2674 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002675 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2676 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677
2678 // For replies from SimCard interface
2679 private Handler mHandler;
2680
2681 // For async handler to identify request type
2682 private static final int SUPPLY_PIN_COMPLETE = 100;
2683
Michele Berionne5e411512020-11-13 02:36:59 +00002684 UnlockSim(int phoneId, IccCard simCard) {
2685 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 mSimCard = simCard;
2687 }
2688
2689 @Override
2690 public void run() {
2691 Looper.prepare();
2692 synchronized (UnlockSim.this) {
2693 mHandler = new Handler() {
2694 @Override
2695 public void handleMessage(Message msg) {
2696 AsyncResult ar = (AsyncResult) msg.obj;
2697 switch (msg.what) {
2698 case SUPPLY_PIN_COMPLETE:
2699 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2700 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002701 mRetryCount = msg.arg1;
2702 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002703 CommandException.Error error = null;
2704 if (ar.exception instanceof CommandException) {
2705 error = ((CommandException) (ar.exception))
2706 .getCommandError();
2707 }
2708 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002709 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002710 } else if (error == CommandException.Error.ABORTED) {
2711 /* When UiccCardApp dispose, handle message and return
2712 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002713 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002714 } else {
2715 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2716 }
2717 } else {
2718 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 mDone = true;
2721 UnlockSim.this.notifyAll();
2722 }
2723 break;
2724 }
2725 }
2726 };
2727 UnlockSim.this.notifyAll();
2728 }
2729 Looper.loop();
2730 }
2731
2732 /*
2733 * Use PIN or PUK to unlock SIM card
2734 *
2735 * If PUK is null, unlock SIM card with PIN
2736 *
2737 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302738 *
2739 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2740 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 */
Wink Saville9de0f752013-10-22 19:04:03 -07002742 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743
2744 while (mHandler == null) {
2745 try {
2746 wait();
2747 } catch (InterruptedException e) {
2748 Thread.currentThread().interrupt();
2749 }
2750 }
2751 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2752
2753 if (puk == null) {
2754 mSimCard.supplyPin(pin, callback);
2755 } else {
2756 mSimCard.supplyPuk(puk, pin, callback);
2757 }
2758
2759 while (!mDone) {
2760 try {
2761 Log.d(LOG_TAG, "wait for done");
2762 wait();
2763 } catch (InterruptedException e) {
2764 // Restore the interrupted status
2765 Thread.currentThread().interrupt();
2766 }
2767 }
2768 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002769 int[] resultArray = new int[2];
2770 resultArray[0] = mResult;
2771 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002772
2773 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002774 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002775 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302776 // This instance is no longer reused, so quit its thread's looper.
2777 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002778
Wink Saville9de0f752013-10-22 19:04:03 -07002779 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781 }
2782
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002783 /**
2784 * This method has been removed due to privacy and stability concerns.
2785 */
2786 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002788 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2789 return;
Wink Saville36469e72014-06-11 15:17:00 -07002790 }
2791
Nathan Harold1f889d82020-06-04 17:05:26 -07002792 @Override
2793 public void updateServiceLocationWithPackageName(String callingPackage) {
2794 mApp.getSystemService(AppOpsManager.class)
2795 .checkPackage(Binder.getCallingUid(), callingPackage);
2796
Nathan Haroldf096d982020-11-18 17:18:06 -08002797 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002798 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2799 // Callers targeting S have no business invoking this method.
2800 return;
2801 }
2802
2803 LocationAccessPolicy.LocationPermissionResult locationResult =
2804 LocationAccessPolicy.checkLocationPermission(mApp,
2805 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2806 .setCallingPackage(callingPackage)
2807 .setCallingFeatureId(null)
2808 .setCallingPid(Binder.getCallingPid())
2809 .setCallingUid(Binder.getCallingUid())
2810 .setMethod("updateServiceLocation")
2811 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2812 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2813 .build());
2814 // Apps that lack location permission have no business calling this method;
2815 // however, because no permission was declared in the public API, denials must
2816 // all be "soft".
2817 switch (locationResult) {
2818 case DENIED_HARD: /* fall through */
2819 case DENIED_SOFT:
2820 return;
2821 }
2822
2823 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
Ling Mac28f0212023-03-24 16:07:15 -07002826 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
2831
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002832 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002833 @Override
2834 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002835 return isRadioOnWithFeature(callingPackage, null);
2836 }
2837
2838
2839 @Override
2840 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2841 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2842 callingFeatureId);
2843 }
2844
2845 @Deprecated
2846 @Override
2847 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2848 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002849 }
2850
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002852 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2853 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002855 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002856 return false;
2857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 return isRadioOnForSubscriber(subId);
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002865 }
2866
2867 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 final Phone phone = getPhone(subId);
2871 if (phone != null) {
2872 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2873 } else {
2874 return false;
2875 }
2876 } finally {
2877 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 }
2880
2881 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002882 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
Wink Saville36469e72014-06-11 15:17:00 -07002884
Wink Savilleb564aae2014-10-23 10:18:09 -07002885 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887
2888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 final Phone phone = getPhone(subId);
2891 if (phone != null) {
2892 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 }
Wink Saville36469e72014-06-11 15:17:00 -07002897 }
2898
2899 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002900 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002901 }
2902
Wink Savilleb564aae2014-10-23 10:18:09 -07002903 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905
2906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 final Phone phone = getPhone(subId);
2909 if (phone == null) {
2910 return false;
2911 }
2912 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2913 toggleRadioOnOffForSubscriber(subId);
2914 }
2915 return true;
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 }
Wink Saville36469e72014-06-11 15:17:00 -07002920
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002921 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002922 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002923 /*
2924 * If any of the Radios are available, it will need to be
2925 * shutdown. So return true if any Radio is available.
2926 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2930 Phone phone = PhoneFactory.getPhone(i);
2931 if (phone != null && phone.isRadioAvailable()) return true;
2932 }
2933 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2934 return false;
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002937 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002938 }
2939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002941 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 enforceModifyPermission();
2943
2944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2947 logv("Shutting down Phone " + i);
2948 shutdownRadioUsingPhoneId(i);
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002952 }
2953 }
2954
2955 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002956 Phone phone = PhoneFactory.getPhone(phoneId);
2957 if (phone != null && phone.isRadioAvailable()) {
2958 phone.shutdownRadio();
2959 }
2960 }
2961
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002962 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002963 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964
Ling Ma83dc5ea2023-01-12 15:06:04 -08002965 if (!turnOn) {
2966 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2967 }
2968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2972 if (defaultPhone != null) {
2973 defaultPhone.setRadioPower(turnOn);
2974 return true;
2975 } else {
2976 loge("There's no default phone.");
2977 return false;
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002981 }
Wink Saville36469e72014-06-11 15:17:00 -07002982 }
2983
Wink Savilleb564aae2014-10-23 10:18:09 -07002984 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986
Ling Ma83dc5ea2023-01-12 15:06:04 -08002987 if (!turnOn) {
2988 log("setRadioPowerForSubscriber off: subId=" + subId
2989 + ",callingPackage=" + getCurrentPackageName());
2990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 final long identity = Binder.clearCallingIdentity();
2992 try {
2993 final Phone phone = getPhone(subId);
2994 if (phone != null) {
2995 phone.setRadioPower(turnOn);
2996 return true;
2997 } else {
2998 return false;
2999 }
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 }
3004
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003005 /**
3006 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3007 * no reason to power it off. When any of the voters want to power it off, it will be turned
3008 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3009 * powering it off, and these radio off votes will be cleared.
3010 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3011 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3012 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3013 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3014 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3015 * check its vote.
3016 *
3017 * @param subId The subscription ID.
3018 * @param reason The reason for powering off radio.
3019 * @return true on success and false on failure.
3020 */
3021 public boolean requestRadioPowerOffForReason(int subId,
3022 @TelephonyManager.RadioPowerReason int reason) {
3023 enforceModifyPermission();
3024
Ling Ma83dc5ea2023-01-12 15:06:04 -08003025 log("requestRadioPowerOffForReason: subId=" + subId
3026 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003027 final long identity = Binder.clearCallingIdentity();
3028 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003029 boolean result = false;
3030 for (Phone phone : PhoneFactory.getPhones()) {
3031 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003032 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003033 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003034 if (!result) {
3035 loge("requestRadioPowerOffForReason: no phone exists");
3036 }
3037 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
3041 }
3042
3043 /**
3044 * Remove the vote on powering off the radio for a reason, as requested by
3045 * {@link requestRadioPowerOffForReason}.
3046 *
3047 * @param subId The subscription ID.
3048 * @param reason The reason for powering off radio.
3049 * @return true on success and false on failure.
3050 */
3051 public boolean clearRadioPowerOffForReason(int subId,
3052 @TelephonyManager.RadioPowerReason int reason) {
3053 enforceModifyPermission();
3054
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003057 boolean result = false;
3058 for (Phone phone : PhoneFactory.getPhones()) {
3059 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003060 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003061 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003062 if (!result) {
3063 loge("clearRadioPowerOffForReason: no phone exists");
3064 }
3065 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
3069 }
3070
3071 /**
3072 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3073 *
3074 * @param subId The subscription ID.
3075 * @param callingPackage The package making the call.
3076 * @param callingFeatureId The feature in the package.
3077 * @return List of reasons for powering off radio.
3078 */
3079 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3080 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3081
3082 final long identity = Binder.clearCallingIdentity();
3083 List result = new ArrayList();
3084 try {
3085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3086 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3087 return result;
3088 }
3089
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003090 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003091 if (phone != null) {
3092 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003093 } else {
3094 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003095 }
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
3099 return result;
3100 }
3101
Wink Saville36469e72014-06-11 15:17:00 -07003102 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003103 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003104 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106
3107 final long identity = Binder.clearCallingIdentity();
3108 try {
Jack Yu285100e2022-12-02 22:48:35 -08003109 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110 final Phone phone = getPhone(subId);
3111 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003112 phone.getDataSettingsManager().setDataEnabled(
3113 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 return true;
3115 } else {
3116 return false;
3117 }
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 }
3122
Wink Saville36469e72014-06-11 15:17:00 -07003123 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003124 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003125 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
Jack Yu285100e2022-12-02 22:48:35 -08003130 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 final Phone phone = getPhone(subId);
3132 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003133 phone.getDataSettingsManager().setDataEnabled(
3134 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 return true;
3136 } else {
3137 return false;
3138 }
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 }
3143
Sanket Padawe356d7632015-06-22 14:03:32 -07003144 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003145 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 final Phone phone = getPhone(subId);
3149 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003150 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 } else {
3152 return false;
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
3159 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003160 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003161 }
3162
pkanwarae03a6b2016-11-06 20:37:09 -08003163 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 enforceCallPermission();
3165
3166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3169 return;
3170 }
3171 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3172 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
3175 }
pkanwar32d516d2016-10-14 19:37:38 -07003176 };
3177
Wink Savilleb564aae2014-10-23 10:18:09 -07003178 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003179 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3184 return false;
3185 }
3186 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 }
3191
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003192 /**
3193 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3194 * tag on getCallState Binder call.
3195 */
3196 @Deprecated
3197 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003199 if (CompatChanges.isChangeEnabled(
3200 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3201 Binder.getCallingUid())) {
3202 // Do not allow this API to be called on API version 31+, it should only be
3203 // called on old apps using this Binder call directly.
3204 throw new SecurityException("This method can only be used for applications "
3205 + "targeting API version 30 or less.");
3206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
Ling Mac28f0212023-03-24 16:07:15 -07003209 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3210 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
3214 }
3215
3216 @Override
3217 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3218 if (CompatChanges.isChangeEnabled(
3219 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3220 Binder.getCallingUid())) {
3221 // Check READ_PHONE_STATE for API version 31+
3222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3223 featureId, "getCallStateForSubscription")) {
3224 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3225 + "targeting API level 31+.");
3226 }
3227 }
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3232 PhoneConstantConversions.convertCallState(phone.getState());
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003239 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003240 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003241 }
3242
3243 @Override
3244 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 final long identity = Binder.clearCallingIdentity();
3246 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003247 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003249 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 } else {
3251 return PhoneConstantConversions.convertDataState(
3252 PhoneConstants.DataState.DISCONNECTED);
3253 }
3254 } finally {
3255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 }
3258
Sanket Padawe356d7632015-06-22 14:03:32 -07003259 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003260 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003261 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003262 }
3263
3264 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003265 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266 final long identity = Binder.clearCallingIdentity();
3267 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003268 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003270 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 } else {
3272 return TelephonyManager.DATA_ACTIVITY_NONE;
3273 }
3274 } finally {
3275 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 }
3278
3279 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003280 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003282 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003283
3284 LocationAccessPolicy.LocationPermissionResult locationResult =
3285 LocationAccessPolicy.checkLocationPermission(mApp,
3286 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3287 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003288 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003289 .setCallingPid(Binder.getCallingPid())
3290 .setCallingUid(Binder.getCallingUid())
3291 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003292 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003293 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3294 .build());
3295 switch (locationResult) {
3296 case DENIED_HARD:
3297 throw new SecurityException("Not allowed to access cell location");
3298 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003299 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3300 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 }
3302
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003303 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003307 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003308 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
Svetoslav64fad262015-04-14 14:35:21 -07003312 }
3313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003314 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003315 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003316 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3317 // registered cell info, so return a NULL country instead.
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003320 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3321 // Get default phone in this case.
3322 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3323 }
Jack Yu285100e2022-12-02 22:48:35 -08003324 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003325 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003326 if (phone == null) return "";
3327 ServiceStateTracker sst = phone.getServiceStateTracker();
3328 if (sst == null) return "";
3329 LocaleTracker lt = sst.getLocaleTracker();
3330 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003331 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003335 }
3336
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003337 /**
3338 * This method was removed due to potential issues caused by performing partial
3339 * updates of service state, and lack of a credible use case.
3340 *
3341 * This has the ability to break the telephony implementation by disabling notification of
3342 * changes in device connectivity. DO NOT USE THIS!
3343 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003344 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003345 public void enableLocationUpdates() {
3346 mApp.enforceCallingOrSelfPermission(
3347 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 }
3349
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003350 /**
3351 * This method was removed due to potential issues caused by performing partial
3352 * updates of service state, and lack of a credible use case.
3353 *
3354 * This has the ability to break the telephony implementation by disabling notification of
3355 * changes in device connectivity. DO NOT USE THIS!
3356 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003357 @Override
3358 public void disableLocationUpdates() {
3359 mApp.enforceCallingOrSelfPermission(
3360 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003361 }
3362
3363 @Override
3364 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003365 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3366 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003367 try {
3368 mApp.getSystemService(AppOpsManager.class)
3369 .checkPackage(Binder.getCallingUid(), callingPackage);
3370 } catch (SecurityException e) {
3371 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3372 throw e;
3373 }
3374
Nathan Haroldf096d982020-11-18 17:18:06 -08003375 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003376 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3377 throw new SecurityException(
3378 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3379 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003380
Jordan Liu1617b712019-07-10 15:06:26 -07003381 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003382 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3383 return null;
3384 }
Svetoslav64fad262015-04-14 14:35:21 -07003385
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003386 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003388 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003389 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390
Nathan Haroldf180aac2018-06-01 18:43:55 -07003391 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3392 for (CellInfo ci : info) {
3393 if (ci instanceof CellInfoGsm) {
3394 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3395 } else if (ci instanceof CellInfoWcdma) {
3396 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003398 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003399 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003400 }
3401
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003402 private List<CellInfo> getCachedCellInfo() {
3403 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3404 for (Phone phone : PhoneFactory.getPhones()) {
3405 List<CellInfo> info = phone.getAllCellInfo();
3406 if (info != null) cellInfos.addAll(info);
3407 }
3408 return cellInfos;
3409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003410
3411 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003412 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003413 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003414 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003415
3416 LocationAccessPolicy.LocationPermissionResult locationResult =
3417 LocationAccessPolicy.checkLocationPermission(mApp,
3418 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3419 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003420 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003421 .setCallingPid(Binder.getCallingPid())
3422 .setCallingUid(Binder.getCallingUid())
3423 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003424 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003425 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3426 .build());
3427 switch (locationResult) {
3428 case DENIED_HARD:
3429 throw new SecurityException("Not allowed to access cell info");
3430 case DENIED_SOFT:
3431 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003432 }
3433
Nathan Haroldf096d982020-11-18 17:18:06 -08003434 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003435 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3436 return getCachedCellInfo();
3437 }
3438
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003439 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003440 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3444 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003445 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003446 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447 if (info != null) cellInfos.addAll(info);
3448 }
3449 return cellInfos;
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 }
3453 }
3454
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003455 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003456 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3457 String callingFeatureId) {
3458 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3459 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003460 }
3461
3462 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003463 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3464 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003465 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003466 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003467 }
3468
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003469 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3470 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003471 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003472 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003473
3474 LocationAccessPolicy.LocationPermissionResult locationResult =
3475 LocationAccessPolicy.checkLocationPermission(mApp,
3476 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3477 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003478 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003479 .setCallingPid(Binder.getCallingPid())
3480 .setCallingUid(Binder.getCallingUid())
3481 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003482 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3483 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003484 .build());
3485 switch (locationResult) {
3486 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003487 if (TelephonyPermissions
3488 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003489 // Safetynet logging for b/154934934
3490 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3491 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003492 throw new SecurityException("Not allowed to access cell info");
3493 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003494 if (TelephonyPermissions
3495 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003496 // Safetynet logging for b/154934934
3497 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3498 }
Nathan Harold5320c422019-05-09 10:26:08 -07003499 try {
3500 cb.onCellInfo(new ArrayList<CellInfo>());
3501 } catch (RemoteException re) {
3502 // Drop without consequences
3503 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003504 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003505 }
3506
Nathan Harolda939a962019-05-09 10:13:47 -07003507
3508 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003509 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3510
3511 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3512 }
3513
3514 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003515 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003516 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003517 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003518
3519 final long identity = Binder.clearCallingIdentity();
3520 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003521 Phone phone = getPhone(subId);
3522 if (phone == null) {
3523 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3524 } else {
3525 phone.setCellInfoListRate(rateInMillis, workSource);
3526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003530 }
3531
Shishir Agrawala9f32182016-04-12 12:00:16 -07003532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003533 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003534 Phone phone = PhoneFactory.getPhone(slotIndex);
3535 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003536 return null;
3537 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003538 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003539 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003540 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003541 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003542 return null;
3543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 return phone.getImei();
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003551 }
3552
3553 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003554 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3555 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3556 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3557 callingFeatureId, "getPrimaryImei")) {
3558 throw new SecurityException("Caller does not have permission");
3559 }
3560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 for (Phone phone : PhoneFactory.getPhones()) {
3563 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3564 return phone.getImei();
3565 }
3566 }
3567 throw new UnsupportedOperationException("Operation not supported");
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
3570 }
3571 }
3572
3573 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003574 public String getTypeAllocationCodeForSlot(int slotIndex) {
3575 Phone phone = PhoneFactory.getPhone(slotIndex);
3576 String tac = null;
3577 if (phone != null) {
3578 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003579 try {
3580 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3581 } catch (IndexOutOfBoundsException e) {
3582 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3583 return null;
3584 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003585 }
3586 return tac;
3587 }
3588
3589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003590 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003591 try {
3592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3593 } catch (SecurityException se) {
3594 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3595 throw new SecurityException("Package " + callingPackage + " does not belong to "
3596 + Binder.getCallingUid());
3597 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003598 Phone phone = PhoneFactory.getPhone(slotIndex);
3599 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003600 return null;
3601 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003602
Jeff Davidson913390f2018-02-23 17:11:49 -08003603 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003604 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003605 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003606 return null;
3607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 return phone.getMeid();
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
3614 }
Jack Yu2af8d712017-03-15 17:14:14 -07003615 }
3616
3617 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003618 public String getManufacturerCodeForSlot(int slotIndex) {
3619 Phone phone = PhoneFactory.getPhone(slotIndex);
3620 String manufacturerCode = null;
3621 if (phone != null) {
3622 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003623 try {
3624 manufacturerCode =
3625 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3626 } catch (IndexOutOfBoundsException e) {
3627 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3628 return null;
3629 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003630 }
3631 return manufacturerCode;
3632 }
3633
3634 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003635 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3636 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003637 Phone phone = PhoneFactory.getPhone(slotIndex);
3638 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003639 return null;
3640 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003641 int subId = phone.getSubId();
3642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003643 mApp, subId, callingPackage, callingFeatureId,
3644 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003645 return null;
3646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 return phone.getDeviceSvn();
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
3653 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003654 }
3655
fionaxu43304da2017-11-27 22:51:16 -08003656 @Override
3657 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 final Phone phone = getPhone(subId);
3661 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
fionaxu43304da2017-11-27 22:51:16 -08003665 }
3666
3667 @Override
3668 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 final Phone phone = getPhone(subId);
3672 return phone == null ? null : phone.getCarrierName();
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
fionaxu43304da2017-11-27 22:51:16 -08003676 }
3677
calvinpanffe225e2018-11-01 19:43:06 +08003678 @Override
chen xu0026ca62019-03-06 15:28:50 -08003679 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 final Phone phone = getPhone(subId);
3683 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003684 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
3688 }
3689
3690 @Override
chen xu0026ca62019-03-06 15:28:50 -08003691 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003695 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
3699 }
3700
chen xu651eec72018-11-11 19:03:44 -08003701 @Override
chen xu864e11c2018-12-06 22:10:03 -08003702 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3703 if (!isSubscriptionMccMnc) {
3704 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3705 }
chen xu651eec72018-11-11 19:03:44 -08003706 final Phone phone = PhoneFactory.getPhone(slotIndex);
3707 if (phone == null) {
3708 return TelephonyManager.UNKNOWN_CARRIER_ID;
3709 }
3710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
3716 }
3717
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 //
3719 // Internal helper methods.
3720 //
3721
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003722 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003723 * Make sure the caller is the calling package itself
3724 *
3725 * @throws SecurityException if the caller is not the calling package
3726 */
3727 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3728 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003729 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3730 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003731 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003732 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003733 } catch (PackageManager.NameNotFoundException e) {
3734 // packageUid is -1
3735 }
3736 if (packageUid != callingUid) {
3737 throw new SecurityException(message + ": Package " + callingPackage
3738 + " does not belong to " + callingUid);
3739 }
3740 }
3741
3742 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003743 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3744 *
3745 * @throws SecurityException if the caller does not have the required permission
3746 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003747 @VisibleForTesting
3748 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003749 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3750 }
3751
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003752 /**
arunvoddud7401012022-12-15 16:08:12 +00003753 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003754 *
3755 * @throws SecurityException if the caller does not have the required permission
3756 */
3757 @VisibleForTesting
3758 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003759 enforceReadPermission(null);
3760 }
3761
3762 /**
3763 * Make sure the caller has the READ_PHONE_STATE permissions.
3764 *
3765 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3766 */
3767 @VisibleForTesting
3768 public void enforceReadPermission(String msg) {
3769 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003770 }
3771
Shuo Qian3b6ee772019-11-13 17:43:31 -08003772 private void enforceActiveEmergencySessionPermission() {
3773 mApp.enforceCallingOrSelfPermission(
3774 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3775 }
3776
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003777 /**
3778 * Make sure the caller has the CALL_PHONE permission.
3779 *
3780 * @throws SecurityException if the caller does not have the required permission
3781 */
3782 private void enforceCallPermission() {
3783 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3784 }
3785
paulhu5a773602019-08-23 19:17:33 +08003786 private void enforceSettingsPermission() {
3787 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003788 }
3789
Michele Berionne5e411512020-11-13 02:36:59 +00003790 private void enforceRebootPermission() {
3791 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3792 }
3793
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003794 /**
3795 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3796 * @param message - log message to print.
3797 * @throws SecurityException if the caller does not have the required permission
3798 */
3799 private void enforceSatelliteCommunicationPermission(String message) {
3800 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3801 }
3802
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003803 private String createTelUrl(String number) {
3804 if (TextUtils.isEmpty(number)) {
3805 return null;
3806 }
3807
Jake Hambye994d462014-02-03 13:10:13 -08003808 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003809 }
3810
Ihab Awadf9e92732013-12-05 18:02:52 -08003811 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003812 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003813 }
3814
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003815 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003816 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003817 }
3818
Ihab Awadf9e92732013-12-05 18:02:52 -08003819 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003820 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003821 }
3822
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003823 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003824 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003825 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003826 }
3827
Sanket Padawe356d7632015-06-22 14:03:32 -07003828 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003829 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 final Phone phone = PhoneFactory.getPhone(slotIndex);
3833 if (phone == null) {
3834 return PhoneConstants.PHONE_TYPE_NONE;
3835 } else {
3836 return phone.getPhoneType();
3837 }
3838 } finally {
3839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003841 }
3842
3843 /**
3844 * Returns the CDMA ERI icon index to display
3845 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003847 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3848 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3849 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003850 }
3851
Sanket Padawe356d7632015-06-22 14:03:32 -07003852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003853 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3854 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 mApp, subId, callingPackage, callingFeatureId,
3857 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003858 return -1;
3859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860
3861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
3864 if (phone != null) {
3865 return phone.getCdmaEriIconIndex();
3866 } else {
3867 return -1;
3868 }
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003872 }
3873
3874 /**
3875 * Returns the CDMA ERI icon mode,
3876 * 0 - ON
3877 * 1 - FLASHING
3878 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003879 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003880 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3881 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3882 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003883 }
3884
Sanket Padawe356d7632015-06-22 14:03:32 -07003885 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003886 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3887 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003889 mApp, subId, callingPackage, callingFeatureId,
3890 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003891 return -1;
3892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893
3894 final long identity = Binder.clearCallingIdentity();
3895 try {
3896 final Phone phone = getPhone(subId);
3897 if (phone != null) {
3898 return phone.getCdmaEriIconMode();
3899 } else {
3900 return -1;
3901 }
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003905 }
3906
3907 /**
3908 * Returns the CDMA ERI text,
3909 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003910 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003911 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3912 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3913 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003914 }
3915
Sanket Padawe356d7632015-06-22 14:03:32 -07003916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003917 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3918 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003920 mApp, subId, callingPackage, callingFeatureId,
3921 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003922 return null;
3923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924
3925 final long identity = Binder.clearCallingIdentity();
3926 try {
3927 final Phone phone = getPhone(subId);
3928 if (phone != null) {
3929 return phone.getCdmaEriText();
3930 } else {
3931 return null;
3932 }
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003936 }
3937
3938 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003939 * Returns the CDMA MDN.
3940 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003941 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003942 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3944 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945
3946 final long identity = Binder.clearCallingIdentity();
3947 try {
3948 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003949 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 return phone.getLine1Number();
3951 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 return null;
3954 }
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003957 }
3958 }
3959
3960 /**
3961 * Returns the CDMA MIN.
3962 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003963 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003964 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3966 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967
3968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 final Phone phone = getPhone(subId);
3971 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3972 return phone.getCdmaMin();
3973 } else {
3974 return null;
3975 }
3976 } finally {
3977 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003978 }
3979 }
3980
Hall Liud892bec2018-11-30 14:51:45 -08003981 @Override
3982 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3983 INumberVerificationCallback callback, String callingPackage) {
3984 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3985 != PERMISSION_GRANTED) {
3986 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3987 }
3988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3989
3990 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3991 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003992 throw new SecurityException("Calling package must be configured in the device config: "
3993 + "calling package: " + callingPackage
3994 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003995 }
3996
3997 if (range == null) {
3998 throw new NullPointerException("Range must be non-null");
3999 }
4000
4001 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004002 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004003
4004 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4005 }
4006
Junda Liuca05d5d2014-08-14 22:36:34 -07004007 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004008 * Returns true if CDMA provisioning needs to run.
4009 */
4010 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 final long identity = Binder.clearCallingIdentity();
4012 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004013 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004017 }
4018
4019 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004020 * Sets the voice mail number of a given subId.
4021 */
4022 @Override
4023 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004024 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4025 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004026
4027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4030 new Pair<String, String>(alphaTag, number), new Integer(subId));
4031 return success;
4032 } finally {
4033 Binder.restoreCallingIdentity(identity);
4034 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004035 }
4036
Ta-wei Yen87c49842016-05-13 21:19:52 -07004037 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004038 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004040 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4041 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004042 if (!TextUtils.equals(callingPackage, systemDialer)) {
4043 throw new SecurityException("caller must be system dialer");
4044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4049 if (phoneAccountHandle == null) {
4050 return null;
4051 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004052 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 } finally {
4054 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004055 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004056 }
4057
4058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004059 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4060 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004061 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004063 mApp, subId, callingPackage, callingFeatureId,
4064 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004065 return null;
4066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004068 final long identity = Binder.clearCallingIdentity();
4069 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004070 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004074 }
4075
4076 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004077 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4078 VisualVoicemailSmsFilterSettings settings) {
4079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080
4081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004084 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004088 }
4089
4090 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004091 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4092 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093
4094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004101 }
4102
4103 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004104 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4105 String callingPackage, int subId) {
4106 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107
4108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004111 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004115 }
4116
4117 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004118 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120
4121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004124 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004128 }
4129
4130 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004131 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4132 String callingAttributionTag, int subId, String number, int port, String text,
4133 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004135 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004136 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004137 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004138 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4139 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004140 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004141
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004142 /**
fionaxu0152e512016-11-14 13:36:14 -08004143 * Sets the voice activation state of a given subId.
4144 */
4145 @Override
4146 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4148 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149
4150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 final Phone phone = getPhone(subId);
4153 if (phone != null) {
4154 phone.setVoiceActivationState(activationState);
4155 } else {
4156 loge("setVoiceActivationState fails with invalid subId: " + subId);
4157 }
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004160 }
4161 }
4162
4163 /**
4164 * Sets the data activation state of a given subId.
4165 */
4166 @Override
4167 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4169 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170
4171 final long identity = Binder.clearCallingIdentity();
4172 try {
4173 final Phone phone = getPhone(subId);
4174 if (phone != null) {
4175 phone.setDataActivationState(activationState);
4176 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004177 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 }
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004181 }
4182 }
4183
4184 /**
4185 * Returns the voice activation state of a given subId.
4186 */
4187 @Override
4188 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190
fionaxu0152e512016-11-14 13:36:14 -08004191 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 if (phone != null) {
4195 return phone.getVoiceActivationState();
4196 } else {
4197 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4198 }
4199 } finally {
4200 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004201 }
4202 }
4203
4204 /**
4205 * Returns the data activation state of a given subId.
4206 */
4207 @Override
4208 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210
fionaxu0152e512016-11-14 13:36:14 -08004211 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 if (phone != null) {
4215 return phone.getDataActivationState();
4216 } else {
4217 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4218 }
4219 } finally {
4220 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004221 }
4222 }
4223
4224 /**
Wink Saville36469e72014-06-11 15:17:00 -07004225 * Returns the unread count of voicemails for a subId
4226 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004227 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004228 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4229 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004231 mApp, subId, callingPackage, callingFeatureId,
4232 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004233 return 0;
4234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 final Phone phone = getPhone(subId);
4238 if (phone != null) {
4239 return phone.getVoiceMessageCount();
4240 } else {
4241 return 0;
4242 }
4243 } finally {
4244 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004246 }
4247
4248 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004249 * returns true, if the device is in a state where both voice and data
4250 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004251 */
4252 @Override
4253 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
Ling Mac28f0212023-03-24 16:07:15 -07004256 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 } finally {
4258 Binder.restoreCallingIdentity(identity);
4259 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004260 }
4261
4262 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004263 * Send the dialer code if called from the current default dialer or the caller has
4264 * carrier privilege.
4265 * @param inputCode The dialer code to send
4266 */
4267 @Override
4268 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004269 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004270 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004271 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4272 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004273 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004275 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277
4278 final long identity = Binder.clearCallingIdentity();
4279 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004280 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
fionaxu235cc5e2017-03-06 22:25:57 -08004284 }
4285
Pengquan Menga1bb6272018-09-06 09:59:22 -07004286 @Override
4287 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004288 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004289 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4290 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004291 final long identity = Binder.clearCallingIdentity();
4292 try {
4293 if (!isActiveSubscription(subId)) {
4294 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4295 }
4296 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004299 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004300 }
4301
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004303 public boolean isInEmergencySmsMode() {
4304 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 for (Phone phone : PhoneFactory.getPhones()) {
4308 if (phone.isInEmergencySmsMode()) {
4309 return true;
4310 }
4311 }
4312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
4315 return false;
4316 }
4317
shilu366312e2019-12-17 09:28:10 -08004318 /**
4319 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4320 * @param subId The subscription to use to check the configuration.
4321 * @param c The callback that will be used to send the result.
4322 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004323 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004324 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4325 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004326 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004327 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004328
4329 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4330 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4331 "IMS not available on device.");
4332 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 final long token = Binder.clearCallingIdentity();
4334 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004335 int slotId = getSlotIndexOrException(subId);
4336 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004337
4338 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4339 if (controller != null) {
4340 ImsManager imsManager = controller.getImsManager(subId);
4341 if (imsManager != null) {
4342 imsManager.addRegistrationCallbackForSubscription(c, subId);
4343 } else {
4344 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4345 }
4346 } else {
4347 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4348 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004349 } catch (ImsException e) {
4350 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 } finally {
4352 Binder.restoreCallingIdentity(token);
4353 }
4354 }
4355
shilu366312e2019-12-17 09:28:10 -08004356 /**
4357 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4358 * @param subId The subscription to use to check the configuration.
4359 * @param c The callback that will be used to send the result.
4360 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004362 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004363 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004364 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004365 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4366 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4367 }
Meng Wangafbc5852019-09-19 17:37:13 -07004368 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004369
Meng Wangafbc5852019-09-19 17:37:13 -07004370 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004371 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4372 if (controller != null) {
4373 ImsManager imsManager = controller.getImsManager(subId);
4374 if (imsManager != null) {
4375 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4376 } else {
4377 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4378 + "is inactive, ignoring unregister.");
4379 // If the ImsManager is not valid, just return, since the callback
4380 // will already have been removed internally.
4381 }
4382 }
Meng Wangafbc5852019-09-19 17:37:13 -07004383 } finally {
4384 Binder.restoreCallingIdentity(token);
4385 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 }
4387
Brad Ebingera34a6c22019-10-22 17:36:18 -07004388 /**
4389 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4390 */
4391 @Override
4392 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4393 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4394 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4395 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4396 "IMS not available on device.");
4397 }
4398 final long token = Binder.clearCallingIdentity();
4399 try {
4400 Phone phone = getPhone(subId);
4401 if (phone == null) {
4402 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4403 + subId + "'");
4404 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4405 }
4406 phone.getImsRegistrationState(regState -> {
4407 try {
4408 consumer.accept((regState == null)
4409 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4410 } catch (RemoteException e) {
4411 // Ignore if the remote process is no longer available to call back.
4412 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4413 }
4414 });
4415 } finally {
4416 Binder.restoreCallingIdentity(token);
4417 }
4418 }
4419
4420 /**
4421 * Get the transport type for the IMS service registration state.
4422 */
4423 @Override
4424 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004425 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004426 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004427 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4428 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4429 "IMS not available on device.");
4430 }
4431 final long token = Binder.clearCallingIdentity();
4432 try {
4433 Phone phone = getPhone(subId);
4434 if (phone == null) {
4435 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4436 + subId + "'");
4437 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4438 }
4439 phone.getImsRegistrationTech(regTech -> {
4440 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4441 int regTechConverted = (regTech == null)
4442 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4443 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4444 regTechConverted);
4445 try {
4446 consumer.accept(regTechConverted);
4447 } catch (RemoteException e) {
4448 // Ignore if the remote process is no longer available to call back.
4449 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4450 }
4451 });
4452 } finally {
4453 Binder.restoreCallingIdentity(token);
4454 }
4455 }
4456
shilu366312e2019-12-17 09:28:10 -08004457 /**
4458 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4459 * @param subId The subscription to use to check the configuration.
4460 * @param c The callback that will be used to send the result.
4461 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004463 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4464 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004465 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004466 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004467 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4468 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4469 "IMS not available on device.");
4470 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 final long token = Binder.clearCallingIdentity();
4472 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004473 int slotId = getSlotIndexOrException(subId);
4474 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004475
4476 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4477 if (controller != null) {
4478 ImsManager imsManager = controller.getImsManager(subId);
4479 if (imsManager != null) {
4480 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4481 } else {
4482 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4483 }
4484 } else {
4485 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4486 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004487 } catch (ImsException e) {
4488 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 } finally {
4490 Binder.restoreCallingIdentity(token);
4491 }
4492 }
4493
shilu366312e2019-12-17 09:28:10 -08004494 /**
4495 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4496 * @param subId The subscription to use to check the configuration.
4497 * @param c The callback that will be used to send the result.
4498 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004500 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004501 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004502 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004503 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4504 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4505 }
Meng Wangafbc5852019-09-19 17:37:13 -07004506
4507 final long token = Binder.clearCallingIdentity();
4508 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004509 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4510 if (controller != null) {
4511 ImsManager imsManager = controller.getImsManager(subId);
4512 if (imsManager != null) {
4513 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4514 } else {
4515 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4516 + " is inactive, ignoring unregister.");
4517 // If the ImsManager is not valid, just return, since the callback
4518 // will already have been removed internally.
4519 }
4520 }
Meng Wangafbc5852019-09-19 17:37:13 -07004521 } finally {
4522 Binder.restoreCallingIdentity(token);
4523 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 }
4525
4526 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004527 public boolean isCapable(int subId, int capability, int regTech) {
4528 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 final long token = Binder.clearCallingIdentity();
4530 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004531 int slotId = getSlotIndexOrException(subId);
4532 verifyImsMmTelConfiguredOrThrow(slotId);
4533 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4534 } catch (com.android.ims.ImsException e) {
4535 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4536 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004537 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004538 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4539 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004540 } finally {
4541 Binder.restoreCallingIdentity(token);
4542 }
4543 }
4544
4545 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004546 public boolean isAvailable(int subId, int capability, int regTech) {
4547 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004548 final long token = Binder.clearCallingIdentity();
4549 try {
4550 Phone phone = getPhone(subId);
4551 if (phone == null) return false;
4552 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004553 } catch (com.android.ims.ImsException e) {
4554 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4555 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004556 } finally {
4557 Binder.restoreCallingIdentity(token);
4558 }
4559 }
4560
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004561 /**
4562 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4563 * subscription.
4564 * @param subId The subscription to use to check the configuration.
4565 * @param callback The callback that will be used to send the result.
4566 * @param capability The MmTelFeature capability that will be used to send the result.
4567 * @param transportType The transport type of the MmTelFeature capability.
4568 */
4569 @Override
4570 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4571 int transportType) {
4572 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004573 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4574 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4575 "IMS not available on device.");
4576 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004577 final long token = Binder.clearCallingIdentity();
4578 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004579 int slotId = getSlotIndex(subId);
4580 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4581 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4582 + subId + "'");
4583 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4584 }
4585 verifyImsMmTelConfiguredOrThrow(slotId);
4586 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4587 transportType, aBoolean -> {
4588 try {
4589 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4590 } catch (RemoteException e) {
4591 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4592 + "running. Ignore");
4593 }
4594 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004595 } catch (ImsException e) {
4596 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004597 } finally {
4598 Binder.restoreCallingIdentity(token);
4599 }
4600 }
4601
shilu366312e2019-12-17 09:28:10 -08004602 /**
4603 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4604 * @param subId The subscription to use to check the configuration.
4605 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 @Override
4607 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004609 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004610
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 final long token = Binder.clearCallingIdentity();
4612 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004613 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004614 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004615 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004616 } catch (ImsException e) {
4617 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004618 } finally {
4619 Binder.restoreCallingIdentity(token);
4620 }
4621 }
4622
4623 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004624 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004626 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004627 final long identity = Binder.clearCallingIdentity();
4628 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004629 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004630 // This setting doesn't require an active ImsService connection, so do not verify. The
4631 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004632 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004633 } catch (ImsException e) {
4634 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
shilu366312e2019-12-17 09:28:10 -08004640 /**
4641 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4642 * @param subId The subscription to use to check the configuration.
4643 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004644 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004645 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004646 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004647 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004648 final long identity = Binder.clearCallingIdentity();
4649 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004650 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004651 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004652 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004653 } catch (ImsException e) {
4654 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
4658 }
4659
4660 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004661 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004663 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004664 final long identity = Binder.clearCallingIdentity();
4665 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004666 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004667 // This setting doesn't require an active ImsService connection, so do not verify. The
4668 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004669 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004670 } catch (ImsException e) {
4671 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004672 } finally {
4673 Binder.restoreCallingIdentity(identity);
4674 }
4675 }
4676
shilu366312e2019-12-17 09:28:10 -08004677 /**
4678 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4679 * @param subId The subscription to use to check the configuration.
4680 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004681 @Override
4682 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004683 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004684 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004685 final long identity = Binder.clearCallingIdentity();
4686 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004687 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004688 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004689 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004690 } catch (ImsException e) {
4691 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
4695 }
4696
4697 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004698 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004700 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004701 final long identity = Binder.clearCallingIdentity();
4702 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004703 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004704 // This setting doesn't require an active ImsService connection, so do not verify. The
4705 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004706 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004707 } catch (ImsException e) {
4708 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004709 } finally {
4710 Binder.restoreCallingIdentity(identity);
4711 }
4712 }
4713
shilu366312e2019-12-17 09:28:10 -08004714 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004715 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4716 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4717 * @param subId The subscription to use to check the configuration.
4718 */
4719 @Override
4720 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004721 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004722 mApp, subId, "isCrossSimCallingEnabledByUser");
4723 final long identity = Binder.clearCallingIdentity();
4724 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004725 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004726 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004727 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004728 } catch (ImsException e) {
4729 throw new ServiceSpecificException(e.getCode());
4730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
4733 }
4734
4735 /**
4736 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4737 * Requires MODIFY_PHONE_STATE permission.
4738 * @param subId The subscription to use to check the configuration.
4739 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4740 * false otherwise
4741 */
4742 @Override
4743 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4745 "setCrossSimCallingEnabled");
4746 final long identity = Binder.clearCallingIdentity();
4747 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004748 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004749 // This setting doesn't require an active ImsService connection, so do not verify. The
4750 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004751 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004752 } catch (ImsException e) {
4753 throw new ServiceSpecificException(e.getCode());
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
4757 }
4758
4759 /**
shilu366312e2019-12-17 09:28:10 -08004760 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4761 * @param subId The subscription to use to check the configuration.
4762 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004763 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004764
Brad Ebinger35c841c2018-10-01 10:40:55 -07004765 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004766 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004767 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 final long identity = Binder.clearCallingIdentity();
4769 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004770 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004771 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004772 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004773 } catch (ImsException e) {
4774 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004775 } finally {
4776 Binder.restoreCallingIdentity(identity);
4777 }
4778 }
4779
4780 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004781 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004783 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 final long identity = Binder.clearCallingIdentity();
4785 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004786 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004787 // This setting doesn't require an active ImsService connection, so do not verify. The
4788 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004789 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004790 } catch (ImsException e) {
4791 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004792 } finally {
4793 Binder.restoreCallingIdentity(identity);
4794 }
4795 }
4796
4797 @Override
4798 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4800 "setVoWiFiNonPersistent");
4801 final long identity = Binder.clearCallingIdentity();
4802 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004803 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004804 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004805 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004806 } catch (ImsException e) {
4807 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004808 } finally {
4809 Binder.restoreCallingIdentity(identity);
4810 }
4811 }
4812
shilu366312e2019-12-17 09:28:10 -08004813 /**
4814 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4815 * @param subId The subscription to use to check the configuration.
4816 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004817 @Override
4818 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004819 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004820 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004821 final long identity = Binder.clearCallingIdentity();
4822 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004823 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004824 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004825 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004826 } catch (ImsException e) {
4827 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004828 } finally {
4829 Binder.restoreCallingIdentity(identity);
4830 }
4831 }
4832
4833 @Override
4834 public void setVoWiFiModeSetting(int subId, int mode) {
4835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4836 "setVoWiFiModeSetting");
4837 final long identity = Binder.clearCallingIdentity();
4838 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004839 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004840 // This setting doesn't require an active ImsService connection, so do not verify. The
4841 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004842 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004843 } catch (ImsException e) {
4844 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
4848 }
4849
4850 @Override
4851 public int getVoWiFiRoamingModeSetting(int subId) {
4852 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4853 final long identity = Binder.clearCallingIdentity();
4854 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004855 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004856 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004857 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004858 } catch (ImsException e) {
4859 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
4863 }
4864
4865 @Override
4866 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4868 "setVoWiFiRoamingModeSetting");
4869 final long identity = Binder.clearCallingIdentity();
4870 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004871 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004872 // This setting doesn't require an active ImsService connection, so do not verify. The
4873 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004874 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004875 } catch (ImsException e) {
4876 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004877 } finally {
4878 Binder.restoreCallingIdentity(identity);
4879 }
4880 }
4881
4882 @Override
4883 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4885 "setRttCapabilityEnabled");
4886 final long identity = Binder.clearCallingIdentity();
4887 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004888 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004889 // This setting doesn't require an active ImsService connection, so do not verify. The
4890 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004891 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004892 } catch (ImsException e) {
4893 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
4897 }
4898
shilu366312e2019-12-17 09:28:10 -08004899 /**
4900 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4901 * @param subId The subscription to use to check the configuration.
4902 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004903 @Override
4904 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004905 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004906 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004907 final long identity = Binder.clearCallingIdentity();
4908 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004909 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004910 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004911 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004912 } catch (ImsException e) {
4913 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
4917 }
4918
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004919 @Override
4920 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4921 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004922
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004923 final long identity = Binder.clearCallingIdentity();
4924 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004925 if (!isImsAvailableOnDevice()) {
4926 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4927 "IMS not available on device.");
4928 }
4929 int slotId = getSlotIndexOrException(subId);
4930 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004931
4932 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4933 if (controller != null) {
4934 ImsManager imsManager = controller.getImsManager(subId);
4935 if (imsManager != null) {
4936 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4937 } else {
4938 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4939 }
4940 } else {
4941 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4942 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004943 } catch (ImsException e) {
4944 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
4948 }
4949
4950 @Override
4951 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4952 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004953
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004954 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004955 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4956 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4957 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004959 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4960 if (controller != null) {
4961 ImsManager imsManager = controller.getImsManager(subId);
4962 if (imsManager != null) {
4963 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4964 } else {
4965 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4966 + " is inactive, ignoring unregister.");
4967 // If the ImsManager is not valid, just return, since the callback will already
4968 // have been removed internally.
4969 }
4970 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
4974 }
4975
joonhunshincffb7fc2021-11-28 07:32:01 +00004976 @Override
4977 public void registerFeatureProvisioningChangedCallback(int subId,
4978 IFeatureProvisioningCallback callback) {
4979 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4980 mApp, subId, "registerFeatureProvisioningChangedCallback");
4981
4982 final long identity = Binder.clearCallingIdentity();
4983 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4984 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4985 }
4986
joonhunshin91bc1952022-04-29 08:47:15 +00004987 try {
4988 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4989 if (controller == null) {
4990 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4991 "Device does not support IMS");
4992 }
4993 controller.addFeatureProvisioningChangedCallback(subId, callback);
4994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004997 }
4998
4999 @Override
5000 public void unregisterFeatureProvisioningChangedCallback(int subId,
5001 IFeatureProvisioningCallback callback) {
5002 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5003 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5004
5005 final long identity = Binder.clearCallingIdentity();
5006 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5007 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5008 }
5009
joonhunshin91bc1952022-04-29 08:47:15 +00005010 try {
5011 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5012 if (controller == null) {
5013 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5014 return;
5015 }
5016 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5017 } finally {
5018 Binder.restoreCallingIdentity(identity);
5019 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005020 }
allenwtsu99c623b2020-01-03 18:24:23 +08005021
5022 private void checkModifyPhoneStatePermission(int subId, String message) {
5023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5024 message);
5025 }
5026
allenwtsu99c623b2020-01-03 18:24:23 +08005027 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005028 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005029 boolean isProvisioned) {
5030 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5031
5032 final long identity = Binder.clearCallingIdentity();
5033 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005034 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5035 if (controller == null) {
5036 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5037 return;
5038 }
5039 controller.setRcsProvisioningStatusForCapability(
5040 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005041 } finally {
5042 Binder.restoreCallingIdentity(identity);
5043 }
allenwtsu99c623b2020-01-03 18:24:23 +08005044 }
5045
5046
5047 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005048 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5049 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5050 mApp, subId, "getRcsProvisioningStatusForCapability");
5051
allenwtsu99c623b2020-01-03 18:24:23 +08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005054 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5055 if (controller == null) {
5056 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5057
5058 // device does not support IMS, this method will return true always.
5059 return true;
5060 }
5061 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005062 } finally {
5063 Binder.restoreCallingIdentity(identity);
5064 }
5065 }
5066
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005067 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005068 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5069 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005070 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005071
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005072 final long identity = Binder.clearCallingIdentity();
5073 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005074 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5075 if (controller == null) {
5076 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5077 return;
5078 }
5079 controller.setImsProvisioningStatusForCapability(
5080 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005081 } finally {
5082 Binder.restoreCallingIdentity(identity);
5083 }
5084 }
5085
5086 @Override
5087 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005088 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5089 mApp, subId, "getProvisioningStatusForCapability");
5090
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005093 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5094 if (controller == null) {
5095 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005096
joonhunshin91bc1952022-04-29 08:47:15 +00005097 // device does not support IMS, this method will return true always.
5098 return true;
5099 }
5100 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005101 } finally {
5102 Binder.restoreCallingIdentity(identity);
5103 }
5104 }
5105
5106 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005107 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5108 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5109 mApp, subId, "isProvisioningRequiredForCapability");
5110
5111 final long identity = Binder.clearCallingIdentity();
5112 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005113 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5114 if (controller == null) {
5115 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5116
5117 // device does not support IMS, this method will return false
5118 return false;
5119 }
5120 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005123 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005124 }
5125
5126 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005127 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5129 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005130
joonhunshincffb7fc2021-11-28 07:32:01 +00005131 final long identity = Binder.clearCallingIdentity();
5132 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005133 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5134 if (controller == null) {
5135 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5136
5137 // device does not support IMS, this method will return false
5138 return false;
5139 }
5140 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005141 } finally {
5142 Binder.restoreCallingIdentity(identity);
5143 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005144 }
5145
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005146 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005147 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005148 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5149 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5150 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005151 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5152 mApp, subId, "getImsProvisioningInt");
5153
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005157 int slotId = getSlotIndex(subId);
5158 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5159 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5160 + subId + "' for key:" + key);
5161 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5162 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005163
joonhunshin91bc1952022-04-29 08:47:15 +00005164 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5165 if (controller == null) {
5166 loge("getImsProvisioningInt: Device does not support IMS");
5167
5168 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5169 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5170 }
5171 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005172 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5173 return retVal;
5174 }
5175
calvinpanb5a34062021-02-08 19:59:36 +08005176 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005177 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005178 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5179 + subId + "' for key:" + key);
5180 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005181 } finally {
5182 Binder.restoreCallingIdentity(identity);
5183 }
5184 }
5185
5186 @Override
5187 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5189 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5190 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005191 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5192 mApp, subId, "getImsProvisioningString");
5193
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005197 int slotId = getSlotIndex(subId);
5198 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5199 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5200 + subId + "' for key:" + key);
5201 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5202 }
calvinpanb5a34062021-02-08 19:59:36 +08005203 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005204 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005205 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5206 + subId + "' for key:" + key);
5207 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
5211 }
5212
5213 @Override
5214 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005215 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5216 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5217 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5219 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005220
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005224 int slotId = getSlotIndex(subId);
5225 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5226 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5227 + subId + "' for key:" + key);
5228 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5229 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005230
joonhunshin91bc1952022-04-29 08:47:15 +00005231 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5232 if (controller == null) {
5233 loge("setImsProvisioningInt: Device does not support IMS");
5234
5235 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5236 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5237 }
5238 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005239 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5240 return retVal;
5241 }
5242
calvinpanb5a34062021-02-08 19:59:36 +08005243 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5244 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005245 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005246 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005247 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
5251 }
5252
5253 @Override
5254 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005255 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5256 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5257 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5259 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005260 final long identity = Binder.clearCallingIdentity();
5261 try {
5262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005263 int slotId = getSlotIndex(subId);
5264 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5265 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5266 + subId + "' for key:" + key);
5267 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5268 }
calvinpanb5a34062021-02-08 19:59:36 +08005269 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5270 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005271 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005272 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005273 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
5277 }
5278
Brad Ebinger919631e2021-06-02 17:46:35 -07005279 /**
5280 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5281 * for the given slot ID or no ImsResolver instance has been created.
5282 * @param slotId The slot ID that the IMS service is created for.
5283 * @throws ImsException If there is no ImsService configured for this slot.
5284 */
5285 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5286 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5287 ImsFeature.FEATURE_MMTEL)) {
5288 throw new ImsException("This subscription does not support MMTEL over IMS",
5289 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5290 }
5291 }
5292
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005293 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005294 int slotId = SubscriptionManager.getSlotIndex(subId);
5295 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005296 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5297 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005298 }
5299 return slotId;
5300 }
5301
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005302 private int getSlotIndex(int subId) {
5303 int slotId = SubscriptionManager.getSlotIndex(subId);
5304 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5305 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5306 }
5307 return slotId;
5308 }
5309
Wink Saville36469e72014-06-11 15:17:00 -07005310 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005311 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005312 */
5313 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005314 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5315 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005316 try {
5317 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5318 } catch (SecurityException se) {
5319 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5320 throw new SecurityException("Package " + callingPackage + " does not belong to "
5321 + Binder.getCallingUid());
5322 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005323 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005324 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005325 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005326 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005327 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005328 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005329 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005330 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5331 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 final Phone phone = getPhone(subId);
5336 if (phone != null) {
5337 return phone.getServiceState().getDataNetworkType();
5338 } else {
5339 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5340 }
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005344 }
5345
5346 /**
5347 * Returns the data network type
5348 */
5349 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005350 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005351 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005352 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005353 }
5354
5355 /**
5356 * Returns the data network type for a subId
5357 */
5358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005359 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5360 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005361 String functionName = "getDataNetworkTypeForSubscriber";
5362 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5363 mApp, functionName)) {
5364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5365 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5366 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5367 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005368 }
5369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 final long identity = Binder.clearCallingIdentity();
5371 try {
5372 final Phone phone = getPhone(subId);
5373 if (phone != null) {
5374 return phone.getServiceState().getDataNetworkType();
5375 } else {
5376 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5377 }
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005381 }
5382
5383 /**
Wink Saville36469e72014-06-11 15:17:00 -07005384 * Returns the Voice network type for a subId
5385 */
5386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005387 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5388 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005389 String functionName = "getVoiceNetworkTypeForSubscriber";
5390 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5391 mApp, functionName)) {
5392 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5393 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5394 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5395 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005396 }
5397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 final long identity = Binder.clearCallingIdentity();
5399 try {
5400 final Phone phone = getPhone(subId);
5401 if (phone != null) {
5402 return phone.getServiceState().getVoiceNetworkType();
5403 } else {
5404 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5405 }
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005409 }
5410
5411 /**
5412 * @return true if a ICC card is present
5413 */
5414 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005415 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005416 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005417 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005418 }
5419
5420 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005421 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005422 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005423 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005424 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 final Phone phone = PhoneFactory.getPhone(slotIndex);
5428 if (phone != null) {
5429 return phone.getIccCard().hasIccCard();
5430 } else {
5431 return false;
5432 }
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005436 }
5437
5438 /**
5439 * Return if the current radio is LTE on CDMA. This
5440 * is a tri-state return value as for a period of time
5441 * the mode may be unknown.
5442 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005443 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005444 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005445 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005446 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005448 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5449 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5450 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005451 }
5452
Sanket Padawe356d7632015-06-22 14:03:32 -07005453 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005454 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5455 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005456 try {
5457 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5458 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005459 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5460 }
5461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 final Phone phone = getPhone(subId);
5465 if (phone == null) {
5466 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5467 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005468 return TelephonyProperties.lte_on_cdma_device()
5469 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 }
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005473 }
Wink Saville36469e72014-06-11 15:17:00 -07005474 }
5475
Wink Saville36469e72014-06-11 15:17:00 -07005476 /**
5477 * {@hide}
5478 * Returns Default subId, 0 in the case of single standby.
5479 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005480 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005481 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005482 }
5483
Shishir Agrawala9f32182016-04-12 12:00:16 -07005484 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005485 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005486 }
5487
Wink Savilleb564aae2014-10-23 10:18:09 -07005488 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005489 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005490 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005491
Pengquan Menge92a50d2018-09-21 15:54:48 -07005492 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005493 return getSubscriptionManagerService().isActiveSubId(subId,
5494 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005495 }
5496
Ihab Awadf2177b72013-11-25 13:33:23 -08005497 /**
5498 * @see android.telephony.TelephonyManager.WifiCallingChoices
5499 */
5500 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501 final long identity = Binder.clearCallingIdentity();
5502 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005503 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5505 getWhenToMakeWifiCallsDefaultPreference());
5506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005509 }
5510
5511 /**
5512 * @see android.telephony.TelephonyManager.WifiCallingChoices
5513 */
5514 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005518 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
5522 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005523 }
5524
Sailesh Nepald1e68152013-12-12 19:08:02 -08005525 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005526 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005527 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005528 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005529
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005530 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5531 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5532 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005533 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005534 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005535 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005536 }
5537 return PhoneFactory.getPhone(phoneId);
5538 }
5539
Shishir Agrawal566b7612013-10-28 14:41:00 -07005540 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005541 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005542 @NonNull IccLogicalChannelRequest request) {
5543 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5544 /*message=*/ "iccOpenLogicalChannel");
5545
5546 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5547 // Verify that the callingPackage in the request belongs to the calling UID
5548 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5549
5550 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005551 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005552
Rambo Wanga1782702021-11-10 20:15:19 -08005553 private Phone getPhoneFromValidIccLogicalChannelRequest(
5554 @NonNull IccLogicalChannelRequest request, String message) {
5555 Phone phone;
5556 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5558 mApp, request.subId, message);
5559 phone = getPhoneFromSubId(request.subId);
5560 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5561 enforceModifyPermission();
5562 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5563 } else {
5564 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005565 }
Rambo Wanga1782702021-11-10 20:15:19 -08005566 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005567 }
5568
5569 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005570 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571 final long identity = Binder.clearCallingIdentity();
5572 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005573 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005575 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5576 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005577 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5578 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 loge("The calling package is not allowed to access ISD-R.");
5580 throw new SecurityException(
5581 "The calling package is not allowed to access ISD-R.");
5582 }
Derek Tan740e1672017-06-27 14:56:27 -07005583 }
Derek Tan740e1672017-06-27 14:56:27 -07005584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005586 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5587 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 return response;
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005592 }
5593
5594 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005595 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5596 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5597 /*message=*/"iccCloseLogicalChannel");
5598
5599 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5600
5601 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005602 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005603
Rambo Wanga1782702021-11-10 20:15:19 -08005604 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5605 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005606 // before this feature is enabled, this API should only return false if
5607 // the operation fails instead of throwing runtime exception for
5608 // backward-compatibility.
5609 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5610 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 final long identity = Binder.clearCallingIdentity();
5612 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005613 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005614 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 }
Chen Xue9d737e2022-01-01 23:41:31 -08005616 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005617 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005618 Boolean success = false;
5619 if (result instanceof RuntimeException) {
5620 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005621 if (shouldThrowExceptionOnFailure) {
5622 throw (RuntimeException) result;
5623 } else {
5624 return false;
5625 }
Chen Xue9d737e2022-01-01 23:41:31 -08005626 } else if (result instanceof Boolean) {
5627 success = (Boolean) result;
5628 } else {
5629 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5630 }
Rambo Wanga1782702021-11-10 20:15:19 -08005631 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632 return success;
5633 } finally {
5634 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005636 }
5637
5638 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005639 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005640 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005643 if (DBG) {
5644 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5645 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5646 + p3 + " data=" + data);
5647 }
5648 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5649 command, p1, p2, p3, data);
5650 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005651
Jordan Liu4c733742019-02-28 12:03:40 -08005652 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005653 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005654 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005655 enforceModifyPermission();
5656 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005657 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005658 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5659 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005660 }
5661 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005662 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5663 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005664 }
5665
5666 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5667 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 final long identity = Binder.clearCallingIdentity();
5669 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005670 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 return "";
5672 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005675 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5676 null /* workSource */);
5677 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 // Append the returned status code to the end of the response payload.
5680 String s = Integer.toHexString(
5681 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5682 if (response.payload != null) {
5683 s = IccUtils.bytesToHexString(response.payload) + s;
5684 }
5685 return s;
5686 } finally {
5687 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005688 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005689 }
Jake Hambye994d462014-02-03 13:10:13 -08005690
Evan Charltonc66da362014-05-16 14:06:40 -07005691 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005692 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5693 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5695 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005697 if (DBG) {
5698 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5699 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5700 }
5701 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5702 cla, command, p1, p2, p3, data);
5703 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005704
Jordan Liu4c733742019-02-28 12:03:40 -08005705 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005706 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005707 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005708 enforceModifyPermission();
5709 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5710 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005711 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005712 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5713 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005714 }
5715
5716 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005717 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5718 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005719 }
5720
5721 // open APDU basic channel assuming the caller has sufficient permissions
5722 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5723 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5727 && TextUtils.equals(ISDR_AID, data)) {
5728 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005729 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5730 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 if (bestComponent == null
5732 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5733 loge("The calling package is not allowed to select ISD-R.");
5734 throw new SecurityException(
5735 "The calling package is not allowed to select ISD-R.");
5736 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005737 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005740 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5741 null /* workSource */);
5742 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 // Append the returned status code to the end of the response payload.
5745 String s = Integer.toHexString(
5746 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5747 if (response.payload != null) {
5748 s = IccUtils.bytesToHexString(response.payload) + s;
5749 }
5750 return s;
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005753 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005754 }
5755
5756 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005757 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005758 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5760 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
5764 if (DBG) {
5765 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5766 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5767 }
5768
5769 IccIoResult response =
5770 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5771 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5772 subId);
5773
5774 if (DBG) {
5775 log("Exchange SIM_IO [R]" + response);
5776 }
5777
5778 byte[] result = null;
5779 int length = 2;
5780 if (response.payload != null) {
5781 length = 2 + response.payload.length;
5782 result = new byte[length];
5783 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5784 } else {
5785 result = new byte[length];
5786 }
5787
5788 result[length - 1] = (byte) response.sw2;
5789 result[length - 2] = (byte) response.sw1;
5790 return result;
5791 } finally {
5792 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005793 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005794 }
5795
Nathan Haroldb3014052017-01-25 15:57:32 -08005796 /**
5797 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5798 * on a particular subscription
5799 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005800 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5801 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005803 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005804 return null;
5805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 if (appType != TelephonyManager.APPTYPE_USIM
5810 && appType != TelephonyManager.APPTYPE_SIM) {
5811 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5812 return null;
5813 }
5814 Object response = sendRequest(
5815 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5816 if (response instanceof String[]) {
5817 return (String[]) response;
5818 }
yincheng zhao2737e882019-09-06 17:06:54 -07005819 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005821 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 } finally {
5823 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005824 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005825 }
5826
yincheng zhao2737e882019-09-06 17:06:54 -07005827 /**
5828 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5829 * subscription.
5830 *
5831 * @param subId the id of the subscription.
5832 * @param appType the uicc app type, must be USIM or SIM.
5833 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5834 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005835 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005836 * @return number of fplmns that is successfully written to the SIM.
5837 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005838 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5839 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5841 mApp, subId, "setForbiddenPlmns");
5842
yincheng zhao2737e882019-09-06 17:06:54 -07005843 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5844 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5845 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5846 }
5847 if (fplmns == null) {
5848 throw new IllegalArgumentException("Fplmn List provided is null");
5849 }
5850 for (String fplmn : fplmns) {
5851 if (!CellIdentity.isValidPlmn(fplmn)) {
5852 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5853 }
5854 }
5855 final long identity = Binder.clearCallingIdentity();
5856 try {
5857 Object response = sendRequest(
5858 CMD_SET_FORBIDDEN_PLMNS,
5859 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5860 subId);
5861 return (int) response;
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
5865 }
5866
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005867 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005868 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5870 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 final long identity = Binder.clearCallingIdentity();
5873 try {
5874 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5875 if (response.payload == null) {
5876 return "";
5877 }
Evan Charltonc66da362014-05-16 14:06:40 -07005878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 // Append the returned status code to the end of the response payload.
5880 String s = Integer.toHexString(
5881 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5882 s = IccUtils.bytesToHexString(response.payload) + s;
5883 return s;
5884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
Evan Charltonc66da362014-05-16 14:06:40 -07005887 }
5888
Jake Hambye994d462014-02-03 13:10:13 -08005889 /**
5890 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5891 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5892 *
5893 * @param itemID the ID of the item to read
5894 * @return the NV item as a String, or null on error.
5895 */
5896 @Override
5897 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005898 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5900 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901
5902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005905 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5907 return value;
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
Jake Hambye994d462014-02-03 13:10:13 -08005911 }
5912
5913 /**
5914 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5915 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5916 *
5917 * @param itemID the ID of the item to read
5918 * @param itemValue the value to write, as a String
5919 * @return true on success; false on any failure
5920 */
5921 @Override
5922 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5925 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926
5927 final long identity = Binder.clearCallingIdentity();
5928 try {
5929 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5930 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005931 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5933 return success;
5934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
Jake Hambye994d462014-02-03 13:10:13 -08005937 }
5938
5939 /**
5940 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5941 * Used for device configuration by some CDMA operators.
5942 *
5943 * @param preferredRoamingList byte array containing the new PRL
5944 * @return true on success; false on any failure
5945 */
5946 @Override
5947 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5949 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950
5951 final long identity = Binder.clearCallingIdentity();
5952 try {
5953 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5954 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5955 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5956 return success;
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
Jake Hambye994d462014-02-03 13:10:13 -08005960 }
5961
5962 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005963 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005964 * Used for device configuration by some CDMA operators.
5965 *
chen xu6dac5ab2018-10-26 17:39:23 -07005966 * @param slotIndex - device slot.
5967 *
Jake Hambye994d462014-02-03 13:10:13 -08005968 * @return true on success; false on any failure
5969 */
5970 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005971 public boolean resetModemConfig(int slotIndex) {
5972 Phone phone = PhoneFactory.getPhone(slotIndex);
5973 if (phone != null) {
5974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5975 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976
chen xu6dac5ab2018-10-26 17:39:23 -07005977 final long identity = Binder.clearCallingIdentity();
5978 try {
5979 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5980 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5981 return success;
5982 } finally {
5983 Binder.restoreCallingIdentity(identity);
5984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 }
chen xu6dac5ab2018-10-26 17:39:23 -07005986 return false;
5987 }
5988
5989 /**
5990 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5991 *
5992 * @param slotIndex - device slot.
5993 *
5994 * @return true on success; false on any failure
5995 */
5996 @Override
5997 public boolean rebootModem(int slotIndex) {
5998 Phone phone = PhoneFactory.getPhone(slotIndex);
5999 if (phone != null) {
6000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6001 mApp, phone.getSubId(), "rebootModem");
6002
6003 final long identity = Binder.clearCallingIdentity();
6004 try {
6005 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6006 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6007 return success;
6008 } finally {
6009 Binder.restoreCallingIdentity(identity);
6010 }
6011 }
6012 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006013 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006014
Brad Ebinger51f743a2017-01-23 13:50:20 -08006015 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006016 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6017 * {@link #disableIms(int)}.
6018 * @param slotIndex device slot.
6019 */
6020 public void resetIms(int slotIndex) {
6021 enforceModifyPermission();
6022
6023 final long identity = Binder.clearCallingIdentity();
6024 try {
6025 if (mImsResolver == null) {
6026 // may happen if the does not support IMS.
6027 return;
6028 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006029 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
6033 }
6034
6035 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006036 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6037 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006038 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006039 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006040 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041
6042 final long identity = Binder.clearCallingIdentity();
6043 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006044 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006045 // may happen if the device does not support IMS.
6046 return;
6047 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006048 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006052 }
6053
6054 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006055 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6056 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006057 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006058 public void disableIms(int slotId) {
6059 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006063 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006064 // may happen if the device does not support IMS.
6065 return;
6066 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006067 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006071 }
6072
6073 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006074 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6075 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006076 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006077 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006078 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080
6081 final long identity = Binder.clearCallingIdentity();
6082 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006083 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006084 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6085 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006086 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006087 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 } finally {
6089 Binder.restoreCallingIdentity(identity);
6090 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006091 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006092 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006093 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6094 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006095 @Override
6096 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006097 enforceModifyPermission();
6098
6099 final long identity = Binder.clearCallingIdentity();
6100 try {
6101 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006102 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006103 } finally {
6104 Binder.restoreCallingIdentity(identity);
6105 }
6106 }
6107
6108 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006109 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006110 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006111 */
6112 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114
6115 final long identity = Binder.clearCallingIdentity();
6116 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006117 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006118 // may happen if the device does not support IMS.
6119 return null;
6120 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006121 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 } finally {
6123 Binder.restoreCallingIdentity(identity);
6124 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006125 }
6126
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006127 /**
6128 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006129 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006130 */
6131 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133
6134 final long identity = Binder.clearCallingIdentity();
6135 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006136 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006137 // may happen if the device does not support IMS.
6138 return null;
6139 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006140 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006144 }
6145
Brad Ebinger884c07b2018-02-15 16:17:40 -08006146 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006147 * Sets the ImsService Package Name that Telephony will bind to.
6148 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006149 * @param slotIndex the slot ID that the ImsService should bind for.
6150 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006151 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006152 * @param featureTypes An integer array of feature types associated with a packageName.
6153 * @param packageName The name of the package that the current configuration will be replaced
6154 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006155 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006156 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006157 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6158 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006159 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006161 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 final long identity = Binder.clearCallingIdentity();
6164 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006165 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006166 // may happen if the device does not support IMS.
6167 return false;
6168 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006169 Map<Integer, String> featureConfig = new HashMap<>();
6170 for (int featureType : featureTypes) {
6171 featureConfig.put(featureType, packageName);
6172 }
6173 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6174 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 } finally {
6176 Binder.restoreCallingIdentity(identity);
6177 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006178 }
6179
6180 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006181 * Clears any carrier ImsService overrides for the slot index specified that were previously
6182 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6183 *
6184 * This should only be used for testing.
6185 *
6186 * @param slotIndex the slot ID that the ImsService should bind for.
6187 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6188 */
6189 @Override
6190 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006191 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6192 "clearCarrierImsServiceOverride");
6193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006194 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006195
6196 final long identity = Binder.clearCallingIdentity();
6197 try {
6198 if (mImsResolver == null) {
6199 // may happen if the device does not support IMS.
6200 return false;
6201 }
6202 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6203 } finally {
6204 Binder.restoreCallingIdentity(identity);
6205 }
6206 }
6207
6208 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006209 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006210 *
6211 * @param slotId The slot that the ImsService is associated with.
6212 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6213 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006214 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006215 * @return the package name of the ImsService configuration.
6216 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006217 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6218 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006219 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006220 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6221 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 final long identity = Binder.clearCallingIdentity();
6224 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006225 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006226 // may happen if the device does not support IMS.
6227 return "";
6228 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006229 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006230 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6231 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006235 }
6236
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006237 /**
6238 * Get the MmTelFeature state associated with the requested subscription id.
6239 * @param subId The subscription that the MmTelFeature is associated with.
6240 * @param callback A callback with an integer containing the
6241 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6242 */
6243 @Override
6244 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6245 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006246 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6247 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6248 "IMS not available on device.");
6249 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006250 final long token = Binder.clearCallingIdentity();
6251 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006252 int slotId = getSlotIndex(subId);
6253 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6254 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6255 + subId + "'");
6256 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6257 }
6258 verifyImsMmTelConfiguredOrThrow(slotId);
6259 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6260 try {
6261 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6262 } catch (RemoteException e) {
6263 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6264 + "Ignore");
6265 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006266 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006267 } catch (ImsException e) {
6268 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006269 } finally {
6270 Binder.restoreCallingIdentity(token);
6271 }
6272 }
6273
Daniel Brightbb5840b2021-01-12 15:48:18 -08006274 /**
6275 * Sets the ims registration state on all valid {@link Phone}s.
6276 */
6277 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279
6280 final long identity = Binder.clearCallingIdentity();
6281 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006282 // NOTE: Before S, this method only set the default phone.
6283 for (final Phone phone : PhoneFactory.getPhones()) {
6284 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6285 phone.setImsRegistrationState(registered);
6286 }
6287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
Wink Saville36469e72014-06-11 15:17:00 -07006291 }
6292
6293 /**
Stuart Scott54788802015-03-30 13:18:01 -07006294 * Set the network selection mode to automatic.
6295 *
6296 */
6297 @Override
6298 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6300 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301
6302 final long identity = Binder.clearCallingIdentity();
6303 try {
shilufc958392020-01-20 11:36:01 -08006304 if (!isActiveSubscription(subId)) {
6305 return;
6306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006308 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6309 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
Stuart Scott54788802015-03-30 13:18:01 -07006313 }
6314
Jack Yud10cdd42020-09-28 20:28:01 -07006315 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006316 * Ask the radio to connect to the input network and change selection mode to manual.
6317 *
6318 * @param subId the id of the subscription.
6319 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6320 * the operator to attach to.
6321 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6322 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6323 * normal network selection next time.
6324 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006325 */
6326 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006327 public boolean setNetworkSelectionModeManual(
6328 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6330 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006331
Jack Yu285100e2022-12-02 22:48:35 -08006332 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006333 if (!isActiveSubscription(subId)) {
6334 return false;
6335 }
6336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006338 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006340 if (DBG) {
6341 log("setNetworkSelectionModeManual: subId: " + subId
6342 + " operator: " + operatorInfo);
6343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006348 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006349 /**
shilu84f6e8b2019-12-19 13:58:01 -08006350 * Get the manual network selection
6351 *
6352 * @param subId the id of the subscription.
6353 *
6354 * @return the previously saved user selected PLMN
6355 */
6356 @Override
6357 public String getManualNetworkSelectionPlmn(int subId) {
6358 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006359 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6360 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006361
6362 final long identity = Binder.clearCallingIdentity();
6363 try {
6364 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006365 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006366 }
6367
6368 final Phone phone = getPhone(subId);
6369 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006370 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006371 }
6372 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6373 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006374 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006375 } finally {
6376 Binder.restoreCallingIdentity(identity);
6377 }
6378 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006379
6380 /**
6381 * Scans for available networks.
6382 */
6383 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006384 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6385 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6387 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006388 LocationAccessPolicy.LocationPermissionResult locationResult =
6389 LocationAccessPolicy.checkLocationPermission(mApp,
6390 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6391 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006392 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006393 .setCallingPid(Binder.getCallingPid())
6394 .setCallingUid(Binder.getCallingUid())
6395 .setMethod("getCellNetworkScanResults")
6396 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006397 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6398 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006399 .build());
6400 switch (locationResult) {
6401 case DENIED_HARD:
6402 throw new SecurityException("Not allowed to access scan results -- location");
6403 case DENIED_SOFT:
6404 return null;
6405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406
Pengquan Menga1bb6272018-09-06 09:59:22 -07006407 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 try {
6409 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006410 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006415 }
6416
6417 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006418 * Get the call forwarding info, given the call forwarding reason.
6419 */
6420 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006421 public void getCallForwarding(int subId, int callForwardingReason,
6422 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006423 enforceReadPrivilegedPermission("getCallForwarding");
6424 long identity = Binder.clearCallingIdentity();
6425 try {
6426 if (DBG) {
6427 log("getCallForwarding: subId " + subId
6428 + " callForwardingReason" + callForwardingReason);
6429 }
Hall Liu27d24262020-09-18 19:04:59 -07006430
6431 Phone phone = getPhone(subId);
6432 if (phone == null) {
6433 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006434 callback.onError(
6435 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006436 } catch (RemoteException e) {
6437 // ignore
6438 }
6439 return;
6440 }
6441
6442 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6443 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6444 @Override
6445 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6446 try {
6447 callback.onCallForwardingInfoAvailable(info);
6448 } catch (RemoteException e) {
6449 // ignore
6450 }
6451 }
6452
6453 @Override
6454 public void onError(int error) {
6455 try {
6456 callback.onError(error);
6457 } catch (RemoteException e) {
6458 // ignore
6459 }
6460 }
6461 });
6462 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
6468 /**
6469 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6470 * reason, the number to forward, and the timeout before the forwarding is attempted.
6471 */
6472 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006473 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6474 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006475 enforceModifyPermission();
6476 long identity = Binder.clearCallingIdentity();
6477 try {
6478 if (DBG) {
6479 log("setCallForwarding: subId " + subId
6480 + " callForwardingInfo" + callForwardingInfo);
6481 }
Hall Liu27d24262020-09-18 19:04:59 -07006482
6483 Phone phone = getPhone(subId);
6484 if (phone == null) {
6485 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006486 callback.accept(
6487 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006488 } catch (RemoteException e) {
6489 // ignore
6490 }
6491 return;
6492 }
6493
6494 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6495 FunctionalUtils.ignoreRemoteException(callback::accept));
6496
6497 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006498 } finally {
6499 Binder.restoreCallingIdentity(identity);
6500 }
6501 }
6502
6503 /**
Hall Liu27d24262020-09-18 19:04:59 -07006504 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006505 */
6506 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006507 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006508 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006509 long identity = Binder.clearCallingIdentity();
6510 try {
Hall Liu27d24262020-09-18 19:04:59 -07006511 Phone phone = getPhone(subId);
6512 if (phone == null) {
6513 try {
6514 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6515 } catch (RemoteException e) {
6516 // ignore
6517 }
6518 return;
6519 }
SongFerngWang0e767992021-03-31 22:08:45 +08006520 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6521 PersistableBundle c = configManager.getConfigForSubId(subId);
6522 boolean requireUssd = c.getBoolean(
6523 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006524
Shuo Qian4a594052020-01-23 11:59:30 -08006525 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006526 if (requireUssd) {
6527 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6528 getSubscriptionCarrierId(subId));
6529 String newUssdCommand = "";
6530 try {
6531 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006532 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006533 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6534 } catch (NullPointerException e) {
6535 loge("Failed to generate USSD number" + e);
6536 }
6537 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6538 mMainThreadHandler, callback, carrierXmlParser,
6539 CarrierXmlParser.SsEntry.SSAction.QUERY);
6540 final String ussdCommand = newUssdCommand;
6541 Executors.newSingleThreadExecutor().execute(() -> {
6542 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6543 });
6544 } else {
6545 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6546 callback::accept);
6547 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6548 }
Shuo Qian4a594052020-01-23 11:59:30 -08006549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
6552 }
6553
6554 /**
Hall Liu27d24262020-09-18 19:04:59 -07006555 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006556 */
6557 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006558 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006559 enforceModifyPermission();
6560 long identity = Binder.clearCallingIdentity();
6561 try {
Hall Liu27d24262020-09-18 19:04:59 -07006562 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6563
6564 Phone phone = getPhone(subId);
6565 if (phone == null) {
6566 try {
6567 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6568 } catch (RemoteException e) {
6569 // ignore
6570 }
6571 return;
6572 }
6573
SongFerngWang0e767992021-03-31 22:08:45 +08006574 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6575 PersistableBundle c = configManager.getConfigForSubId(subId);
6576 boolean requireUssd = c.getBoolean(
6577 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006578
SongFerngWang0e767992021-03-31 22:08:45 +08006579 if (DBG) log("getCallWaitingStatus: subId " + subId);
6580 if (requireUssd) {
6581 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6582 getSubscriptionCarrierId(subId));
6583 CarrierXmlParser.SsEntry.SSAction ssAction =
6584 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6585 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6586 String newUssdCommand = "";
6587 try {
6588 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006589 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006590 .makeCommand(ssAction, null);
6591 } catch (NullPointerException e) {
6592 loge("Failed to generate USSD number" + e);
6593 }
6594 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6595 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6596 final String ussdCommand = newUssdCommand;
6597 Executors.newSingleThreadExecutor().execute(() -> {
6598 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6599 });
6600 } else {
6601 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6602 FunctionalUtils.ignoreRemoteException(callback::accept));
6603
6604 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6605 }
Shuo Qian4a594052020-01-23 11:59:30 -08006606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
6609 }
6610
6611 /**
yinxub1bed742017-04-17 11:45:04 -07006612 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006613 *
yinxub1bed742017-04-17 11:45:04 -07006614 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006615 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6616 * location related information which will be sent if the caller already possess
6617 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006618 * @param request contains the radio access networks with bands/channels to scan
6619 * @param messenger callback messenger for scan results or errors
6620 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006621 * @return the id of the requested scan which can be used to stop the scan.
6622 */
6623 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006624 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6625 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006626 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6628 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006629 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006630 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6631 if (!renounceFineLocationAccess) {
6632 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006633 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6634 .setCallingPackage(callingPackage)
6635 .setCallingFeatureId(callingFeatureId)
6636 .setCallingPid(Binder.getCallingPid())
6637 .setCallingUid(Binder.getCallingUid())
6638 .setMethod("requestNetworkScan")
6639 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6640 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6641 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6642 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006643 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006644 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006645 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6646 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006647 if (e != null) {
6648 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6649 throw e;
6650 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006651 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006652 return TelephonyScanManager.INVALID_SCAN_ID;
6653 }
6654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 }
Hall Liu912dfd32019-04-25 14:02:26 -07006656 int callingUid = Binder.getCallingUid();
6657 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006658 final long identity = Binder.clearCallingIdentity();
6659 try {
6660 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006661 renounceFineLocationAccess, request, messenger, binder,
6662 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006663 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006664 } finally {
6665 Binder.restoreCallingIdentity(identity);
6666 }
yinxu504e1392017-04-12 16:03:22 -07006667 }
6668
Hall Liub2ac8ef2019-02-28 15:56:23 -08006669 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006670 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006671 boolean hasCarrierPriv;
6672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6675 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6676 } finally {
6677 Binder.restoreCallingIdentity(identity);
6678 }
Hall Liu558027f2019-05-15 19:14:05 -07006679 boolean hasNetworkScanPermission =
6680 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006681 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006682
6683 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6684 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6685 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006686 }
6687
6688 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6689 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006690 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6691 return new SecurityException("Specific channels must not be"
6692 + " scanned without location access.");
6693 }
6694 }
6695 }
6696
Hall Liub2ac8ef2019-02-28 15:56:23 -08006697 return null;
6698 }
6699
yinxu504e1392017-04-12 16:03:22 -07006700 /**
6701 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006702 *
6703 * @param subId id of the subscription
6704 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006705 */
6706 @Override
6707 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6709 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710
Hall Liu912dfd32019-04-25 14:02:26 -07006711 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 final long identity = Binder.clearCallingIdentity();
6713 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006714 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
yinxu504e1392017-04-12 16:03:22 -07006718 }
6719
6720 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006721 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006722 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006723 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006724 */
6725 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006726 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006727 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006728 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006729 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730
6731 final long identity = Binder.clearCallingIdentity();
6732 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006733 if (DBG) log("getAllowedNetworkTypesBitmask");
6734 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6735 int networkTypesBitmask = (result != null ? result[0] : -1);
6736 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6737 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 } finally {
6739 Binder.restoreCallingIdentity(identity);
6740 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006741 }
6742
6743 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006744 * Get the allowed network types for certain reason.
6745 *
6746 * @param subId the id of the subscription.
6747 * @param reason the reason the allowed network type change is taking place
6748 * @return the allowed network types.
6749 */
6750 @Override
6751 public long getAllowedNetworkTypesForReason(int subId,
6752 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006753 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006754 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006755 final long identity = Binder.clearCallingIdentity();
6756 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006757 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
6761 }
6762
6763 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006764 * Enable/Disable E-UTRA-NR Dual Connectivity
6765 * @param subId subscription id of the sim card
6766 * @param nrDualConnectivityState expected NR dual connectivity state
6767 * This can be passed following states
6768 * <ol>
6769 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6770 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6771 * <li>Disable NR dual connectivity and force secondary cell to be released
6772 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6773 * </ol>
6774 * @return operation result.
6775 */
6776 @Override
6777 public int setNrDualConnectivityState(int subId,
6778 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6780 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006781 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006782 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6783 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6784 }
6785
Sooraj Sasindran37444802020-08-11 10:40:43 -07006786 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6787 final long identity = Binder.clearCallingIdentity();
6788 try {
6789 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6790 nrDualConnectivityState, subId,
6791 workSource);
6792 if (DBG) log("enableNRDualConnectivity result: " + result);
6793 return result;
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
6796 }
6797 }
6798
6799 /**
6800 * Is E-UTRA-NR Dual Connectivity enabled
6801 * @return true if dual connectivity is enabled else false
6802 */
6803 @Override
6804 public boolean isNrDualConnectivityEnabled(int subId) {
6805 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006806 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006807 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006808 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006809 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6810 return false;
6811 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6816 null, subId, workSource);
6817 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6818 return isEnabled;
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
6822 }
6823
6824 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006825 * Set the allowed network types of the device and
6826 * provide the reason triggering the allowed network change.
6827 *
6828 * @param subId the id of the subscription.
6829 * @param reason the reason the allowed network type change is taking place
6830 * @param allowedNetworkTypes the allowed network types.
6831 * @return true on success; false on any failure.
6832 */
6833 @Override
6834 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006835 @TelephonyManager.AllowedNetworkTypesReason int reason,
6836 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6838 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006839 // If the caller only has carrier privileges, then they should not be able to override
6840 // any network types which were set for security reasons.
6841 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6842 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006843 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006844 throw new SecurityException(
6845 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006846 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006847 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006848 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006849 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006850 return false;
6851 }
6852 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6853 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006854 return false;
6855 }
6856
Jack Yu5b494332023-01-23 18:18:04 +00006857 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6858 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006859
Jack Yue37dd262022-12-16 11:53:37 -08006860 Phone phone = getPhone(subId);
6861 if (phone == null) {
6862 return false;
6863 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006864
Jack Yue37dd262022-12-16 11:53:37 -08006865 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006866 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006867 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006868 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006869
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006870 final long identity = Binder.clearCallingIdentity();
6871 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006872 Boolean success = (Boolean) sendRequest(
6873 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6874 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6875
6876 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6877 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006878 } finally {
6879 Binder.restoreCallingIdentity(identity);
6880 }
6881 }
6882
6883 /**
Miaoa84611c2019-03-15 09:21:10 +08006884 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006885 *
Miaoa84611c2019-03-15 09:21:10 +08006886 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006887 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006888 * @hide
6889 */
6890 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006891 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006894 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 try {
Miaoa84611c2019-03-15 09:21:10 +08006896 if (phone != null) {
6897 return phone.hasMatchedTetherApnSetting();
6898 } else {
6899 return false;
6900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006901 } finally {
6902 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006903 }
Junda Liu475951f2014-11-07 16:45:03 -08006904 }
6905
6906 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006907 * Get the user enabled state of Mobile Data.
6908 *
6909 * TODO: remove and use isUserDataEnabled.
6910 * This can't be removed now because some vendor codes
6911 * calls through ITelephony directly while they should
6912 * use TelephonyManager.
6913 *
6914 * @return true on enabled
6915 */
6916 @Override
6917 public boolean getDataEnabled(int subId) {
6918 return isUserDataEnabled(subId);
6919 }
6920
6921 /**
6922 * Get whether mobile data is enabled per user setting.
6923 *
6924 * There are other factors deciding whether mobile data is actually enabled, but they are
6925 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006926 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006927 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6928 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006929 *
6930 * @return {@code true} if data is enabled else {@code false}
6931 */
6932 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006933 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006934 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006935 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006936 try {
6937 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6938 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006939 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006940 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6941 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006942 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006944 mApp, subId, functionName);
6945
Robert Greenwalt646120a2014-05-23 11:54:03 -07006946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947
6948 final long identity = Binder.clearCallingIdentity();
6949 try {
Jack Yu285100e2022-12-02 22:48:35 -08006950 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006951 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6952 Phone phone = PhoneFactory.getPhone(phoneId);
6953 if (phone != null) {
6954 boolean retVal = phone.isUserDataEnabled();
6955 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6956 return retVal;
6957 } else {
6958 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6959 return false;
6960 }
6961 } finally {
6962 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006963 }
6964 }
6965
6966 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006967 * Checks if the device is capable of mobile data by considering whether whether the
6968 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6969 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006970 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006971 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006972 */
6973 @Override
6974 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006975 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006976 try {
6977 try {
6978 mApp.enforceCallingOrSelfPermission(
6979 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006980 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006981 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006982 try {
6983 mApp.enforceCallingOrSelfPermission(
6984 android.Manifest.permission.READ_PHONE_STATE,
6985 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006986 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006987 mApp.enforceCallingOrSelfPermission(
6988 permission.READ_BASIC_PHONE_STATE, functionName);
6989 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006990 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006991 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006992 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994
6995 final long identity = Binder.clearCallingIdentity();
6996 try {
Jack Yu285100e2022-12-02 22:48:35 -08006997 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 Phone phone = PhoneFactory.getPhone(phoneId);
6999 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007000 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007001 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 return retVal;
7003 } else {
7004 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7005 return false;
7006 }
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007009 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007010 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007011
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007012 /**
7013 * Check if data is enabled for a specific reason
7014 * @param subId Subscription index
7015 * @param reason the reason the data enable change is taking place
7016 * @return {@code true} if the overall data is enabled; {@code false} if not.
7017 */
7018 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007019 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007020 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007021 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007022 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007023 try {
7024 mApp.enforceCallingOrSelfPermission(
7025 android.Manifest.permission.ACCESS_NETWORK_STATE,
7026 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007027 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007028 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7029 functionName);
7030 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007031 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007032 try {
7033 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007034 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007035 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007037 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007038 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007039 }
7040
7041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
Jack Yu285100e2022-12-02 22:48:35 -08007044 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007045 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007046 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007047 + " reason=" + reason);
7048 }
7049 Phone phone = PhoneFactory.getPhone(phoneId);
7050 if (phone != null) {
7051 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007052 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007053 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007054 return retVal;
7055 } else {
7056 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007057 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007058 + subId + " retVal=false");
7059 }
7060 return false;
7061 }
7062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
7065 }
7066
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007067 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007068 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007069 // No permission needed; this only lets the caller inspect their own status.
7070 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007071 }
Junda Liu29340342014-07-10 15:23:27 -07007072
7073 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007074 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007075 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007076 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7077 }
7078
7079 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7080 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007081 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007082 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007083 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7084 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007085 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7086 if (cpt == null) {
7087 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007088 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7089 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007090 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007091 }
7092
7093 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007094 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007095 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007096 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007097 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007098 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007099 Phone phone = getPhone(subId);
7100 if (phone == null) {
7101 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7102 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7103 }
7104 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7105 if (cpt == null) {
7106 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007107 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7108 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007109 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007110 }
7111
7112 @Override
7113 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007114 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007115 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7116 }
7117
7118 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007119 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007120 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007121 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007122 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007123 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7124 Phone phone = PhoneFactory.getPhone(phoneId);
7125 if (phone == null) {
7126 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007127 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007128 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7129 if (cpt == null) {
7130 continue;
7131 }
7132 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007133 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7134 break;
7135 }
7136 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007137 return result;
Junda Liu29340342014-07-10 15:23:27 -07007138 }
Derek Tan89e89d42014-07-08 17:00:10 -07007139
7140 @Override
Junda Liue64de782015-04-16 17:19:16 -07007141 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007142 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007143 Phone phone = PhoneFactory.getPhone(phoneId);
7144 if (phone == null) {
7145 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007146 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007147 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7148 if (cpt == null) {
7149 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007150 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007151 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007152 }
7153
Amith Yamasani6e118872016-02-19 12:53:51 -08007154 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007155 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007156 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007157 Phone phone = PhoneFactory.getPhone(phoneId);
7158 if (phone == null) {
7159 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007160 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007161 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7162 if (cpt == null) {
7163 return Collections.emptyList();
7164 }
7165 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007166 }
7167
chen xuf7e9fe82019-05-09 19:31:02 -07007168 @Override
7169 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007170 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007171 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007172 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007173 try {
7174 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7175 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7176 }
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007179 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007180 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007181 }
7182
Rambo Wang6812ffb2022-03-15 16:54:17 -07007183 @Override
7184 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7185 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7186
7187 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7188 if (phone == null) {
7189 return null;
7190 }
7191 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7192 if (cpt == null) {
7193 return null;
7194 }
7195 return cpt.getCarrierServicePackageName();
7196 }
7197
Wink Savilleb564aae2014-10-23 10:18:09 -07007198 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007199 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007200 UiccPort port = phone == null ? null : phone.getUiccPort();
7201 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007202 return null;
7203 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007204 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007205 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007206 return null;
7207 }
7208 return iccId;
7209 }
7210
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007211 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007212 public void setCallComposerStatus(int subId, int status) {
7213 enforceModifyPermission();
7214
7215 final long identity = Binder.clearCallingIdentity();
7216 try {
7217 Phone phone = getPhone(subId);
7218 if (phone != null) {
7219 Phone defaultPhone = phone.getImsPhone();
7220 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7221 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7222 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007223 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7224 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007225 }
7226 }
Shuo Qian284ae752020-12-22 19:10:14 -08007227 } catch (ImsException e) {
7228 throw new ServiceSpecificException(e.getCode());
7229 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007230 Binder.restoreCallingIdentity(identity);
7231 }
7232 }
7233
7234 @Override
7235 public int getCallComposerStatus(int subId) {
7236 enforceReadPrivilegedPermission("getCallComposerStatus");
7237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 Phone phone = getPhone(subId);
7241 if (phone != null) {
7242 Phone defaultPhone = phone.getImsPhone();
7243 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7244 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7245 return imsPhone.getCallComposerStatus();
7246 }
7247 }
7248 } finally {
7249 Binder.restoreCallingIdentity(identity);
7250 }
7251 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7252 }
7253
7254 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007255 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7256 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007257 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007258 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 final String iccId = getIccId(subId);
7263 final Phone phone = getPhone(subId);
7264 if (phone == null) {
7265 return false;
7266 }
7267 final String subscriberId = phone.getSubscriberId();
7268
7269 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007270 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007271 + subscriberId + " to " + number);
7272 }
7273
7274 if (TextUtils.isEmpty(iccId)) {
7275 return false;
7276 }
7277
7278 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7279
7280 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7281 if (alphaTag == null) {
7282 editor.remove(alphaTagPrefKey);
7283 } else {
7284 editor.putString(alphaTagPrefKey, alphaTag);
7285 }
7286
7287 // Record both the line number and IMSI for this ICCID, since we need to
7288 // track all merged IMSIs based on line number
7289 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7290 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7291 if (number == null) {
7292 editor.remove(numberPrefKey);
7293 editor.remove(subscriberPrefKey);
7294 } else {
7295 editor.putString(numberPrefKey, number);
7296 editor.putString(subscriberPrefKey, subscriberId);
7297 }
7298
7299 editor.commit();
7300 return true;
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007303 }
Derek Tan7226c842014-07-02 17:42:23 -07007304 }
7305
7306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007307 public String getLine1NumberForDisplay(int subId, String callingPackage,
7308 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007309 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007311 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007312 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007313 return null;
7314 }
Derek Tan97ebb422014-09-05 16:55:38 -07007315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 String iccId = getIccId(subId);
7319 if (iccId != null) {
7320 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7321 if (DBG_MERGE) {
7322 log("getLine1NumberForDisplay returning "
7323 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7324 }
7325 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7328 return null;
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007331 }
Derek Tan7226c842014-07-02 17:42:23 -07007332 }
7333
7334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007335 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7336 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007338 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007339 return null;
7340 }
Derek Tan97ebb422014-09-05 16:55:38 -07007341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 final long identity = Binder.clearCallingIdentity();
7343 try {
7344 String iccId = getIccId(subId);
7345 if (iccId != null) {
7346 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7347 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7348 }
7349 return null;
7350 } finally {
7351 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007352 }
Derek Tan7226c842014-07-02 17:42:23 -07007353 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007354
7355 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007356 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7357 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007358 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7359 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007361 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007362 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007363 return null;
7364 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007365
Jordan Liub49b04b2019-05-06 14:45:15 -07007366 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7367 // the process, where TelephonyManager was instantiated.
7368 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007369 final long identity = Binder.clearCallingIdentity();
7370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007371 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 final TelephonyManager tele = TelephonyManager.from(context);
7373 final SubscriptionManager sub = SubscriptionManager.from(context);
7374
7375 // Figure out what subscribers are currently active
7376 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377
Jordan Liub49b04b2019-05-06 14:45:15 -07007378 // Only consider subs which match the current subId
7379 // This logic can be simplified. See b/131189269 for progress.
7380 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007381 activeSubscriberIds.add(tele.getSubscriberId(subId));
7382 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383
7384 // First pass, find a number override for an active subscriber
7385 String mergeNumber = null;
7386 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7387 for (String key : prefs.keySet()) {
7388 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7389 final String subscriberId = (String) prefs.get(key);
7390 if (activeSubscriberIds.contains(subscriberId)) {
7391 final String iccId = key.substring(
7392 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7393 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7394 mergeNumber = (String) prefs.get(numberKey);
7395 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007396 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 + " for active subscriber " + subscriberId);
7398 }
7399 if (!TextUtils.isEmpty(mergeNumber)) {
7400 break;
7401 }
7402 }
7403 }
7404 }
7405
7406 // Shortcut when no active merged subscribers
7407 if (TextUtils.isEmpty(mergeNumber)) {
7408 return null;
7409 }
7410
7411 // Second pass, find all subscribers under that line override
7412 final ArraySet<String> result = new ArraySet<>();
7413 for (String key : prefs.keySet()) {
7414 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7415 final String number = (String) prefs.get(key);
7416 if (mergeNumber.equals(number)) {
7417 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7418 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7419 final String subscriberId = (String) prefs.get(subscriberKey);
7420 if (!TextUtils.isEmpty(subscriberId)) {
7421 result.add(subscriberId);
7422 }
7423 }
7424 }
7425 }
7426
7427 final String[] resultArray = result.toArray(new String[result.size()]);
7428 Arrays.sort(resultArray);
7429 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007430 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7432 }
7433 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007434 } finally {
7435 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007436 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007437 }
7438
7439 @Override
zoey chen38003472019-12-13 17:16:31 +08007440 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7441 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007442
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
7445 final TelephonyManager telephonyManager = mApp.getSystemService(
7446 TelephonyManager.class);
7447 String subscriberId = telephonyManager.getSubscriberId(subId);
7448 if (subscriberId == null) {
7449 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007450 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007451 + subId);
7452 }
7453 return null;
7454 }
7455
Jack Yu3beaf9d2023-04-14 09:17:27 -07007456 final SubscriptionInfo info = getSubscriptionManagerService()
7457 .getSubscriptionInfo(subId);
7458 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007459 // If it doesn't belong to any group, return just subscriberId of itself.
7460 if (groupUuid == null) {
7461 return new String[]{subscriberId};
7462 }
7463
7464 // Get all subscriberIds from the group.
7465 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07007466 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
7467 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7468 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007469 for (SubscriptionInfo subInfo : groupInfos) {
7470 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7471 if (subscriberId != null) {
7472 mergedSubscriberIds.add(subscriberId);
7473 }
7474 }
7475
7476 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7477 } finally {
7478 Binder.restoreCallingIdentity(identity);
7479
7480 }
7481 }
7482
7483 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007484 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007485 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007486 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
7490 final Phone phone = getPhone(subId);
7491 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007495 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007496
7497 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007498 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007499 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7500 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007501 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7502 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 final Phone phone = getPhone(subId);
7507 if (phone == null) {
7508 return false;
7509 }
7510 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7511 cdmaNonRoamingList);
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007514 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007515 }
7516
7517 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007518 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007519 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007520 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007521 if (phone == null) {
7522 return raf;
7523 }
7524
Shuo Qiandee53402020-05-29 14:08:15 -07007525 try {
7526 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007527 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007528 mApp, phone.getSubId(), "getRadioAccessFamily");
7529 } catch (SecurityException e) {
7530 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7531 throw e;
7532 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 final long identity = Binder.clearCallingIdentity();
7535 try {
chen xub97461a2018-10-26 14:17:57 -07007536 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 } finally {
7538 Binder.restoreCallingIdentity(identity);
7539 }
chen xub97461a2018-10-26 14:17:57 -07007540 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007541 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007542
7543 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007544 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007545 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007546 try {
7547 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7548 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007549 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007550 }
7551 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007552 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007553 }
7554 RoleManager rm = mApp.getSystemService(RoleManager.class);
7555 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7556 if (!dialerRoleHolders.contains(callingPackage)) {
7557 throw new SecurityException("App must be the dialer role holder to"
7558 + " upload a call composer pic");
7559 }
7560
7561 Executors.newSingleThreadExecutor().execute(() -> {
7562 ByteArrayOutputStream output = new ByteArrayOutputStream(
7563 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7564 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7565 boolean readUntilEnd = false;
7566 int totalBytesRead = 0;
7567 byte[] buffer = new byte[16 * 1024];
7568 while (true) {
7569 int numRead;
7570 try {
7571 numRead = input.read(buffer);
7572 } catch (IOException e) {
7573 try {
7574 fd.checkError();
7575 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7576 null);
7577 } catch (IOException e1) {
7578 // This means that the other side closed explicitly with an error. If this
7579 // happens, log and ignore.
7580 loge("Remote end of call composer picture pipe closed: " + e1);
7581 }
7582 break;
7583 }
7584 if (numRead == -1) {
7585 readUntilEnd = true;
7586 break;
7587 }
7588 totalBytesRead += numRead;
7589 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7590 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7591 try {
7592 input.close();
7593 } catch (IOException e) {
7594 // ignore
7595 }
7596 break;
7597 }
7598 output.write(buffer, 0, numRead);
7599 }
7600 // Generally, the remote end will close the file descriptors. The only case where we
7601 // close is above, where the picture size is too big.
7602
7603 try {
7604 fd.checkError();
7605 } catch (IOException e) {
7606 loge("Remote end for call composer closed with an error: " + e);
7607 return;
7608 }
7609
Hall Liuaa4211e2021-01-20 15:43:39 -08007610 if (!readUntilEnd) {
7611 loge("Did not finish reading entire image; aborting");
7612 return;
7613 }
Hall Liu82694d52020-12-11 18:22:04 -08007614
Hall Liuaa4211e2021-01-20 15:43:39 -08007615 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7616 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7617 new CallComposerPictureTransfer.Factory() {},
7618 imageData,
7619 (result) -> {
7620 if (result.first != null) {
7621 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7622 Bundle outputResult = new Bundle();
7623 outputResult.putParcelable(
7624 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7625 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7626 outputResult);
7627 } else {
7628 callback.send(result.second, null);
7629 }
7630 }
7631 );
Hall Liu82694d52020-12-11 18:22:04 -08007632 });
7633 }
7634
7635 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007636 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007637 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007638 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639
7640 final long identity = Binder.clearCallingIdentity();
7641 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007642 ImsManager.getInstance(defaultPhone.getContext(),
7643 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 } finally {
7645 Binder.restoreCallingIdentity(identity);
7646 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007647 }
7648
7649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007650 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007651 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7653 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007654 return false;
7655 }
Svet Ganovb320e182015-04-16 12:30:10 -07007656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 final long identity = Binder.clearCallingIdentity();
7658 try {
7659 // Check the user preference and the system-level IMS setting. Even if the user has
7660 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7661 // In the long run, we may instead need to check if there exists a connection service
7662 // which can support video calling.
7663 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007664 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 return imsManager.isVtEnabledByPlatform()
7666 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7667 && imsManager.isVtEnabledByUser();
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
7670 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007671 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007672
Andrew Leea1239f22015-03-02 17:44:07 -08007673 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007674 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7675 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007677 mApp, subId, callingPackage, callingFeatureId,
7678 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 return false;
7680 }
7681
7682 final long identity = Binder.clearCallingIdentity();
7683 try {
7684 CarrierConfigManager configManager =
7685 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007686 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
7690 }
Andrew Leea1239f22015-03-02 17:44:07 -08007691 }
7692
7693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007694 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007696 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 return false;
7698 }
7699
7700 final long identity = Binder.clearCallingIdentity();
7701 try {
7702 CarrierConfigManager configManager =
7703 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007704 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007705 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7706 } finally {
7707 Binder.restoreCallingIdentity(identity);
7708 }
Andrew Leea1239f22015-03-02 17:44:07 -08007709 }
7710
Andrew Lee9431b832015-03-09 18:46:45 -07007711 @Override
7712 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007713 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007714 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007715 }
7716
7717 @Override
7718 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 final long identity = Binder.clearCallingIdentity();
7720 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007721 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 } finally {
7723 Binder.restoreCallingIdentity(identity);
7724 }
Andrew Lee9431b832015-03-09 18:46:45 -07007725 }
7726
Hall Liuf6668912018-10-31 17:05:23 -07007727 /**
7728 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7729 * support for the feature and device firmware support.
7730 *
7731 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7732 */
7733 @Override
7734 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007736 final Phone phone = getPhone(subscriptionId);
7737 if (phone == null) {
7738 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7739 return false;
7740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007742 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7744 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007745 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 return isCarrierSupported && isDeviceSupported;
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
7749 }
Hall Liu98187582018-01-22 19:15:32 -08007750 }
7751
Hall Liuf6668912018-10-31 17:05:23 -07007752 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007753 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7754 * RTT setting, will return true if the device and carrier both support RTT.
7755 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007756 */
7757 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 final long identity = Binder.clearCallingIdentity();
7759 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007760 boolean isRttSupported = isRttSupported(subscriptionId);
7761 boolean isUserRttSettingOn = Settings.Secure.getInt(
7762 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7763 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7764 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7765 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 } finally {
7767 Binder.restoreCallingIdentity(identity);
7768 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007769 }
7770
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007771 @Deprecated
7772 @Override
7773 public String getDeviceId(String callingPackage) {
7774 return getDeviceIdWithFeature(callingPackage, null);
7775 }
7776
Sanket Padawe7310cc72015-01-14 09:53:20 -08007777 /**
7778 * Returns the unique device ID of phone, for example, the IMEI for
7779 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7780 *
7781 * <p>Requires Permission:
7782 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7783 */
7784 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007785 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007786 try {
7787 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7788 } catch (SecurityException se) {
7789 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7790 throw new SecurityException("Package " + callingPackage + " does not belong to "
7791 + Binder.getCallingUid());
7792 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007793 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007794 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007795 return null;
7796 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007797 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007798 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007799 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007800 return null;
7801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802
7803 final long identity = Binder.clearCallingIdentity();
7804 try {
7805 return phone.getDeviceId();
7806 } finally {
7807 Binder.restoreCallingIdentity(identity);
7808 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007809 }
7810
Ping Sunc67b7c22016-03-02 19:16:45 +08007811 /**
7812 * {@hide}
7813 * Returns the IMS Registration Status on a particular subid
7814 *
7815 * @param subId
7816 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007817 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007818 Phone phone = getPhone(subId);
7819 if (phone != null) {
7820 return phone.isImsRegistered();
7821 } else {
7822 return false;
7823 }
7824 }
7825
Santos Cordon7a1885b2015-02-03 11:15:19 -08007826 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007827 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007828 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007830 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007831 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7832 }
7833 final long identity = Binder.clearCallingIdentity();
7834 try {
7835 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7836 } finally {
7837 Binder.restoreCallingIdentity(identity);
7838 }
7839 }
7840
7841 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007842 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007843 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007844 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007845 mApp,
7846 subscriptionId,
7847 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7848 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007849 final long identity = Binder.clearCallingIdentity();
7850 try {
7851 Phone phone = getPhone(subscriptionId);
7852 if (phone == null) {
7853 return null;
7854 }
7855 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7856 } finally {
7857 Binder.restoreCallingIdentity(identity);
7858 }
7859 }
7860
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007861 /**
7862 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007863 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007864 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 final long identity = Binder.clearCallingIdentity();
7866 try {
7867 Phone phone = getPhone(subId);
7868 if (phone != null) {
7869 return phone.isWifiCallingEnabled();
7870 } else {
7871 return false;
7872 }
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007875 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007876 }
7877
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007878 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007879 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007880 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007881 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 Phone phone = getPhone(subId);
7885 if (phone != null) {
7886 return phone.isVideoEnabled();
7887 } else {
7888 return false;
7889 }
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007892 }
7893 }
7894
7895 /**
7896 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7897 * defined in {@link ImsRegistrationImplBase}.
7898 */
7899 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 final long identity = Binder.clearCallingIdentity();
7901 try {
7902 Phone phone = getPhone(subId);
7903 if (phone != null) {
7904 return phone.getImsRegistrationTech();
7905 } else {
7906 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7907 }
7908 } finally {
7909 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007910 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007911 }
7912
Stuart Scott8eef64f2015-04-08 15:13:54 -07007913 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007914 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007915 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007916 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7917 return;
7918 }
Kai Shif70f46f2021-03-03 13:59:46 -08007919 Phone defaultPhone = getDefaultPhone();
7920 if (defaultPhone != null) {
7921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7922 mApp, getDefaultPhone().getSubId(), "factoryReset");
7923 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007924 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007925
Svet Ganovcc087f82015-05-12 20:35:54 -07007926 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007927 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7928 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007929 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007930 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007931 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007932 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007933 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007934 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007935 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007936 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007937 // There has been issues when Sms raw table somehow stores orphan
7938 // fragments. They lead to garbled message when new fragments come
7939 // in and combined with those stale ones. In case this happens again,
7940 // user can reset all network settings which will clean up this table.
7941 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007942 // Clean up IMS settings as well here.
7943 int slotId = getSlotIndex(subId);
7944 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7945 ImsManager.getInstance(mApp, slotId).factoryReset();
7946 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007947
Kai Shif70f46f2021-03-03 13:59:46 -08007948 if (defaultPhone == null) {
7949 return;
7950 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007951 // Erase modem config if erase modem on network setting is enabled.
7952 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7953 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7954 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007955 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007956 }
Kai Shif70f46f2021-03-03 13:59:46 -08007957
7958 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007959 } finally {
7960 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007961 }
7962 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007963
SongFerngWangfd89b102021-05-27 22:44:54 +08007964 @VisibleForTesting
7965 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7966 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7967 return;
7968 }
7969 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7970 RILConstants.PREFERRED_NETWORK_MODE);
7971 SubscriptionManager.setSubscriptionProperty(subId,
7972 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7973 "user=" + defaultNetworkType);
7974 phone.loadAllowedNetworksFromSubscriptionDatabase();
7975 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7976 defaultNetworkType, null);
7977 }
7978
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007979 private void cleanUpSmsRawTable(Context context) {
7980 ContentResolver resolver = context.getContentResolver();
7981 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7982 resolver.delete(uri, null, null);
7983 }
7984
Narayan Kamath1c496c22015-04-16 14:40:19 +01007985 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007986 public String getSimLocaleForSubscriber(int subId) {
7987 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7988 final Phone phone = getPhone(subId);
7989 if (phone == null) {
7990 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007991 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 final long identity = Binder.clearCallingIdentity();
7994 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07007995 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
7996 phone.getContext().getOpPackageName(),
7997 phone.getContext().getAttributionTag());
7998 if (info == null) {
7999 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8000 return null;
chen xu6291c472019-02-04 12:55:53 -08008001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 // Try and fetch the locale from the carrier properties or from the SIM language
8003 // preferences (EF-PL and EF-LI)...
8004 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008006 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8007 if (localeFromDefaultSim != null) {
8008 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8009 if (DBG) log("Using locale from subId: " + subId + " locale: "
8010 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008011 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008012 } else {
8013 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 }
8015 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 // The SIM language preferences only store a language (e.g. fr = French), not an
8018 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8019 // the SIM and carrier preferences does not include a country we add the country
8020 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008021 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008023 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008024 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 }
8026
8027 if (DBG) log("No locale found - returning null");
8028 return null;
8029 } finally {
8030 Binder.restoreCallingIdentity(identity);
8031 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008032 }
8033
tom hsu0b59d292022-09-29 23:49:21 +08008034 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008035 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008036 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008037 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008038 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008039 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8040 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008041 Locale.forLanguageTag(localeTag).getCountry())) {
8042 return localeTag;
8043 }
8044 }
8045 return inputLocale.toLanguageTag();
8046 }
8047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 /**
8049 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8050 */
8051 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008052 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
8053 mApp.getOpPackageName(), mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008054 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008055
Gary Jian3aa9a762022-01-24 16:41:19 +08008056 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8057 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008058
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008059 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008060 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8061 * representing the state of the modem.
8062 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008063 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8064 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008065 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008066 */
8067 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008068 public void requestModemActivityInfo(ResultReceiver result) {
8069 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008070 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071
8072 final long identity = Binder.clearCallingIdentity();
8073 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008074 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 } finally {
8076 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008077 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008078 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008079
Gary Jian76280a42022-12-07 16:18:33 +08008080 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008081 // less than total activity duration.
8082 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8083 if (info == null) {
8084 return false;
8085 }
8086 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008087 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008088 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8089
Hall Liu49656c02020-10-09 19:00:11 -07008090 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8091
Siddharth Rayb8114062018-06-17 15:02:38 -07008092 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008093 && (info.getSleepTimeMillis() <= activityDurationMs)
8094 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008095 }
8096
Gary Jian3aa9a762022-01-24 16:41:19 +08008097 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8098 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8099 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8100 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8101
8102 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8103 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8104 }
8105
8106 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8107 mLastModemActivityInfo.setReceiveTimeMillis(
8108 rat,
8109 freq,
8110 info.getReceiveTimeMillis(rat, freq)
8111 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8112 }
8113
8114 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8115 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8116 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8117 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8118
8119 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8120 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8121 }
8122 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8123 mLastModemActivityInfo.setReceiveTimeMillis(
8124 rat,
8125 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8126 }
8127
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008128 /**
8129 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8130 * @param info recent ModemActivityInfo
8131 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008132 private void mergeModemActivityInfo(ModemActivityInfo info) {
8133 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008134 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008135 boolean matched;
8136 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8137 matched = false;
8138 int rat = info.getSpecificInfoRat(i);
8139 int freq = info.getSpecificInfoFrequencyRange(i);
8140 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8141 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8142 //if it already exists
8143 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8144 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8145 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8146 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8147 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8148 updateLastModemActivityInfo(info, rat, freq);
8149 matched = true;
8150 }
8151 } else {
8152 updateLastModemActivityInfo(info, rat);
8153 matched = true;
8154 }
8155 }
8156 }
8157
8158 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008159 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008160 new ActivityStatsTechSpecificInfo(
8161 rat,
8162 freq,
8163 info.getTransmitTimeMillis(rat, freq),
8164 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008165 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008166 }
8167 }
8168 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8169 mLastModemActivitySpecificInfo =
8170 new ActivityStatsTechSpecificInfo[merged.size()];
8171 merged.toArray(mLastModemActivitySpecificInfo);
8172
8173 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8174 mLastModemActivityInfo.setSleepTimeMillis(
8175 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008176 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008177 mLastModemActivityInfo.setIdleTimeMillis(
8178 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008179 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008180
8181 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008182 new ModemActivityInfo(
8183 mLastModemActivityInfo.getTimestampMillis(),
8184 mLastModemActivityInfo.getSleepTimeMillis(),
8185 mLastModemActivityInfo.getIdleTimeMillis(),
8186 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008187 }
8188
8189 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8190 ActivityStatsTechSpecificInfo[] info) {
8191 int infoSize = info.length;
8192 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8193 for (int i = 0; i < infoSize; i++) {
8194 ret[i] = new ActivityStatsTechSpecificInfo(
8195 info[i].getRat(), info[i].getFrequencyRange(),
8196 info[i].getTransmitTimeMillis(),
8197 (int) info[i].getReceiveTimeMillis());
8198 }
8199 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008200 }
8201
Jack Yu85bd38a2015-11-09 11:34:32 -08008202 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008203 * Returns the service state information on specified subscription.
8204 */
8205 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008206 public ServiceState getServiceStateForSubscriber(int subId,
8207 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8208 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008209 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008210 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008211 return null;
8212 }
8213
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008214 boolean hasFinePermission = false;
8215 boolean hasCoarsePermission = false;
8216 if (!renounceFineLocationAccess) {
8217 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8218 LocationAccessPolicy.checkLocationPermission(mApp,
8219 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8220 .setCallingPackage(callingPackage)
8221 .setCallingFeatureId(callingFeatureId)
8222 .setCallingPid(Binder.getCallingPid())
8223 .setCallingUid(Binder.getCallingUid())
8224 .setMethod("getServiceStateForSubscriber")
8225 .setLogAsInfo(true)
8226 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8227 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8228 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8229 .build());
8230 hasFinePermission =
8231 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8232 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008233
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008234 if (!renounceCoarseLocationAccess) {
8235 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8236 LocationAccessPolicy.checkLocationPermission(mApp,
8237 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8238 .setCallingPackage(callingPackage)
8239 .setCallingFeatureId(callingFeatureId)
8240 .setCallingPid(Binder.getCallingPid())
8241 .setCallingUid(Binder.getCallingUid())
8242 .setMethod("getServiceStateForSubscriber")
8243 .setLogAsInfo(true)
8244 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8245 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8246 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8247 .build());
8248 hasCoarsePermission =
8249 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8250 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008251
Jack Yu479f40e2020-10-27 21:29:25 -07008252 final Phone phone = getPhone(subId);
8253 if (phone == null) {
8254 return null;
8255 }
8256
Jordan Liu0f2bc442020-11-18 16:47:37 -08008257 final long identity = Binder.clearCallingIdentity();
8258
Jack Yu479f40e2020-10-27 21:29:25 -07008259 boolean isCallingPackageDataService = phone.getDataServicePackages()
8260 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008262 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008263 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8264 .getSubscriptionInfoInternal(subId);
8265 if (subInfo == null || !subInfo.isActive()) {
8266 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8267 + "subId=" + subId);
8268 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008269 }
8270
Hall Liuf19c44f2018-11-27 14:38:17 -08008271 ServiceState ss = phone.getServiceState();
8272
8273 // Scrub out the location info in ServiceState depending on what level of access
8274 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008275 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008276 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8277 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008281 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008282
8283 /**
8284 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8285 *
8286 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8287 * voicemail ringtone.
8288 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8289 * PhoneAccount.
8290 */
8291 @Override
8292 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8296 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008297 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008304 }
8305
8306 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008307 * Sets the per-account voicemail ringtone.
8308 *
8309 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8310 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8311 *
8312 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8313 * voicemail ringtone.
8314 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8315 * PhoneAccount.
8316 */
8317 @Override
8318 public void setVoicemailRingtoneUri(String callingPackage,
8319 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008320 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008322 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8323 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8325 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8326 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328
8329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8332 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008333 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 }
8335 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008338 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008339 }
8340
8341 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008342 * Returns whether vibration is set for voicemail notification in Phone settings.
8343 *
8344 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8345 * voicemail vibration setting.
8346 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8347 */
8348 @Override
8349 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350 final long identity = Binder.clearCallingIdentity();
8351 try {
8352 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8353 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008354 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8358 } finally {
8359 Binder.restoreCallingIdentity(identity);
8360 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008361 }
8362
Youhan Wange64578a2016-05-02 15:32:42 -07008363 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008364 * Sets the per-account voicemail vibration.
8365 *
8366 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8367 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8368 *
8369 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8370 * voicemail vibration setting.
8371 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8372 * specific PhoneAccount.
8373 */
8374 @Override
8375 public void setVoicemailVibrationEnabled(String callingPackage,
8376 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008377 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008378 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008379 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8380 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8382 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8383 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008384 }
8385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8389 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008390 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 }
8392 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008395 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008396 }
8397
8398 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008399 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8400 *
8401 * @throws SecurityException if the caller does not have the required permission
8402 */
arunvoddud7401012022-12-15 16:08:12 +00008403 @VisibleForTesting
8404 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008406 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008407 }
8408
8409 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008410 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8411 * permission.
8412 *
8413 * @throws SecurityException if the caller does not have the required permission
8414 */
8415 private void enforceSendSmsPermission() {
8416 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8417 }
8418
8419 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008420 * Make sure either called from same process as self (phone) or IPC caller has interact across
8421 * users permission.
8422 *
8423 * @throws SecurityException if the caller does not have the required permission
8424 */
8425 private void enforceInteractAcrossUsersPermission(String message) {
8426 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8427 }
8428
8429 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008430 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008431 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008432 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008433 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008434 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 final long identity = Binder.clearCallingIdentity();
8436 try {
8437 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008438 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439 if (componentName == null) {
8440 throw new SecurityException(
8441 "Caller not current active visual voicemail package[null]");
8442 }
8443 String vvmPackage = componentName.getPackageName();
8444 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008445 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 }
8447 } finally {
8448 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008449 }
8450 }
8451
8452 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008453 * Return the application ID for the app type.
8454 *
8455 * @param subId the subscription ID that this request applies to.
8456 * @param appType the uicc app type.
8457 * @return Application ID for specificied app type, or null if no uicc.
8458 */
8459 @Override
8460 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008461 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008462 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008463
8464 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008465 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 if (phone == null) {
8467 return null;
8468 }
8469 String aid = null;
8470 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008471 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472 .getApplicationByType(appType).getAid();
8473 } catch (Exception e) {
8474 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8475 }
8476 return aid;
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008479 }
Youhan Wange64578a2016-05-02 15:32:42 -07008480 }
8481
Youhan Wang4001d252016-05-11 10:29:41 -07008482 /**
8483 * Return the Electronic Serial Number.
8484 *
8485 * @param subId the subscription ID that this request applies to.
8486 * @return ESN or null if error.
8487 */
8488 @Override
8489 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008490 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008491 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008492
8493 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008494 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 if (phone == null) {
8496 return null;
8497 }
8498 String esn = null;
8499 try {
8500 esn = phone.getEsn();
8501 } catch (Exception e) {
8502 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8503 }
8504 return esn;
8505 } finally {
8506 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008507 }
Youhan Wang4001d252016-05-11 10:29:41 -07008508 }
8509
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008510 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008511 * Return the Preferred Roaming List Version.
8512 *
8513 * @param subId the subscription ID that this request applies to.
8514 * @return PRLVersion or null if error.
8515 */
8516 @Override
8517 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008518 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008519 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520
8521 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008522 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523 if (phone == null) {
8524 return null;
8525 }
8526 String cdmaPrlVersion = null;
8527 try {
8528 cdmaPrlVersion = phone.getCdmaPrlVersion();
8529 } catch (Exception e) {
8530 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8531 }
8532 return cdmaPrlVersion;
8533 } finally {
8534 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008535 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008536 }
8537
8538 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008539 * Get snapshot of Telephony histograms
8540 * @return List of Telephony histograms
8541 * @hide
8542 */
8543 @Override
8544 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8546 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547
8548 final long identity = Binder.clearCallingIdentity();
8549 try {
8550 return RIL.getTelephonyRILTimingHistograms();
8551 } finally {
8552 Binder.restoreCallingIdentity(identity);
8553 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008554 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008555
8556 /**
8557 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008558 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8559 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008560 * Require system privileges. In the future we may add this to carrier APIs.
8561 *
Michele Berionne482f8202018-11-27 18:57:59 -08008562 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008563 */
8564 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008565 @TelephonyManager.SetCarrierRestrictionResult
8566 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008567 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008568 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008569
Michele Berionne482f8202018-11-27 18:57:59 -08008570 if (carrierRestrictionRules == null) {
8571 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008572 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 final long identity = Binder.clearCallingIdentity();
8575 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008576 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008577 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 } finally {
8579 Binder.restoreCallingIdentity(identity);
8580 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008581 }
8582
8583 /**
8584 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008585 * Get the allowed carrier list and the excluded carrier list, including the priority between
8586 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008587 * Require system privileges. In the future we may add this to carrier APIs.
8588 *
Michele Berionne482f8202018-11-27 18:57:59 -08008589 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008590 */
8591 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008592 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008593 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008595
8596 final long identity = Binder.clearCallingIdentity();
8597 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008598 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8599 if (response instanceof CarrierRestrictionRules) {
8600 return (CarrierRestrictionRules) response;
8601 }
8602 // Response is an Exception of some kind,
8603 // which is signalled to the user as a NULL retval
8604 return null;
8605 } catch (Exception e) {
8606 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8607 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008611 }
8612
fionaxu59545b42016-05-25 15:53:37 -07008613 /**
arunvoddud7401012022-12-15 16:08:12 +00008614 * Fetches the carrier restriction status of the device and sends the status to the caller
8615 * through the callback.
8616 *
8617 * @param callback The callback that will be used to send the result.
8618 * @throws SecurityException if the caller does not have the required permission/privileges or
8619 * the caller is not allowlisted.
8620 */
8621 @Override
8622 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8623 enforceReadPermission("getCarrierRestrictionStatus");
8624 int carrierId = validateCallerAndGetCarrierId(packageName);
8625 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8626 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8627 throw new SecurityException("Not an authorized caller");
8628 }
8629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8632 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8633 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
8637 }
8638
arunvoddu567f2b42023-04-25 17:22:00 +00008639 @Override
8640 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
8641 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
8642 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8643 return allowListInfo.getShaIdList(pkgName, carrierId);
8644 }
8645
arunvoddud7401012022-12-15 16:08:12 +00008646 @VisibleForTesting
8647 public int validateCallerAndGetCarrierId(String packageName) {
8648 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8649 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8650 }
8651
8652 /**
fionaxu59545b42016-05-25 15:53:37 -07008653 * Action set from carrier signalling broadcast receivers to enable/disable radio
8654 * @param subId the subscription ID that this action applies to.
8655 * @param enabled control enable or disable radio.
8656 * {@hide}
8657 */
8658 @Override
8659 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8660 enforceModifyPermission();
8661 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008662
8663 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008664 if (phone == null) {
8665 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8666 return;
8667 }
8668 try {
8669 phone.carrierActionSetRadioEnabled(enabled);
8670 } catch (Exception e) {
8671 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008672 } finally {
8673 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008674 }
8675 }
8676
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008677 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008678 * Enable or disable Voice over NR (VoNR)
8679 * @param subId the subscription ID that this action applies to.
8680 * @param enabled enable or disable VoNR.
8681 * @return operation result.
8682 */
8683 @Override
8684 public int setVoNrEnabled(int subId, boolean enabled) {
8685 enforceModifyPermission();
8686 final Phone phone = getPhone(subId);
8687
8688 final long identity = Binder.clearCallingIdentity();
8689 if (phone == null) {
8690 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8691 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8692 }
8693
8694 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8695 try {
8696 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8697 workSource);
8698 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008699
8700 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8701 if (DBG) {
8702 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8703 }
8704 SubscriptionManager.setSubscriptionProperty(
8705 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8706 (enabled ? "1" : "0"));
8707 }
8708
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008709 return result;
8710 } finally {
8711 Binder.restoreCallingIdentity(identity);
8712 }
8713 }
8714
8715 /**
8716 * Is voice over NR enabled
8717 * @return true if VoNR is enabled else false
8718 */
8719 @Override
8720 public boolean isVoNrEnabled(int subId) {
8721 enforceReadPrivilegedPermission("isVoNrEnabled");
8722 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8726 null, subId, workSource);
8727 if (DBG) log("isVoNrEnabled: " + isEnabled);
8728 return isEnabled;
8729 } finally {
8730 Binder.restoreCallingIdentity(identity);
8731 }
8732 }
8733
8734 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008735 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8736 * network status based on which carrier apps could apply actions accordingly,
8737 * enable/disable default url handler for example.
8738 *
8739 * @param subId the subscription ID that this action applies to.
8740 * @param report control start/stop reporting the default network status.
8741 * {@hide}
8742 */
8743 @Override
8744 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8745 enforceModifyPermission();
8746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008747
8748 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008749 if (phone == null) {
8750 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8751 return;
8752 }
8753 try {
8754 phone.carrierActionReportDefaultNetworkStatus(report);
8755 } catch (Exception e) {
8756 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008757 } finally {
8758 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008759 }
8760 }
8761
8762 /**
fionaxud9622282017-07-17 17:51:30 -07008763 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8764 * @param subId the subscription ID that this action applies to.
8765 * {@hide}
8766 */
8767 @Override
8768 public void carrierActionResetAll(int subId) {
8769 enforceModifyPermission();
8770 final Phone phone = getPhone(subId);
8771 if (phone == null) {
8772 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8773 return;
8774 }
8775 try {
8776 phone.carrierActionResetAll();
8777 } catch (Exception e) {
8778 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8779 }
8780 }
8781
8782 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008783 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8784 * bug report is being generated.
8785 */
8786 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008787 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008788 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8789 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008790 writer.println("Permission Denial: can't dump Phone from pid="
8791 + Binder.getCallingPid()
8792 + ", uid=" + Binder.getCallingUid()
8793 + "without permission "
8794 + android.Manifest.permission.DUMP);
8795 return;
8796 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008797 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008798 }
Jack Yueb89b242016-06-22 13:27:47 -07008799
Brad Ebingerdac2f002018-04-03 15:17:52 -07008800 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008801 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8802 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8803 @NonNull String[] args) {
8804 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8805 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008806 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008807 }
8808
Jack Yueb89b242016-06-22 13:27:47 -07008809 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008810 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008811 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008812 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008813 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008814 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008815 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008816 */
8817 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008818 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008819 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008820 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8821 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8822 try {
8823 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008824 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008825 } catch (SecurityException se) {
8826 enforceModifyPermission();
8827 }
8828 } else {
8829 enforceModifyPermission();
8830 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008831
Nate Myrenae97d192023-06-09 15:22:31 -07008832 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
8833 && null != callingPackage && opEnableMobileDataByUser()) {
8834 mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
8835 callingPackage, null, null);
8836 }
8837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008838 final long identity = Binder.clearCallingIdentity();
8839 try {
8840 Phone phone = getPhone(subId);
8841 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008842 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8843 phone.carrierActionSetMeteredApnsEnabled(enabled);
8844 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008845 phone.getDataSettingsManager().setDataEnabled(
8846 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848 }
8849 } finally {
8850 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008851 }
8852 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008853
8854 /**
8855 * Get Client request stats
8856 * @return List of Client Request Stats
8857 * @hide
8858 */
8859 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008860 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8861 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008863 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008864 return null;
8865 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008866 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008868 final long identity = Binder.clearCallingIdentity();
8869 try {
8870 if (phone != null) {
8871 return phone.getClientRequestStats();
8872 }
8873
8874 return null;
8875 } finally {
8876 Binder.restoreCallingIdentity(identity);
8877 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008878 }
8879
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008880 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008881 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008882 if (uid == Process.ROOT_UID && packageName == null) {
8883 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8884 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8885 // exception. ROOT_UID seems not to have a valid package name returned by
8886 // PackageManager, so just fake it here to avoid issues when running telephony shell
8887 // commands that plumb through the RIL as root, like so:
8888 // $ adb root
8889 // $ adb shell cmd phone ...
8890 packageName = "root";
8891 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008892 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008893 }
Jack Yueb4124c2017-02-16 15:32:43 -08008894
8895 /**
Grace Chen70990072017-03-24 17:21:30 -07008896 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008897 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008898 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008899 * @param state State of SIM (power down, power up, pass through)
8900 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8901 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8902 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008903 *
8904 **/
8905 @Override
Grace Chen70990072017-03-24 17:21:30 -07008906 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008907 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008908 Phone phone = PhoneFactory.getPhone(slotIndex);
8909
vagdeviaf9a5b92018-08-15 16:01:53 -07008910 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 final long identity = Binder.clearCallingIdentity();
8913 try {
8914 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008915 phone.setSimPowerState(state, null, workSource);
8916 }
8917 } finally {
8918 Binder.restoreCallingIdentity(identity);
8919 }
8920 }
8921
8922 /**
8923 * Set SIM card power state.
8924 *
8925 * @param slotIndex SIM slot id.
8926 * @param state State of SIM (power down, power up, pass through)
8927 * @param callback callback to trigger after success or failure
8928 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8929 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8930 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8931 *
8932 **/
8933 @Override
8934 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8935 IIntegerConsumer callback) {
8936 enforceModifyPermission();
8937 Phone phone = PhoneFactory.getPhone(slotIndex);
8938
8939 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8940
8941 final long identity = Binder.clearCallingIdentity();
8942 try {
8943 if (phone != null) {
8944 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8945 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008946 }
8947 } finally {
8948 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008949 }
8950 }
Shuo Qiandd210312017-04-12 22:11:33 +00008951
Tyler Gunn65d45c22017-06-05 11:22:26 -07008952 private boolean isUssdApiAllowed(int subId) {
8953 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008954 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008955 if (configManager == null) {
8956 return false;
8957 }
8958 PersistableBundle pb = configManager.getConfigForSubId(subId);
8959 if (pb == null) {
8960 return false;
8961 }
8962 return pb.getBoolean(
8963 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8964 }
8965
Shuo Qiandd210312017-04-12 22:11:33 +00008966 /**
Ling Mac28f0212023-03-24 16:07:15 -07008967 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00008968 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07008969 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00008970 */
goneil9c5f4872017-12-05 14:07:56 -08008971 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008972 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008973 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 final long identity = Binder.clearCallingIdentity();
8975 try {
Ling Mac28f0212023-03-24 16:07:15 -07008976 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 } finally {
8978 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008979 }
8980 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008981
8982 /**
8983 * Get the current signal strength information for the given subscription.
8984 * Because this information is not updated when the device is in a low power state
8985 * it should not be relied-upon to be current.
8986 * @param subId Subscription index
8987 * @return the most recent cached signal strength info from the modem
8988 */
8989 @Override
8990 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008991 final long identity = Binder.clearCallingIdentity();
8992 try {
8993 Phone p = getPhone(subId);
8994 if (p == null) {
8995 return null;
8996 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008998 return p.getSignalStrength();
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009002 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009003
Pengquan Meng77b7f132018-08-22 14:49:57 -07009004 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009005 * Get the current modem radio state for the given slot.
9006 * @param slotIndex slot index.
9007 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009008 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009009 * @return the current radio power state from the modem
9010 */
9011 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009012 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009013 Phone phone = PhoneFactory.getPhone(slotIndex);
9014 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9016 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009017 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9018 }
9019
9020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 return phone.getRadioPowerState();
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
9027 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9028 }
9029
9030 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009031 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9032 *
9033 * <p>Requires one of the following permissions:
9034 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009035 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009036 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9037 * privileges.
9038 *
9039 * @param subId subscription id
9040 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9041 * {@code false}.
9042 */
9043 @Override
9044 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009045 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009046 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009047 try {
9048 mApp.enforceCallingOrSelfPermission(
9049 android.Manifest.permission.ACCESS_NETWORK_STATE,
9050 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009051 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009052 mApp.enforceCallingOrSelfPermission(
9053 permission.READ_BASIC_PHONE_STATE, functionName);
9054 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009055 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009056 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009057 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009058 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009059
Pengquan Menga1bb6272018-09-06 09:59:22 -07009060 boolean isEnabled = false;
9061 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009062 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009063 Phone phone = getPhone(subId);
9064 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009065 } finally {
9066 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009067 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009068 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009069 }
9070
9071
9072 /**
9073 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9074 *
9075 * <p> Requires permission:
9076 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9077 * privileges.
9078 *
9079 * @param subId subscription id
9080 * @param isEnabled {@code true} means enable, {@code false} means disable.
9081 */
9082 @Override
9083 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9085 mApp, subId, "setDataRoamingEnabled");
9086
Pengquan Menga1bb6272018-09-06 09:59:22 -07009087 final long identity = Binder.clearCallingIdentity();
9088 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009089 Phone phone = getPhone(subId);
9090 if (phone != null) {
9091 phone.setDataRoamingEnabled(isEnabled);
9092 }
9093 } finally {
9094 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009095 }
9096 }
9097
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009098 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009099 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009100 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009101 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009102 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009103
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009104 boolean isAllowed = true;
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009107 Phone phone = getPhone(subId);
9108 if (phone != null) {
9109 isAllowed = phone.isCspPlmnEnabled();
9110 }
9111 } finally {
9112 Binder.restoreCallingIdentity(identity);
9113 }
9114 return isAllowed;
9115 }
9116
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009117 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9118 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009119 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009120 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009121 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009122 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9123 if (phone == null) {
9124 return false;
9125 }
9126 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9127 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9128 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009129 }
9130
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009131 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009132 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009133 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009134 mApp.getSystemService(AppOpsManager.class)
9135 .checkPackage(Binder.getCallingUid(), callingPackage);
9136
Jordan Liu1e142fc2019-04-22 15:10:43 -07009137 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009138 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009139 try {
9140 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009141 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009142 } catch (SecurityException e) {
9143 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9144 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009145 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009146 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009147 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009148 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009149 }
sandeepjsb6c87872021-09-27 15:34:44 +00009150 // checking compatibility, if calling app's target SDK is T and beyond.
9151 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9152 Binder.getCallingUid())) {
9153 isIccIdAccessRestricted = true;
9154 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009155 final long identity = Binder.clearCallingIdentity();
9156 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009157 UiccController uiccController = UiccController.getInstance();
9158 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009159 if (hasReadPermission) {
9160 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009161 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009162
9163 // Remove private info if the caller doesn't have access
9164 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9165 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009166 //setting the value after compatibility check
9167 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009168 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9169 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009170 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009171 if (card == null) {
9172 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009173 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009174 continue;
9175 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009176 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9177 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009178 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009179 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009180 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009181 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9182 for (UiccPortInfo portInfo : portInfos) {
9183 UiccPort port = uiccController.getUiccPortForSlot(
9184 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9185 if (port == null) {
9186 // assume no access if port is null
9187 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9188 continue;
9189 }
9190 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9191 uiccPortInfos.add(portInfo);
9192 } else {
9193 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9194 }
9195 }
9196 filteredInfos.add(new UiccCardInfo(
9197 cardInfo.isEuicc(),
9198 cardInfo.getCardId(),
9199 null,
9200 cardInfo.getPhysicalSlotIndex(),
9201 cardInfo.isRemovable(),
9202 cardInfo.isMultipleEnabledProfilesSupported(),
9203 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009204 }
9205 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009206 } finally {
9207 Binder.restoreCallingIdentity(identity);
9208 }
9209 }
9210
sandeepjsb6c87872021-09-27 15:34:44 +00009211 /**
9212 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9213 * generally private and require carrier privileges to view.
9214 *
9215 * @hide
9216 */
9217 @NonNull
9218 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9219 List<UiccPortInfo> portinfo = new ArrayList<>();
9220 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9221 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9222 }
9223 return new UiccCardInfo(
9224 cardInfo.isEuicc(),
9225 cardInfo.getCardId(),
9226 null,
9227 cardInfo.getPhysicalSlotIndex(),
9228 cardInfo.isRemovable(),
9229 cardInfo.isMultipleEnabledProfilesSupported(),
9230 portinfo
9231 );
9232 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009233
sandeepjsb6c87872021-09-27 15:34:44 +00009234 /**
9235 * @hide
9236 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9237 * These values are generally private and require carrier privileges to view.
9238 */
9239 @NonNull
9240 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9241 return new UiccPortInfo(
9242 UiccPortInfo.ICCID_REDACTED,
9243 portInfo.getPortIndex(),
9244 portInfo.getLogicalSlotIndex(),
9245 portInfo.isActive()
9246 );
9247 }
9248 @Override
9249 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009250 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009251 mApp.getSystemService(AppOpsManager.class)
9252 .checkPackage(Binder.getCallingUid(), callingPackage);
9253
sandeepjsb6c87872021-09-27 15:34:44 +00009254 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009255
Aman Guptaf3c90b32022-03-17 04:54:16 +00009256 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9257 // we are reading iccId which is PII data.
9258 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009259
9260 // checking compatibility, if calling app's target SDK is T and beyond.
9261 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9262 Binder.getCallingUid())) {
9263 isLogicalSlotAccessRestricted = true;
9264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009265 final long identity = Binder.clearCallingIdentity();
9266 try {
9267 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009268 if (slots == null || slots.length == 0) {
9269 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009270 return null;
9271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009272 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9273 for (int i = 0; i < slots.length; i++) {
9274 UiccSlot slot = slots[i];
9275 if (slot == null) {
9276 continue;
9277 }
9278
Jordan Liu7be7e652019-05-06 18:55:02 +00009279 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009280 UiccCard card = slot.getUiccCard();
9281 if (card != null) {
9282 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009283 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009284 cardId = slot.getEid();
9285 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009286 // If cardId is null, use iccId of default port as cardId.
9287 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009289 }
9290
Jordan Liu857451f2019-05-09 16:35:35 -07009291 if (cardId != null) {
9292 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9293 // if cardId is an EID, it's all digits so this is fine
9294 cardId = IccUtils.stripTrailingFs(cardId);
9295 }
9296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009297 int cardState = 0;
9298 switch (slot.getCardState()) {
9299 case CARDSTATE_ABSENT:
9300 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9301 break;
9302 case CARDSTATE_PRESENT:
9303 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9304 break;
9305 case CARDSTATE_ERROR:
9306 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9307 break;
9308 case CARDSTATE_RESTRICTED:
9309 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9310 break;
9311 default:
9312 break;
9313
9314 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009315 List<UiccPortInfo> portInfos = new ArrayList<>();
9316 int[] portIndexes = slot.getPortList();
9317 for (int portIdx : portIndexes) {
9318 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009319 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009320 portInfos.add(new UiccPortInfo(iccId, portIdx,
9321 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009323 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009324 slot.isEuicc(),
9325 cardId,
9326 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009327 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009328 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009329 //setting the value after compatibility check
9330 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009331 }
9332 return infos;
9333 } finally {
9334 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009335 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009336 }
9337
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009338 /* Returns null if doesn't have read permission or carrier privilege access. */
9339 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9340 boolean hasReadPermission) {
9341 String iccId = slot.getIccId(portIndex);
9342 if (hasReadPermission) { // if has read permission
9343 return iccId;
9344 } else {
9345 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9346 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9347 // if no read permission, checking carrier privilege access
9348 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9349 return iccId;
9350 }
9351 }
9352 }
9353 // No read permission or carrier privilege access.
9354 return UiccPortInfo.ICCID_REDACTED;
9355 }
9356
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009357 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009358 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009359 public boolean switchSlots(int[] physicalSlots) {
9360 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009361
9362 final long identity = Binder.clearCallingIdentity();
9363 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009364 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9365 for (int i = 0; i < physicalSlots.length; i++) {
9366 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9367 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9368 physicalSlots[i], i));
9369 }
9370 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009371 } finally {
9372 Binder.restoreCallingIdentity(identity);
9373 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009374 }
Jack Yu4c988042018-02-27 15:30:01 -08009375
9376 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009377 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9378 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9379 enforceModifyPermission();
9380
9381 final long identity = Binder.clearCallingIdentity();
9382 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009383 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009384 } finally {
9385 Binder.restoreCallingIdentity(identity);
9386 }
9387 }
9388
9389 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009390 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009391 final long identity = Binder.clearCallingIdentity();
9392 try {
9393 return UiccController.getInstance().getCardIdForDefaultEuicc();
9394 } finally {
9395 Binder.restoreCallingIdentity(identity);
9396 }
9397 }
9398
Pengquan Meng85728fb2018-03-12 16:31:21 -07009399 /**
goneil47ffb6e2018-04-06 15:40:58 -07009400 * A test API to reload the UICC profile.
9401 *
9402 * <p>Requires that the calling app has permission
9403 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9404 * @hide
9405 */
9406 @Override
9407 public void refreshUiccProfile(int subId) {
9408 enforceModifyPermission();
9409
9410 final long identity = Binder.clearCallingIdentity();
9411 try {
9412 Phone phone = getPhone(subId);
9413 if (phone == null) {
9414 return;
9415 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009416 UiccPort uiccPort = phone.getUiccPort();
9417 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009418 return;
9419 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009420 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009421 if (uiccProfile == null) {
9422 return;
9423 }
9424 uiccProfile.refresh();
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
9429
9430 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009431 * Returns false if the mobile data is disabled by default, otherwise return true.
9432 */
9433 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009434 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009435 }
9436
9437 /**
9438 * Returns true if the data roaming is enabled by default, i.e the system property
9439 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9440 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9441 */
9442 private boolean getDefaultDataRoamingEnabled(int subId) {
9443 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009444 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009445 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009446 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9447 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9448 return isDataRoamingEnabled;
9449 }
9450
9451 /**
9452 * Returns the default network type for the given {@code subId}, if the default network type is
9453 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9454 */
9455 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009456 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009457 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009458 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9459 return list.get(phoneId);
9460 }
9461 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009462 }
fionaxua13278b2018-03-21 00:08:13 -07009463
9464 @Override
9465 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009466 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009467 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009468
9469 final long identity = Binder.clearCallingIdentity();
9470 try {
9471 final Phone phone = getPhone(subId);
9472 if (phone == null) {
9473 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9474 return;
9475 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009476 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9477 if (cpt != null) {
9478 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9479 }
9480 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009481 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9482 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009483 if (carrierPrivilegeRules == null) {
9484 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9485 } else {
9486 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009488 } finally {
9489 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009490 }
fionaxua13278b2018-03-21 00:08:13 -07009491 }
9492
9493 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009494 public void setCarrierServicePackageOverride(
9495 int subId, String carrierServicePackage, String callingPackage) {
9496 TelephonyPermissions.enforceShellOnly(
9497 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9498
Benedict Wong66477622023-02-03 23:30:57 +00009499 final long identity = Binder.clearCallingIdentity();
9500 try {
9501 final Phone phone = getPhone(subId);
9502 if (phone == null || phone.getSubId() != subId) {
9503 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9504 throw new IllegalArgumentException("No phone for subid");
9505 }
9506 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9507 if (cpt == null) {
9508 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9509 throw new IllegalStateException("No CPT for phone");
9510 }
9511 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9512 } finally {
9513 Binder.restoreCallingIdentity(identity);
9514 }
9515 }
9516
9517 @Override
fionaxua13278b2018-03-21 00:08:13 -07009518 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009519 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009520
9521 final long identity = Binder.clearCallingIdentity();
9522 try {
9523 final Phone phone = getPhone(subId);
9524 if (phone == null) {
9525 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9526 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9527 }
9528 return phone.getCarrierIdListVersion();
9529 } finally {
9530 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009531 }
fionaxua13278b2018-03-21 00:08:13 -07009532 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009533
9534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009535 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9536 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009538 mApp, subId, callingPackage, callingFeatureId,
9539 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009540 return -1;
9541 }
9542
9543 final long identity = Binder.clearCallingIdentity();
9544 try {
9545 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9546 } finally {
9547 Binder.restoreCallingIdentity(identity);
9548 }
9549 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009550
9551 @Override
9552 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009553 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009554 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009555 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009556
9557 final long identity = Binder.clearCallingIdentity();
9558 try {
9559 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563 }
9564
9565 @Override
9566 public boolean setCdmaRoamingMode(int subId, int mode) {
9567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9568 mApp, subId, "setCdmaRoamingMode");
9569
9570 final long identity = Binder.clearCallingIdentity();
9571 try {
9572 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9573 } finally {
9574 Binder.restoreCallingIdentity(identity);
9575 }
9576 }
9577
9578 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009579 public int getCdmaSubscriptionMode(int subId) {
9580 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009581 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009582 mApp, subId, "getCdmaSubscriptionMode");
9583
9584 final long identity = Binder.clearCallingIdentity();
9585 try {
9586 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
9589 }
9590 }
9591
9592 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009593 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9595 mApp, subId, "setCdmaSubscriptionMode");
9596
9597 final long identity = Binder.clearCallingIdentity();
9598 try {
9599 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009604
sqianc5eccab2018-10-19 18:46:41 -07009605 @Override
sqian8c685422019-02-22 15:55:18 -08009606 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009607 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009608 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009609 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9610 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009611 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9612 }
9613 final long identity = Binder.clearCallingIdentity();
9614 try {
sqian854d44b2018-12-12 16:48:18 -08009615 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9616 for (Phone phone: PhoneFactory.getPhones()) {
9617 if (phone.getEmergencyNumberTracker() != null
9618 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9619 emergencyNumberListInternal.put(
9620 phone.getSubId(),
9621 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9622 }
sqian11b7a0e2018-12-05 18:48:28 -08009623 }
sqian854d44b2018-12-12 16:48:18 -08009624 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009625 } finally {
9626 Binder.restoreCallingIdentity(identity);
9627 }
sqianc5eccab2018-10-19 18:46:41 -07009628 }
9629
9630 @Override
sqian8c685422019-02-22 15:55:18 -08009631 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009632 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009633 if (!exactMatch) {
9634 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009635 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009636 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009637 }
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
sqian854d44b2018-12-12 16:48:18 -08009640 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009641 //Note: we ignore passed in param exactMatch. We can remove it once
9642 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009643 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009644 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009645 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009646 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009647 }
sqian11b7a0e2018-12-05 18:48:28 -08009648 }
9649 return false;
9650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
9654
sqianf4ca7ed2019-01-15 18:32:07 -08009655 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009656 * Start emergency callback mode for GsmCdmaPhone for testing.
9657 */
9658 @Override
9659 public void startEmergencyCallbackMode() {
9660 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9661 "startEmergencyCallbackMode");
9662 enforceModifyPermission();
9663 final long identity = Binder.clearCallingIdentity();
9664 try {
9665 for (Phone phone : PhoneFactory.getPhones()) {
9666 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9667 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9668 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9669 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9670 gsmCdmaPhone.obtainMessage(
9671 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9672 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9673 }
9674 }
9675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
9679
9680 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009681 * Update emergency number list for test mode.
9682 */
9683 @Override
9684 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9685 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9686 "updateEmergencyNumberListTestMode");
9687
9688 final long identity = Binder.clearCallingIdentity();
9689 try {
9690 for (Phone phone: PhoneFactory.getPhones()) {
9691 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9692 if (tracker != null) {
9693 tracker.executeEmergencyNumberTestModeCommand(action, num);
9694 }
9695 }
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
9698 }
9699 }
9700
9701 /**
9702 * Get the full emergency number list for test mode.
9703 */
9704 @Override
9705 public List<String> getEmergencyNumberListTestMode() {
9706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9707 "getEmergencyNumberListTestMode");
9708
9709 final long identity = Binder.clearCallingIdentity();
9710 try {
9711 Set<String> emergencyNumbers = new HashSet<>();
9712 for (Phone phone: PhoneFactory.getPhones()) {
9713 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9714 if (tracker != null) {
9715 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9716 emergencyNumbers.add(num.getNumber());
9717 }
9718 }
9719 }
9720 return new ArrayList<>(emergencyNumbers);
9721 } finally {
9722 Binder.restoreCallingIdentity(identity);
9723 }
9724 }
9725
chen xud6b45bd2018-10-30 22:27:10 -07009726 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009727 public int getEmergencyNumberDbVersion(int subId) {
9728 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9729
9730 final long identity = Binder.clearCallingIdentity();
9731 try {
9732 final Phone phone = getPhone(subId);
9733 if (phone == null) {
9734 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9735 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9736 }
9737 return phone.getEmergencyNumberDbVersion();
9738 } finally {
9739 Binder.restoreCallingIdentity(identity);
9740 }
9741 }
9742
9743 @Override
9744 public void notifyOtaEmergencyNumberDbInstalled() {
9745 enforceModifyPermission();
9746
9747 final long identity = Binder.clearCallingIdentity();
9748 try {
9749 for (Phone phone: PhoneFactory.getPhones()) {
9750 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9751 if (tracker != null) {
9752 tracker.updateOtaEmergencyNumberDatabase();
9753 }
9754 }
9755 } finally {
9756 Binder.restoreCallingIdentity(identity);
9757 }
9758 }
9759
9760 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009761 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009762 enforceActiveEmergencySessionPermission();
9763
9764 final long identity = Binder.clearCallingIdentity();
9765 try {
9766 for (Phone phone: PhoneFactory.getPhones()) {
9767 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9768 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009769 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9770 }
9771 }
9772 } finally {
9773 Binder.restoreCallingIdentity(identity);
9774 }
9775 }
9776
9777 @Override
9778 public void resetOtaEmergencyNumberDbFilePath() {
9779 enforceActiveEmergencySessionPermission();
9780
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
9783 for (Phone phone: PhoneFactory.getPhones()) {
9784 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9785 if (tracker != null) {
9786 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009787 }
9788 }
9789 } finally {
9790 Binder.restoreCallingIdentity(identity);
9791 }
9792 }
9793
9794 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009795 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9796 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9797 Phone phone = getPhone(subId);
9798 if (phone == null) {
9799 return null;
9800 }
9801 final long identity = Binder.clearCallingIdentity();
9802 try {
9803 UiccProfile profile = UiccController.getInstance()
9804 .getUiccProfileForPhone(phone.getPhoneId());
9805 if (profile != null) {
9806 return profile.getCertsFromCarrierPrivilegeAccessRules();
9807 }
9808 } finally {
9809 Binder.restoreCallingIdentity(identity);
9810 }
9811 return null;
9812 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009813
9814 /**
9815 * Enable or disable a modem stack.
9816 */
9817 @Override
9818 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9819 enforceModifyPermission();
9820
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
9823 Phone phone = PhoneFactory.getPhone(slotIndex);
9824 if (phone == null) {
9825 return false;
9826 } else {
9827 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9828 }
9829 } finally {
9830 Binder.restoreCallingIdentity(identity);
9831 }
9832 }
Michelecea4cf22018-12-21 15:00:11 -08009833
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009834 /**
9835 * Whether a modem stack is enabled or not.
9836 */
9837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009838 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9839 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009840 Phone phone = PhoneFactory.getPhone(slotIndex);
9841 if (phone == null) return false;
9842
9843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009844 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9845 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009846 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9847 }
9848
9849 final long identity = Binder.clearCallingIdentity();
9850 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009851 try {
9852 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9853 } catch (NoSuchElementException ex) {
9854 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9855 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009856 } finally {
9857 Binder.restoreCallingIdentity(identity);
9858 }
9859 }
9860
Michelecea4cf22018-12-21 15:00:11 -08009861 @Override
Michele0ea7d782019-03-19 14:58:42 -07009862 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009863 enforceModifyPermission();
9864
9865 final long identity = Binder.clearCallingIdentity();
9866 try {
9867 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009868 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009869 .commit();
9870 } finally {
9871 Binder.restoreCallingIdentity(identity);
9872 }
9873 }
9874
9875 @Override
Michele0ea7d782019-03-19 14:58:42 -07009876 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009877 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009878 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009879 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9880 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009881 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009882 }
Michelecea4cf22018-12-21 15:00:11 -08009883
9884 final long identity = Binder.clearCallingIdentity();
9885 try {
Michele0ea7d782019-03-19 14:58:42 -07009886 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009887 } finally {
9888 Binder.restoreCallingIdentity(identity);
9889 }
9890 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009891
Michele0ea7d782019-03-19 14:58:42 -07009892 @TelephonyManager.IsMultiSimSupportedResult
9893 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009894 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9895 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9896 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009897 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9898 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009899 }
9900 // Check if the hardware supports multisim functionality. If usage of multisim is not
9901 // supported by the modem, indicate that it is restricted.
9902 PhoneCapability staticCapability =
9903 mPhoneConfigurationManager.getStaticPhoneCapability();
9904 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009905 loge("isMultiSimSupportedInternal: no static configuration available");
9906 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009907 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009908 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009909 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9910 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009911 }
9912 // Check if support of multiple SIMs is restricted by carrier
9913 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009914 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009915 }
9916
Michele0ea7d782019-03-19 14:58:42 -07009917 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009918 }
9919
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009920 /**
9921 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009922 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9923 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9924 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009925 * @param numOfSims number of active sims we want to switch to
9926 */
9927 @Override
9928 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009929 if (numOfSims == 1) {
9930 enforceModifyPermission();
9931 } else {
9932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9933 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9934 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009935 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009936
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009937 try {
Michele30b57b22019-03-01 12:01:14 -08009938 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009939 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009940 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9941 return;
9942 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009943 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 }
9948
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009949 @Override
9950 public boolean isApplicationOnUicc(int subId, int appType) {
9951 enforceReadPrivilegedPermission("isApplicationOnUicc");
9952 Phone phone = getPhone(subId);
9953 if (phone == null) {
9954 return false;
9955 }
9956 final long identity = Binder.clearCallingIdentity();
9957 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009958 UiccPort uiccPort = phone.getUiccPort();
9959 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009960 return false;
9961 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009962 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009963 if (uiccProfile == null) {
9964 return false;
9965 }
9966 if (TelephonyManager.APPTYPE_SIM <= appType
9967 && appType <= TelephonyManager.APPTYPE_ISIM) {
9968 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9969 }
9970 return false;
9971 } finally {
9972 Binder.restoreCallingIdentity(identity);
9973 }
9974 }
9975
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009976 /**
chen xub4baa772019-04-03 10:23:41 -07009977 * Get whether making changes to modem configurations will trigger reboot.
9978 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009979 */
9980 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009981 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9982 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009984 mApp, subId, callingPackage, callingFeatureId,
9985 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009986 return false;
9987 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009988 final long identity = Binder.clearCallingIdentity();
9989 try {
9990 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9991 } finally {
9992 Binder.restoreCallingIdentity(identity);
9993 }
9994 }
9995
Nathan Harold29f5f052019-02-15 13:41:57 -08009996 private void updateModemStateMetrics() {
9997 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9998 // TODO: check the state for each modem if the api is ready.
9999 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10000 }
10001
Pengquan Meng3889a572019-01-23 11:16:29 -080010002 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010003 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010004 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010005 // Verify that the callingPackage belongs to the calling UID
10006 mApp.getSystemService(AppOpsManager.class)
10007 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010008 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010009 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010010 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010011 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10012 if (slotInfos != null) {
10013 for (int i = 0; i < slotInfos.length; i++) {
10014 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10015 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10016 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10017 portInfo.getLogicalSlotIndex()));
10018 }
10019 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010020 }
10021 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010022 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010023 } finally {
10024 Binder.restoreCallingIdentity(identity);
10025 }
10026 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010027
10028 /**
10029 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010030 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010031 */
jimsunf9ec1622022-09-13 21:18:43 +080010032 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010033 @Override
10034 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010035 return getHalVersion(HAL_SERVICE_RADIO);
10036 }
10037
10038 /**
10039 * Get the HAL Version of a specific service
10040 */
10041 @Override
10042 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010043 Phone phone = getDefaultPhone();
10044 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010045 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010046 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10047 return hv.major * 100 + hv.minor;
10048 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010049
10050 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010051 * Get the current calling package name.
10052 * @return the current calling package name
10053 */
10054 @Override
10055 public String getCurrentPackageName() {
10056 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10057 }
10058
10059 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010060 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10061 * corresponding network requests on a subId.
10062 *
10063 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010064 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010065 * 2) APN is un-metered for this subscription, or
10066 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010067 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010068 *
10069 * @return whether data is allowed for a apn type.
10070 *
10071 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010072 */
10073 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010074 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010075 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10076 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010077
10078 // Now that all security checks passes, perform the operation as ourselves.
10079 final long identity = Binder.clearCallingIdentity();
10080 try {
10081 Phone phone = getPhone(subId);
10082 if (phone == null) return false;
10083
Jack Yu27422a52022-03-21 10:38:05 -070010084 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010085 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010086 isMetered = phone.getDataNetworkController().getDataConfigManager()
10087 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10088 phone.getServiceState().getDataRoaming());
10089 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010090 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010091 } finally {
10092 Binder.restoreCallingIdentity(identity);
10093 }
10094 }
10095
10096 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010097 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010098 enforceReadPrivilegedPermission("isApnMetered");
10099
10100 // Now that all security checks passes, perform the operation as ourselves.
10101 final long identity = Binder.clearCallingIdentity();
10102 try {
10103 Phone phone = getPhone(subId);
10104 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010105 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10106 DataUtils.apnTypeToNetworkCapability(apnType),
10107 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010108 } finally {
10109 Binder.restoreCallingIdentity(identity);
10110 }
10111 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010112
10113 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010114 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10115 int subscriptionId, IBooleanConsumer resultCallback) {
10116 enforceModifyPermission();
10117 long token = Binder.clearCallingIdentity();
10118 try {
10119 Phone phone = getPhone(subscriptionId);
10120 if (phone == null) {
10121 try {
10122 if (resultCallback != null) {
10123 resultCallback.accept(false);
10124 }
10125 } catch (RemoteException e) {
10126 // ignore
10127 }
10128 return;
10129 }
10130 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10131 Pair.create(specifiers, (x) -> {
10132 try {
10133 if (resultCallback != null) {
10134 resultCallback.accept(x);
10135 }
10136 } catch (RemoteException e) {
10137 // ignore
10138 }
10139 });
10140 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10141 } finally {
10142 Binder.restoreCallingIdentity(token);
10143 }
10144 }
10145
10146 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010147 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10148 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010149 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010150 mApp, subId, "getSystemSelectionChannels");
10151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10152 final long identity = Binder.clearCallingIdentity();
10153 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010154 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10155 if (result instanceof IllegalStateException) {
10156 throw (IllegalStateException) result;
10157 }
10158 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010159 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10160 return specifiers;
10161 } finally {
10162 Binder.restoreCallingIdentity(identity);
10163 }
10164 }
10165
10166 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010167 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010168 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010169 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010170 }
10171
10172 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010173 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10174 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010175 if (callingPackage == null) {
10176 callingPackage = getCurrentPackageName();
10177 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010178 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10179 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010180 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10181 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010182 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10183 }
10184 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10185 Intent intent = new Intent();
10186 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10187 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10188 // Bring up choose default SMS subscription dialog right now
10189 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10190 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10191 mApp.startActivity(intent);
10192 }
chen xud5ca2d52019-05-28 15:20:57 -070010193
10194 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010195 public void showSwitchToManagedProfileDialog() {
10196 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010197 try {
10198 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10199 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10200 // for work telephony.
10201 Intent intent = new Intent(Intent.ACTION_SENDTO);
10202 intent.setData(Uri.parse("smsto:"));
10203 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10204 mApp.startActivity(intent);
10205 } catch (ActivityNotFoundException e) {
10206 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10207 Intent intent = new Intent();
10208 intent.setClass(mApp, ErrorDialogActivity.class);
10209 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10210 mApp.startActivity(intent);
10211 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010212 }
10213
10214 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010215 public String getMmsUAProfUrl(int subId) {
10216 //TODO investigate if this API should require proper permission check in R b/133791609
10217 final long identity = Binder.clearCallingIdentity();
10218 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010219 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10220 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10221 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10222 return carrierUAProfUrl;
10223 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010224 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10225 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010226 } finally {
10227 Binder.restoreCallingIdentity(identity);
10228 }
10229 }
10230
10231 @Override
10232 public String getMmsUserAgent(int subId) {
10233 //TODO investigate if this API should require proper permission check in R b/133791609
10234 final long identity = Binder.clearCallingIdentity();
10235 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010236 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10237 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10238 if (!TextUtils.isEmpty(carrierUserAgent)) {
10239 return carrierUserAgent;
10240 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010241 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10242 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010243 } finally {
10244 Binder.restoreCallingIdentity(identity);
10245 }
10246 }
Jack Yub07d4972019-05-28 16:12:25 -070010247
10248 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010249 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10250 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010251
Jack Yub07d4972019-05-28 16:12:25 -070010252 final long identity = Binder.clearCallingIdentity();
10253 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010254 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010255 if (phone == null) return false;
10256
Ling Maf188d502022-09-16 15:22:36 -070010257 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010258 } finally {
10259 Binder.restoreCallingIdentity(identity);
10260 }
10261 }
10262
10263 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010264 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010265 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010266 enforceModifyPermission();
10267
changbettyd5c246e2019-12-24 15:40:37 +080010268 final long identity = Binder.clearCallingIdentity();
10269 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010270 Phone phone = getPhone(subscriptionId);
10271 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010272
Ling Maf188d502022-09-16 15:22:36 -070010273 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010274 } finally {
10275 Binder.restoreCallingIdentity(identity);
10276 }
10277 }
10278
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010279 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010280 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010281 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10282 * otherwise.
10283 */
10284 @Override
10285 public void setCepEnabled(boolean isCepEnabled) {
10286 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10287
10288 final long identity = Binder.clearCallingIdentity();
10289 try {
10290 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10291 for (Phone phone : PhoneFactory.getPhones()) {
10292 Phone defaultPhone = phone.getImsPhone();
10293 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10294 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10295 ImsPhoneCallTracker imsPhoneCallTracker =
10296 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10297 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10298 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10299 + imsPhone.getMsisdn());
10300 }
10301 }
10302 } finally {
10303 Binder.restoreCallingIdentity(identity);
10304 }
10305 }
allenwtsu46dcc572020-01-08 18:24:03 +080010306
10307 /**
10308 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10309 *
10310 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10311 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10312 * before being read.
10313 */
10314 @Override
10315 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10316 isCompressed) {
10317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10318 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010319 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10320 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10321 }
10322 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010323 // ProvisioningManager can not handle ServiceSpecificException.
10324 // Throw the IllegalStateException and annotate ProvisioningManager.
10325 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010326 }
10327
10328 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010329 try {
Hui Wang761a6682020-10-31 05:12:53 +000010330 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10331 } finally {
10332 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010333 }
10334 }
zoey chene02881a2019-12-30 16:11:23 +080010335
10336 @Override
10337 public boolean isIccLockEnabled(int subId) {
10338 enforceReadPrivilegedPermission("isIccLockEnabled");
10339
10340 // Now that all security checks passes, perform the operation as ourselves.
10341 final long identity = Binder.clearCallingIdentity();
10342 try {
10343 Phone phone = getPhone(subId);
10344 if (phone != null && phone.getIccCard() != null) {
10345 return phone.getIccCard().getIccLockEnabled();
10346 } else {
10347 return false;
10348 }
10349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
10354 /**
10355 * Set the ICC pin lock enabled or disabled.
10356 *
10357 * @return an integer representing the status of IccLock enabled or disabled in the following
10358 * three cases:
10359 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10360 * successfully.
10361 * - Positive number and zero for remaining password attempts.
10362 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10363 *
10364 */
10365 @Override
10366 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10367 enforceModifyPermission();
10368
10369 Phone phone = getPhone(subId);
10370 if (phone == null) {
10371 return 0;
10372 }
10373 // Now that all security checks passes, perform the operation as ourselves.
10374 final long identity = Binder.clearCallingIdentity();
10375 try {
10376 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10377 new Pair<Boolean, String>(enabled, password), phone, null);
10378 return attemptsRemaining;
10379
10380 } catch (Exception e) {
10381 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 return 0;
10386 }
10387
10388 /**
10389 * Change the ICC password used in ICC pin lock.
10390 *
10391 * @return an integer representing the status of IccLock changed in the following three cases:
10392 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10393 * - Positive number and zero for remaining password attempts.
10394 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10395 *
10396 */
10397 @Override
10398 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10399 enforceModifyPermission();
10400
10401 Phone phone = getPhone(subId);
10402 if (phone == null) {
10403 return 0;
10404 }
10405 // Now that all security checks passes, perform the operation as ourselves.
10406 final long identity = Binder.clearCallingIdentity();
10407 try {
10408 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10409 new Pair<String, String>(oldPassword, newPassword), phone, null);
10410 return attemptsRemaining;
10411
10412 } catch (Exception e) {
10413 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10414 } finally {
10415 Binder.restoreCallingIdentity(identity);
10416 }
10417 return 0;
10418 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010419
10420 /**
10421 * Request for receiving user activity notification
10422 */
10423 @Override
10424 public void requestUserActivityNotification() {
10425 if (!mNotifyUserActivity.get()
10426 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10427 mNotifyUserActivity.set(true);
10428 }
10429 }
10430
10431 /**
10432 * Called when userActivity is signalled in the power manager.
10433 * This is safe to call from any thread, with any window manager locks held or not.
10434 */
10435 @Override
10436 public void userActivity() {
10437 // ***************************************
10438 // * Inherited from PhoneWindowManager *
10439 // ***************************************
10440 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10441 // WITH ITS LOCKS HELD.
10442 //
10443 // This code must be VERY careful about the locks
10444 // it acquires.
10445 // In fact, the current code acquires way too many,
10446 // and probably has lurking deadlocks.
10447
10448 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10449 throw new SecurityException("Only the OS may call notifyUserActivity()");
10450 }
10451
10452 if (mNotifyUserActivity.getAndSet(false)) {
10453 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10454 USER_ACTIVITY_NOTIFICATION_DELAY);
10455 }
10456 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010457
10458 @Override
10459 public boolean canConnectTo5GInDsdsMode() {
10460 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10461 }
Jack Yud10cdd42020-09-28 20:28:01 -070010462
10463 @Override
10464 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10465 String callingFeatureId) {
10466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10467 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10468 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10469 }
10470
10471 Phone phone = getPhone(subId);
10472 if (phone == null) {
10473 throw new RuntimeException("phone is not available");
10474 }
10475 // Now that all security checks passes, perform the operation as ourselves.
10476 final long identity = Binder.clearCallingIdentity();
10477 try {
10478 return phone.getEquivalentHomePlmns();
10479 } finally {
10480 Binder.restoreCallingIdentity(identity);
10481 }
10482 }
Daniel Bright59e67312020-11-13 11:49:37 -080010483
10484 @Override
10485 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010486 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10487 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010488 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010489 if (radioInterfaceCapabilities == null) {
10490 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010491 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010492 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010493 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010494
Hui Wang641e81c2020-10-12 12:14:23 -070010495 @Override
10496 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10497 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010498 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10499 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10500 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10501 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10502 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010503 if (DBG) {
10504 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10505 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10506 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10507 }
10508
10509 if (!SubscriptionManager.isValidSubscriptionId(subId)
10510 || appType < TelephonyManager.APPTYPE_UNKNOWN
10511 || appType > TelephonyManager.APPTYPE_ISIM
10512 || nafUrl == null || securityProtocol == null || callback == null) {
10513 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10514 if (callback != null) {
10515 try {
10516 callback.onAuthenticationFailure(
10517 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10518 } catch (RemoteException exception) {
10519 log("Fail to notify onAuthenticationFailure due to " + exception);
10520 }
10521 return;
10522 }
10523 }
10524
10525 final long token = Binder.clearCallingIdentity();
10526 try {
10527 getGbaManager(subId).bootstrapAuthenticationRequest(
10528 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010529 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010530 } finally {
10531 Binder.restoreCallingIdentity(token);
10532 }
10533 }
10534
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010535 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010536 * Attempts to set the radio power state for all phones for thermal reason.
10537 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010538 * requested radio power state will actually be set. See {@link
10539 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10540 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010541 * @param enable {@code true} if trying to turn radio on.
10542 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10543 * false}.
10544 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010545 private boolean setRadioPowerForThermal(boolean enable) {
10546 boolean isPhoneAvailable = false;
10547 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10548 Phone phone = PhoneFactory.getPhone(i);
10549 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010550 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010551 isPhoneAvailable = true;
10552 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010553 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010554
10555 // return true if successfully informed the phone object about the thermal radio power
10556 // request.
10557 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010558 }
10559
10560 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010561 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010562 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10563 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10564 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10565 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10566 throw new IllegalArgumentException("modem does not support data throttling");
10567 }
10568
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010569 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10570 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010571 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010572 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10573 }
10574
Sarah Chinecc78c42022-03-31 21:16:48 -070010575 setDataEnabledForReason(
10576 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010577
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010578 if (isDataThrottlingSupported) {
10579 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010580 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010581 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10582 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10583 } else if (thermalMitigationResult
10584 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010585 log("Modem likely does not support data throttling on secondary carrier. Data " +
10586 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10587 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010588 }
10589 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010590 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010591
10592 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010593 }
10594
Jack Nudelman644b91a2021-03-12 14:09:48 -080010595 private static List<String> getThermalMitigationAllowlist(Context context) {
10596 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10597 for (String pckg : context.getResources()
10598 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10599 sThermalMitigationAllowlistedPackages.add(pckg);
10600 }
10601 }
10602
10603 return sThermalMitigationAllowlistedPackages;
10604 }
10605
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010606 private boolean isAnyPhoneInEmergencyState() {
10607 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10608 if (tm.isInEmergencyCall()) {
10609 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10610 return true;
10611 }
10612 for (Phone phone : PhoneFactory.getPhones()) {
10613 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10614 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010615 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10616 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010617 return true;
10618 }
10619 }
10620
10621 return false;
10622 }
10623
Jack Nudelman644b91a2021-03-12 14:09:48 -080010624 /**
10625 * Used by shell commands to add an authorized package name for thermal mitigation.
10626 * @param packageName name of package to be allowlisted
10627 * @param context
10628 */
10629 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10630 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10631 sThermalMitigationAllowlistedPackages.add(packageName);
10632 }
10633
10634 /**
10635 * Used by shell commands to remove an authorized package name for thermal mitigation.
10636 * @param packageName name of package to remove from allowlist
10637 * @param context
10638 */
10639 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10640 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10641 sThermalMitigationAllowlistedPackages.remove(packageName);
10642 }
10643
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010644 /**
10645 * Thermal mitigation request to control functionalities at modem.
10646 *
10647 * @param subId the id of the subscription.
10648 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010649 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010650 *
10651 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10652 */
10653 @Override
10654 @ThermalMitigationResult
10655 public int sendThermalMitigationRequest(
10656 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010657 ThermalMitigationRequest thermalMitigationRequest,
10658 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010659 enforceModifyPermission();
10660
Jack Nudelman644b91a2021-03-12 14:09:48 -080010661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10662 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10663 .contains(callingPackage)) {
10664 throw new SecurityException("Calling package must be configured in the device config. "
10665 + "calling package: " + callingPackage);
10666 }
10667
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010668 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10669 final long identity = Binder.clearCallingIdentity();
10670
10671 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10672 try {
10673 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10674 switch (thermalMitigationAction) {
10675 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10676 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010677 handleDataThrottlingRequest(subId,
10678 thermalMitigationRequest.getDataThrottlingRequest(),
10679 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010680 break;
10681 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10682 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10683 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10684 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10685 }
10686
10687 // Ensure that radio is on. If not able to power on due to phone being
10688 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010689 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010690 thermalMitigationResult =
10691 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10692 break;
10693 }
10694
10695 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010696 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010697 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10698 break;
10699 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10700 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10701 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10702 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10703 }
10704
10705 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10706 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010707 Phone phone = getPhone(subId);
10708 if (phone == null) {
10709 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010710 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010711 break;
10712 }
10713
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010714 TelephonyConnectionService service =
10715 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010716 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010717 Log.e(LOG_TAG, "An emergency call is pending");
10718 thermalMitigationResult =
10719 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10720 break;
10721 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010722 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010723 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010724 break;
10725 }
10726 } else {
10727 thermalMitigationResult =
10728 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10729 break;
10730 }
10731
10732 // Turn radio off. If not able to power off due to phone being unavailable,
10733 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010734 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010735 thermalMitigationResult =
10736 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10737 break;
10738 }
10739 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010740 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010741 break;
10742 default:
10743 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10744 + "not exist. Requested action: " + thermalMitigationAction);
10745 }
10746 } catch (IllegalArgumentException e) {
10747 throw e;
10748 } catch (Exception e) {
10749 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10750 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10751 } finally {
10752 Binder.restoreCallingIdentity(identity);
10753 }
10754
10755 if (DBG) {
10756 log("thermalMitigationRequest returning with thermalMitigationResult: "
10757 + thermalMitigationResult);
10758 }
10759
10760 return thermalMitigationResult;
10761 }
Hui Wang641e81c2020-10-12 12:14:23 -070010762
10763 /**
10764 * Set the GbaService Package Name that Telephony will bind to.
10765 *
10766 * @param subId The sim that the GbaService is associated with.
10767 * @param packageName The name of the package to be replaced with.
10768 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10769 */
10770 @Override
10771 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10772 enforceModifyPermission();
10773
10774 final long identity = Binder.clearCallingIdentity();
10775 try {
10776 return getGbaManager(subId).overrideServicePackage(packageName);
10777 } finally {
10778 Binder.restoreCallingIdentity(identity);
10779 }
10780 }
10781
10782 /**
10783 * Return the package name of the currently bound GbaService.
10784 *
10785 * @param subId The sim that the GbaService is associated with.
10786 * @return the package name of the GbaService configuration, null if GBA is not supported.
10787 */
10788 @Override
10789 public String getBoundGbaService(int subId) {
10790 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10791
10792 final long identity = Binder.clearCallingIdentity();
10793 try {
10794 return getGbaManager(subId).getServicePackage();
10795 } finally {
10796 Binder.restoreCallingIdentity(identity);
10797 }
10798 }
10799
10800 /**
10801 * Set the release time for telephony to unbind GbaService.
10802 *
10803 * @param subId The sim that the GbaService is associated with.
10804 * @param interval The release time to unbind GbaService by millisecond.
10805 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10806 */
10807 @Override
10808 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10809 enforceModifyPermission();
10810
10811 final long identity = Binder.clearCallingIdentity();
10812 try {
10813 return getGbaManager(subId).overrideReleaseTime(interval);
10814 } finally {
10815 Binder.restoreCallingIdentity(identity);
10816 }
10817 }
10818
10819 /**
10820 * Return the release time for telephony to unbind GbaService.
10821 *
10822 * @param subId The sim that the GbaService is associated with.
10823 * @return The release time to unbind GbaService by millisecond.
10824 */
10825 @Override
10826 public int getGbaReleaseTime(int subId) {
10827 enforceReadPrivilegedPermission("getGbaReleaseTime");
10828
10829 final long identity = Binder.clearCallingIdentity();
10830 try {
10831 return getGbaManager(subId).getReleaseTime();
10832 } finally {
10833 Binder.restoreCallingIdentity(identity);
10834 }
10835 }
10836
10837 private GbaManager getGbaManager(int subId) {
10838 GbaManager instance = GbaManager.getInstance(subId);
10839 if (instance == null) {
10840 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10841 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10842 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10843 }
10844 return instance;
10845 }
Hui Wang761a6682020-10-31 05:12:53 +000010846
10847 /**
10848 * indicate whether the device and the carrier can support
10849 * RCS VoLTE single registration.
10850 */
10851 @Override
10852 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010853 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10854 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10855 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10856 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010857
10858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10859 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10860 }
10861
10862 final long identity = Binder.clearCallingIdentity();
10863 try {
10864 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10865 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010866 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10867 if (isCapable != null) {
10868 return isCapable;
10869 }
Hui Wang761a6682020-10-31 05:12:53 +000010870 }
Hui Wang67af90e2021-06-04 16:57:15 -070010871 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10872 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
10877
10878 /**
10879 * Register RCS provisioning callback.
10880 */
10881 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010882 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010883 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010884 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010885 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010886 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10887 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010888
10889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10890 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10891 }
10892 if (!isImsAvailableOnDevice()) {
10893 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10894 "IMS not available on device.");
10895 }
10896
10897 final long identity = Binder.clearCallingIdentity();
10898 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010899 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010900 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010901 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10902 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010903 }
Hui Wang761a6682020-10-31 05:12:53 +000010904 } finally {
10905 Binder.restoreCallingIdentity(identity);
10906 }
10907 }
10908
10909 /**
10910 * Unregister RCS provisioning callback.
10911 */
10912 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010913 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010914 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010915 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010916 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010917 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10918 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010919
10920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10921 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10922 }
10923 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010924 // operation failed silently
10925 Rlog.w(LOG_TAG, "IMS not available on device.");
10926 return;
Hui Wang761a6682020-10-31 05:12:53 +000010927 }
10928
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010931 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010932 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010933 } finally {
10934 Binder.restoreCallingIdentity(identity);
10935 }
10936 }
10937
10938 /**
10939 * trigger RCS reconfiguration.
10940 */
10941 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010942 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10943 "triggerRcsReconfiguration",
10944 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010945
10946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10947 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10948 }
10949 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010950 // ProvisioningManager can not handle ServiceSpecificException.
10951 // Throw the IllegalStateException and annotate ProvisioningManager.
10952 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010953 }
10954
10955 final long identity = Binder.clearCallingIdentity();
10956 try {
10957 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
10963 /**
10964 * Provide the client configuration parameters of the RCS application.
10965 */
10966 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010967 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10968 "setRcsClientConfiguration",
10969 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010970
10971 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10972 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10973 }
10974 if (!isImsAvailableOnDevice()) {
10975 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10976 "IMS not available on device.");
10977 }
10978
10979 final long identity = Binder.clearCallingIdentity();
10980
10981 try {
10982 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10983 if (configBinder == null) {
10984 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010985 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10986 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010987 } else {
10988 configBinder.setRcsClientConfiguration(rcc);
10989 }
joonhunshin3e154242021-09-17 06:33:39 +000010990
10991 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10992 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010993 } catch (RemoteException e) {
10994 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010995 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10996 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010997 } finally {
10998 Binder.restoreCallingIdentity(identity);
10999 }
11000 }
11001
11002 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011003 * Enables or disables the test mode for RCS VoLTE single registration.
11004 */
11005 @Override
11006 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11007 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11008 "setRcsSingleRegistrationTestModeEnabled");
11009
11010 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11011 }
11012
11013 /**
11014 * Gets the test mode for RCS VoLTE single registration.
11015 */
11016 @Override
11017 public boolean getRcsSingleRegistrationTestModeEnabled() {
11018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11019 "getRcsSingleRegistrationTestModeEnabled");
11020
11021 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11022 }
11023
11024 /**
Hui Wang761a6682020-10-31 05:12:53 +000011025 * Overrides the config of RCS VoLTE single registration enabled for the device.
11026 */
11027 @Override
11028 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11029 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11030 "setDeviceSingleRegistrationEnabledOverride");
11031 enforceModifyPermission();
11032
11033 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11034 : Boolean.parseBoolean(enabledStr);
11035 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011036 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011037 }
11038
11039 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011040 * Sends a device to device communication message. Only usable via shell.
11041 * @param message message to send.
11042 * @param value message value.
11043 */
11044 @Override
11045 public void sendDeviceToDeviceMessage(int message, int value) {
11046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011047 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011048 enforceModifyPermission();
11049
11050 final long identity = Binder.clearCallingIdentity();
11051 try {
11052 TelephonyConnectionService service =
11053 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11054 if (service == null) {
11055 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11056 return;
11057 }
11058 service.sendTestDeviceToDeviceMessage(message, value);
11059 } finally {
11060 Binder.restoreCallingIdentity(identity);
11061 }
11062 }
11063
Tyler Gunnbabbda02021-02-10 11:05:02 -080011064 /**
11065 * Sets the specified device to device transport active.
11066 * @param transport The transport to set active.
11067 */
11068 @Override
11069 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11071 "setActiveDeviceToDeviceTransport");
11072 enforceModifyPermission();
11073
11074 final long identity = Binder.clearCallingIdentity();
11075 try {
11076 TelephonyConnectionService service =
11077 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11078 if (service == null) {
11079 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11080 return;
11081 }
11082 service.setActiveDeviceToDeviceTransport(transport);
11083 } finally {
11084 Binder.restoreCallingIdentity(identity);
11085 }
11086 }
Tyler Gunn92479152021-01-20 16:30:10 -080011087
Tyler Gunnd4339262021-05-03 14:46:49 -070011088 @Override
11089 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11091 "setDeviceToDeviceForceEnabled");
11092
11093 final long identity = Binder.clearCallingIdentity();
11094 try {
11095 Arrays.stream(PhoneFactory.getPhones()).forEach(
11096 p -> {
11097 Phone thePhone = p.getImsPhone();
11098 if (thePhone != null && thePhone instanceof ImsPhone) {
11099 ImsPhone imsPhone = (ImsPhone) thePhone;
11100 CallTracker tracker = imsPhone.getCallTracker();
11101 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11102 ImsPhoneCallTracker imsPhoneCallTracker =
11103 (ImsPhoneCallTracker) tracker;
11104 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11105 }
11106 }
11107 }
11108 );
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
11113
Tyler Gunn92479152021-01-20 16:30:10 -080011114 /**
Hui Wang761a6682020-10-31 05:12:53 +000011115 * Gets the config of RCS VoLTE single registration enabled for the device.
11116 */
11117 @Override
11118 public boolean getDeviceSingleRegistrationEnabled() {
11119 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11120 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11121 }
11122
11123 /**
11124 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11125 */
11126 @Override
11127 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11128 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11129 "setCarrierSingleRegistrationEnabledOverride");
11130 enforceModifyPermission();
11131
11132 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11133 : Boolean.parseBoolean(enabledStr);
11134 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11135 subId, enabled);
11136 }
11137
11138 /**
11139 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11140 */
11141 @Override
11142 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11143 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11144 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11145 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011146
11147 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011148 * Overrides the ims feature validation result
11149 */
11150 @Override
11151 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11153 "setImsFeatureValidationOverride");
11154
11155 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11156 : Boolean.parseBoolean(enabledStr);
11157 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11158 subId, enabled);
11159 }
11160
11161 /**
11162 * Gets the ims feature validation override value
11163 */
11164 @Override
11165 public boolean getImsFeatureValidationOverride(int subId) {
11166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11167 "getImsFeatureValidationOverride");
11168 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11169 }
11170
11171 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011172 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11173 * their mobile plan.
11174 */
11175 @Override
11176 public String getMobileProvisioningUrl() {
11177 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11178 final long identity = Binder.clearCallingIdentity();
11179 try {
11180 return getDefaultPhone().getMobileProvisioningUrl();
11181 } finally {
11182 Binder.restoreCallingIdentity(identity);
11183 }
11184 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011185
James.cf Linbcdf8b32021-01-14 16:44:13 +080011186 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011187 * Get the EAB contact from the EAB database.
11188 */
11189 @Override
11190 public String getContactFromEab(String contact) {
11191 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11192 enforceModifyPermission();
11193 final long identity = Binder.clearCallingIdentity();
11194 try {
11195 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 }
11200
11201 /**
Calvin Pana1434322021-07-01 19:27:01 +080011202 * Get the EAB capability from the EAB database.
11203 */
11204 @Override
11205 public String getCapabilityFromEab(String contact) {
11206 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11207 enforceModifyPermission();
11208 final long identity = Binder.clearCallingIdentity();
11209 try {
11210 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11211 } finally {
11212 Binder.restoreCallingIdentity(identity);
11213 }
11214 }
11215
11216 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011217 * Remove the EAB contacts from the EAB database.
11218 */
11219 @Override
11220 public int removeContactFromEab(int subId, String contacts) {
11221 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11222 enforceModifyPermission();
11223 final long identity = Binder.clearCallingIdentity();
11224 try {
11225 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11226 } finally {
11227 Binder.restoreCallingIdentity(identity);
11228 }
11229 }
11230
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011231 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011232 public boolean getDeviceUceEnabled() {
11233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11234 final long identity = Binder.clearCallingIdentity();
11235 try {
11236 return mApp.getDeviceUceEnabled();
11237 } finally {
11238 Binder.restoreCallingIdentity(identity);
11239 }
11240 }
11241
11242 @Override
11243 public void setDeviceUceEnabled(boolean isEnabled) {
11244 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11245 final long identity = Binder.clearCallingIdentity();
11246 try {
11247 mApp.setDeviceUceEnabled(isEnabled);
11248 } finally {
11249 Binder.restoreCallingIdentity(identity);
11250 }
11251 }
11252
Brad Ebinger14d467f2021-02-12 06:18:28 +000011253 /**
11254 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11255 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11256 */
11257 // Used for SHELL command only right now.
11258 @Override
11259 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11260 List<String> featureTags) {
11261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11262 "addUceRegistrationOverrideShell");
11263 final long identity = Binder.clearCallingIdentity();
11264 try {
11265 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11266 new ArraySet<>(featureTags));
11267 } catch (ImsException e) {
11268 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11269 } finally {
11270 Binder.restoreCallingIdentity(identity);
11271 }
11272 }
11273
11274 /**
11275 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11276 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11277 */
11278 // Used for SHELL command only right now.
11279 @Override
11280 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11281 List<String> featureTags) {
11282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11283 "removeUceRegistrationOverrideShell");
11284 final long identity = Binder.clearCallingIdentity();
11285 try {
11286 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11287 new ArraySet<>(featureTags));
11288 } catch (ImsException e) {
11289 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11290 } finally {
11291 Binder.restoreCallingIdentity(identity);
11292 }
11293 }
11294
11295 /**
11296 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11297 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11298 */
11299 // Used for SHELL command only right now.
11300 @Override
11301 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11302 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11303 "clearUceRegistrationOverrideShell");
11304 final long identity = Binder.clearCallingIdentity();
11305 try {
11306 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11307 } catch (ImsException e) {
11308 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11309 } finally {
11310 Binder.restoreCallingIdentity(identity);
11311 }
11312 }
11313
11314 /**
11315 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11316 */
11317 // Used for SHELL command only right now.
11318 @Override
11319 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11320 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11321 "getLatestRcsContactUceCapabilityShell");
11322 final long identity = Binder.clearCallingIdentity();
11323 try {
11324 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11325 } catch (ImsException e) {
11326 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11327 } finally {
11328 Binder.restoreCallingIdentity(identity);
11329 }
11330 }
11331
11332 /**
11333 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11334 * device does not have an active PUBLISH.
11335 */
11336 // Used for SHELL command only right now.
11337 @Override
11338 public String getLastUcePidfXmlShell(int subId) {
11339 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11340 final long identity = Binder.clearCallingIdentity();
11341 try {
11342 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11343 } catch (ImsException e) {
11344 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11345 } finally {
11346 Binder.restoreCallingIdentity(identity);
11347 }
11348 }
11349
James.cf Line8713a42021-04-29 16:04:26 +080011350 /**
11351 * Remove UCE requests cannot be sent to the network status.
11352 */
11353 // Used for SHELL command only right now.
11354 @Override
11355 public boolean removeUceRequestDisallowedStatus(int subId) {
11356 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11357 final long identity = Binder.clearCallingIdentity();
11358 try {
11359 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11360 } catch (ImsException e) {
11361 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11362 } finally {
11363 Binder.restoreCallingIdentity(identity);
11364 }
11365 }
11366
James.cf Lin18bb9002021-05-25 01:37:38 +080011367 /**
11368 * Remove UCE requests cannot be sent to the network status.
11369 */
11370 // Used for SHELL command only.
11371 @Override
11372 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11373 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11374 final long identity = Binder.clearCallingIdentity();
11375 try {
11376 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11377 } catch (ImsException e) {
11378 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11379 } finally {
11380 Binder.restoreCallingIdentity(identity);
11381 }
11382 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011383
James.cf Lin4b784aa2021-01-31 03:25:15 +080011384 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011385 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11386 String callingPackage) {
11387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11388 mApp, subId, "setSignalStrengthUpdateRequest");
11389
11390 final int callingUid = Binder.getCallingUid();
11391 // Verify that tha callingPackage belongs to the calling UID
11392 mApp.getSystemService(AppOpsManager.class)
11393 .checkPackage(callingUid, callingPackage);
11394
Rambo Wang3607f502021-02-01 21:51:40 -080011395 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011396
11397 final long identity = Binder.clearCallingIdentity();
11398 try {
11399 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11400 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11401
11402 if (result instanceof IllegalStateException) {
11403 throw (IllegalStateException) result;
11404 }
11405 } finally {
11406 Binder.restoreCallingIdentity(identity);
11407 }
11408 }
11409
11410 @Override
11411 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11412 String callingPackage) {
11413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11414 mApp, subId, "clearSignalStrengthUpdateRequest");
11415
11416 final int callingUid = Binder.getCallingUid();
11417 // Verify that tha callingPackage belongs to the calling UID
11418 mApp.getSystemService(AppOpsManager.class)
11419 .checkPackage(callingUid, callingPackage);
11420
11421 final long identity = Binder.clearCallingIdentity();
11422 try {
11423 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11424 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11425
11426 if (result instanceof IllegalStateException) {
11427 throw (IllegalStateException) result;
11428 }
11429 } finally {
11430 Binder.restoreCallingIdentity(identity);
11431 }
11432 }
11433
Rambo Wang3607f502021-02-01 21:51:40 -080011434 private static void validateSignalStrengthUpdateRequest(Context context,
11435 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011436 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11437 // phone/system process do not have further restriction on request
11438 return;
11439 }
11440
11441 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011442 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011443 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011444 context.enforceCallingOrSelfPermission(
11445 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11446 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011447 }
11448
11449 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011450 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011451 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011452 || info.isEnabled()) {
11453 throw new IllegalArgumentException(
11454 "Only system can set hide fields in SignalThresholdInfo");
11455 }
11456
11457 // Thresholds length for each RAN need in range. This has been validated in
11458 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11459 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11460 final int[] thresholds = info.getThresholds();
11461 Objects.requireNonNull(thresholds);
11462 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11463 || thresholds.length
11464 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11465 throw new IllegalArgumentException(
11466 "thresholds length is out of range: " + thresholds.length);
11467 }
11468 }
11469 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011470
11471 /**
11472 * Gets the current phone capability.
11473 *
11474 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11475 * @return the PhoneCapability which describes the data connection capability of modem.
11476 * It's used to evaluate possible phone config change, for example from single
11477 * SIM device to multi-SIM device.
11478 */
11479 @Override
11480 public PhoneCapability getPhoneCapability() {
11481 enforceReadPrivilegedPermission("getPhoneCapability");
11482 final long identity = Binder.clearCallingIdentity();
11483 try {
11484 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11485 } finally {
11486 Binder.restoreCallingIdentity(identity);
11487 }
11488 }
Michele Berionne5e411512020-11-13 02:36:59 +000011489
11490 /**
11491 * Prepare TelephonyManager for an unattended reboot. The reboot is
11492 * required to be done shortly after the API is invoked.
11493 */
11494 @Override
11495 @TelephonyManager.PrepareUnattendedRebootResult
11496 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011497 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011498 enforceRebootPermission();
11499
11500 final long identity = Binder.clearCallingIdentity();
11501 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011502 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011503 } finally {
11504 Binder.restoreCallingIdentity(identity);
11505 }
11506 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011507
11508 /**
11509 * Request to get the current slicing configuration including URSP rules and
11510 * NSSAIs (configured, allowed and rejected).
11511 *
11512 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11513 */
11514 @Override
11515 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011516 TelephonyPermissions
11517 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11518 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011519
11520 final long identity = Binder.clearCallingIdentity();
11521 try {
11522 Phone phone = getDefaultPhone();
11523 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11524 } finally {
11525 Binder.restoreCallingIdentity(identity);
11526 }
11527 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011528
11529 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011530 * Check whether the given premium capability is available for purchase from the carrier.
11531 *
11532 * @param capability The premium capability to check.
11533 * @param subId The subId to check the premium capability for.
11534 *
11535 * @return Whether the given premium capability is available to purchase.
11536 */
11537 @Override
11538 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11539 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11540 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11541 log("Premium capability "
11542 + TelephonyManager.convertPremiumCapabilityToString(capability)
11543 + " is not available for purchase due to missing permissions.");
11544 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11545 + "permission READ_BASIC_PHONE_STATE.");
11546 }
11547
11548 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011549 if (phone == null) {
11550 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11551 return false;
11552 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011553 final long identity = Binder.clearCallingIdentity();
11554 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070011555 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011556 .isPremiumCapabilityAvailableForPurchase(capability);
11557 } finally {
11558 Binder.restoreCallingIdentity(identity);
11559 }
11560 }
11561
11562 /**
11563 * Purchase the given premium capability from the carrier.
11564 *
11565 * @param capability The premium capability to purchase.
11566 * @param callback The result of the purchase request.
11567 * @param subId The subId to purchase the premium capability for.
11568 */
11569 @Override
11570 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11571 log("purchasePremiumCapability: capability="
11572 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11573 + getCurrentPackageName());
11574
11575 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11576 mApp, "purchasePremiumCapability")) {
11577 log("purchasePremiumCapability "
11578 + TelephonyManager.convertPremiumCapabilityToString(capability)
11579 + " failed due to missing permissions.");
11580 throw new SecurityException("purchasePremiumCapability requires permission "
11581 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011582 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11583 mApp, "purchasePremiumCapability")) {
11584 log("purchasePremiumCapability "
11585 + TelephonyManager.convertPremiumCapabilityToString(capability)
11586 + " failed due to missing permissions.");
11587 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011588 }
11589
11590 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011591 if (phone == null) {
11592 try {
11593 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11594 callback.accept(result);
11595 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11596 } catch (RemoteException e) {
11597 String logStr = "Purchase premium capability "
11598 + TelephonyManager.convertPremiumCapabilityToString(capability)
11599 + " failed due to RemoteException handling null phone: " + e;
11600 if (DBG) log(logStr);
11601 AnomalyReporter.reportAnomaly(
11602 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11603 }
11604 return;
11605 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011606
11607 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011608 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011609 callingProcess = mApp.getPackageManager().getApplicationInfo(
11610 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011611 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011612 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011613 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011614
11615 boolean isVisible = false;
11616 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11617 if (am != null) {
11618 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11619 if (processes != null) {
11620 for (ActivityManager.RunningAppProcessInfo process : processes) {
11621 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070011622 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080011623 if (process.processName.equals(callingProcess) && process.importance
11624 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11625 isVisible = true;
11626 break;
11627 }
11628 }
11629 }
11630 }
11631
11632 if (!isVisible) {
11633 try {
11634 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11635 callback.accept(result);
11636 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11637 } catch (RemoteException e) {
11638 String logStr = "Purchase premium capability "
11639 + TelephonyManager.convertPremiumCapabilityToString(capability)
11640 + " failed due to RemoteException handling background application: " + e;
11641 if (DBG) log(logStr);
11642 AnomalyReporter.reportAnomaly(
11643 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11644 }
11645 return;
11646 }
11647
Sarah Chin71b3a852022-09-28 15:54:19 -070011648 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011649 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011650 }
11651
11652 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011653 * Register an IMS connection state callback
11654 */
11655 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011656 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11657 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011658 if (feature == ImsFeature.FEATURE_MMTEL) {
11659 // ImsMmTelManager
11660 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11661 TelephonyPermissions
11662 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11663 mApp, subId, "registerImsStateCallback");
11664 } else if (feature == ImsFeature.FEATURE_RCS) {
11665 // ImsRcsManager or SipDelegateManager
11666 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11667 Binder.getCallingUid(), "registerImsStateCallback",
11668 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11669 Manifest.permission.READ_PRECISE_PHONE_STATE,
11670 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11671 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11672 }
11673
11674 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11675 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11676 "IMS not available on device.");
11677 }
11678
11679 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11680 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11681 }
11682
11683 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11684 if (controller == null) {
11685 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11686 "IMS not available on device.");
11687 }
11688
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011689 if (callingPackage == null) {
11690 callingPackage = getCurrentPackageName();
11691 }
11692
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011693 final long token = Binder.clearCallingIdentity();
11694 try {
11695 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011696 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011697 } catch (ImsException e) {
11698 throw new ServiceSpecificException(e.getCode());
11699 } finally {
11700 Binder.restoreCallingIdentity(token);
11701 }
11702 }
11703
11704 /**
11705 * Unregister an IMS connection state callback
11706 */
11707 @Override
11708 public void unregisterImsStateCallback(IImsStateCallback cb) {
11709 final long token = Binder.clearCallingIdentity();
11710 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11711 if (controller == null) {
11712 return;
11713 }
11714 try {
11715 controller.unregisterImsStateCallback(cb);
11716 } finally {
11717 Binder.restoreCallingIdentity(token);
11718 }
11719 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011720
11721 /**
11722 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11723 *
11724 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11725 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11726 * SecurityException.
11727 * If there is current registered network this value will be same as the registered cell
11728 * identity. If the device goes out of service the previous cell identity is cached and
11729 * will be returned. If the cache age of the Cell identity is more than 24 hours
11730 * it will be cleared and null will be returned.
11731 *
11732 */
11733 @Override
11734 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11735 String callingFeatureId) {
11736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11737 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11738 LocationAccessPolicy.checkLocationPermission(mApp,
11739 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11740 .setCallingPackage(callingPackage)
11741 .setCallingFeatureId(callingFeatureId)
11742 .setCallingPid(Binder.getCallingPid())
11743 .setCallingUid(Binder.getCallingUid())
11744 .setMethod("getLastKnownCellIdentity")
11745 .setLogAsInfo(true)
11746 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11747 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11748 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11749 .build());
11750
11751 boolean hasFinePermission =
11752 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11753 if (!hasFinePermission
11754 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11755 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011756 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011757 }
11758
11759 final long identity = Binder.clearCallingIdentity();
11760 try {
Ling Mac28f0212023-03-24 16:07:15 -070011761 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011762 if (sst == null) return null;
11763 return sst.getLastKnownCellIdentity();
11764 } finally {
11765 Binder.restoreCallingIdentity(identity);
11766 }
11767 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011768
jimsun3b9ccac2021-10-26 15:01:23 +080011769 /**
11770 * Sets the modem service class Name that Telephony will bind to.
11771 *
11772 * @param serviceName The class name of the modem service.
11773 * @return true if the operation is succeed, otherwise false.
11774 */
11775 public boolean setModemService(String serviceName) {
11776 Log.d(LOG_TAG, "setModemService - " + serviceName);
11777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011779 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11780 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011781 return mPhoneConfigurationManager.setModemService(serviceName);
11782 }
11783
11784 /**
11785 * Return the class name of the currently bounded modem service.
11786 *
11787 * @return the class name of the modem service.
11788 */
11789 public String getModemService() {
11790 String result;
11791 Log.d(LOG_TAG, "getModemService");
11792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11793 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011794 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011795 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11796 "getModemService");
11797 result = mPhoneConfigurationManager.getModemService();
11798 Log.d(LOG_TAG, "result = " + result);
11799 return result;
11800 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011801
11802 @Override
11803 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11804 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11805 mApp.enforceCallingOrSelfPermission(
11806 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11808
11809 final long identity = Binder.clearCallingIdentity();
11810 try {
11811 Phone phone = getPhone(subId);
11812 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011813 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11814 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011815 phone.setVoiceServiceStateOverride(hasService);
11816 } finally {
11817 Binder.restoreCallingIdentity(identity);
11818 }
11819 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011820
11821 /**
11822 * set removable eSIM as default eUICC.
11823 *
11824 * @hide
11825 */
11826 @Override
11827 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11828 enforceModifyPermission();
11829 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11830
11831 final long identity = Binder.clearCallingIdentity();
11832 try {
11833 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11834 } finally {
11835 Binder.restoreCallingIdentity(identity);
11836 }
11837 }
11838
11839 /**
11840 * Returns whether the removable eSIM is default eUICC or not.
11841 *
11842 * @hide
11843 */
11844 @Override
11845 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11846 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11847 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11848
11849 final long identity = Binder.clearCallingIdentity();
11850 try {
11851 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11852 } finally {
11853 Binder.restoreCallingIdentity(identity);
11854 }
11855 }
11856
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011857 /**
11858 * Get the component name of the default app to direct respond-via-message intent for the
11859 * user associated with this subscription, update the cache if there is no respond-via-message
11860 * application currently configured for this user.
11861 * @return component name of the app and class to direct Respond Via Message intent to, or
11862 * {@code null} if the functionality is not supported.
11863 * @hide
11864 */
11865 @Override
11866 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11867 boolean updateIfNeeded) {
11868 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011869
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011870 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11871
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011872 UserHandle userHandle = null;
11873 final long identity = Binder.clearCallingIdentity();
11874 try {
11875 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11876 } finally {
11877 Binder.restoreCallingIdentity(identity);
11878 }
11879 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11880 updateIfNeeded, userHandle);
11881 }
Jack Yuf5badd92022-12-08 00:50:53 -080011882
11883 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011884 * Set whether the device is able to connect with null ciphering or integrity
11885 * algorithms. This is a global setting and will apply to all active subscriptions
11886 * and all new subscriptions after this.
11887 *
11888 * @param enabled when true, null cipher and integrity algorithms are allowed.
11889 * @hide
11890 */
11891 @Override
11892 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11893 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11894 enforceModifyPermission();
11895 checkForNullCipherAndIntegritySupport();
11896
11897 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11898 // for listening to these preference changes and applying them immediately.
11899 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11900 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11901 editor.apply();
11902
11903 for (Phone phone: PhoneFactory.getPhones()) {
11904 phone.handleNullCipherEnabledChange();
11905 }
11906 }
11907
11908
11909 /**
11910 * Get whether the device is able to connect with null ciphering or integrity
11911 * algorithms. Note that this retrieves the phone-global preference and not
11912 * the state of the radio.
11913 *
11914 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11915 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11916 * version for this feature.
11917 * @hide
11918 */
11919 @Override
11920 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11921 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11922 enforceReadPermission();
11923 checkForNullCipherAndIntegritySupport();
11924 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11925 }
11926
11927 private void checkForNullCipherAndIntegritySupport() {
11928 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11929 throw new UnsupportedOperationException(
11930 "Null cipher and integrity operations require HAL 2.1 or above");
11931 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011932 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11933 throw new UnsupportedOperationException(
11934 "Null cipher and integrity operations unsupported by modem");
11935 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011936 }
11937
11938 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011939 * Get the SIM state for the slot index.
11940 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11941 *
11942 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11943 */
11944 @Override
11945 @SimState
11946 public int getSimStateForSlotIndex(int slotIndex) {
11947 IccCardConstants.State simState;
11948 if (slotIndex < 0) {
11949 simState = IccCardConstants.State.UNKNOWN;
11950 } else {
11951 Phone phone = null;
11952 try {
11953 phone = PhoneFactory.getPhone(slotIndex);
11954 } catch (IllegalStateException e) {
11955 // ignore
11956 }
11957 if (phone == null) {
11958 simState = IccCardConstants.State.UNKNOWN;
11959 } else {
11960 IccCard icc = phone.getIccCard();
11961 if (icc == null) {
11962 simState = IccCardConstants.State.UNKNOWN;
11963 } else {
11964 simState = icc.getState();
11965 }
11966 }
11967 }
11968 return simState.ordinal();
11969 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011970
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011971 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
11972 boolean enableLogcat,
11973 long logcatStartTimestampMillis, boolean enableTelecomDump,
11974 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080011975 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
11976 TelephonyManager.EmergencyCallDiagnosticParams edp =
11977 new TelephonyManager.EmergencyCallDiagnosticParams();
11978 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
11979 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
11980 edp.setTelecomDumpSysCollection(enableTelecomDump);
11981 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
11982 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
11983 Executors.newCachedThreadPool(), db,
11984 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
11985 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080011986 }
11987
11988 /**
11989 * Request telephony to persist state for debugging emergency call failures.
11990 *
11991 * @param dropBoxTag Tag to use when persisting data to dropbox service.
11992 * @param enableLogcat whether to collect logcat output
11993 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
11994 * @param enableTelecomDump whether to collect telecom dumpsys
11995 * @param enableTelephonyDump whether to collect telephony dumpsys
11996 */
11997 @Override
11998 @RequiresPermission(android.Manifest.permission.DUMP)
11999 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12000 long logcatStartTimestampMillis, boolean enableTelecomDump,
12001 boolean enableTelephonyDump) {
12002 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12003 "persistEmergencyCallDiagnosticData");
12004 final long identity = Binder.clearCallingIdentity();
12005 try {
12006 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12007 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12008
12009 } finally {
12010 Binder.restoreCallingIdentity(identity);
12011 }
12012 }
12013
Hui Wang9b5793a2022-12-05 14:38:06 -060012014 /**
12015 * Get current cell broadcast ranges.
12016 */
12017 @Override
12018 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12019 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12020 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12021 "getCellBroadcastIdRanges");
12022 final long identity = Binder.clearCallingIdentity();
12023 try {
12024 return getPhone(subId).getCellBroadcastIdRanges();
12025 } finally {
12026 Binder.restoreCallingIdentity(identity);
12027 }
12028 }
12029
12030 /**
12031 * Set reception of cell broadcast messages with the list of the given ranges
12032 *
12033 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12034 */
12035 @Override
12036 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12037 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12038 @Nullable IIntegerConsumer callback) {
12039 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12040 "setCellBroadcastIdRanges");
12041 final long identity = Binder.clearCallingIdentity();
12042 try {
12043 Phone phone = getPhoneFromSubId(subId);
12044 if (DBG) {
12045 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12046 }
12047 phone.setCellBroadcastIdRanges(ranges, result -> {
12048 if (callback != null) {
12049 try {
12050 callback.accept(result);
12051 } catch (RemoteException e) {
12052 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12053 }
12054 }
12055 });
12056 } finally {
12057 Binder.restoreCallingIdentity(identity);
12058 }
12059 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012060
12061 /**
12062 * Returns whether the device supports the domain selection service.
12063 *
12064 * @return {@code true} if the device supports the domain selection service.
12065 */
12066 @Override
12067 public boolean isDomainSelectionSupported() {
12068 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12069 "isDomainSelectionSupported");
12070
12071 final long identity = Binder.clearCallingIdentity();
12072 try {
12073 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12074 } finally {
12075 Binder.restoreCallingIdentity(identity);
12076 }
12077 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012078
12079 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012080 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12081 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12082 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012083 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012084 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012085 * @param enableSatellite {@code true} to enable the satellite modem and
12086 * {@code false} to disable.
12087 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12088 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012089 *
12090 * @throws SecurityException if the caller doesn't have the required permission.
12091 */
12092 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012093 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12094 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012095 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012096 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12097 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012098 }
12099
12100 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012101 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012102 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012103 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012104 * @param result The result receiver that returns whether the satellite modem is enabled
12105 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012106 *
12107 * @throws SecurityException if the caller doesn't have the required permission.
12108 */
12109 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012110 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12111 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012112 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012113 }
12114
12115 /**
Sarah Chin43457982023-02-15 17:50:38 -080012116 * Request to get whether the satellite service demo mode is enabled.
12117 *
12118 * @param subId The subId of the subscription to check whether the satellite demo mode
12119 * is enabled for.
12120 * @param result The result receiver that returns whether the satellite demo mode is enabled
12121 * if the request is successful or an error code if the request failed.
12122 *
12123 * @throws SecurityException if the caller doesn't have the required permission.
12124 */
12125 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012126 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12127 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12128 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012129 }
12130
12131 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012132 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012133 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012134 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012135 * @param result The result receiver that returns whether the satellite service is supported on
12136 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012137 */
12138 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012139 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012140 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012141 }
12142
12143 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012144 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012145 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012146 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012147 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12148 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012149 *
12150 * @throws SecurityException if the caller doesn't have required permission.
12151 */
12152 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012153 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12154 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012155 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012156 }
12157
12158 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012159 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012160 * This can be called by the pointing UI when the user starts pointing to the satellite.
12161 * Modem should continue to report the pointing input as the device or satellite moves.
12162 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012163 * @param subId The subId of the subscription to start satellite transmission updates for.
12164 * @param resultCallback The callback to get the result of the request.
12165 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012166 *
12167 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012168 */
12169 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012170 public void startSatelliteTransmissionUpdates(int subId,
12171 @NonNull IIntegerConsumer resultCallback,
12172 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12173 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12174 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012175 }
12176
12177 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012178 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012179 * This can be called by the pointing UI when the user stops pointing to the satellite.
12180 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012181 * @param subId The subId of the subscription to stop satellite transmission updates for.
12182 * @param resultCallback The callback to get the result of the request.
12183 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12184 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012185 *
12186 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012187 */
12188 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012189 public void stopSatelliteTransmissionUpdates(int subId,
12190 @NonNull IIntegerConsumer resultCallback,
12191 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12192 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12193 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012194 }
12195
12196 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012197 * Register the subscription with a satellite provider.
12198 * This is needed to register the subscription if the provider allows dynamic registration.
12199 *
12200 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012201 * @param token The token to be used as a unique identifier for provisioning with satellite
12202 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012203 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012204 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012205 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012206 * @return The signal transport used by the caller to cancel the provision request,
12207 * or {@code null} if the request failed.
12208 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012209 * @throws SecurityException if the caller doesn't have the required permission.
12210 */
12211 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012212 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012213 @NonNull String token, @NonNull byte[] provisionData,
12214 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012215 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012216 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12217 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012218 }
12219
12220 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012221 * Unregister the device/subscription with the satellite provider.
12222 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012223 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012224 * should report as deprovisioned.
12225 *
12226 * @param subId The subId of the subscription to be deprovisioned.
12227 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012228 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012229 *
12230 * @throws SecurityException if the caller doesn't have the required permission.
12231 */
12232 @Override
12233 public void deprovisionSatelliteService(int subId,
12234 @NonNull String token, @NonNull IIntegerConsumer callback) {
12235 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012236 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012237 }
12238
12239 /**
Sarah Chin43457982023-02-15 17:50:38 -080012240 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012241 *
Sarah Chin43457982023-02-15 17:50:38 -080012242 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012243 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012244 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012245 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012246 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012247 * @throws SecurityException if the caller doesn't have the required permission.
12248 */
12249 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012250 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
12251 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012252 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012253 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012254 }
12255
12256 /**
Sarah Chin43457982023-02-15 17:50:38 -080012257 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012258 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012259 *
Sarah Chin43457982023-02-15 17:50:38 -080012260 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012261 * @param callback The callback that was passed to
12262 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012263 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012264 * @throws SecurityException if the caller doesn't have the required permission.
12265 */
12266 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012267 public void unregisterForSatelliteProvisionStateChanged(
12268 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012269 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012270 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012271 }
12272
12273 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012274 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012275 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012276 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012277 * @param result The result receiver that returns whether the device is provisioned with a
12278 * satellite provider if the request is successful or an error code if the
12279 * request failed.
12280 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012281 * @throws SecurityException if the caller doesn't have the required permission.
12282 */
12283 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012284 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12285 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012286 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012287 }
12288
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012289 /**
Sarah Chin43457982023-02-15 17:50:38 -080012290 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012291 *
Sarah Chin43457982023-02-15 17:50:38 -080012292 * @param subId The subId of the subscription to register for satellite modem state changed.
12293 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012294 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012295 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012296 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012297 * @throws SecurityException if the caller doesn't have the required permission.
12298 */
12299 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012300 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012301 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012302 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012303 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012304 }
12305
12306 /**
Sarah Chin43457982023-02-15 17:50:38 -080012307 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012308 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012309 *
Sarah Chin43457982023-02-15 17:50:38 -080012310 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012311 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012312 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012313 *
12314 * @throws SecurityException if the caller doesn't have the required permission.
12315 */
12316 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012317 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012318 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012319 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012320 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012321 }
12322
12323 /**
12324 * Register to receive incoming datagrams over satellite.
12325 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012326 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012327 * @param callback The callback to handle incoming datagrams over satellite.
12328 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012329 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080012330 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012331 * @throws SecurityException if the caller doesn't have the required permission.
12332 */
12333 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012334 @SatelliteManager.SatelliteResult public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012335 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012336 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012337 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012338 }
12339
12340 /**
12341 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012342 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012343 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012344 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12345 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012346 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012347 *
12348 * @throws SecurityException if the caller doesn't have the required permission.
12349 */
12350 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012351 public void unregisterForSatelliteDatagram(int subId,
12352 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012353 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012354 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012355 }
12356
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012357 /**
12358 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012359 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012360 * This method requests modem to check if there are any pending datagrams to be received over
12361 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000012362 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012363 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012364 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012365 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012366 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012367 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012368 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012369 @Override
12370 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012371 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012372 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012373 }
12374
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012375 /**
12376 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012377 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012378 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12379 * input to this method. Datagram received here will be passed down to modem without any
12380 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012381 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012382 * @param subId The subId of the subscription to send satellite datagrams for.
12383 * @param datagramType datagram type indicating whether the datagram is of type
12384 * SOS_SMS or LOCATION_SHARING.
12385 * @param datagram encoded gateway datagram which is encrypted by the caller.
12386 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012387 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12388 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000012389 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012390 *
12391 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012392 */
12393 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012394 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12395 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12396 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012397 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012398 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12399 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012400 }
12401
Sarah Chindf715ec2023-02-13 13:46:24 -080012402 /**
12403 * Request to get whether satellite communication is allowed for the current location.
12404 *
12405 * @param subId The subId of the subscription to check whether satellite communication is
12406 * allowed for the current location for.
12407 * @param result The result receiver that returns whether satellite communication is allowed
12408 * for the current location if the request is successful or an error code
12409 * if the request failed.
12410 *
12411 * @throws SecurityException if the caller doesn't have the required permission.
12412 */
12413 @Override
12414 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12415 @NonNull ResultReceiver result) {
12416 enforceSatelliteCommunicationPermission(
12417 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012418 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12419 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012420 }
12421
12422 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012423 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080012424 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012425 * @param subId The subId to get the time after which the satellite will be visible for.
12426 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012427 * be visible if the request is successful or an error code if the request failed.
12428 *
12429 * @throws SecurityException if the caller doesn't have the required permission.
12430 */
12431 @Override
12432 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12433 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012434 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012435 }
12436
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012437 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012438 * Inform that Device is aligned to satellite for demo mode.
12439 *
12440 * @param subId The subId to get the time after which the satellite will be visible for.
12441 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
12442 * {@code false} Device fails to align with the satellite for demo mode.
12443 *
12444 * @throws SecurityException if the caller doesn't have required permission.
12445 */
12446 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
12447
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012448 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000012449 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000012450 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000012451 }
12452
12453 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000012454 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
12455 * by modem.
12456 *
12457 * @param subId The subId of the subscription to request for.
12458 * @param reason Reason for disallowing satellite communication for carrier.
12459 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12460 * operation.
12461 *
12462 * @throws SecurityException if the caller doesn't have required permission.
12463 */
12464 public void addSatelliteAttachRestrictionForCarrier(int subId,
12465 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12466 @NonNull IIntegerConsumer callback) {
12467 enforceSatelliteCommunicationPermission("addSatelliteAttachRestrictionForCarrier");
12468 final long identity = Binder.clearCallingIdentity();
12469 try {
12470 mSatelliteController.addSatelliteAttachRestrictionForCarrier(subId, reason, callback);
12471 } finally {
12472 Binder.restoreCallingIdentity(identity);
12473 }
12474 }
12475
12476 /**
12477 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
12478 * by modem.
12479 *
12480 * @param subId The subId of the subscription to request for.
12481 * @param reason Reason for disallowing satellite communication.
12482 * @param callback Listener for the {@link SatelliteManager.SatelliteError} result of the
12483 * operation.
12484 *
12485 * @throws SecurityException if the caller doesn't have required permission.
12486 */
12487 public void removeSatelliteAttachRestrictionForCarrier(int subId,
12488 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
12489 @NonNull IIntegerConsumer callback) {
12490 enforceSatelliteCommunicationPermission("removeSatelliteAttachRestrictionForCarrier");
12491 final long identity = Binder.clearCallingIdentity();
12492 try {
12493 mSatelliteController.removeSatelliteAttachRestrictionForCarrier(subId, reason,
12494 callback);
12495 } finally {
12496 Binder.restoreCallingIdentity(identity);
12497 }
12498 }
12499
12500 /**
12501 * Get reasons for disallowing satellite communication, as requested by
12502 * {@link #addSatelliteAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
12503 *
12504 * @param subId The subId of the subscription to request for.
12505 *
12506 * @return Integer array of reasons for disallowing satellite communication.
12507 *
12508 * @throws SecurityException if the caller doesn't have the required permission.
12509 */
12510 public @NonNull int[] getSatelliteAttachRestrictionReasonsForCarrier(
12511 int subId) {
12512 enforceSatelliteCommunicationPermission("getSatelliteAttachRestrictionReasonsForCarrier");
12513 final long identity = Binder.clearCallingIdentity();
12514 try {
12515 Set<Integer> reasonSet =
12516 mSatelliteController.getSatelliteAttachRestrictionReasonsForCarrier(subId);
12517 return reasonSet.stream().mapToInt(i->i).toArray();
12518 } finally {
12519 Binder.restoreCallingIdentity(identity);
12520 }
12521 }
12522
12523 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000012524 * Request to get the signal strength of the satellite connection.
12525 *
12526 * @param subId The subId of the subscription to request for.
12527 * @param result Result receiver to get the error code of the request and the current signal
12528 * strength of the satellite connection.
12529 *
12530 * @throws SecurityException if the caller doesn't have required permission.
12531 */
12532 @Override
12533 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
12534 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
12535 final long identity = Binder.clearCallingIdentity();
12536 try {
12537 mSatelliteController.requestNtnSignalStrength(subId, result);
12538 } finally {
12539 Binder.restoreCallingIdentity(identity);
12540 }
12541 }
12542
12543 /**
12544 * Registers for NTN signal strength changed from satellite modem.
12545 *
12546 * @param subId The subId of the subscription to request for.
12547 * @param callback The callback to handle the NTN signal strength changed event.
12548 *
12549 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
12550 *
12551 * @throws SecurityException if the caller doesn't have the required permission.
12552 */
12553 @Override
12554 @SatelliteManager.SatelliteResult public int registerForNtnSignalStrengthChanged(
12555 int subId, @NonNull INtnSignalStrengthCallback callback) {
12556 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
12557 final long identity = Binder.clearCallingIdentity();
12558 try {
12559 return mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
12560 } finally {
12561 Binder.restoreCallingIdentity(identity);
12562 }
12563 }
12564
12565 /**
12566 * Unregisters for NTN signal strength changed from satellite modem.
12567 * If callback was not registered before, the request will be ignored.
12568 *
12569 * @param subId The subId of the subscription to unregister for provision state changed.
12570 * @param callback The callback that was passed to
12571 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
12572 *
12573 * @throws SecurityException if the caller doesn't have the required permission.
12574 */
12575 @Override
12576 public void unregisterForNtnSignalStrengthChanged(
12577 int subId, @NonNull INtnSignalStrengthCallback callback) {
12578 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
12579 final long identity = Binder.clearCallingIdentity();
12580 try {
12581 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
12582 } finally {
12583 Binder.restoreCallingIdentity(identity);
12584 }
12585 }
12586
12587 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070012588 * This API can be used by only CTS to update satellite vendor service package name.
12589 *
12590 * @param servicePackageName The package name of the satellite vendor service.
12591 * @return {@code true} if the satellite vendor service is set successfully,
12592 * {@code false} otherwise.
12593 */
12594 public boolean setSatelliteServicePackageName(String servicePackageName) {
12595 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
12596 TelephonyPermissions.enforceShellOnly(
12597 Binder.getCallingUid(), "setSatelliteServicePackageName");
12598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12599 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12600 "setSatelliteServicePackageName");
12601 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
12602 }
12603
12604 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070012605 * This API can be used by only CTS to update satellite gateway service package name.
12606 *
12607 * @param servicePackageName The package name of the satellite gateway service.
12608 * @return {@code true} if the satellite gateway service is set successfully,
12609 * {@code false} otherwise.
12610 */
12611 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
12612 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
12613 TelephonyPermissions.enforceShellOnly(
12614 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
12615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12616 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12617 "setSatelliteGatewayServicePackageName");
12618 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
12619 }
12620
12621 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070012622 * This API can be used by only CTS to update satellite pointing UI app package and class names.
12623 *
12624 * @param packageName The package name of the satellite pointing UI app.
12625 * @param className The class name of the satellite pointing UI app.
12626 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
12627 * {@code false} otherwise.
12628 */
12629 public boolean setSatellitePointingUiClassName(
12630 @Nullable String packageName, @Nullable String className) {
12631 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
12632 + ", className=" + className);
12633 TelephonyPermissions.enforceShellOnly(
12634 Binder.getCallingUid(), "setSatellitePointingUiClassName");
12635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12636 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12637 "setSatelliteGatewayServicePackageName");
12638 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
12639 }
12640
12641 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070012642 * This API can be used by only CTS to update the timeout duration in milliseconds that
12643 * satellite should stay at listening mode to wait for the next incoming page before disabling
12644 * listening mode.
12645 *
12646 * @param timeoutMillis The timeout duration in millisecond.
12647 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12648 */
12649 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
12650 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
12651 TelephonyPermissions.enforceShellOnly(
12652 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
12653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12654 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12655 "setSatelliteListeningTimeoutDuration");
12656 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
12657 }
12658
12659 /**
Hakjun Choiae365972023-04-25 11:00:31 +000012660 * This API can be used by only CTS to update the timeout duration in milliseconds whether
12661 * the device is aligned with the satellite for demo mode
12662 *
12663 * @param timeoutMillis The timeout duration in millisecond.
12664 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
12665 */
12666 public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
12667 Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
12668 TelephonyPermissions.enforceShellOnly(
12669 Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
12670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12671 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12672 "setDeviceAlignedTimeoutDuration");
12673 return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
12674 }
12675
12676 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070012677 * This API can be used in only testing to override connectivity status in monitoring emergency
12678 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
12679 *
12680 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
12681 * of the following values to enable the override:
12682 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
12683 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
12684 * To disable the override, use -1 for handoverType.
12685 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
12686 * delaySeconds after the emergency call starts.
12687 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
12688 */
12689 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
12690 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
12691 TelephonyPermissions.enforceShellOnly(
12692 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
12693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12694 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12695 "setEmergencyCallToSatelliteHandoverType");
12696 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
12697 handoverType, delaySeconds);
12698 }
12699
12700 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000012701 * This API can be used by only CTS to override the cached value for the device overlay config
12702 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
12703 * outgoing satellite datagrams should be sent to modem in demo mode.
12704 *
12705 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
12706 * satellite modem or not.
12707 *
12708 * @return {@code true} if the operation is successful, {@code false} otherwise.
12709 */
12710 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
12711 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
12712 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
12713 + "disabled");
12714 return false;
12715 }
12716 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
12717 TelephonyPermissions.enforceShellOnly(
12718 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
12719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
12720 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12721 "setShouldSendDatagramToModemInDemoMode");
12722 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
12723 shouldSendToModemInDemoMode);
12724 }
12725
12726 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012727 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12728 *
12729 * <p>This method behaves in one of the following ways:
12730 * <ul>
12731 * <li>return true : if the calling package has the appop permission {@link
12732 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12733 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12734 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12735 * Owner device identifier access check, or the calling package has carrier privileges</>
12736 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12737 * </ul>
12738 */
12739 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12740 String callingPackage, @Nullable String callingFeatureId, String message) {
12741 for (Phone phone : PhoneFactory.getPhones()) {
12742 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12743 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12744 return true;
12745 }
12746 }
12747 return false;
12748 }
arunvoddud7401012022-12-15 16:08:12 +000012749
12750 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012751 * @return The subscription manager service instance.
12752 */
12753 public SubscriptionManagerService getSubscriptionManagerService() {
12754 return SubscriptionManagerService.getInstance();
12755 }
12756
12757 /**
arunvoddud7401012022-12-15 16:08:12 +000012758 * Class binds the consumer[callback] and carrierId.
12759 */
12760 private static class CallerCallbackInfo {
12761 private final Consumer<Integer> mConsumer;
12762 private final int mCarrierId;
12763
12764 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12765 mConsumer = consumer;
12766 mCarrierId = carrierId;
12767 }
12768
12769 public Consumer<Integer> getConsumer() {
12770 return mConsumer;
12771 }
12772
12773 public int getCarrierId() {
12774 return mCarrierId;
12775 }
12776 }
Jack Yufa8ed012023-02-11 15:42:28 -080012777}